1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/tests/browser/browser_localStorage_privatestorageevent.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,109 @@ 1.4 +function test() { 1.5 + waitForExplicitFinish(); 1.6 + 1.7 + let windowsToClose = []; 1.8 + function testOnWindow(options, callback) { 1.9 + let win = OpenBrowserWindow(options); 1.10 + windowsToClose.push(win); 1.11 + win.addEventListener("load", function onLoad() { 1.12 + win.removeEventListener("load", onLoad, false); 1.13 + win.addEventListener("DOMContentLoaded", function onInnerLoad() { 1.14 + if (win.content.location.href != "about:blank") { 1.15 + win.gBrowser.loadURI("about:blank"); 1.16 + return; 1.17 + } 1.18 + win.removeEventListener("DOMContentLoaded", onInnerLoad, true); 1.19 + executeSoon(function() callback(win)); 1.20 + }, true); 1.21 + if (!options) { 1.22 + win.gBrowser.loadURI("about:blank"); 1.23 + } 1.24 + }, false); 1.25 + } 1.26 + 1.27 + Services.prefs.setIntPref("browser.startup.page", 0); 1.28 + Services.prefs.setCharPref("browser.startup.homepage_override.mstone", "ignore"); 1.29 + 1.30 + registerCleanupFunction(function() { 1.31 + Services.prefs.clearUserPref("browser.startup.page"); 1.32 + Services.prefs.clearUserPref("browser.startup.homepage_override.mstone"); 1.33 + for (var i in windowsToClose) { 1.34 + windowsToClose[i].close(); 1.35 + } 1.36 + }); 1.37 + 1.38 + var phase = 0; 1.39 + function step(data) { 1.40 + switch (++phase) { 1.41 + case 1: 1.42 + is(data, "reply", "should have got reply message"); 1.43 + privWin.postMessage('query?', 'http://mochi.test:8888'); 1.44 + break; 1.45 + case 2: 1.46 + is(data.split(':')[0], "data", "should have got data message"); 1.47 + is(data.split(':')[1], "false", "priv window should not see event"); 1.48 + privWin.postMessage('setKey', 'http://mochi.test:8888'); 1.49 + break; 1.50 + case 3: 1.51 + is(data, "reply", "should have got reply message"); 1.52 + pubWin.postMessage('query?', 'http://mochi.test:8888'); 1.53 + break; 1.54 + case 4: 1.55 + is(data.split(':')[0], "data", "should have got data message"); 1.56 + is(data.split(':')[1], "false", "pub window should not see event"); 1.57 + finish(); 1.58 + break; 1.59 + } 1.60 + } 1.61 + 1.62 + let loads = 0; 1.63 + function waitForLoad() { 1.64 + loads++; 1.65 + if (loads != 2) { 1.66 + return; 1.67 + }; 1.68 + pubWin.postMessage('setKey', 'http://mochi.test:8888'); 1.69 + } 1.70 + 1.71 + var privWin; 1.72 + testOnWindow({private: true}, function(aPrivWin) { 1.73 + let doc = aPrivWin.content.document; 1.74 + let iframe = doc.createElement('iframe'); 1.75 + iframe.setAttribute('id', 'target2'); 1.76 + doc.body.appendChild(iframe); 1.77 + aPrivWin.content.is = is; 1.78 + aPrivWin.content.isnot = isnot; 1.79 + aPrivWin.content.ok = ok; 1.80 + iframe.onload = function() { 1.81 + privWin = iframe.contentWindow; 1.82 + privWin.addEventListener('message', function msgHandler(ev) { 1.83 + if (ev.data == 'setKey' || ev.data == 'query?') 1.84 + return; 1.85 + step(ev.data); 1.86 + }, true); 1.87 + waitForLoad(); 1.88 + }; 1.89 + iframe.src = "http://mochi.test:8888/browser/dom/tests/browser/page_privatestorageevent.html"; 1.90 + }); 1.91 + 1.92 + var pubWin; 1.93 + testOnWindow(undefined, function(aWin) { 1.94 + let doc = aWin.content.document; 1.95 + let iframe = doc.createElement('iframe'); 1.96 + iframe.setAttribute('id', 'target'); 1.97 + doc.body.appendChild(iframe); 1.98 + aWin.content.is = is; 1.99 + aWin.content.isnot = isnot; 1.100 + aWin.content.ok = ok; 1.101 + iframe.onload = function() { 1.102 + pubWin = iframe.contentWindow; 1.103 + pubWin.addEventListener('message', function msgHandler(ev) { 1.104 + if (ev.data == 'setKey' || ev.data == 'query?') 1.105 + return; 1.106 + step(ev.data); 1.107 + }, true); 1.108 + waitForLoad(); 1.109 + }; 1.110 + iframe.src = "http://mochi.test:8888/browser/dom/tests/browser/page_privatestorageevent.html"; 1.111 + }); 1.112 +} 1.113 \ No newline at end of file