blob: 2e966d425788c0a02b1bb25a4c045089fede5ce7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
<!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) {
const iframe_scope = 'blank.html';
const scope = 'resources/' + iframe_scope;
var frame;
var registration;
var controller;
return service_worker_unregister(t, scope)
.then(function() {
t.add_cleanup(function() {
return service_worker_unregister(t, scope);
});
return with_iframe(scope);
})
.then(function(f) {
frame = f;
return frame.contentWindow.navigator.serviceWorker.register(
'empty-worker.js', {scope: iframe_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(iframe_scope);
})
.then(function(frameRegistration) {
assert_equals(frameRegistration.active, controller);
frame.remove();
});
}, 'controller is set upon reload after registration');
</script>
</body>
|