blob: dd71c9b892ea4e1c022f6976795f1ee9730c6b94 [file] [log] [blame]
<!DOCTYPE html>
<title>Service Worker: Registration using Link header</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/test-helpers.sub.js"></script>
<body>
<script>
function get_newest_worker(registration) {
if (registration.installing)
return registration.installing;
if (registration.waiting)
return registration.waiting;
if (registration.active)
return registration.active;
}
promise_test(function(t) {
var scope = normalizeURL('resources/blank.html?fetch');
var header = '<empty-worker.js>; rel=serviceworker; scope="' + scope + '"';
var resource = 'resources/link-header.py?Link=' +
encodeURIComponent(header);
return with_iframe(scope)
.then(frame =>
Promise.all([frame.contentWindow.navigator.serviceWorker.ready,
fetch(resource)]))
.then(([registration, response]) => {
assert_equals(registration.scope, scope);
assert_equals(get_newest_worker(registration).scriptURL,
normalizeURL('resources/empty-worker.js'));
return registration.unregister();
});
}, 'fetch can trigger service worker installation');
promise_test(function(t) {
var scope = normalizeURL('resources/blank.html?iframe');
var header = '<empty-worker.js>; rel=serviceworker; scope="' + scope + '"';
var resource = 'resources/link-header.py?Link=' +
encodeURIComponent(header);
return with_iframe(scope)
.then(frame =>
Promise.all([frame.contentWindow.navigator.serviceWorker.ready,
with_iframe(resource)]))
.then(([registration, frame]) => {
assert_equals(registration.scope, scope);
assert_equals(get_newest_worker(registration).scriptURL,
normalizeURL('resources/empty-worker.js'));
return registration.unregister();
});
}, 'An iframe can trigger service worker installation');
promise_test(function(t) {
var scope = normalizeURL('resources/blank.html?css');
var header = '<empty-worker.js>; rel=serviceworker; scope="' + scope + '"';
var resource = 'resources/link-header.py?Link=' +
encodeURIComponent(header);
return with_iframe(scope)
.then(frame => {
var link = document.createElement('link');
link.setAttribute('rel', 'stylesheet');
link.setAttribute('type', 'text/css');
link.setAttribute('href', resource);
document.getElementsByTagName('head')[0].appendChild(link);
return frame.contentWindow.navigator.serviceWorker.ready;
})
.then(registration => {
assert_equals(registration.scope, scope);
assert_equals(get_newest_worker(registration).scriptURL,
normalizeURL('resources/empty-worker.js'));
return registration.unregister();
});
}, 'A stylesheet can trigger service worker installation');
</script>