OLD | NEW |
---|---|
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <title>Service Worker: navigator.serviceWorker.ready</title> | 2 <title>Service Worker: navigator.serviceWorker.ready</title> |
3 <script src="../resources/testharness.js"></script> | 3 <script src="../resources/testharness.js"></script> |
4 <script src="../resources/testharnessreport.js"></script> | 4 <script src="../resources/testharnessreport.js"></script> |
5 <script src="resources/test-helpers.js"></script> | 5 <script src="resources/test-helpers.js"></script> |
6 <body> | 6 <body> |
7 <script> | 7 <script> |
8 test(function() { | 8 test(function() { |
9 var promise = navigator.serviceWorker.ready; | 9 var promise = navigator.serviceWorker.ready; |
10 assert_equals(promise, navigator.serviceWorker.ready, | 10 assert_equals(promise, navigator.serviceWorker.ready, |
11 'repeated access to ready without intervening ' + | 11 'repeated access to ready without intervening ' + |
12 'registrations should return the same Promise object'); | 12 'registrations should return the same Promise object'); |
13 }, 'ready returns the same Promise object'); | 13 }, 'ready returns the same Promise object'); |
14 | 14 |
15 async_test(function(t) { | 15 async_test(function(t) { |
16 with_iframe('resources/blank.html?uncontrolled') | 16 with_iframe('resources/blank.html?uncontrolled') |
17 .then(t.step_func(function(frame) { | 17 .then(t.step_func(function(frame) { |
18 var promise = frame.contentWindow.navigator.serviceWorker.ready; | 18 var promise = frame.contentWindow.navigator.serviceWorker.ready; |
19 assert_equals(Object.getPrototypeOf(promise), | 19 assert_equals(Object.getPrototypeOf(promise), |
20 frame.contentWindow.Promise.prototype, | 20 frame.contentWindow.Promise.prototype, |
21 'the Promise should be in the context of the ' + | 21 'the Promise should be in the context of the ' + |
22 'related document'); | 22 'related document'); |
23 frame.remove(); | 23 unload_iframe(frame); |
24 t.done(); | 24 t.done(); |
25 })); | 25 })); |
26 }, 'ready returns a Promise object in the context of the related document'); | 26 }, 'ready returns a Promise object in the context of the related document'); |
27 | 27 |
28 async_test(function(t) { | 28 async_test(function(t) { |
29 var url = 'resources/empty-worker.js'; | 29 var url = 'resources/empty-worker.js'; |
30 var scope = 'resources/blank.html?ready-active'; | 30 var scope = 'resources/blank.html?ready-controlled'; |
31 var expected_url = normalizeURL(url); | |
31 var frame; | 32 var frame; |
32 var registered_service_worker; | |
33 | 33 |
34 service_worker_unregister_and_register(t, url, scope) | 34 service_worker_unregister_and_register(t, url, scope) |
35 .then(t.step_func(function(registration) { | 35 .then(function(registration) { |
36 return wait_for_update(t, registration); | 36 return wait_for_activated(t, registration); |
37 })) | 37 }) |
38 .then(t.step_func(function(service_worker) { | 38 .then(function() { return with_iframe(scope); }) |
39 registered_service_worker = service_worker; | 39 .then(function(f) { |
40 return wait_for_state(t, service_worker, 'activating'); | |
41 })) | |
42 .then(t.step_func(function() { | |
43 return with_iframe(scope); | |
44 })) | |
45 .then(t.step_func(function(f) { | |
46 frame = f; | 40 frame = f; |
47 return frame.contentWindow.navigator.serviceWorker.ready; | 41 return frame.contentWindow.navigator.serviceWorker.ready; |
48 })) | 42 }) |
49 .then(t.step_func(function(service_worker) { | 43 .then(function(registration) { |
50 assert_equals(service_worker, | 44 assert_equals(registration.installing, null, |
51 frame.contentWindow.navigator.serviceWorker.active, | 45 'installing should be null'); |
52 'ready should resolve to the active ServiceWorker'); | 46 assert_equals(registration.waiting, null, |
53 assert_equals(Object.getPrototypeOf(service_worker), | 47 'waiting should be null'); |
54 frame.contentWindow.ServiceWorker.prototype, | 48 assert_equals(registration.active.scriptURL, expected_url, |
55 'the prototype of the ServiceWorker from ready ' + | 49 'active after ready should not be null'); |
56 'should be from the ServiceWorkerContainer\'s ' + | 50 assert_equals( |
57 'context'); | 51 frame.contentWindow.navigator.serviceWorker.controller.scriptURL, |
58 assert_equals(Object.getPrototypeOf(registered_service_worker), | 52 expected_url, |
59 ServiceWorker.prototype, | 53 'controlled document should have a controller'); |
60 'the prototype of the ServiceWorker from register ' + | 54 |
61 'should be from the registering context'); | 55 unload_iframe(frame); |
62 // This is a logical consequence of the different prototypes | |
63 assert_not_equals(service_worker, registered_service_worker, | |
64 'ready should resolve to a different ' + | |
65 'ServiceWorker than register because of ' + | |
66 'different prototypes'); | |
67 frame.remove(); | |
68 service_worker_unregister_and_done(t, scope); | 56 service_worker_unregister_and_done(t, scope); |
69 })); | 57 }) |
70 }, 'ready resolves to active'); | 58 .catch(unreached_rejection(t)); |
59 }, 'ready on a controlled document'); | |
60 | |
61 async_test(function(t) { | |
62 var url = 'resources/empty-worker.js'; | |
63 var scope = 'resources/blank.html?ready-potential-controlled'; | |
64 var expected_url = normalizeURL(url); | |
65 var frame; | |
66 | |
67 with_iframe(scope) | |
68 .then(function(f) { | |
69 frame = f; | |
70 return navigator.serviceWorker.register(url, {scope:scope}); | |
71 }) | |
72 .then(function(registration) { | |
73 return wait_for_activated(t, registration); | |
horo
2014/09/10 08:57:54
is this needed?
nhiroki
2014/09/11 08:16:37
Good catch. This is needless. Removed.
| |
74 }) | |
75 .then(function() { | |
76 return frame.contentWindow.navigator.serviceWorker.ready; | |
77 }) | |
78 .then(function(registration) { | |
79 assert_equals(registration.installing, null, | |
80 'installing should be null'); | |
81 assert_equals(registration.waiting, null, | |
82 'waiting should be null.') | |
83 assert_equals(registration.active.scriptURL, expected_url, | |
84 'active after ready should not be null'); | |
85 assert_equals(frame.contentWindow.navigator.serviceWorker.controller, | |
86 null, | |
87 'uncontrolled document should not have a controller'); | |
88 | |
89 unload_iframe(frame); | |
90 service_worker_unregister_and_done(t, scope); | |
91 }) | |
92 .catch(unreached_rejection(t)); | |
93 }, 'ready on a potential controlled document'); | |
94 | |
95 async_test(function(t) { | |
96 var url = 'resources/empty-worker.js'; | |
97 var scope = 'resources/blank.html?ready-after-unregister'; | |
98 var expected_url = normalizeURL(url); | |
99 var frame; | |
100 | |
101 service_worker_unregister_and_register(t, url, scope) | |
102 .then(function(registration) { | |
103 return wait_for_activated(t, registration); | |
104 }) | |
105 .then(function() { return with_iframe(scope); }) | |
106 .then(function(f) { | |
107 frame = f; | |
108 return navigator.serviceWorker.unregister(scope); | |
109 }) | |
110 .then(function() { | |
111 return frame.contentWindow.navigator.serviceWorker.ready; | |
112 }) | |
113 .then(function(registration) { | |
114 assert_equals(registration.installing, null, | |
115 'installing should be null'); | |
116 assert_equals(registration.waiting, null, | |
117 'waiting should be null'); | |
118 assert_equals(registration.active.scriptURL, expected_url, | |
119 'active after ready should not be null'); | |
120 assert_equals( | |
121 frame.contentWindow.navigator.serviceWorker.controller.scriptURL, | |
122 expected_url, | |
123 'controlled document should have a controller'); | |
124 | |
125 unload_iframe(frame); | |
126 service_worker_unregister_and_done(t, scope); | |
127 }) | |
128 .catch(unreached_rejection(t)); | |
129 }, 'ready after unregistration'); | |
71 | 130 |
horo
2014/09/10 08:57:53
could you please add test for
register(script1.j
nhiroki
2014/09/11 08:16:36
Hmmm... I wrote such tests and they showed unexpec
| |
72 // FIXME: When replace() is implemented add a test that .ready is | 131 // FIXME: When replace() is implemented add a test that .ready is |
73 // repeatedly created and settled. | 132 // repeatedly created and settled. |
74 </script> | 133 </script> |
OLD | NEW |