зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1181127 - Mochitest for nofetch handler optimization. r=bkelly
This commit is contained in:
Родитель
82cfe6ab4d
Коммит
6f3c7b97ba
|
@ -214,6 +214,7 @@ support-files =
|
|||
sharedWorker_fetch.js
|
||||
async_waituntil_worker.js
|
||||
lazy_worker.js
|
||||
nofetch_handler_worker.js
|
||||
|
||||
[test_bug1151916.html]
|
||||
[test_bug1240436.html]
|
||||
|
@ -319,3 +320,4 @@ tags = openwindow
|
|||
[test_xslt.html]
|
||||
[test_async_waituntil.html]
|
||||
[test_worker_reference_gc_timeout.html]
|
||||
[test_nofetch_handler.html]
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
function handleFetch(event) {
|
||||
event.respondWith(new Response('intercepted'));
|
||||
}
|
||||
|
||||
self.oninstall = function(event) {
|
||||
addEventListener('fetch', handleFetch);
|
||||
self.onfetch = handleFetch;
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test for Bug 1181127</title>
|
||||
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script src="/tests/SimpleTest/SpawnTask.js"></script>
|
||||
<script src="error_reporting_helpers.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
|
||||
</head>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1181127">Mozilla Bug 1181127</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
</pre>
|
||||
|
||||
<script class="testbody" type="text/javascript">
|
||||
|
||||
add_task(function setupPrefs() {
|
||||
return SpecialPowers.pushPrefEnv({"set": [
|
||||
["dom.serviceWorkers.enabled", true],
|
||||
["dom.serviceWorkers.testing.enabled", true],
|
||||
// Make sure the event handler during the install event persists. This ensures
|
||||
// the reason for which the interception doesn't occur is because of the
|
||||
// handlesFetch=false flag from ServiceWorkerInfo.
|
||||
["dom.serviceWorkers.idle_timeout", 299999],
|
||||
]});
|
||||
});
|
||||
|
||||
var iframeg;
|
||||
function create_iframe(url) {
|
||||
return new Promise(function(res) {
|
||||
iframe = document.createElement('iframe');
|
||||
iframe.src = url;
|
||||
iframe.onload = function() { res(iframe) }
|
||||
document.body.appendChild(iframe);
|
||||
iframeg = iframe;
|
||||
})
|
||||
}
|
||||
|
||||
add_task(function* test_nofetch_worker() {
|
||||
let registration = yield navigator.serviceWorker.register(
|
||||
"nofetch_handler_worker.js", { scope: "./nofetch_handler_worker/"} )
|
||||
.then(function(registration) {
|
||||
var worker = registration.installing;
|
||||
return new Promise(function(resolve) {
|
||||
worker.addEventListener('statechange', function() {
|
||||
if (worker.state === 'activated') {
|
||||
resolve(registration);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
let iframe = yield create_iframe("./nofetch_handler_worker/doesnt_exist.html");
|
||||
ok(!iframe.contentDocument.body.innerHTML.includes("intercepted"), "Request was not intercepted.");
|
||||
|
||||
yield SpecialPowers.popPrefEnv();
|
||||
yield registration.unregister();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Загрузка…
Ссылка в новой задаче