OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <!-- FIXME: Move this test out of chromium/ when PHP is no longer needed | 2 <title>Service Worker: Registration using Link header</title> |
3 to set the Link header (crbug.com/347864). | |
4 --> | |
5 <script src="/resources/testharness.js"></script> | 3 <script src="/resources/testharness.js"></script> |
6 <script src="/resources/testharnessreport.js"></script> | 4 <script src="/resources/testharnessreport.js"></script> |
7 <script src="../resources/test-helpers.js"></script> | 5 <script src="resources/test-helpers.sub.js"></script> |
8 <body> | 6 <body> |
9 <script> | 7 <script> |
| 8 function get_newest_worker(registration) { |
| 9 if (registration.installing) |
| 10 return registration.installing; |
| 11 if (registration.waiting) |
| 12 return registration.waiting; |
| 13 if (registration.active) |
| 14 return registration.active; |
| 15 } |
| 16 |
10 promise_test(function(t) { | 17 promise_test(function(t) { |
11 var scope = normalizeURL('resources/blank.html?fetch'); | 18 var scope = normalizeURL('resources/blank.html?fetch'); |
12 var header = '<empty-worker.js>; rel=serviceworker; scope="' + scope + '"'; | 19 var header = '<empty-worker.js>; rel=serviceworker; scope="' + scope + '"'; |
13 var resource = 'resources/link-header.php?Link=' + | 20 var resource = 'resources/link-header.py?Link=' + |
14 encodeURIComponent(header); | 21 encodeURIComponent(header); |
15 return with_iframe(scope) | 22 return with_iframe(scope) |
16 .then(frame => | 23 .then(frame => |
17 Promise.all([frame.contentWindow.navigator.serviceWorker.ready, | 24 Promise.all([frame.contentWindow.navigator.serviceWorker.ready, |
18 fetch(resource)])) | 25 fetch(resource)])) |
19 .then(([registration, response]) => { | 26 .then(([registration, response]) => { |
20 assert_equals(registration.scope, scope); | 27 assert_equals(registration.scope, scope); |
| 28 assert_equals(get_newest_worker(registration).scriptURL, |
| 29 normalizeURL('resources/empty-worker.js')); |
| 30 return registration.unregister(); |
21 }); | 31 }); |
22 }, 'fetch can trigger service worker installation'); | 32 }, 'fetch can trigger service worker installation'); |
23 | 33 |
24 promise_test(function(t) { | 34 promise_test(function(t) { |
25 var scope = normalizeURL('resources/blank.html?iframe'); | 35 var scope = normalizeURL('resources/blank.html?iframe'); |
26 var header = '<empty-worker.js>; rel=serviceworker; scope="' + scope + '"'; | 36 var header = '<empty-worker.js>; rel=serviceworker; scope="' + scope + '"'; |
27 var resource = 'resources/link-header.php?Link=' + | 37 var resource = 'resources/link-header.py?Link=' + |
28 encodeURIComponent(header); | 38 encodeURIComponent(header); |
29 return with_iframe(scope) | 39 return with_iframe(scope) |
30 .then(frame => | 40 .then(frame => |
31 Promise.all([frame.contentWindow.navigator.serviceWorker.ready, | 41 Promise.all([frame.contentWindow.navigator.serviceWorker.ready, |
32 with_iframe(resource)])) | 42 with_iframe(resource)])) |
33 .then(([registration, frame]) => { | 43 .then(([registration, frame]) => { |
34 assert_equals(registration.scope, scope); | 44 assert_equals(registration.scope, scope); |
| 45 assert_equals(get_newest_worker(registration).scriptURL, |
| 46 normalizeURL('resources/empty-worker.js')); |
| 47 return registration.unregister(); |
35 }); | 48 }); |
36 }, 'An iframe can trigger service worker installation'); | 49 }, 'An iframe can trigger service worker installation'); |
37 | 50 |
38 promise_test(function(t) { | 51 promise_test(function(t) { |
39 var scope = normalizeURL('resources/blank.html?css'); | 52 var scope = normalizeURL('resources/blank.html?css'); |
40 var header = '<empty-worker.js>; rel=serviceworker; scope="' + scope + '"'; | 53 var header = '<empty-worker.js>; rel=serviceworker; scope="' + scope + '"'; |
41 var resource = 'resources/link-header.php?Link=' + | 54 var resource = 'resources/link-header.py?Link=' + |
42 encodeURIComponent(header); | 55 encodeURIComponent(header); |
43 return with_iframe(scope) | 56 return with_iframe(scope) |
44 .then(frame => { | 57 .then(frame => { |
45 var link = document.createElement('link'); | 58 var link = document.createElement('link'); |
46 link.setAttribute('rel', 'stylesheet'); | 59 link.setAttribute('rel', 'stylesheet'); |
47 link.setAttribute('type', 'text/css'); | 60 link.setAttribute('type', 'text/css'); |
48 link.setAttribute('href', resource); | 61 link.setAttribute('href', resource); |
49 document.getElementsByTagName('head')[0].appendChild(link); | 62 document.getElementsByTagName('head')[0].appendChild(link); |
50 return frame.contentWindow.navigator.serviceWorker.ready; | 63 return frame.contentWindow.navigator.serviceWorker.ready; |
51 }) | 64 }) |
52 .then(registration => { | 65 .then(registration => { |
53 assert_equals(registration.scope, scope); | 66 assert_equals(registration.scope, scope); |
| 67 assert_equals(get_newest_worker(registration).scriptURL, |
| 68 normalizeURL('resources/empty-worker.js')); |
| 69 return registration.unregister(); |
54 }); | 70 }); |
55 }, 'A stylesheet can trigger service worker installation'); | 71 }, 'A stylesheet can trigger service worker installation'); |
56 | 72 |
57 </script> | 73 </script> |
OLD | NEW |