Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 3 subtest issues.
- This WPT test may be referenced by the following Test IDs:
- /fetch/compression-dictionary/dictionary-registration.tentative.https.html - WPT Dashboard Interop Dashboard
<!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}`);
await registerAltDictionaryAndWait(t);
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');
compression_dictionary_promise_test(async (t) => {
const pattern = "%7B";
await fetch(`${kRegisterDictionaryPath}?id=id1&match=${pattern}`);
await registerAltDictionaryAndWait(t);
const headers = await (await fetch('./resources/echo-headers.py')).json();
assert_false("available-dictionary" in headers);
}, 'Dictionary with invalid match string is not registered');
compression_dictionary_promise_test(async (t) => {
const pattern = encodeURIComponent(`${CROSS_ORIGIN_RESOURCES_URL}/echo-headers.py`);
await fetch(`${kRegisterDictionaryPath}?id=id1&match=${pattern}`);
await registerAltDictionaryAndWait(t);
const headers = await (await fetch('./resources/echo-headers.py')).json();
assert_false("available-dictionary" in headers);
}, 'Dictionary with match string for a different origin is not registered');
compression_dictionary_promise_test(async (t) => {
const pattern = "%2Ffetch%2Fcompression-dictionary%2Fresources%2Fecho-headers.py";
await fetch(`${kRegisterDictionaryPath}?id=id1&type=bogus&match=${pattern}`);
await registerAltDictionaryAndWait(t);
const headers = await (await fetch('./resources/echo-headers.py')).json();
assert_false("available-dictionary" in headers);
}, 'Dictionary with unsupported type is not registered');
compression_dictionary_promise_test(async (t) => {
const match_dest = encodeURIComponent('("asdf")');
const pattern = "%2Ffetch%2Fcompression-dictionary%2Fresources%2Fecho-headers.py";
await fetch(`${kRegisterDictionaryPath}?id=id1&match-dest=${match_dest}&match=${pattern}`);
await registerAltDictionaryAndWait(t);
const headers = await (await fetch('./resources/echo-headers.py')).json();
assert_false("available-dictionary" in headers);
}, 'Dictionary with unknown match-dest is not used for fetch() API');
compression_dictionary_promise_test(async (t) => {
const dictionary_id = 'a'.repeat(1024);
const dict = await (await fetch(`${kRegisterDictionaryPath}?id=${dictionary_id}`)).text();
assert_equals(
await waitUntilAvailableDictionaryHeader(t, {}),
kDefaultDictionaryHashBase64);
assert_equals(await checkHeader('dictionary-id', {}), `"${dictionary_id}"`);
}, 'Dictionary registration with 1024 character dictionary ID');
compression_dictionary_promise_test(async (t) => {
const dictionary_id = 'a'.repeat(1025);
const pattern = "%2Ffetch%2Fcompression-dictionary%2Fresources%2Fecho-headers.py";
await fetch(`${kRegisterDictionaryPath}?id=${dictionary_id}&match=${pattern}`);
await registerAltDictionaryAndWait(t);
const headers = await (await fetch('./resources/echo-headers.py')).json();
assert_false("available-dictionary" in headers);
}, 'Dictionary with 1025 character dictionary ID is not registered');
compression_dictionary_promise_test(async (t) => {
const extra_option = encodeURIComponent('unknown-option="some-value"');
const dict = await (await fetch(`${kRegisterDictionaryPath}?id=test&extra-header-option=${extra_option}`)).text();
assert_equals(
await waitUntilAvailableDictionaryHeader(t, {}),
kDefaultDictionaryHashBase64);
assert_equals(await checkHeader('dictionary-id', {}), '"test"');
}, 'Dictionary registration with unknown extra options succeeds');
compression_dictionary_promise_test(async (t) => {
const match_dest = encodeURIComponent('()');
const dict = await (await fetch(`${kRegisterDictionaryPath}?id=test&match-dest=${match_dest}`)).text();
assert_equals(
await waitUntilAvailableDictionaryHeader(t, {}),
kDefaultDictionaryHashBase64);
assert_equals(await checkHeader('dictionary-id', {}), '"test"');
}, 'Dictionary registration with empty match-dest list acts as wildcard');
compression_dictionary_promise_test(async (t) => {
const match_dest = encodeURIComponent('("")');
const dict = await (await fetch(`${kRegisterDictionaryPath}?id=test&match-dest=${match_dest}`)).text();
assert_equals(
await waitUntilAvailableDictionaryHeader(t, {}),
kDefaultDictionaryHashBase64);
assert_equals(await checkHeader('dictionary-id', {}), '"test"');
}, 'Dictionary registration with matching fetch destination');
compression_dictionary_promise_test(async (t) => {
const match_dest = encodeURIComponent('("script")');
const pattern = "%2Ffetch%2Fcompression-dictionary%2Fresources%2Fecho-headers.py";
await fetch(`${kRegisterDictionaryPath}?id=id1&match-dest=${match_dest}&match=${pattern}`);
await registerAltDictionaryAndWait(t);
const headers = await (await fetch('./resources/echo-headers.py')).json();
assert_false("available-dictionary" in headers);
}, 'Dictionary with non-matching match-dest is not used');
compression_dictionary_promise_test(async (t) => {
await fetch(`${kRegisterDictionaryPath}?id=id1&use-as-dictionary=%3F0`);
await registerAltDictionaryAndWait(t);
const headers = await (await fetch('./resources/echo-headers.py')).json();
assert_false("available-dictionary" in headers);
}, 'Dictionary with malformed structured header is not registered');
compression_dictionary_promise_test(async (t) => {
await fetch(`${kRegisterDictionaryPath}?id=id1&max-age=0`);
await registerAltDictionaryAndWait(t);
const headers = await (await fetch('./resources/echo-headers.py')).json();
assert_false("available-dictionary" in headers);
}, 'Dictionary with max-age=0 is not registered');
compression_dictionary_promise_test(async (t) => {
const dictionary_path1 = `${kRegisterDictionaryPath}?id=specific&content=specific&match=%2Ffetch%2Fcompression-dictionary%2Fresources%2Fecho-headers.py`;
const dictionary_path2 = `${kRegisterDictionaryPath}?id=general&content=general&match=%2Ffetch%2Fcompression-dictionary%2Fresources%2F*`;
const expected_specific_hash = await calculateDictionaryHash('specific');
const expected_general_hash = await calculateDictionaryHash('general');
await fetch(dictionary_path1);
await fetch(dictionary_path2);
const hash = await waitUntilAvailableDictionaryHeader(t, {expected_header: expected_specific_hash});
assert_equals(hash, expected_specific_hash);
}, 'Overlapping match patterns prioritize the more specific dictionary');
compression_dictionary_promise_test(async (t) => {
await fetch(kRegisterDictionaryPath);
assert_equals(
await waitUntilAvailableDictionaryHeader(t, {}),
kDefaultDictionaryHashBase64);
const redirect_url = `/common/redirect.py?location=${encodeURIComponent(`${SAME_ORIGIN_RESOURCES_URL}/echo-headers.py`)}`;
const headers = await (await fetch(redirect_url)).json();
assert_equals(headers['available-dictionary'], kDefaultDictionaryHashBase64);
}, 'Available-Dictionary header is added when target of redirect matches dictionary');
</script>
</body>