File: dictionary-registration.tentative.https.html

package info (click to toggle)
firefox 144.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,637,504 kB
  • sloc: cpp: 7,576,692; javascript: 6,430,831; ansic: 3,748,119; python: 1,398,978; xml: 628,810; asm: 438,679; java: 186,194; sh: 63,212; makefile: 19,159; objc: 13,086; perl: 12,986; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 53; csh: 10
file content (107 lines) | stat: -rw-r--r-- 4,975 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<meta name="timeout" content="long"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/common/utils.js"></script>
<script src="./resources/compression-dictionary-util.sub.js"></script>
</head>
<body>
<script>

compression_dictionary_promise_test(async (t) => {
  const dict = await (await fetch(kRegisterDictionaryPath)).text();
  assert_equals(dict, kDefaultDictionaryContent);
  // Wait until `available-dictionary` header is available.
  assert_equals(
      await waitUntilAvailableDictionaryHeader(t, {}),
      kDefaultDictionaryHashBase64);
}, 'Simple dictionary registration and unregistration');

compression_dictionary_promise_test(async (t) => {
  const dict = await (await fetch(`${kRegisterDictionaryPath}?id=test`)).text();
  // Wait until `available-dictionary` header is available.
  assert_equals(
      await waitUntilAvailableDictionaryHeader(t, {}),
      kDefaultDictionaryHashBase64);
  assert_equals(await checkHeader('dictionary-id', {}), '"test"');
}, 'Dictionary registration with dictionary ID');

compression_dictionary_promise_test(async (t) => {
  // Registers a first dictionary.
  const dictionary_path1 = `${kRegisterDictionaryPath}?id=id1`;
  const dict1 = await (await fetch(dictionary_path1)).text();
  // Wait until `available-dictionary` header is available.
  assert_equals(
      await waitUntilAvailableDictionaryHeader(t, {}),
      kDefaultDictionaryHashBase64);
  // Check the `dictionary-id` header.
  assert_equals(await checkHeader('dictionary-id', {}), '"id1"');

  // Registers a second dictionary.
  const kAlternativeDictionaryContent =
      'This is an alternative test dictionary.';
  const dictionary_path2 =
      `${kRegisterDictionaryPath}?content=${kAlternativeDictionaryContent}&id=id2`;
  const expected_dictionary_header =
      await calculateDictionaryHash(kAlternativeDictionaryContent);
  const dict2 = await (await fetch(dictionary_path2)).text();
  assert_equals(dict2, kAlternativeDictionaryContent);
  // Wait until `available-dictionary` header is available.
  // Note: Passing `expected_header` to ignore the old dictionary.
  assert_equals(
      await waitUntilAvailableDictionaryHeader(
          t, {expected_header: expected_dictionary_header}),
      expected_dictionary_header);
  // Check the `dictionary-id` header.
  assert_equals(await checkHeader('dictionary-id', {}), '"id2"');
}, 'New dictionary registration overrides the existing one');

compression_dictionary_promise_test(async (t) => {
  // Dictionary responses often include
  // Vary: available-dictionary, accept-encoding
  // We need to make sure that the browser cache does not actually vary
  // based on those headers, otherwise a resource that uses itself as a
  // dictionary would trigger a second fetch of the same resource.
  const dictionaryUrl = `${SAME_ORIGIN_RESOURCES_URL}/register-dictionary.py?id=cache`;
  const dict = await (await fetch(dictionaryUrl)).text();
  assert_equals(dict, kDefaultDictionaryContent);
  // Wait until `available-dictionary` header is available.
  assert_equals(
      await waitUntilAvailableDictionaryHeader(t, {}),
      kDefaultDictionaryHashBase64);

  // re-fetch the dictionary (should come from cache)
  const dict2 = await (await fetch(dictionaryUrl)).text();
  assert_equals(dict2, kDefaultDictionaryContent);

  const entries = performance.getEntriesByName(dictionaryUrl);
  assert_equals(entries.length, 2);
  assert_not_equals(entries[0].transferSize, 0);
  assert_equals(entries[1].transferSize, 0);
}, 'Dictionary registration does not invalidate cache entry');

compression_dictionary_promise_test(async (t) => {
  // Register a dictionary that has already expired (age > max-age).
  // Make sure it is on a path separate from another dictionary so they can
  // be checked independently.
  const pattern = "%2Ffetch%2Fcompression-dictionary%2Fresources%2Fecho-headers.py";
  await fetch(`${kRegisterDictionaryPath}?id=id1&age=7200&max-age=3600&match=${pattern}`);
  // register another dictionary that we can use to tell when the first
  // dictionary should also be registered (since the first dictionary
  // should not send any headers that can be detected directly).
  const pattern2 = "%2Ffetch%2Fcompression-dictionary%2Fresources%2Fecho-headers2.py";
  await fetch(`${kRegisterDictionaryPath}?id=id2&match=${pattern2}`);
  assert_equals(
      await waitUntilAvailableDictionaryHeader(t, {use_alt_path: true}),
      kDefaultDictionaryHashBase64);
  assert_equals((await checkHeaders({use_alt_path: true}))['dictionary-id'], '"id2"');
  // Make sure the expired dictionary isn't announced as being available.
  const headers = await (await fetch('./resources/echo-headers.py')).json();
  assert_false("available-dictionary" in headers);
}, 'Expired dictionary is not used');

</script>
</body>