Chromium Code Reviews| Index: LayoutTests/http/tests/serviceworker/ready.html |
| diff --git a/LayoutTests/http/tests/serviceworker/ready.html b/LayoutTests/http/tests/serviceworker/ready.html |
| index 05da69921881ae34916e4073f538d8e17b2e80b6..c8026a7a38f59c84bf9e774a110a3b1c5639941e 100644 |
| --- a/LayoutTests/http/tests/serviceworker/ready.html |
| +++ b/LayoutTests/http/tests/serviceworker/ready.html |
| @@ -20,54 +20,113 @@ async_test(function(t) { |
| frame.contentWindow.Promise.prototype, |
| 'the Promise should be in the context of the ' + |
| 'related document'); |
| - frame.remove(); |
| + unload_iframe(frame); |
| t.done(); |
| })); |
| }, 'ready returns a Promise object in the context of the related document'); |
| async_test(function(t) { |
| var url = 'resources/empty-worker.js'; |
| - var scope = 'resources/blank.html?ready-active'; |
| + var scope = 'resources/blank.html?ready-controlled'; |
| + var expected_url = normalizeURL(url); |
| var frame; |
| - var registered_service_worker; |
| service_worker_unregister_and_register(t, url, scope) |
| - .then(t.step_func(function(registration) { |
| - return wait_for_update(t, registration); |
| - })) |
| - .then(t.step_func(function(service_worker) { |
| - registered_service_worker = service_worker; |
| - return wait_for_state(t, service_worker, 'activating'); |
| - })) |
| - .then(t.step_func(function() { |
| - return with_iframe(scope); |
| - })) |
| - .then(t.step_func(function(f) { |
| + .then(function(registration) { |
| + return wait_for_activated(t, registration); |
| + }) |
| + .then(function() { return with_iframe(scope); }) |
| + .then(function(f) { |
| frame = f; |
| return frame.contentWindow.navigator.serviceWorker.ready; |
| - })) |
| - .then(t.step_func(function(service_worker) { |
| - assert_equals(service_worker, |
| - frame.contentWindow.navigator.serviceWorker.active, |
| - 'ready should resolve to the active ServiceWorker'); |
| - assert_equals(Object.getPrototypeOf(service_worker), |
| - frame.contentWindow.ServiceWorker.prototype, |
| - 'the prototype of the ServiceWorker from ready ' + |
| - 'should be from the ServiceWorkerContainer\'s ' + |
| - 'context'); |
| - assert_equals(Object.getPrototypeOf(registered_service_worker), |
| - ServiceWorker.prototype, |
| - 'the prototype of the ServiceWorker from register ' + |
| - 'should be from the registering context'); |
| - // This is a logical consequence of the different prototypes |
| - assert_not_equals(service_worker, registered_service_worker, |
| - 'ready should resolve to a different ' + |
| - 'ServiceWorker than register because of ' + |
| - 'different prototypes'); |
| - frame.remove(); |
| + }) |
| + .then(function(registration) { |
| + assert_equals(registration.installing, null, |
| + 'installing should be null'); |
| + assert_equals(registration.waiting, null, |
| + 'waiting should be null'); |
| + assert_equals(registration.active.scriptURL, expected_url, |
| + 'active after ready should not be null'); |
| + assert_equals( |
| + frame.contentWindow.navigator.serviceWorker.controller.scriptURL, |
| + expected_url, |
| + 'controlled document should have a controller'); |
| + |
| + unload_iframe(frame); |
| service_worker_unregister_and_done(t, scope); |
| - })); |
| - }, 'ready resolves to active'); |
| + }) |
| + .catch(unreached_rejection(t)); |
| + }, 'ready on a controlled document'); |
| + |
| +async_test(function(t) { |
| + var url = 'resources/empty-worker.js'; |
| + var scope = 'resources/blank.html?ready-potential-controlled'; |
| + var expected_url = normalizeURL(url); |
| + var frame; |
| + |
| + with_iframe(scope) |
| + .then(function(f) { |
| + frame = f; |
| + return navigator.serviceWorker.register(url, {scope:scope}); |
| + }) |
| + .then(function(registration) { |
| + 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.
|
| + }) |
| + .then(function() { |
| + return frame.contentWindow.navigator.serviceWorker.ready; |
| + }) |
| + .then(function(registration) { |
| + assert_equals(registration.installing, null, |
| + 'installing should be null'); |
| + assert_equals(registration.waiting, null, |
| + 'waiting should be null.') |
| + assert_equals(registration.active.scriptURL, expected_url, |
| + 'active after ready should not be null'); |
| + assert_equals(frame.contentWindow.navigator.serviceWorker.controller, |
| + null, |
| + 'uncontrolled document should not have a controller'); |
| + |
| + unload_iframe(frame); |
| + service_worker_unregister_and_done(t, scope); |
| + }) |
| + .catch(unreached_rejection(t)); |
| + }, 'ready on a potential controlled document'); |
| + |
| +async_test(function(t) { |
| + var url = 'resources/empty-worker.js'; |
| + var scope = 'resources/blank.html?ready-after-unregister'; |
| + var expected_url = normalizeURL(url); |
| + var frame; |
| + |
| + service_worker_unregister_and_register(t, url, scope) |
| + .then(function(registration) { |
| + return wait_for_activated(t, registration); |
| + }) |
| + .then(function() { return with_iframe(scope); }) |
| + .then(function(f) { |
| + frame = f; |
| + return navigator.serviceWorker.unregister(scope); |
| + }) |
| + .then(function() { |
| + return frame.contentWindow.navigator.serviceWorker.ready; |
| + }) |
| + .then(function(registration) { |
| + assert_equals(registration.installing, null, |
| + 'installing should be null'); |
| + assert_equals(registration.waiting, null, |
| + 'waiting should be null'); |
| + assert_equals(registration.active.scriptURL, expected_url, |
| + 'active after ready should not be null'); |
| + assert_equals( |
| + frame.contentWindow.navigator.serviceWorker.controller.scriptURL, |
| + expected_url, |
| + 'controlled document should have a controller'); |
| + |
| + unload_iframe(frame); |
| + service_worker_unregister_and_done(t, scope); |
| + }) |
| + .catch(unreached_rejection(t)); |
| + }, 'ready after unregistration'); |
|
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
|
| // FIXME: When replace() is implemented add a test that .ready is |
| // repeatedly created and settled. |