1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/indexedDB/ipc/test_ipc.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,182 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<head> 1.7 + <title>Test for OOP IndexedDB</title> 1.8 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.9 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.10 +</head> 1.11 + <body> 1.12 + 1.13 + <script type="application/javascript;version=1.7"> 1.14 + "use strict"; 1.15 + 1.16 + SimpleTest.waitForExplicitFinish(); 1.17 + 1.18 + // This isn't a single test, really... It runs the entirety of the IndexedDB 1.19 + // tests. Each of those has a normal timeout handler, so there's no point in 1.20 + // having a timeout here. I'm setting this really high just to avoid getting 1.21 + // killed. 1.22 + SimpleTest.requestLongerTimeout(100); 1.23 + 1.24 + // Disable crash observers as it breaks later tests. 1.25 + function iframeScriptFirst() { 1.26 + SpecialPowers.prototype.registerProcessCrashObservers = function() { }; 1.27 + SpecialPowers.prototype.unregisterProcessCrashObservers = function() { }; 1.28 + 1.29 + content.wrappedJSObject.RunSet.reloadAndRunAll({ 1.30 + preventDefault: function() { }, 1.31 + __exposedProps__: { preventDefault: 'r' } 1.32 + }); 1.33 + } 1.34 + 1.35 + function iframeScriptSecond() { 1.36 + let isMainProcess = content.wrappedJSObject.SpecialPowers.isMainProcess(); 1.37 + 1.38 + sendAsyncMessage("test:indexedDB:ipcProcessType", 1.39 + { isMainProcess: isMainProcess }); 1.40 + 1.41 + let TestRunner = content.wrappedJSObject.TestRunner; 1.42 + 1.43 + let oldComplete = TestRunner.onComplete; 1.44 + 1.45 + TestRunner.onComplete = function() { 1.46 + TestRunner.onComplete = oldComplete; 1.47 + 1.48 + sendAsyncMessage("test:indexedDB:ipcTestComplete"); 1.49 + 1.50 + if (oldComplete) { 1.51 + oldComplete(); 1.52 + } 1.53 + }; 1.54 + 1.55 + function sendTestMessage(msg) { 1.56 + sendAsyncMessage("test:indexedDB:ipcTestMessage", { msg: msg }); 1.57 + } 1.58 + 1.59 + TestRunner.log = sendTestMessage; 1.60 + TestRunner.error = sendTestMessage; 1.61 + } 1.62 + 1.63 + let regexString = 1.64 + "^(TEST-PASS|TEST-UNEXPECTED-PASS|TEST-KNOWN-FAIL|TEST-UNEXPECTED-FAIL" + 1.65 + "|TEST-DEBUG-INFO|TEST-INFO) \\| ([^\\|]+) \\|(.*)"; 1.66 + 1.67 + let regex = new RegExp(regexString); 1.68 + 1.69 + let seenTestMessage = false; 1.70 + 1.71 + function onTestMessage(data) { 1.72 + seenTestMessage = true; 1.73 + let message = SpecialPowers.wrap(data).data.msg; 1.74 + let match = regex.exec(message); 1.75 + if (match) { 1.76 + let state = match[1]; 1.77 + let details = match[2] + " | " + match[3]; 1.78 + 1.79 + switch (state) { 1.80 + case "TEST-PASS": 1.81 + case "TEST-KNOWN-FAIL": 1.82 + ok(true, details); 1.83 + break; 1.84 + 1.85 + case "TEST-UNEXPECTED-FAIL": 1.86 + case "TEST-UNEXPECTED-PASS": 1.87 + ok(false, details); 1.88 + break; 1.89 + 1.90 + case "TEST-INFO": 1.91 + case "TEST-DEBUG-INFO": 1.92 + default: 1.93 + info(details); 1.94 + } 1.95 + } 1.96 + } 1.97 + 1.98 + let usingChildProcess = false; 1.99 + 1.100 + function onProcessType(data) { 1.101 + let isMainProcess = SpecialPowers.wrap(data).data.isMainProcess; 1.102 + usingChildProcess = !isMainProcess; 1.103 + } 1.104 + 1.105 + function onTestComplete() { 1.106 + is(usingChildProcess, true, "Expecting to run in child process"); 1.107 + is(seenTestMessage, true, "Expecting to receive messages from child"); 1.108 + SpecialPowers.removePermission("browser", window.location.href); 1.109 + SimpleTest.executeSoon(function () { SimpleTest.finish(); }); 1.110 + } 1.111 + 1.112 + function runTests() { 1.113 + let iframe = document.createElement("iframe"); 1.114 + SpecialPowers.wrap(iframe).mozbrowser = true; 1.115 + iframe.id = "iframe"; 1.116 + iframe.style.width = "100%"; 1.117 + iframe.style.height = "1000px"; 1.118 + 1.119 + function iframeLoadSecond() { 1.120 + ok(true, "Got second iframe load event."); 1.121 + iframe.removeEventListener("mozbrowserloadend", iframeLoadSecond); 1.122 + let mm = SpecialPowers.getBrowserFrameMessageManager(iframe); 1.123 + mm.loadFrameScript("data:,(" + iframeScriptSecond.toString() + ")();", 1.124 + false); 1.125 + } 1.126 + 1.127 + function iframeLoadFirst() { 1.128 + ok(true, "Got first iframe load event."); 1.129 + iframe.removeEventListener("mozbrowserloadend", iframeLoadFirst); 1.130 + iframe.addEventListener("mozbrowserloadend", iframeLoadSecond); 1.131 + 1.132 + let mm = SpecialPowers.getBrowserFrameMessageManager(iframe); 1.133 + 1.134 + let comp = SpecialPowers.wrap(SpecialPowers.Components); 1.135 + 1.136 + let spObserver = 1.137 + comp.classes["@mozilla.org/special-powers-observer;1"] 1.138 + .getService(comp.interfaces.nsIMessageListener); 1.139 + 1.140 + mm.addMessageListener("SPPrefService", spObserver); 1.141 + mm.addMessageListener("SPProcessCrashService", spObserver); 1.142 + mm.addMessageListener("SPPingService", spObserver); 1.143 + mm.addMessageListener("SpecialPowers.Quit", spObserver); 1.144 + mm.addMessageListener("SPPermissionManager", spObserver); 1.145 + mm.addMessageListener("SPObserverService", spObserver); 1.146 + 1.147 + mm.addMessageListener("test:indexedDB:ipcTestMessage", onTestMessage); 1.148 + mm.addMessageListener("test:indexedDB:ipcProcessType", onProcessType); 1.149 + mm.addMessageListener("test:indexedDB:ipcTestComplete", onTestComplete); 1.150 + 1.151 + let specialPowersBase = "chrome://specialpowers/content/"; 1.152 + mm.loadFrameScript(specialPowersBase + "MozillaLogger.js", false); 1.153 + mm.loadFrameScript(specialPowersBase + "specialpowersAPI.js", false); 1.154 + mm.loadFrameScript(specialPowersBase + "specialpowers.js", false); 1.155 + 1.156 + mm.loadFrameScript("data:,(" + iframeScriptFirst.toString() + ")();", 1.157 + false); 1.158 + } 1.159 + 1.160 + iframe.addEventListener("mozbrowserloadend", iframeLoadFirst); 1.161 + 1.162 + // Strip this filename and one directory level and then add "/test". 1.163 + let href = window.location.href; 1.164 + href = href.substring(0, href.lastIndexOf('/')); 1.165 + href = href.substring(0, href.lastIndexOf('/')); 1.166 + iframe.src = href + "/test?consoleLevel=INFO"; 1.167 + 1.168 + document.body.appendChild(iframe); 1.169 + } 1.170 + 1.171 + addEventListener("load", function() { 1.172 + SpecialPowers.addPermission("browser", true, document); 1.173 + SpecialPowers.pushPrefEnv({ 1.174 + "set": [ 1.175 + // TODO: remove this as part of bug 820712 1.176 + ["network.disable.ipc.security", true], 1.177 + 1.178 + ["dom.ipc.browser_frames.oop_by_default", true], 1.179 + ["dom.mozBrowserFramesEnabled", true] 1.180 + ] 1.181 + }, runTests); 1.182 + }); 1.183 + </script> 1.184 +</body> 1.185 +</html>