Bug 1270119 - Rewrite browser_localStorage_privatestoragevent.js to run on e10s, r=jdm

This commit is contained in:
Michael Layzell 2016-05-03 10:47:09 -04:00
Родитель ec6390b365
Коммит fe89e56dfa
3 изменённых файлов: 71 добавлений и 122 удалений

Просмотреть файл

@ -34,7 +34,6 @@ skip-if = e10s
skip-if = e10s
[browser_frame_elements.js]
[browser_localStorage_privatestorageevent.js]
skip-if = e10s
[browser_test_new_window_from_content.js]
skip-if = (toolkit == 'android' || buildapp == 'b2g' || buildapp == 'mulet') || (os == "linux" && debug) # see bug 1261495 for Linux debug time outs
support-files =

Просмотреть файл

@ -1,109 +1,76 @@
function test() {
waitForExplicitFinish();
let windowsToClose = [];
function testOnWindow(options, callback) {
let win = OpenBrowserWindow(options);
windowsToClose.push(win);
win.addEventListener("load", function onLoad() {
win.removeEventListener("load", onLoad, false);
win.addEventListener("DOMContentLoaded", function onInnerLoad() {
if (win.content.location.href != "about:blank") {
win.gBrowser.loadURI("about:blank");
return;
}
win.removeEventListener("DOMContentLoaded", onInnerLoad, true);
executeSoon(() => callback(win));
}, true);
if (!options) {
win.gBrowser.loadURI("about:blank");
}
}, false);
}
Services.prefs.setIntPref("browser.startup.page", 0);
Services.prefs.setCharPref("browser.startup.homepage_override.mstone", "ignore");
registerCleanupFunction(function() {
Services.prefs.clearUserPref("browser.startup.page");
Services.prefs.clearUserPref("browser.startup.homepage_override.mstone");
for (var i in windowsToClose) {
windowsToClose[i].close();
}
add_task(function *() {
var privWin = OpenBrowserWindow({private: true});
yield new privWin.Promise(resolve => {
privWin.addEventListener('load', function onLoad() {
privWin.removeEventListener('load', onLoad, false);
resolve();
});
});
var phase = 0;
function step(data) {
switch (++phase) {
case 1:
is(data, "reply", "should have got reply message");
privWin.postMessage('query?', 'http://mochi.test:8888');
break;
case 2:
is(data.split(':')[0], "data", "should have got data message");
is(data.split(':')[1], "false", "priv window should not see event");
privWin.postMessage('setKey', 'http://mochi.test:8888');
break;
case 3:
is(data, "reply", "should have got reply message");
pubWin.postMessage('query?', 'http://mochi.test:8888');
break;
case 4:
is(data.split(':')[0], "data", "should have got data message");
is(data.split(':')[1], "false", "pub window should not see event");
finish();
break;
}
}
let loads = 0;
function waitForLoad() {
loads++;
if (loads != 2) {
return;
};
pubWin.postMessage('setKey', 'http://mochi.test:8888');
}
var privWin;
testOnWindow({private: true}, function(aPrivWin) {
let doc = aPrivWin.content.document;
let iframe = doc.createElement('iframe');
iframe.setAttribute('id', 'target2');
doc.body.appendChild(iframe);
aPrivWin.content.is = is;
aPrivWin.content.isnot = isnot;
aPrivWin.content.ok = ok;
iframe.onload = function() {
privWin = iframe.contentWindow;
privWin.addEventListener('message', function msgHandler(ev) {
if (ev.data == 'setKey' || ev.data == 'query?')
return;
step(ev.data);
}, true);
waitForLoad();
};
iframe.src = "http://mochi.test:8888/browser/dom/tests/browser/page_privatestorageevent.html";
var pubWin = OpenBrowserWindow({private: false});
yield new pubWin.Promise(resolve => {
pubWin.addEventListener('load', function onLoad() {
pubWin.removeEventListener('load', onLoad, false);
resolve();
});
});
var pubWin;
testOnWindow(undefined, function(aWin) {
let doc = aWin.content.document;
let iframe = doc.createElement('iframe');
iframe.setAttribute('id', 'target');
doc.body.appendChild(iframe);
aWin.content.is = is;
aWin.content.isnot = isnot;
aWin.content.ok = ok;
iframe.onload = function() {
pubWin = iframe.contentWindow;
pubWin.addEventListener('message', function msgHandler(ev) {
if (ev.data == 'setKey' || ev.data == 'query?')
return;
step(ev.data);
}, true);
waitForLoad();
};
iframe.src = "http://mochi.test:8888/browser/dom/tests/browser/page_privatestorageevent.html";
var URL = "http://mochi.test:8888/browser/dom/tests/browser/page_privatestorageevent.html";
var privTab = privWin.gBrowser.addTab(URL);
yield BrowserTestUtils.browserLoaded(privWin.gBrowser.getBrowserForTab(privTab));
var privBrowser = gBrowser.getBrowserForTab(privTab);
var pubTab = pubWin.gBrowser.addTab(URL);
yield BrowserTestUtils.browserLoaded(pubWin.gBrowser.getBrowserForTab(pubTab));
var pubBrowser = gBrowser.getBrowserForTab(pubTab);
// Check if pubWin can see privWin's storage events
yield ContentTask.spawn(pubBrowser, null, function(opts) {
content.window.gotStorageEvent = false;
content.window.addEventListener('storage', ev => {
content.window.gotStorageEvent = true;
});
});
}
yield ContentTask.spawn(privBrowser, null, function(opts) {
content.window.localStorage['key'] = 'ablooabloo';
});
let pubSaw = yield ContentTask.spawn(pubBrowser, null, function(opts) {
return content.window.gotStorageEvent;
});
ok(!pubSaw, "pubWin shouldn't be able to see privWin's storage events");
yield ContentTask.spawn(privBrowser, null, function(opts) {
content.window.gotStorageEvent = false;
content.window.addEventListener('storage', ev => {
content.window.gotStorageEvent = true;
});
});
// Check if privWin can see pubWin's storage events
yield ContentTask.spawn(privBrowser, null, function(opts) {
content.window.gotStorageEvent = false;
content.window.addEventListener('storage', ev => {
content.window.gotStorageEvent = true;
});
});
yield ContentTask.spawn(pubBrowser, null, function(opts) {
content.window.localStorage['key'] = 'ablooabloo';
});
let privSaw = yield ContentTask.spawn(privBrowser, null, function(opts) {
return content.window.gotStorageEvent;
});
ok(!privSaw, "privWin shouldn't be able to see pubWin's storage events");
yield BrowserTestUtils.removeTab(privTab);
yield BrowserTestUtils.closeWindow(privWin);
yield BrowserTestUtils.removeTab(pubTab);
yield BrowserTestUtils.closeWindow(pubWin);
});

Просмотреть файл

@ -1,22 +1,5 @@
<html>
<body>
la la la la
<script>
var gotStorageEvent = false;
window.addEventListener('storage', function(ev) {
gotStorageEvent = true;
}, false);
window.addEventListener('message', function(ev) {
if (['data:true', 'data:false', 'reply'].indexOf(ev.data) != -1)
return;
if (ev.data == 'query?') {
postMessage('data:' + gotStorageEvent, 'http://mochi.test:8888');
return;
}
localStorage['key'] = 'ablooabloo';
postMessage('reply', 'http://mochi.test:8888');
}, false);
</script>
</body>
</html>