Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!DOCTYPE html> | |
| 2 <title>Service Worker: Skip waiting</title> | |
| 3 <script src="../resources/testharness.js"></script> | |
| 4 <script src="../resources/testharnessreport.js"></script> | |
| 5 <script src="resources/test-helpers.js"></script> | |
| 6 <script> | |
| 7 | |
| 8 async_test(function(t) { | |
|
jsbell
2014/11/13 23:07:51
Can you use the service_worker_test() helper to re
xiang
2014/11/28 08:00:48
Thanks for the suggestion, I split them to smaller
| |
| 9 var scope = 'resources/skip-waiting-no-client'; | |
| 10 var url = 'resources/skip-waiting.js'; | |
| 11 function onMessage(e) { | |
| 12 var message = e.data; | |
|
jsbell
2014/11/13 23:07:51
Only need 2 more spaces of indent here (6 total)
| |
| 13 assert_equals(message, 'done', | |
| 14 'skipWaiting promise should be resolved'); | |
| 15 service_worker_unregister_and_done(t, scope); | |
| 16 } | |
| 17 service_worker_unregister_and_register(t, url, scope) | |
| 18 .then(function(registration) { | |
| 19 return wait_for_update(t, registration); | |
| 20 }) | |
| 21 .then(function(sw) { | |
| 22 var messageChannel = new MessageChannel(); | |
| 23 messageChannel.port1.onmessage = t.step_func(onMessage); | |
| 24 sw.postMessage({port: messageChannel.port2}, [messageChannel.port2]); | |
| 25 }) | |
| 26 .catch(unreached_rejection(t)); | |
| 27 }, 'Test skipWaiting when no client attached'); | |
| 28 | |
| 29 async_test(function(t) { | |
| 30 var scope = 'resources/multiple-skip-waiting'; | |
| 31 var url = 'resources/skip-waiting.js'; | |
| 32 function onMessage(e) { | |
| 33 var message = e.data; | |
| 34 assert_equals(message, 'done', | |
| 35 'multiple skipWaiting promises should be resolved'); | |
|
jsbell
2014/11/13 23:07:51
This message would be a lot clearer if it was in t
| |
| 36 service_worker_unregister_and_done(t, scope); | |
| 37 } | |
| 38 service_worker_unregister_and_register(t, url, scope) | |
| 39 .then(function(registration) { | |
| 40 return wait_for_update(t, registration); | |
| 41 }) | |
| 42 .then(function(sw) { | |
| 43 var messageChannel = new MessageChannel(); | |
| 44 messageChannel.port1.onmessage = t.step_func(onMessage); | |
| 45 sw.postMessage({port: messageChannel.port2}, [messageChannel.port2]); | |
| 46 }) | |
| 47 .catch(unreached_rejection(t)); | |
| 48 }, 'Test multiple skipWaiting be called'); | |
|
jsbell
2014/11/13 23:07:50
How about: 'skipWaiting() called multiple times' ?
| |
| 49 | |
| 50 async_test(function(t) { | |
| 51 var scope = 'resources/doctype.html'; | |
| 52 var url1 = 'resources/empty.js'; | |
| 53 var url2 = 'resources/skip-waiting.js'; | |
| 54 var iframeContainer; | |
| 55 function onControllerChanged() { | |
| 56 assert_equals( | |
| 57 iframeContainer.controller.scriptURL, normalizeURL(url2), | |
| 58 'Controller scriptURL should change to the second one'); | |
| 59 service_worker_unregister_and_done(t, scope); | |
| 60 } | |
| 61 service_worker_unregister_and_register(t, url1, scope) | |
| 62 .then(function(registration) { | |
| 63 return wait_for_update(t, registration); | |
| 64 }) | |
| 65 .then(function(sw) { | |
| 66 return wait_for_state(t, sw, 'activated'); | |
| 67 }) | |
| 68 .then(function() { | |
| 69 return with_iframe(scope); | |
| 70 }) | |
| 71 .then(function(frame) { | |
| 72 iframeContainer = frame.contentWindow.navigator.serviceWorker; | |
| 73 assert_equals( | |
| 74 iframeContainer.controller.scriptURL, normalizeURL(url1), | |
| 75 'Document controller scriptURL should equal to the first one'); | |
| 76 iframeContainer.oncontrollerchange = t.step_func(onControllerChanged); | |
| 77 return navigator.serviceWorker.register(url2, { scope : scope }); | |
|
jsbell
2014/11/13 23:07:50
Nit: no space after {, after :, or before } in obj
xiang
2014/11/28 08:00:48
Done.
| |
| 78 }) | |
| 79 .catch(unreached_rejection(t)); | |
| 80 }, 'Test skipWaiting while client is using registration'); | |
| 81 | |
| 82 async_test(function(t) { | |
| 83 var scope1 = 'resources/simple'; | |
| 84 var scope2 = 'resources/simple.html'; | |
| 85 var url1 = 'resources/empty.js'; | |
| 86 var url2 = 'resources/skip-waiting.js'; | |
| 87 var iframeContainer; | |
| 88 function onControllerChanged() { | |
| 89 assert_equals( | |
| 90 iframeContainer.controller.scriptURL, normalizeURL(url2), | |
| 91 'Controller scriptURL should change to the second one'); | |
| 92 service_worker_unregister_and_done(t, scope2); | |
| 93 } | |
| 94 | |
| 95 service_worker_unregister_and_register(t, url1, scope1) | |
| 96 .then(function(registration) { | |
| 97 return wait_for_update(t, registration); | |
| 98 }) | |
| 99 .then(function(sw) { | |
| 100 return wait_for_state(t, sw, 'activated'); | |
| 101 }) | |
| 102 .then(function() { | |
| 103 return with_iframe(scope2); | |
| 104 }) | |
| 105 .then(function(frame) { | |
| 106 iframeContainer = frame.contentWindow.navigator.serviceWorker; | |
| 107 assert_equals( | |
| 108 iframeContainer.controller.scriptURL, normalizeURL(url1), | |
| 109 'Document controller scriptURL should equal to the first one'); | |
| 110 iframeContainer.oncontrollerchange = t.step_func(onControllerChanged); | |
| 111 return navigator.serviceWorker.register(url2, { scope : scope2 }); | |
| 112 }) | |
| 113 .catch(unreached_rejection(t)); | |
| 114 }, 'Test skipWaiting when client is using different registration'); | |
| 115 | |
| 116 async_test(function(t) { | |
| 117 var scope = 'resources/blank.html'; | |
| 118 var url1 = 'resources/empty.js'; | |
| 119 var url2 = 'resources/skip-waiting.js'; | |
| 120 var iframeContainer, serviceWorker, onMessage, onControllerChanged; | |
| 121 var promise1 = new Promise(function(resolve) { | |
| 122 onMessage = function(e) { | |
| 123 var message = e.data; | |
| 124 assert_equals( | |
| 125 message, 'activating', | |
| 126 'skipWaiting promise should be resolved after activated'); | |
| 127 resolve(); | |
| 128 }; | |
| 129 }); | |
| 130 var promise2 = new Promise(function(resolve) { | |
| 131 onControllerChanged = function() { | |
| 132 assert_equals( | |
| 133 iframeContainer.controller.scriptURL, normalizeURL(url2), | |
| 134 'Controller scriptURL should change to the second one'); | |
| 135 resolve(); | |
| 136 }; | |
| 137 }); | |
| 138 service_worker_unregister_and_register(t, url1, scope) | |
| 139 .then(function(registration) { | |
| 140 return wait_for_update(t, registration); | |
| 141 }) | |
| 142 .then(function(sw) { | |
| 143 return wait_for_state(t, sw, 'activated'); | |
| 144 }) | |
| 145 .then(function() { | |
| 146 return with_iframe(scope); | |
| 147 }) | |
| 148 .then(function(frame) { | |
| 149 iframeContainer = frame.contentWindow.navigator.serviceWorker; | |
| 150 assert_equals( | |
| 151 iframeContainer.controller.scriptURL, normalizeURL(url1), | |
| 152 'Document controller scriptURL should equal to the first one'); | |
| 153 iframeContainer.oncontrollerchange = t.step_func(onControllerChanged); | |
| 154 return navigator.serviceWorker.register(url2, { scope : scope }); | |
| 155 }) | |
| 156 .then(function(registration) { | |
| 157 return wait_for_update(t, registration); | |
| 158 }) | |
| 159 .then(function(sw) { | |
| 160 serviceWorker = sw; | |
| 161 return wait_for_state(t, sw, 'installed'); | |
| 162 }) | |
| 163 .then(function() { | |
| 164 var messageChannel = new MessageChannel(); | |
| 165 messageChannel.port1.onmessage = t.step_func(onMessage); | |
| 166 serviceWorker.postMessage( | |
| 167 {port: messageChannel.port2}, [messageChannel.port2]); | |
| 168 return Promise.all([promise1, promise2]); | |
| 169 }) | |
| 170 .then(function() { | |
| 171 return service_worker_unregister_and_done(t, scope); | |
| 172 }) | |
| 173 .catch(unreached_rejection(t)); | |
| 174 }, 'Test skipWaiting when worker is waiting'); | |
| 175 | |
| 176 </script> | |
| OLD | NEW |