mirror of
https://github.com/servo/servo
synced 2026-05-09 00:22:16 +02:00
55 lines
1.9 KiB
HTML
55 lines
1.9 KiB
HTML
<!DOCTYPE html>
|
|
<title>Service Worker: Controller on reload</title>
|
|
<script src="/resources/testharness.js"></script>
|
|
<script src="/resources/testharnessreport.js"></script>
|
|
<script src="resources/test-helpers.sub.js"></script>
|
|
<body>
|
|
<script>
|
|
promise_test(function(t) {
|
|
var scope = 'resources/blank.html';
|
|
var frame;
|
|
var registration;
|
|
var controller;
|
|
return service_worker_unregister(t, scope)
|
|
.then(function() {
|
|
return with_iframe(scope);
|
|
})
|
|
.then(function(f) {
|
|
frame = f;
|
|
return frame.contentWindow.navigator.serviceWorker.register(
|
|
'resources/empty-worker.js', {scope: scope});
|
|
})
|
|
.then(function(swr) {
|
|
registration = swr;
|
|
return wait_for_state(t, registration.installing, 'activated');
|
|
})
|
|
.then(function() {
|
|
var w = frame.contentWindow;
|
|
assert_equals(w.navigator.serviceWorker.controller, null,
|
|
'controller should be null until the document is ' +
|
|
'reloaded');
|
|
return new Promise(function(resolve) {
|
|
frame.onload = function() { resolve(); }
|
|
w.location.reload();
|
|
});
|
|
})
|
|
.then(function() {
|
|
var w = frame.contentWindow;
|
|
controller = w.navigator.serviceWorker.controller;
|
|
assert_true(controller instanceof w.ServiceWorker,
|
|
'controller should be a ServiceWorker object upon reload');
|
|
|
|
// objects from separate windows should not be equal
|
|
assert_not_equals(controller, registration.active);
|
|
|
|
return w.navigator.serviceWorker.getRegistration();
|
|
})
|
|
.then(function(frameRegistration) {
|
|
assert_equals(frameRegistration.active, controller);
|
|
frame.remove();
|
|
service_worker_unregister_and_done(t, scope);
|
|
});
|
|
}, 'controller is set upon reload after registration');
|
|
</script>
|
|
</body>
|