Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test gets skipped with pattern: os == 'android'
- Manifest: dom/serviceworkers/test/chrome-dFPI.toml includes dom/serviceworkers/test/chrome-common.toml
- Manifest: dom/serviceworkers/test/chrome.toml includes dom/serviceworkers/test/chrome-common.toml
<head>
<title>Test for ServiceWorker - Private Browsing</title>
</head>
<body>
<script type="application/javascript">
const {BrowserTestUtils} = ChromeUtils.importESModule(
);
var mainWindow;
var workerURL = workerScope + "worker.js";
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 registration;
var wP;
function testPrivateWindow() {
testOnWindow(true, function(aWin) {
wP = aWin;
ok(!wP.content.eval('"serviceWorker" in navigator'), "ServiceWorkers are not available for private windows");
runTest();
});
}
function doTests() {
testOnWindow(false, function(aWin) {
wN = aWin;
ok("serviceWorker" in wN.content.navigator, "ServiceWorkers are available for normal windows");
wN.content.navigator.serviceWorker.register(workerURL,
{ scope: workerScope })
.then(function(aRegistration) {
registration = aRegistration;
ok(registration, "Registering a service worker in a normal window should succeed");
testPrivateWindow();
}, function(aError) {
ok(false, "Error registering worker in normal window: " + aError);
testPrivateWindow();
});
});
}
var steps = [
setupWindow,
doTests
];
function cleanup() {
wN.close();
wP.close();
SimpleTest.finish();
}
function runTest() {
if (!steps.length) {
registration.unregister().then(cleanup, cleanup);
return;
}
var step = steps.shift();
step();
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({"set": [
["dom.serviceWorkers.enabled", true],
["dom.serviceWorkers.testing.enabled", true],
["browser.startup.page", 0],
["browser.startup.homepage_override.mstone", "ignore"],
]}, runTest);
</script>
</body>
</html>