static-router-no-fetch-handler.https.html (2286B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title> 4 Static Router: routers are evaluated when there is no fetch handler. 5 </title> 6 <script src="/common/get-host-info.sub.js"></script> 7 <script src="/resources/testharness.js"></script> 8 <script src="/resources/testharnessreport.js"></script> 9 <script src="/service-workers/service-worker/resources/test-helpers.sub.js"> 10 </script> 11 <script src="resources/static-router-helpers.sub.js"> 12 </script> 13 <body> 14 <script> 15 const RULE_KEY_SOURCE_CACHE = 'condition-urlpattern-string-source-cache'; 16 const RULE_KEY_SOURCE_FETCH_EVENT = 17 'condition-request-source-fetch-event'; 18 const RULE_KEY_SOURCE_RACE_NETWORK_AND_FETCH_HANDLER = 19 'condition-urlpattern-string-source-race-network-and-fetch-handler'; 20 const SW_SRC = 'resources/static-router-no-fetch-handler-sw.js'; 21 const CACHED_FILE = 'cache.txt'; 22 23 promise_test(async t => { 24 const worker = await registerAndActivate(t, RULE_KEY_SOURCE_CACHE, SW_SRC); 25 26 // Matched with the main reosurce load. 27 const {contentWindow} = await createIframe(t, `resources/${CACHED_FILE}`); 28 assert_equals(contentWindow.document.body.innerText, "From cache"); 29 30 // Matched with the subreosurce load. 31 const response = await contentWindow.fetch(CACHED_FILE); 32 assert_equals(response.status, 200); 33 assert_equals(await response.text(), "From cache"); 34 35 // Both requests are served from cache. 36 const {requests} = await get_info_from_worker(worker); 37 assert_equals(requests.length, 0); 38 }, 'The router rule is evaluated without fetch handlers in service worker'); 39 40 promise_test(async t => { 41 const worker = 42 await registerAndActivate(t, RULE_KEY_SOURCE_FETCH_EVENT, SW_SRC); 43 t.add_cleanup(() => {reset_info_in_worker(worker)}); 44 45 const {errors} = await get_info_from_worker(worker); 46 assert_equals(errors.length, 1); 47 }, 'addRoutes should raise if the fetch-event source is used without onfetch') 48 49 promise_test(async t => { 50 const worker = 51 await registerAndActivate(t, 52 RULE_KEY_SOURCE_RACE_NETWORK_AND_FETCH_HANDLER, SW_SRC); 53 t.add_cleanup(() => {reset_info_in_worker(worker)}); 54 55 const {errors} = await get_info_from_worker(worker); 56 assert_equals(errors.length, 1); 57 }, 'addRoutes should raise if the race-network-and-fetch-handler source is used without onfetch') 58 59 </script> 60 </body>