Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test gets skipped with pattern: os == 'android'
- Manifest: dom/workers/test/chrome.toml
<head>
<title>Test for SharedWorker - Private Browsing</title>
</head>
<body>
<script type="application/javascript">
const {BrowserTestUtils} = ChromeUtils.importESModule(
);
var mainWindow;
function testOnWindow(aIsPrivate, aCallback) {
var win = mainWindow.OpenBrowserWindow({private: aIsPrivate});
win.addEventListener("load", function() {
win.addEventListener("DOMContentLoaded", function onInnerLoad() {
if (win.content.location.href != contentPage) {
BrowserTestUtils.startLoadingURIString(win.gBrowser, contentPage);
return;
}
win.removeEventListener("DOMContentLoaded", onInnerLoad, true);
SimpleTest.executeSoon(function() { aCallback(win); });
}, true);
}, {capture: true, once: true});
}
function setupWindow() {
mainWindow = window.browsingContext.topChromeWindow;
runTest();
}
var wN;
var wP;
function doTests() {
testOnWindow(false, function(aWin) {
wN = aWin;
testOnWindow(true, function(win) {
wP = win;
var sharedWorker1 = new wP.content.SharedWorker('sharedWorker_privateBrowsing.js');
sharedWorker1.port.onmessage = function(event) {
is(event.data, 1, "Only 1 sharedworker expected in the private window");
var sharedWorker2 = new wN.content.SharedWorker('sharedWorker_privateBrowsing.js');
sharedWorker2.port.onmessage = function(event1) {
is(event1.data, 1, "Only 1 sharedworker expected in the normal window");
var sharedWorker3 = new wP.content.SharedWorker('sharedWorker_privateBrowsing.js');
sharedWorker3.port.onmessage = function(event2) {
is(event2.data, 2, "Only 2 sharedworker expected in the private window");
runTest();
}
}
}
});
});
}
function doSystemSharedWorkerTest() {
try {
let chromeShared =
new wP.SharedWorker("chrome://mochitests/content/dom/workers/test/sharedWorker_privateBrowsing.js");
ok(true, "system SharedWorker created without throwing or crashing!");
} catch (_ex) {
ok(false, "system SharedWorker should not throw or crash");
}
runTest();
}
var steps = [
setupWindow,
doTests,
doSystemSharedWorkerTest,
];
function runTest() {
if (!steps.length) {
wN.close();
wP.close();
SimpleTest.finish();
return;
}
var step = steps.shift();
step();
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({"set": [
["browser.startup.page", 0],
["browser.startup.homepage_override.mstone", "ignore"],
]}, runTest);
</script>
</body>
</html>