dom/tests/browser/browser_localStorage_privatestorageevent.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial