| 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() { |
| 73 return frame.contentWindow.navigator.serviceWorker.ready; |
| 74 }) |
| 75 .then(function(registration) { |
| 76 assert_equals(registration.installing, null, |
| 77 'installing should be null'); |
| 78 assert_equals(registration.waiting, null, |
| 79 'waiting should be null.') |
| 80 assert_equals(registration.active.scriptURL, expected_url, |
| 81 'active after ready should not be null'); |
| 82 assert_equals(frame.contentWindow.navigator.serviceWorker.controller, |
| 83 null, |
| 84 'uncontrolled document should not have a controller'); |
| 85 |
| 86 unload_iframe(frame); |
| 87 service_worker_unregister_and_done(t, scope); |
| 88 }) |
| 89 .catch(unreached_rejection(t)); |
| 90 }, 'ready on a potential controlled document'); |
| 91 |
| 92 async_test(function(t) { |
| 93 var url = 'resources/empty-worker.js'; |
| 94 var scope = 'resources/blank.html?ready-after-unregister'; |
| 95 var expected_url = normalizeURL(url); |
| 96 var frame; |
| 97 |
| 98 service_worker_unregister_and_register(t, url, scope) |
| 99 .then(function(registration) { |
| 100 return wait_for_activated(t, registration); |
| 101 }) |
| 102 .then(function() { return with_iframe(scope); }) |
| 103 .then(function(f) { |
| 104 frame = f; |
| 105 return navigator.serviceWorker.unregister(scope); |
| 106 }) |
| 107 .then(function() { |
| 108 return frame.contentWindow.navigator.serviceWorker.ready; |
| 109 }) |
| 110 .then(function(registration) { |
| 111 assert_equals(registration.installing, null, |
| 112 'installing should be null'); |
| 113 assert_equals(registration.waiting, null, |
| 114 'waiting should be null'); |
| 115 assert_equals(registration.active.scriptURL, expected_url, |
| 116 'active after ready should not be null'); |
| 117 assert_equals( |
| 118 frame.contentWindow.navigator.serviceWorker.controller.scriptURL, |
| 119 expected_url, |
| 120 'controlled document should have a controller'); |
| 121 |
| 122 unload_iframe(frame); |
| 123 service_worker_unregister_and_done(t, scope); |
| 124 }) |
| 125 .catch(unreached_rejection(t)); |
| 126 }, 'ready after unregistration'); |
| 71 | 127 |
| 72 // FIXME: When replace() is implemented add a test that .ready is | 128 // FIXME: When replace() is implemented add a test that .ready is |
| 73 // repeatedly created and settled. | 129 // repeatedly created and settled. |
| 74 </script> | 130 </script> |
| OLD | NEW |