static-router-request-method.https.html (2790B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title> 4 Static Router: routers are evaluated with the request method condition. 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 ROUTER_KEY_MEHOD_GET = 'condition-request-method-get-network'; 16 const ROUTER_KEY_MEHOD_POST = 'condition-request-method-post-network'; 17 const ROUTER_KEY_MEHOD_PUT = 'condition-request-method-put-network'; 18 const ROUTER_KEY_MEHOD_DELETE = 'condition-request-method-delete-network'; 19 const REQUET_SRC = 'resources/direct.py'; 20 21 iframeTest(REQUET_SRC, ROUTER_KEY_MEHOD_GET, async (t, iwin, worker) => { 22 const rnd = randomString(); 23 const response = await iwin.fetch('?nonce=' + rnd); 24 assert_equals(await response.text(), "Network with GET request"); 25 const {requests} = await get_info_from_worker(worker); 26 assert_equals(requests.length, 0); 27 }, 'Subresource load matched with the requestMethod GET condition'); 28 29 iframeTest(REQUET_SRC, ROUTER_KEY_MEHOD_POST, async (t, iwin, worker) => { 30 const rnd = randomString(); 31 const response = await iwin.fetch('?nonce=' + rnd, {method: 'POST'}); 32 assert_equals(await response.text(), "Network with POST request"); 33 const {requests} = await get_info_from_worker(worker); 34 // The navigation request is the only request handled by fetch handler. 35 assert_equals(requests.length, 1); 36 assert_equals(requests[0].mode, 'navigate'); 37 }, 'Subresource load matched with the requestMethod POST condition'); 38 39 iframeTest(REQUET_SRC, ROUTER_KEY_MEHOD_PUT, async (t, iwin, worker) => { 40 const rnd = randomString(); 41 const response = await iwin.fetch('?nonce=' + rnd, {method: 'PUT'}); 42 assert_equals(await response.text(), "Network with PUT request"); 43 const {requests} = await get_info_from_worker(worker); 44 // The navigation request is the only request handled by fetch handler. 45 assert_equals(requests.length, 1); 46 assert_equals(requests[0].mode, 'navigate'); 47 }, 'Subresource load matched with the requestMethod PUT condition'); 48 49 iframeTest(REQUET_SRC, ROUTER_KEY_MEHOD_DELETE, async (t, iwin, worker) => { 50 const rnd = randomString(); 51 const response = await iwin.fetch('?nonce=' + rnd, {method: 'DELETE'}); 52 assert_equals(await response.text(), "Network with DELETE request"); 53 const {requests} = await get_info_from_worker(worker); 54 // The navigation request is the only request handled by fetch handler. 55 assert_equals(requests.length, 1); 56 assert_equals(requests[0].mode, 'navigate'); 57 }, 'Subresource load matched with the requestMethod DELETE condition'); 58 </script> 59 </body>