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..d3668864e87250cf35877453ff16f0603d0c73a6 100644 |
--- a/LayoutTests/http/tests/serviceworker/ready.html |
+++ b/LayoutTests/http/tests/serviceworker/ready.html |
@@ -20,54 +20,110 @@ 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() { |
+ 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'); |
// FIXME: When replace() is implemented add a test that .ready is |
// repeatedly created and settled. |