|
| 1 | +<!DOCTYPE html> |
| 2 | +<head> |
| 3 | +<meta charset="utf-8"> |
| 4 | +<meta name="timeout" content="long"/> |
| 5 | +<script src="./resources/compression-dictionary-util.sub.js"></script> |
| 6 | +<script src="/resources/testharness.js"></script> |
| 7 | +<script src="/resources/testharnessreport.js"></script> |
| 8 | +<link rel="help" href="https://github.com/whatwg/html/pull/11620"> |
| 9 | +<link id="alreadyBrowsingContextConnected" rel="compression-dictionary" href="./resources/register-dictionary.py?alreadyBrowsingContextConnected"></link> |
| 10 | +<script> |
| 11 | + const dynamicallyConnected = document.createElement('link'); |
| 12 | + dynamicallyConnected.rel = 'compression-dictionary'; |
| 13 | + dynamicallyConnected.href = `${kRegisterDictionaryPath}?linkDynamicallyBrowsingContextConnected`; |
| 14 | +</script> |
| 15 | +<link id="hrefDynamicallySet" rel="compression-dictionary"></link> |
| 16 | +<link id="hrefDynamicallyChanged" rel="compression-dictionary" href="./resources/register-dictionary.py?hrefDynamicallyChanged"></link> |
| 17 | +<body> |
| 18 | + <script> |
| 19 | + let fetchedDictionaries = []; |
| 20 | + const observer = new PerformanceObserver((list) => { |
| 21 | + list.getEntries().forEach(entry => { |
| 22 | + const url = new URL(entry.name); |
| 23 | + if (url.pathname == "/fetch/compression-dictionary/resources/register-dictionary.py") { |
| 24 | + fetchedDictionaries.push(url.search); |
| 25 | + } |
| 26 | + }); |
| 27 | + }); |
| 28 | + observer.observe({ type: "resource", buffered: true}); |
| 29 | + |
| 30 | + compression_dictionary_promise_test(async t => { |
| 31 | + // Initially fetched dictionaries. |
| 32 | + let expectedEntries = [ |
| 33 | + "?alreadyBrowsingContextConnected", |
| 34 | + "?hrefDynamicallyChanged", |
| 35 | + ]; |
| 36 | + await t.step_wait(_ => fetchedDictionaries.length >= expectedEntries.length, "initially browsing-context connected <link> should trigger fetch", 5000); |
| 37 | + assert_array_equals(fetchedDictionaries.toSorted(), expectedEntries, "dictionaries fetched for initially browsing-context connected <link>."); |
| 38 | + fetchedDictionaries = []; |
| 39 | + await new Promise(resolve => step_timeout(resolve, 1000)); |
| 40 | + assert_equals(fetchedDictionaries.length, 0, "no more dictionary fetched."); |
| 41 | + |
| 42 | + // browsing-context connected change. |
| 43 | + expectedEntries = [ |
| 44 | + "?linkDynamicallyBrowsingContextConnected", |
| 45 | + ]; |
| 46 | + document.head.appendChild(dynamicallyConnected); |
| 47 | + await t.step_wait(_ => fetchedDictionaries.length >= expectedEntries.length, "browsing-context connecting a link should trigger fetch", 5000); |
| 48 | + assert_array_equals(fetchedDictionaries.toSorted(), expectedEntries, "dictionary fetched after <link> becomes browsing-context connected."); |
| 49 | + fetchedDictionaries = []; |
| 50 | + |
| 51 | + // Dynamic changes to href. |
| 52 | + expectedEntries = [ |
| 53 | + "?hrefDynamicallyChangedBis", |
| 54 | + "?hrefDynamicallySet", |
| 55 | + ]; |
| 56 | + hrefDynamicallySet.setAttribute("href", `${kRegisterDictionaryPath}?hrefDynamicallySet`); |
| 57 | + hrefDynamicallyChanged.setAttribute("href", `${kRegisterDictionaryPath}?hrefDynamicallyChangedBis`); |
| 58 | + await t.step_wait(_ => fetchedDictionaries.length >= expectedEntries.length, "modifying href should trigger fetch", 5000); |
| 59 | + assert_array_equals(fetchedDictionaries.toSorted(), expectedEntries, "dictionaries fetched after dynamic changes to href attribute."); |
| 60 | + fetchedDictionaries = []; |
| 61 | + |
| 62 | + }, "<link rel=compression-dictionary> are fetched after DOM operations."); |
| 63 | + </script> |
| 64 | +</body> |
0 commit comments