gecko-dev/dom/serviceworkers/test/test_bug1151916.html
Brian Grinstead 0d460e3432 Bug 1544322 - Part 2.2 - Remove the [type] attribute for one-liner <script> tags loading files in /tests/SimpleTest/ in dom/ r=bzbarsky
This is split from the previous changeset since if we include dom/ the file size is too
large for phabricator to handle.

This is an autogenerated commit to handle scripts loading mochitest harness files, in
the simple case where the script src is on the same line as the tag.

This was generated with https://bug1544322.bmoattachments.org/attachment.cgi?id=9058170
using the `--part 2` argument.

Differential Revision: https://phabricator.services.mozilla.com/D27457

--HG--
extra : moz-landing-system : lando
2019-04-16 03:53:28 +00:00

106 lines
2.6 KiB
HTML

<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE HTML>
<html>
<head>
<title>Bug 1151916 - Test principal is set on cached serviceworkers</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<!--
If the principal is not set, accessing self.caches in the worker will crash.
-->
</head>
<body>
<p id="display"></p>
<div id="content"></div>
<pre id="test"></pre>
<script class="testbody" type="text/javascript">
var frame;
function listenForMessage() {
var p = new Promise(function(resolve, reject) {
window.onmessage = function(e) {
if (e.data.status == "failed") {
ok(false, "iframe had error " + e.data.message);
reject(e.data.message);
} else if (e.data.status == "success") {
ok(true, "iframe step success " + e.data.message);
resolve(e.data.message);
} else {
ok(false, "Unexpected message " + e.data);
reject();
}
}
});
return p;
}
// We have the iframe register for its own scope so that this page is not
// holding any references when we GC.
function register() {
var p = listenForMessage();
frame = document.createElement("iframe");
document.body.appendChild(frame);
frame.src = "bug1151916_driver.html";
return p;
}
function unloadFrame() {
frame.src = "about:blank";
frame.remove();
frame = null;
}
function gc() {
return new Promise(function(resolve) {
SpecialPowers.exactGC(resolve);
});
}
function testCaches() {
var p = listenForMessage();
frame = document.createElement("iframe");
document.body.appendChild(frame);
frame.src = "bug1151916_driver.html";
return p;
}
function unregister() {
return navigator.serviceWorker.getRegistration("./bug1151916_driver.html").then(function(reg) {
ok(reg instanceof ServiceWorkerRegistration, "Must have valid registration.");
return reg.unregister();
});
}
function runTest() {
register()
.then(unloadFrame)
.then(gc)
.then(testCaches)
.then(unregister)
.catch(function(e) {
ok(false, "Some test failed with error " + e);
}).then(SimpleTest.finish);
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({"set": [
["dom.serviceWorkers.exemptFromPerDomainMax", true],
["dom.serviceWorkers.enabled", true],
["dom.serviceWorkers.testing.enabled", true],
["dom.caches.enabled", true],
]}, runTest);
</script>
</pre>
</body>
</html>