Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Errors
- This test gets skipped with pattern: xorigin
- This test failed 6 times in the preceding 30 days. quicksearch this test
- Manifest: dom/serviceworkers/test/mochitest-dFPI.toml includes dom/serviceworkers/test/mochitest-common.toml
- Manifest: dom/serviceworkers/test/mochitest.toml includes dom/serviceworkers/test/mochitest-common.toml
<!-- Any copyright is dedicated to the Public Domain.
<!DOCTYPE HTML>
<html>
<head>
<title>Validate Interfaces Exposed to Service Workers</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<script type="text/javascript" src="../worker_driver.js"></script>
</head>
<body>
<script class="testbody" type="text/javascript">
function setupSW(registration) {
var iframe;
var worker = registration.installing ||
registration.waiting ||
registration.active;
window.onmessage = function(event) {
if (event.data.type == 'finish') {
iframe.remove();
registration.unregister().then(function(success) {
ok(success, "The service worker should be unregistered successfully");
SimpleTest.finish();
}, function(e) {
dump("Unregistering the SW failed with " + e + "\n");
SimpleTest.finish();
});
} else if (event.data.type == 'status') {
ok(event.data.status, event.data.msg);
} else if (event.data.type == 'getPrefs') {
let result = {};
event.data.prefs.forEach(function(pref) {
result[pref] = SpecialPowers.Services.prefs.getBoolPref(pref);
});
worker.postMessage({
type: 'returnPrefs',
prefs: event.data.prefs,
result
});
} else if (event.data.type == 'getHelperData') {
const { AppConstants } = SpecialPowers.ChromeUtils.importESModule(
"resource://gre/modules/AppConstants.sys.mjs"
);
const isNightly = AppConstants.NIGHTLY_BUILD;
const isEarlyBetaOrEarlier = AppConstants.EARLY_BETA_OR_EARLIER;
const isRelease = AppConstants.RELEASE_OR_BETA;
const isDesktop = !/Mobile|Tablet/.test(navigator.userAgent);
const isMac = AppConstants.platform == "macosx";
const isWindows = AppConstants.platform == "win";
const isAndroid = AppConstants.platform == "android";
const isLinux = AppConstants.platform == "linux";
const isInsecureContext = !window.isSecureContext;
// Currently, MOZ_APP_NAME is always "fennec" for all mobile builds, so we can't use AppConstants for this
const isFennec = isAndroid && SpecialPowers.Cc["@mozilla.org/android/bridge;1"].getService(SpecialPowers.Ci.nsIGeckoViewBridge).isFennec;
const result = {
isNightly, isEarlyBetaOrEarlier, isRelease, isDesktop, isMac,
isWindows, isAndroid, isLinux, isInsecureContext, isFennec
};
worker.postMessage({
type: 'returnHelperData', result
});
}
}
worker.onerror = function(event) {
ok(false, 'Worker had an error: ' + event.data);
SimpleTest.finish();
};
iframe = document.createElement("iframe");
iframe.src = "message_receiver.html";
iframe.onload = function() {
worker.postMessage({ script: "test_serviceworker_interfaces.js" });
};
document.body.appendChild(iframe);
}
function runTest() {
navigator.serviceWorker.register("serviceworker_wrapper.js", {scope: "."})
.then(setupSW);
}
SimpleTest.waitForExplicitFinish();
onload = function() {
var prefs = [
["dom.serviceWorkers.exemptFromPerDomainMax", true],
["dom.serviceWorkers.enabled", true],
["dom.serviceWorkers.testing.enabled", true],
];
SpecialPowers.pushPrefEnv({"set": prefs}, runTest);
};
</script>
</body>
</html>