tor-browser

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

dictionary-registration.tentative.https.html (4975B)


      1 <!DOCTYPE html>
      2 <head>
      3 <meta charset="utf-8">
      4 <meta name="timeout" content="long"/>
      5 <script src="/resources/testharness.js"></script>
      6 <script src="/resources/testharnessreport.js"></script>
      7 <script src="/common/get-host-info.sub.js"></script>
      8 <script src="/common/utils.js"></script>
      9 <script src="./resources/compression-dictionary-util.sub.js"></script>
     10 </head>
     11 <body>
     12 <script>
     13 
     14 compression_dictionary_promise_test(async (t) => {
     15  const dict = await (await fetch(kRegisterDictionaryPath)).text();
     16  assert_equals(dict, kDefaultDictionaryContent);
     17  // Wait until `available-dictionary` header is available.
     18  assert_equals(
     19      await waitUntilAvailableDictionaryHeader(t, {}),
     20      kDefaultDictionaryHashBase64);
     21 }, 'Simple dictionary registration and unregistration');
     22 
     23 compression_dictionary_promise_test(async (t) => {
     24  const dict = await (await fetch(`${kRegisterDictionaryPath}?id=test`)).text();
     25  // Wait until `available-dictionary` header is available.
     26  assert_equals(
     27      await waitUntilAvailableDictionaryHeader(t, {}),
     28      kDefaultDictionaryHashBase64);
     29  assert_equals(await checkHeader('dictionary-id', {}), '"test"');
     30 }, 'Dictionary registration with dictionary ID');
     31 
     32 compression_dictionary_promise_test(async (t) => {
     33  // Registers a first dictionary.
     34  const dictionary_path1 = `${kRegisterDictionaryPath}?id=id1`;
     35  const dict1 = await (await fetch(dictionary_path1)).text();
     36  // Wait until `available-dictionary` header is available.
     37  assert_equals(
     38      await waitUntilAvailableDictionaryHeader(t, {}),
     39      kDefaultDictionaryHashBase64);
     40  // Check the `dictionary-id` header.
     41  assert_equals(await checkHeader('dictionary-id', {}), '"id1"');
     42 
     43  // Registers a second dictionary.
     44  const kAlternativeDictionaryContent =
     45      'This is an alternative test dictionary.';
     46  const dictionary_path2 =
     47      `${kRegisterDictionaryPath}?content=${kAlternativeDictionaryContent}&id=id2`;
     48  const expected_dictionary_header =
     49      await calculateDictionaryHash(kAlternativeDictionaryContent);
     50  const dict2 = await (await fetch(dictionary_path2)).text();
     51  assert_equals(dict2, kAlternativeDictionaryContent);
     52  // Wait until `available-dictionary` header is available.
     53  // Note: Passing `expected_header` to ignore the old dictionary.
     54  assert_equals(
     55      await waitUntilAvailableDictionaryHeader(
     56          t, {expected_header: expected_dictionary_header}),
     57      expected_dictionary_header);
     58  // Check the `dictionary-id` header.
     59  assert_equals(await checkHeader('dictionary-id', {}), '"id2"');
     60 }, 'New dictionary registration overrides the existing one');
     61 
     62 compression_dictionary_promise_test(async (t) => {
     63  // Dictionary responses often include
     64  // Vary: available-dictionary, accept-encoding
     65  // We need to make sure that the browser cache does not actually vary
     66  // based on those headers, otherwise a resource that uses itself as a
     67  // dictionary would trigger a second fetch of the same resource.
     68  const dictionaryUrl = `${SAME_ORIGIN_RESOURCES_URL}/register-dictionary.py?id=cache`;
     69  const dict = await (await fetch(dictionaryUrl)).text();
     70  assert_equals(dict, kDefaultDictionaryContent);
     71  // Wait until `available-dictionary` header is available.
     72  assert_equals(
     73      await waitUntilAvailableDictionaryHeader(t, {}),
     74      kDefaultDictionaryHashBase64);
     75 
     76  // re-fetch the dictionary (should come from cache)
     77  const dict2 = await (await fetch(dictionaryUrl)).text();
     78  assert_equals(dict2, kDefaultDictionaryContent);
     79 
     80  const entries = performance.getEntriesByName(dictionaryUrl);
     81  assert_equals(entries.length, 2);
     82  assert_not_equals(entries[0].transferSize, 0);
     83  assert_equals(entries[1].transferSize, 0);
     84 }, 'Dictionary registration does not invalidate cache entry');
     85 
     86 compression_dictionary_promise_test(async (t) => {
     87  // Register a dictionary that has already expired (age > max-age).
     88  // Make sure it is on a path separate from another dictionary so they can
     89  // be checked independently.
     90  const pattern = "%2Ffetch%2Fcompression-dictionary%2Fresources%2Fecho-headers.py";
     91  await fetch(`${kRegisterDictionaryPath}?id=id1&age=7200&max-age=3600&match=${pattern}`);
     92  // register another dictionary that we can use to tell when the first
     93  // dictionary should also be registered (since the first dictionary
     94  // should not send any headers that can be detected directly).
     95  const pattern2 = "%2Ffetch%2Fcompression-dictionary%2Fresources%2Fecho-headers2.py";
     96  await fetch(`${kRegisterDictionaryPath}?id=id2&match=${pattern2}`);
     97  assert_equals(
     98      await waitUntilAvailableDictionaryHeader(t, {use_alt_path: true}),
     99      kDefaultDictionaryHashBase64);
    100  assert_equals((await checkHeaders({use_alt_path: true}))['dictionary-id'], '"id2"');
    101  // Make sure the expired dictionary isn't announced as being available.
    102  const headers = await (await fetch('./resources/echo-headers.py')).json();
    103  assert_false("available-dictionary" in headers);
    104 }, 'Expired dictionary is not used');
    105 
    106 </script>
    107 </body>