michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: let windowsToClose = []; michael@0: function testOnWindow(options, callback) { michael@0: let win = OpenBrowserWindow(options); michael@0: windowsToClose.push(win); michael@0: win.addEventListener("load", function onLoad() { michael@0: win.removeEventListener("load", onLoad, false); michael@0: win.addEventListener("DOMContentLoaded", function onInnerLoad() { michael@0: if (win.content.location.href != "about:blank") { michael@0: win.gBrowser.loadURI("about:blank"); michael@0: return; michael@0: } michael@0: win.removeEventListener("DOMContentLoaded", onInnerLoad, true); michael@0: executeSoon(function() callback(win)); michael@0: }, true); michael@0: if (!options) { michael@0: win.gBrowser.loadURI("about:blank"); michael@0: } michael@0: }, false); michael@0: } michael@0: michael@0: Services.prefs.setIntPref("browser.startup.page", 0); michael@0: Services.prefs.setCharPref("browser.startup.homepage_override.mstone", "ignore"); michael@0: michael@0: registerCleanupFunction(function() { michael@0: Services.prefs.clearUserPref("browser.startup.page"); michael@0: Services.prefs.clearUserPref("browser.startup.homepage_override.mstone"); michael@0: for (var i in windowsToClose) { michael@0: windowsToClose[i].close(); michael@0: } michael@0: }); michael@0: michael@0: var phase = 0; michael@0: function step(data) { michael@0: switch (++phase) { michael@0: case 1: michael@0: is(data, "reply", "should have got reply message"); michael@0: privWin.postMessage('query?', 'http://mochi.test:8888'); michael@0: break; michael@0: case 2: michael@0: is(data.split(':')[0], "data", "should have got data message"); michael@0: is(data.split(':')[1], "false", "priv window should not see event"); michael@0: privWin.postMessage('setKey', 'http://mochi.test:8888'); michael@0: break; michael@0: case 3: michael@0: is(data, "reply", "should have got reply message"); michael@0: pubWin.postMessage('query?', 'http://mochi.test:8888'); michael@0: break; michael@0: case 4: michael@0: is(data.split(':')[0], "data", "should have got data message"); michael@0: is(data.split(':')[1], "false", "pub window should not see event"); michael@0: finish(); michael@0: break; michael@0: } michael@0: } michael@0: michael@0: let loads = 0; michael@0: function waitForLoad() { michael@0: loads++; michael@0: if (loads != 2) { michael@0: return; michael@0: }; michael@0: pubWin.postMessage('setKey', 'http://mochi.test:8888'); michael@0: } michael@0: michael@0: var privWin; michael@0: testOnWindow({private: true}, function(aPrivWin) { michael@0: let doc = aPrivWin.content.document; michael@0: let iframe = doc.createElement('iframe'); michael@0: iframe.setAttribute('id', 'target2'); michael@0: doc.body.appendChild(iframe); michael@0: aPrivWin.content.is = is; michael@0: aPrivWin.content.isnot = isnot; michael@0: aPrivWin.content.ok = ok; michael@0: iframe.onload = function() { michael@0: privWin = iframe.contentWindow; michael@0: privWin.addEventListener('message', function msgHandler(ev) { michael@0: if (ev.data == 'setKey' || ev.data == 'query?') michael@0: return; michael@0: step(ev.data); michael@0: }, true); michael@0: waitForLoad(); michael@0: }; michael@0: iframe.src = "http://mochi.test:8888/browser/dom/tests/browser/page_privatestorageevent.html"; michael@0: }); michael@0: michael@0: var pubWin; michael@0: testOnWindow(undefined, function(aWin) { michael@0: let doc = aWin.content.document; michael@0: let iframe = doc.createElement('iframe'); michael@0: iframe.setAttribute('id', 'target'); michael@0: doc.body.appendChild(iframe); michael@0: aWin.content.is = is; michael@0: aWin.content.isnot = isnot; michael@0: aWin.content.ok = ok; michael@0: iframe.onload = function() { michael@0: pubWin = iframe.contentWindow; michael@0: pubWin.addEventListener('message', function msgHandler(ev) { michael@0: if (ev.data == 'setKey' || ev.data == 'query?') michael@0: return; michael@0: step(ev.data); michael@0: }, true); michael@0: waitForLoad(); michael@0: }; michael@0: iframe.src = "http://mochi.test:8888/browser/dom/tests/browser/page_privatestorageevent.html"; michael@0: }); michael@0: }