tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

static-router-main-resource.https.html (4415B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <title>
      4  Static Router: simply skip fetch handler for main resource if pattern matches
      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="resources/test-helpers.sub.js"></script>
     10 <script src="resources/static-router-helpers.sub.js"></script>
     11 <body>
     12 <script>
     13 const ROUTER_RULE_KEY = 'condition-urlpattern-constructed-source-network';
     14 const ROUTER_RULE_NOT_KEY = 'condition-urlpattern-not-source-network';
     15 const ROUTER_RULE_KEY_IGNORE_CASE =
     16  'condition-urlpattern-constructed-ignore-case-source-network';
     17 const ROUTER_RULE_KEY_RESPECT_CASE =
     18  'condition-urlpattern-constructed-respect-case-source-network';
     19 const ROUTER_RULE_KEY_URLPATTERN_CACHE =
     20  'condition-urlpattern-string-source-cache';
     21 const ROUTER_RULE_KEY_REQUEST_CACHE = 'condition-request-navigate-source-cache';
     22 const ROUTER_RULE_KEY_URLPATTERN_CACHE_WITH_NAME =
     23  'condition-urlpattern-string-source-cache-with-name';
     24 const REGISTERED_ROUTE = 'resources/direct.txt';
     25 const CACHED_ROUTE = 'resources/cache.txt';
     26 const NON_REGISTERED_ROUTE = 'resources/simple.html';
     27 const NOT_ROUTE = 'resources/not.txt';
     28 const host_info = get_host_info();
     29 const path = new URL(".", window.location).pathname;
     30 
     31 iframeTest(REGISTERED_ROUTE, ROUTER_RULE_KEY, async (t, iwin, worker) => {
     32  const {requests} = await get_info_from_worker(worker);
     33  assert_equals(requests.length, 0);
     34  assert_equals(iwin.document.body.innerText, "Network\n");
     35 }, 'Main resource load matched with the condition');
     36 
     37 iframeTest(REGISTERED_ROUTE, ROUTER_RULE_KEY_IGNORE_CASE, async (t, iwin, worker) => {
     38  const {requests} = await get_info_from_worker(worker);
     39  assert_equals(requests.length, 0);
     40  assert_equals(iwin.document.body.innerText, "Network\n");
     41 }, 'Main resource load matched with the ignore case condition');
     42 
     43 iframeTest(REGISTERED_ROUTE, ROUTER_RULE_KEY_RESPECT_CASE, async (t, iwin, worker) => {
     44  const {requests} = await get_info_from_worker(worker);
     45  assert_equals(requests.length, 1);
     46 }, 'Main resource load matched without the ignore case condition');
     47 
     48 iframeTest(NON_REGISTERED_ROUTE, ROUTER_RULE_KEY, async (t, iwin, worker) => {
     49  const {requests} = await get_info_from_worker(worker);
     50  assert_equals(requests.length, 1);
     51  assert_equals(
     52    requests[0].url,
     53    `${host_info['HTTPS_ORIGIN']}${path}${NON_REGISTERED_ROUTE}`);
     54  assert_equals(requests[0].mode, 'navigate');
     55 }, 'Main resource load not matched with the condition');
     56 
     57 iframeTest(CACHED_ROUTE, ROUTER_RULE_KEY_URLPATTERN_CACHE, async (t, iwin, worker) => {
     58  const {requests} = await get_info_from_worker(worker);
     59  assert_equals(requests.length, 0);
     60  assert_equals(iwin.document.body.innerText, "From cache");
     61 }, 'Main resource load matched with the cache source');
     62 
     63 iframeTest(NON_REGISTERED_ROUTE, ROUTER_RULE_KEY_REQUEST_CACHE, async (t, iwin, worker) => {
     64  const {requests} = await get_info_from_worker(worker);
     65  // When the request matched to the rule with the "cache" source but failed to
     66  // get the cache entry, the fetch handler is not involved and the network
     67  // fallback is triggered instead.
     68  assert_equals(requests.length, 0);
     69  assert_equals(iwin.document.body.innerText, "Here's a simple html file.");
     70 }, 'Main resource fallback to the network when there is no cache entry');
     71 
     72 iframeTest(CACHED_ROUTE, ROUTER_RULE_KEY_URLPATTERN_CACHE_WITH_NAME, async (t, iwin, worker) => {
     73  const {requests} = await get_info_from_worker(worker);
     74  assert_equals(requests.length, 0);
     75  assert_equals(iwin.document.body.innerText, "From cache");
     76 }, 'Main resource load matched with the cache source, with specifying the cache name');
     77 
     78 iframeTest(NOT_ROUTE, ROUTER_RULE_NOT_KEY, async (t, iwin, worker) => {
     79  const {requests} = await get_info_from_worker(worker);
     80  assert_equals(requests.length, 1);
     81  assert_equals(
     82    requests[0].url,
     83    `${host_info['HTTPS_ORIGIN']}${path}${NOT_ROUTE}`);
     84  assert_equals(requests[0].mode, 'navigate');
     85 }, 'Main resource load should not match the condition with not');
     86 
     87 iframeTest(REGISTERED_ROUTE, ROUTER_RULE_NOT_KEY, async (t, iwin, worker) => {
     88  const {requests} = await get_info_from_worker(worker);
     89  assert_equals(requests.length, 0);
     90  assert_equals(iwin.document.body.innerText, "Network\n");
     91 }, 'Main resource load should match the condition without not');
     92 </script>
     93 </body>