dictionary-fetch-with-link-element.tentative.https.html (2974B)
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 function addLinkRelCompressionDictionaryElement(url, crossOrigin) { 15 const link = document.createElement('link'); 16 link.rel = 'compression-dictionary'; 17 link.href = url; 18 if (crossOrigin) { 19 link.crossOrigin = crossOrigin; 20 } 21 document.head.appendChild(link); 22 } 23 24 test(t => { 25 const link_element = document.createElement('link'); 26 assert_true(link_element.relList.supports('compression-dictionary')); 27 }, "Browser supports link element with compression-dictionary rel."); 28 29 compression_dictionary_promise_test(async (t) => { 30 const dict_token = token(); 31 const url = `${kRegisterDictionaryPath}?save_header=${dict_token}`; 32 addLinkRelCompressionDictionaryElement(url); 33 // Wait for a while to ensure that the dictionary is fetched. 34 await new Promise(resolve => window.requestIdleCallback(resolve)); 35 const headers = await waitUntilPreviousRequestHeaders(t, dict_token); 36 assert_true(headers !== undefined, 'Headers should be available'); 37 assert_equals(headers['sec-fetch-mode'], 'cors'); 38 // Wait until `available-dictionary` header is available. 39 assert_equals( 40 await waitUntilAvailableDictionaryHeader(t, {}), 41 kDefaultDictionaryHashBase64); 42 // Check if the data compressed using Brotli with the dictionary can be 43 // decompressed. 44 const data_url = `${kCompressedDataPath}?content_encoding=dcb`; 45 assert_equals(await (await fetch(data_url)).text(), kExpectedCompressedData); 46 }, 'Fetch same origin dictionary using link element'); 47 48 compression_dictionary_promise_test(async (t) => { 49 const dict_token = token(); 50 const url = 51 getRemoteHostUrl(`${kRegisterDictionaryPath}?save_header=${dict_token}`); 52 addLinkRelCompressionDictionaryElement(url, 'anonymous'); 53 // Wait for a while to ensure that the dictionary is fetched. 54 await new Promise(resolve => window.requestIdleCallback(resolve)); 55 const headers = await waitUntilPreviousRequestHeaders( 56 t, dict_token, /*check_remote=*/ true); 57 assert_true(headers !== undefined, 'Headers should be available'); 58 assert_equals(headers['sec-fetch-mode'], 'cors'); 59 60 // Wait until `available-dictionary` header is available. 61 assert_equals( 62 await waitUntilAvailableDictionaryHeader(t, {check_remote: true}), 63 kDefaultDictionaryHashBase64); 64 // Check if the data compressed using Brotli with the dictionary can be 65 // decompressed. 66 const data_url = 67 getRemoteHostUrl(`${kCompressedDataPath}?content_encoding=dcb`); 68 assert_equals(await (await fetch(data_url)).text(), kExpectedCompressedData); 69 }, 'Fetch cross origin dictionary using link element'); 70 71 </script> 72 </body>