dictionary-fetch-with-link-header.tentative.https.html (1992B)
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 async function addIframeWithLinkRelCompressionDictionaryHeader(dict_url) { 15 return new Promise((resolve) => { 16 const base_page_url = './resources/empty.html'; 17 const page_url = 18 base_page_url + 19 `?pipe=header(link,<${dict_url}>; rel="compression-dictionary")`; 20 const iframe = document.createElement('iframe'); 21 iframe.src = page_url; 22 iframe.addEventListener('load', () => { 23 resolve(iframe); 24 }); 25 document.body.appendChild(iframe); 26 }) 27 } 28 29 compression_dictionary_promise_test(async (t) => { 30 const dict_token = token(); 31 const url = new URL( 32 `${kRegisterDictionaryPath}?save_header=${dict_token}`, location.href); 33 const iframe = 34 await addIframeWithLinkRelCompressionDictionaryHeader(url.href); 35 t.add_cleanup(() => { 36 iframe.remove(); 37 }); 38 // Wait for a while to ensure that the dictionary is fetched. 39 await new Promise(resolve => window.requestIdleCallback(resolve)); 40 const headers = await waitUntilPreviousRequestHeaders(t, dict_token); 41 assert_true(headers !== undefined, 'Headers should be available'); 42 assert_equals(headers['sec-fetch-mode'], 'cors'); 43 // Wait until `available-dictionary` header is available. 44 assert_equals( 45 await waitUntilAvailableDictionaryHeader(t, {}), 46 kDefaultDictionaryHashBase64); 47 // Check if the data compressed using Brotli with the dictionary can be 48 // decompressed. 49 const data_url = `${kCompressedDataPath}?content_encoding=dcb`; 50 assert_equals(await (await fetch(data_url)).text(), kExpectedCompressedData); 51 }, 'Fetch same origin dictionary using link header'); 52 53 </script> 54 </body>