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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
<!DOCTYPE html>
<meta name=timeout content=long>
<title>Service Worker: Update should be triggered after a navigation</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/test-helpers.sub.js"></script>
<script>
async function cleanup(frame, registration) {
if (frame)
frame.remove();
if (registration)
await registration.unregister();
}
promise_test(async t => {
const script = 'resources/update_shell.py?filename=empty.js';
const scope = 'resources/scope/update';
let registration;
let frame;
async function run() {
registration = await service_worker_unregister_and_register(
t, script, scope);
await wait_for_state(t, registration.installing, 'activated');
// Navigation should trigger update.
frame = await with_iframe(scope);
await wait_for_update(t, registration);
}
try {
await run();
} finally {
await cleanup(frame, registration);
}
}, 'Update should be triggered after a navigation (no fetch event worker).');
promise_test(async t => {
const script = 'resources/update_shell.py?filename=simple-intercept-worker.js';
const scope = 'resources/scope/update';
let registration;
let frame;
async function run() {
registration = await service_worker_unregister_and_register(
t, script, scope);
await wait_for_state(t, registration.installing, 'activated');
// Navigation should trigger update (network fallback).
frame = await with_iframe(scope + '?ignore');
await wait_for_update(t, registration);
// Navigation should trigger update (respondWith called).
frame.src = scope + '?string';
await wait_for_update(t, registration);
}
try {
await run();
} finally {
await cleanup(frame, registration);
}
}, 'Update should be triggered after a navigation (fetch event worker).');
promise_test(async t => {
const script = 'resources/update_shell.py?filename=empty.js';
const scope = 'resources/';
let registration;
let frame;
async function run() {
registration = await service_worker_unregister_and_register(
t, script, scope);
await wait_for_state(t, registration.installing, 'activated');
// Navigation should trigger update. Don't use with_iframe as it waits for
// the onload event.
frame = document.createElement('iframe');
frame.src = 'resources/malformed-http-response.asis';
document.body.appendChild(frame);
await wait_for_update(t, registration);
}
try {
await run();
} finally {
await cleanup(frame, registration);
}
}, 'Update should be triggered after a navigation (network error).');
</script>
|