|
1 function test() { |
|
2 waitForExplicitFinish(); |
|
3 |
|
4 let windowsToClose = []; |
|
5 function testOnWindow(options, callback) { |
|
6 let win = OpenBrowserWindow(options); |
|
7 windowsToClose.push(win); |
|
8 win.addEventListener("load", function onLoad() { |
|
9 win.removeEventListener("load", onLoad, false); |
|
10 win.addEventListener("DOMContentLoaded", function onInnerLoad() { |
|
11 if (win.content.location.href != "about:blank") { |
|
12 win.gBrowser.loadURI("about:blank"); |
|
13 return; |
|
14 } |
|
15 win.removeEventListener("DOMContentLoaded", onInnerLoad, true); |
|
16 executeSoon(function() callback(win)); |
|
17 }, true); |
|
18 if (!options) { |
|
19 win.gBrowser.loadURI("about:blank"); |
|
20 } |
|
21 }, false); |
|
22 } |
|
23 |
|
24 Services.prefs.setIntPref("browser.startup.page", 0); |
|
25 Services.prefs.setCharPref("browser.startup.homepage_override.mstone", "ignore"); |
|
26 |
|
27 registerCleanupFunction(function() { |
|
28 Services.prefs.clearUserPref("browser.startup.page"); |
|
29 Services.prefs.clearUserPref("browser.startup.homepage_override.mstone"); |
|
30 for (var i in windowsToClose) { |
|
31 windowsToClose[i].close(); |
|
32 } |
|
33 }); |
|
34 |
|
35 var phase = 0; |
|
36 function step(data) { |
|
37 switch (++phase) { |
|
38 case 1: |
|
39 is(data, "reply", "should have got reply message"); |
|
40 privWin.postMessage('query?', 'http://mochi.test:8888'); |
|
41 break; |
|
42 case 2: |
|
43 is(data.split(':')[0], "data", "should have got data message"); |
|
44 is(data.split(':')[1], "false", "priv window should not see event"); |
|
45 privWin.postMessage('setKey', 'http://mochi.test:8888'); |
|
46 break; |
|
47 case 3: |
|
48 is(data, "reply", "should have got reply message"); |
|
49 pubWin.postMessage('query?', 'http://mochi.test:8888'); |
|
50 break; |
|
51 case 4: |
|
52 is(data.split(':')[0], "data", "should have got data message"); |
|
53 is(data.split(':')[1], "false", "pub window should not see event"); |
|
54 finish(); |
|
55 break; |
|
56 } |
|
57 } |
|
58 |
|
59 let loads = 0; |
|
60 function waitForLoad() { |
|
61 loads++; |
|
62 if (loads != 2) { |
|
63 return; |
|
64 }; |
|
65 pubWin.postMessage('setKey', 'http://mochi.test:8888'); |
|
66 } |
|
67 |
|
68 var privWin; |
|
69 testOnWindow({private: true}, function(aPrivWin) { |
|
70 let doc = aPrivWin.content.document; |
|
71 let iframe = doc.createElement('iframe'); |
|
72 iframe.setAttribute('id', 'target2'); |
|
73 doc.body.appendChild(iframe); |
|
74 aPrivWin.content.is = is; |
|
75 aPrivWin.content.isnot = isnot; |
|
76 aPrivWin.content.ok = ok; |
|
77 iframe.onload = function() { |
|
78 privWin = iframe.contentWindow; |
|
79 privWin.addEventListener('message', function msgHandler(ev) { |
|
80 if (ev.data == 'setKey' || ev.data == 'query?') |
|
81 return; |
|
82 step(ev.data); |
|
83 }, true); |
|
84 waitForLoad(); |
|
85 }; |
|
86 iframe.src = "http://mochi.test:8888/browser/dom/tests/browser/page_privatestorageevent.html"; |
|
87 }); |
|
88 |
|
89 var pubWin; |
|
90 testOnWindow(undefined, function(aWin) { |
|
91 let doc = aWin.content.document; |
|
92 let iframe = doc.createElement('iframe'); |
|
93 iframe.setAttribute('id', 'target'); |
|
94 doc.body.appendChild(iframe); |
|
95 aWin.content.is = is; |
|
96 aWin.content.isnot = isnot; |
|
97 aWin.content.ok = ok; |
|
98 iframe.onload = function() { |
|
99 pubWin = iframe.contentWindow; |
|
100 pubWin.addEventListener('message', function msgHandler(ev) { |
|
101 if (ev.data == 'setKey' || ev.data == 'query?') |
|
102 return; |
|
103 step(ev.data); |
|
104 }, true); |
|
105 waitForLoad(); |
|
106 }; |
|
107 iframe.src = "http://mochi.test:8888/browser/dom/tests/browser/page_privatestorageevent.html"; |
|
108 }); |
|
109 } |