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, |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
84 'uncontrolled document should not have a controller'); | 84 'uncontrolled document should not have a controller'); |
85 | 85 |
86 unload_iframe(frame); | 86 unload_iframe(frame); |
87 service_worker_unregister_and_done(t, scope); | 87 service_worker_unregister_and_done(t, scope); |
88 }) | 88 }) |
89 .catch(unreached_rejection(t)); | 89 .catch(unreached_rejection(t)); |
90 }, 'ready on a potential controlled document'); | 90 }, 'ready on a potential controlled document'); |
91 | 91 |
92 async_test(function(t) { | 92 async_test(function(t) { |
93 var url = 'resources/empty-worker.js'; | 93 var url = 'resources/empty-worker.js'; |
94 var scope = 'resources/blank.html?ready-after-unregister'; | 94 var matched_scope = 'resources/blank.html?ready-after-match'; |
95 var expected_url = normalizeURL(url); | 95 var better_matched_scope = 'resources/blank.html?ready-after-match-better'; |
96 var frame; | 96 var frame, registration; |
97 var registration; | |
98 | 97 |
99 service_worker_unregister_and_register(t, url, scope) | 98 with_iframe(better_matched_scope) |
dominicc (has gone to gerrit)
2015/02/16 07:19:22
Shouldn't all tests start with this, in case a tes
falken
2015/02/16 09:20:42
Yep
xiang
2015/02/26 08:50:33
Done.
| |
99 .then(function(f) { | |
100 frame = f; | |
101 return navigator.serviceWorker.register(url, {scope: matched_scope}); | |
102 }) | |
100 .then(function(r) { | 103 .then(function(r) { |
101 registration = r; | 104 registration = r; |
102 return wait_for_state(t, r.installing, 'activated'); | 105 return wait_for_state(t, r.installing, 'activated'); |
103 }) | 106 }) |
104 .then(function() { return with_iframe(scope); }) | 107 .then(function() { |
105 .then(function(f) { | 108 return navigator.serviceWorker.register( |
106 frame = f; | 109 url, {scope: better_matched_scope}); |
107 return registration.unregister(); | |
108 }) | 110 }) |
109 .then(function() { | 111 .then(function() { |
110 return frame.contentWindow.navigator.serviceWorker.ready; | 112 return frame.contentWindow.navigator.serviceWorker.ready; |
111 }) | 113 }) |
112 .then(function(registration) { | 114 .then(function(r) { |
113 assert_equals(registration.installing, null, | 115 assert_equals(r.scope, normalizeURL(better_matched_scope), |
114 'installing should be null'); | 116 'better matched registration should be returned'); |
115 assert_equals(registration.waiting, null, | 117 assert_equals(frame.contentWindow.navigator.serviceWorker.controller, |
116 'waiting should be null'); | 118 null, 'controller should be null'); |
117 assert_equals(registration.active.scriptURL, expected_url, | 119 return registration.unregister(); |
118 'active after ready should not be null'); | 120 }) |
119 assert_equals( | 121 .then(function() { |
120 frame.contentWindow.navigator.serviceWorker.controller.scriptURL, | |
121 expected_url, | |
122 'controlled document should have a controller'); | |
123 | |
124 unload_iframe(frame); | 122 unload_iframe(frame); |
125 service_worker_unregister_and_done(t, scope); | 123 return service_worker_unregister_and_done(t, better_matched_scope); |
126 }) | 124 }) |
127 .catch(unreached_rejection(t)); | 125 .catch(unreached_rejection(t)); |
128 }, 'ready after unregistration'); | 126 }, 'ready after a better matched registration registered'); |
129 | 127 |
130 // FIXME: When replace() is implemented add a test that .ready is | |
131 // repeatedly created and settled. | |
132 </script> | 128 </script> |
OLD | NEW |