зеркало из https://github.com/mozilla/gecko-dev.git
141 строка
5.2 KiB
HTML
141 строка
5.2 KiB
HTML
<!--
|
|
Any copyright is dedicated to the Public Domain.
|
|
http://creativecommons.org/publicdomain/zero/1.0/
|
|
-->
|
|
<!DOCTYPE HTML>
|
|
<html>
|
|
<head>
|
|
<title>Test for SharedWorker</title>
|
|
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
|
|
<script class="testbody" type="text/javascript">
|
|
"use strict";
|
|
|
|
const scrollbarPref = "layout.testing.overlay-scrollbars.always-visible";
|
|
const viewersPref = "browser.sessionhistory.max_total_viewers";
|
|
|
|
const windowRelativeURL = "multi_sharedWorker_frame.html";
|
|
const storedData = "0123456789abcdefghijklmnopqrstuvwxyz";
|
|
|
|
let testGenerator = (function*() {
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
// Force scrollbar to always be shown. The scrollbar setting is
|
|
// necessary to avoid the fade-in/fade-out from evicting our document
|
|
// from the BF cache below. If bug 1049277 is fixed, then we can
|
|
// stop setting the scrollbar pref here.
|
|
SpecialPowers.pushPrefEnv({ set: [[scrollbarPref, true],
|
|
[viewersPref, 10]] },
|
|
sendToGenerator);
|
|
yield undefined;
|
|
|
|
window.addEventListener("message", function(event) {
|
|
if (typeof(event.data) == "string") {
|
|
info(event.data);
|
|
} else {
|
|
sendToGenerator(event);
|
|
}
|
|
});
|
|
|
|
let testWin = window.open(windowRelativeURL, "testWin");
|
|
yield undefined;
|
|
|
|
testWin.postMessage({ command: "retrieve" }, "*");
|
|
|
|
let event = yield undefined;
|
|
ok(event instanceof MessageEvent, "Got a MessageEvent");
|
|
is(event.source, testWin, "Correct window got the event");
|
|
is(event.data.type, "result", "Got a result message");
|
|
is(event.data.data, undefined, "No data stored yet");
|
|
|
|
testWin.postMessage({ command: "store", data: storedData }, "*");
|
|
testWin.postMessage({ command: "retrieve" }, "*");
|
|
|
|
event = yield undefined;
|
|
ok(event instanceof MessageEvent, "Got a MessageEvent");
|
|
is(event.source, testWin, "Correct window got the event");
|
|
is(event.data.type, "result", "Got a result message");
|
|
is(event.data.data, storedData, "Got stored data");
|
|
|
|
// Navigate when the bfcache is disabled.
|
|
info("Navigating to a blank page");
|
|
testWin.onunload = function(){};;
|
|
testWin.location = "blank.html";
|
|
testWin.document.body.offsetTop;
|
|
|
|
yield undefined;
|
|
|
|
info("Navigating to " + windowRelativeURL);
|
|
testWin.onunload = function(){};
|
|
testWin.location = windowRelativeURL;
|
|
testWin.document.body.offsetTop;
|
|
|
|
yield undefined;
|
|
|
|
testWin.postMessage({ command: "retrieve" }, "*");
|
|
|
|
event = yield undefined;
|
|
ok(event instanceof MessageEvent, "Got a MessageEvent");
|
|
is(event.source, testWin, "Correct window got the event");
|
|
is(event.data.type, "result", "Got a result message");
|
|
is(event.data.data, undefined, "No data stored");
|
|
|
|
testWin.postMessage({ command: "store", data: storedData }, "*");
|
|
testWin.postMessage({ command: "retrieve" }, "*");
|
|
|
|
event = yield undefined;
|
|
ok(event instanceof MessageEvent, "Got a MessageEvent");
|
|
is(event.source, testWin, "Correct window got the event");
|
|
is(event.data.type, "result", "Got a result message");
|
|
is(event.data.data, storedData, "Got stored data");
|
|
|
|
// Navigate when the bfcache is enabled.
|
|
info("Navigating to a blank page");
|
|
testWin.location = "blank.html";
|
|
testWin.document.body.offsetTop;
|
|
|
|
yield undefined;
|
|
|
|
for (let i = 0; i < 3; i++) {
|
|
info("Running GC");
|
|
SpecialPowers.exactGC(sendToGenerator);
|
|
yield undefined;
|
|
|
|
// It seems using SpecialPowers.executeSoon() would make the
|
|
// entryGlobal being the BrowserChildGlobal (and that would make the
|
|
// baseURI in the location assignment below being incorrect);
|
|
// setTimeout on the otherhand ensures the entryGlobal is this
|
|
// window.
|
|
info("Waiting the event queue to clear");
|
|
setTimeout(sendToGenerator, 0);
|
|
yield undefined;
|
|
}
|
|
|
|
info("Navigating to " + windowRelativeURL);
|
|
testWin.location = windowRelativeURL;
|
|
testWin.document.body.offsetTop;
|
|
|
|
yield undefined;
|
|
|
|
testWin.postMessage({ command: "retrieve" }, "*");
|
|
|
|
event = yield undefined;
|
|
ok(event instanceof MessageEvent, "Got a MessageEvent");
|
|
is(event.source, testWin, "Correct window got the event");
|
|
is(event.data.type, "result", "Got a result message");
|
|
is(event.data.data, storedData, "Still have data stored");
|
|
|
|
window.removeEventListener("message", sendToGenerator);
|
|
|
|
testWin.close();
|
|
SimpleTest.finish();
|
|
})();
|
|
|
|
let sendToGenerator = testGenerator.next.bind(testGenerator);
|
|
|
|
</script>
|
|
</head>
|
|
<body onload="testGenerator.next();">
|
|
</body>
|
|
</html>
|