Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <head> |
michael@0 | 4 | <title>Test for OOP IndexedDB</title> |
michael@0 | 5 | <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 6 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
michael@0 | 7 | </head> |
michael@0 | 8 | <body> |
michael@0 | 9 | |
michael@0 | 10 | <script type="application/javascript;version=1.7"> |
michael@0 | 11 | "use strict"; |
michael@0 | 12 | |
michael@0 | 13 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 14 | |
michael@0 | 15 | // This isn't a single test, really... It runs the entirety of the IndexedDB |
michael@0 | 16 | // tests. Each of those has a normal timeout handler, so there's no point in |
michael@0 | 17 | // having a timeout here. I'm setting this really high just to avoid getting |
michael@0 | 18 | // killed. |
michael@0 | 19 | SimpleTest.requestLongerTimeout(100); |
michael@0 | 20 | |
michael@0 | 21 | // Disable crash observers as it breaks later tests. |
michael@0 | 22 | function iframeScriptFirst() { |
michael@0 | 23 | SpecialPowers.prototype.registerProcessCrashObservers = function() { }; |
michael@0 | 24 | SpecialPowers.prototype.unregisterProcessCrashObservers = function() { }; |
michael@0 | 25 | |
michael@0 | 26 | content.wrappedJSObject.RunSet.reloadAndRunAll({ |
michael@0 | 27 | preventDefault: function() { }, |
michael@0 | 28 | __exposedProps__: { preventDefault: 'r' } |
michael@0 | 29 | }); |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | function iframeScriptSecond() { |
michael@0 | 33 | let isMainProcess = content.wrappedJSObject.SpecialPowers.isMainProcess(); |
michael@0 | 34 | |
michael@0 | 35 | sendAsyncMessage("test:indexedDB:ipcProcessType", |
michael@0 | 36 | { isMainProcess: isMainProcess }); |
michael@0 | 37 | |
michael@0 | 38 | let TestRunner = content.wrappedJSObject.TestRunner; |
michael@0 | 39 | |
michael@0 | 40 | let oldComplete = TestRunner.onComplete; |
michael@0 | 41 | |
michael@0 | 42 | TestRunner.onComplete = function() { |
michael@0 | 43 | TestRunner.onComplete = oldComplete; |
michael@0 | 44 | |
michael@0 | 45 | sendAsyncMessage("test:indexedDB:ipcTestComplete"); |
michael@0 | 46 | |
michael@0 | 47 | if (oldComplete) { |
michael@0 | 48 | oldComplete(); |
michael@0 | 49 | } |
michael@0 | 50 | }; |
michael@0 | 51 | |
michael@0 | 52 | function sendTestMessage(msg) { |
michael@0 | 53 | sendAsyncMessage("test:indexedDB:ipcTestMessage", { msg: msg }); |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | TestRunner.log = sendTestMessage; |
michael@0 | 57 | TestRunner.error = sendTestMessage; |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | let regexString = |
michael@0 | 61 | "^(TEST-PASS|TEST-UNEXPECTED-PASS|TEST-KNOWN-FAIL|TEST-UNEXPECTED-FAIL" + |
michael@0 | 62 | "|TEST-DEBUG-INFO|TEST-INFO) \\| ([^\\|]+) \\|(.*)"; |
michael@0 | 63 | |
michael@0 | 64 | let regex = new RegExp(regexString); |
michael@0 | 65 | |
michael@0 | 66 | let seenTestMessage = false; |
michael@0 | 67 | |
michael@0 | 68 | function onTestMessage(data) { |
michael@0 | 69 | seenTestMessage = true; |
michael@0 | 70 | let message = SpecialPowers.wrap(data).data.msg; |
michael@0 | 71 | let match = regex.exec(message); |
michael@0 | 72 | if (match) { |
michael@0 | 73 | let state = match[1]; |
michael@0 | 74 | let details = match[2] + " | " + match[3]; |
michael@0 | 75 | |
michael@0 | 76 | switch (state) { |
michael@0 | 77 | case "TEST-PASS": |
michael@0 | 78 | case "TEST-KNOWN-FAIL": |
michael@0 | 79 | ok(true, details); |
michael@0 | 80 | break; |
michael@0 | 81 | |
michael@0 | 82 | case "TEST-UNEXPECTED-FAIL": |
michael@0 | 83 | case "TEST-UNEXPECTED-PASS": |
michael@0 | 84 | ok(false, details); |
michael@0 | 85 | break; |
michael@0 | 86 | |
michael@0 | 87 | case "TEST-INFO": |
michael@0 | 88 | case "TEST-DEBUG-INFO": |
michael@0 | 89 | default: |
michael@0 | 90 | info(details); |
michael@0 | 91 | } |
michael@0 | 92 | } |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | let usingChildProcess = false; |
michael@0 | 96 | |
michael@0 | 97 | function onProcessType(data) { |
michael@0 | 98 | let isMainProcess = SpecialPowers.wrap(data).data.isMainProcess; |
michael@0 | 99 | usingChildProcess = !isMainProcess; |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | function onTestComplete() { |
michael@0 | 103 | is(usingChildProcess, true, "Expecting to run in child process"); |
michael@0 | 104 | is(seenTestMessage, true, "Expecting to receive messages from child"); |
michael@0 | 105 | SpecialPowers.removePermission("browser", window.location.href); |
michael@0 | 106 | SimpleTest.executeSoon(function () { SimpleTest.finish(); }); |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | function runTests() { |
michael@0 | 110 | let iframe = document.createElement("iframe"); |
michael@0 | 111 | SpecialPowers.wrap(iframe).mozbrowser = true; |
michael@0 | 112 | iframe.id = "iframe"; |
michael@0 | 113 | iframe.style.width = "100%"; |
michael@0 | 114 | iframe.style.height = "1000px"; |
michael@0 | 115 | |
michael@0 | 116 | function iframeLoadSecond() { |
michael@0 | 117 | ok(true, "Got second iframe load event."); |
michael@0 | 118 | iframe.removeEventListener("mozbrowserloadend", iframeLoadSecond); |
michael@0 | 119 | let mm = SpecialPowers.getBrowserFrameMessageManager(iframe); |
michael@0 | 120 | mm.loadFrameScript("data:,(" + iframeScriptSecond.toString() + ")();", |
michael@0 | 121 | false); |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | function iframeLoadFirst() { |
michael@0 | 125 | ok(true, "Got first iframe load event."); |
michael@0 | 126 | iframe.removeEventListener("mozbrowserloadend", iframeLoadFirst); |
michael@0 | 127 | iframe.addEventListener("mozbrowserloadend", iframeLoadSecond); |
michael@0 | 128 | |
michael@0 | 129 | let mm = SpecialPowers.getBrowserFrameMessageManager(iframe); |
michael@0 | 130 | |
michael@0 | 131 | let comp = SpecialPowers.wrap(SpecialPowers.Components); |
michael@0 | 132 | |
michael@0 | 133 | let spObserver = |
michael@0 | 134 | comp.classes["@mozilla.org/special-powers-observer;1"] |
michael@0 | 135 | .getService(comp.interfaces.nsIMessageListener); |
michael@0 | 136 | |
michael@0 | 137 | mm.addMessageListener("SPPrefService", spObserver); |
michael@0 | 138 | mm.addMessageListener("SPProcessCrashService", spObserver); |
michael@0 | 139 | mm.addMessageListener("SPPingService", spObserver); |
michael@0 | 140 | mm.addMessageListener("SpecialPowers.Quit", spObserver); |
michael@0 | 141 | mm.addMessageListener("SPPermissionManager", spObserver); |
michael@0 | 142 | mm.addMessageListener("SPObserverService", spObserver); |
michael@0 | 143 | |
michael@0 | 144 | mm.addMessageListener("test:indexedDB:ipcTestMessage", onTestMessage); |
michael@0 | 145 | mm.addMessageListener("test:indexedDB:ipcProcessType", onProcessType); |
michael@0 | 146 | mm.addMessageListener("test:indexedDB:ipcTestComplete", onTestComplete); |
michael@0 | 147 | |
michael@0 | 148 | let specialPowersBase = "chrome://specialpowers/content/"; |
michael@0 | 149 | mm.loadFrameScript(specialPowersBase + "MozillaLogger.js", false); |
michael@0 | 150 | mm.loadFrameScript(specialPowersBase + "specialpowersAPI.js", false); |
michael@0 | 151 | mm.loadFrameScript(specialPowersBase + "specialpowers.js", false); |
michael@0 | 152 | |
michael@0 | 153 | mm.loadFrameScript("data:,(" + iframeScriptFirst.toString() + ")();", |
michael@0 | 154 | false); |
michael@0 | 155 | } |
michael@0 | 156 | |
michael@0 | 157 | iframe.addEventListener("mozbrowserloadend", iframeLoadFirst); |
michael@0 | 158 | |
michael@0 | 159 | // Strip this filename and one directory level and then add "/test". |
michael@0 | 160 | let href = window.location.href; |
michael@0 | 161 | href = href.substring(0, href.lastIndexOf('/')); |
michael@0 | 162 | href = href.substring(0, href.lastIndexOf('/')); |
michael@0 | 163 | iframe.src = href + "/test?consoleLevel=INFO"; |
michael@0 | 164 | |
michael@0 | 165 | document.body.appendChild(iframe); |
michael@0 | 166 | } |
michael@0 | 167 | |
michael@0 | 168 | addEventListener("load", function() { |
michael@0 | 169 | SpecialPowers.addPermission("browser", true, document); |
michael@0 | 170 | SpecialPowers.pushPrefEnv({ |
michael@0 | 171 | "set": [ |
michael@0 | 172 | // TODO: remove this as part of bug 820712 |
michael@0 | 173 | ["network.disable.ipc.security", true], |
michael@0 | 174 | |
michael@0 | 175 | ["dom.ipc.browser_frames.oop_by_default", true], |
michael@0 | 176 | ["dom.mozBrowserFramesEnabled", true] |
michael@0 | 177 | ] |
michael@0 | 178 | }, runTests); |
michael@0 | 179 | }); |
michael@0 | 180 | </script> |
michael@0 | 181 | </body> |
michael@0 | 182 | </html> |