update-bytecheck.https.html (3583B)
1 <!doctype html> 2 <meta charset=utf-8> 3 <title></title> 4 <meta name="timeout" content="long"> 5 <script src="/resources/testharness.js"></script> 6 <script src="resources/testharness-helpers.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 <script src="resources/test-helpers.sub.js"></script> 9 <script src="/common/get-host-info.sub.js"></script> 10 <script> 11 // Tests of updating a service worker. This file contains non-cors cases only. 12 13 /* 14 * @param string main 15 * Decide the content of the main script, where 'default' is for constant 16 * content while 'time' is for time-variant content. 17 * @param string imported 18 * Decide the content of the imported script, where 'default' is for constant 19 * content while 'time' is for time-variant content. 20 */ 21 const settings = [{main: 'default', imported: 'default'}, 22 {main: 'default', imported: 'time' }, 23 {main: 'time', imported: 'default'}, 24 {main: 'time', imported: 'time' }]; 25 26 const host_info = get_host_info(); 27 settings.forEach(({main, imported}) => { 28 promise_test(async (t) => { 29 // Empty path results in the same origin imported scripts. 30 const path = ''; 31 const script = 'resources/bytecheck-worker.py' + 32 '?main=' + main + 33 '&imported=' + imported + 34 '&path=' + path + 35 '&type=classic'; 36 const scope = 'resources/blank.html'; 37 38 // Register a service worker. 39 const swr = await service_worker_unregister_and_register(t, script, scope); 40 t.add_cleanup(() => swr.unregister()); 41 const sw = await wait_for_update(t, swr); 42 await wait_for_state(t, sw, 'activated'); 43 assert_array_equals([swr.active, swr.waiting, swr.installing], 44 [sw, null, null]); 45 46 // Update the service worker registration. 47 await swr.update(); 48 49 // If there should be a new service worker. 50 if (main === 'time' || imported === 'time') { 51 return wait_for_update(t, swr); 52 } 53 // Otherwise, make sure there is no newly created service worker. 54 assert_array_equals([swr.active, swr.waiting, swr.installing], 55 [sw, null, null]); 56 }, `Test(main: ${main}, imported: ${imported})`); 57 }); 58 59 settings.forEach(({main, imported}) => { 60 promise_test(async (t) => { 61 // Empty path results in the same origin imported scripts. 62 const path = './'; 63 const script = 'resources/bytecheck-worker.py' + 64 '?main=' + main + 65 '&imported=' + imported + 66 '&path=' + path + 67 '&type=module'; 68 const scope = 'resources/blank.html'; 69 70 // Register a module service worker. 71 const swr = await service_worker_unregister_and_register(t, script, scope, 72 {type: 'module'}); 73 74 t.add_cleanup(() => swr.unregister()); 75 const sw = await wait_for_update(t, swr); 76 await wait_for_state(t, sw, 'activated'); 77 assert_array_equals([swr.active, swr.waiting, swr.installing], 78 [sw, null, null]); 79 80 // Update the service worker registration. 81 await swr.update(); 82 83 // If there should be a new service worker. 84 if (main === 'time' || imported === 'time') { 85 return wait_for_update(t, swr); 86 } 87 // Otherwise, make sure there is no newly created service worker. 88 assert_array_equals([swr.active, swr.waiting, swr.installing], 89 [sw, null, null]); 90 }, `Test module script(main: ${main}, imported: ${imported})`); 91 }); 92 </script>