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