element-link-icon.sub.html (2295B)
1 <!DOCTYPE html> 2 <!-- 3 [%provenance%] 4 --> 5 <html lang="en"> 6 <meta charset="utf-8"> 7 {%- if subtests|length > 10 %} 8 <meta name="timeout" content="long"> 9 {%- endif %} 10 <title>HTTP headers on request for HTML "link" element with rel="icon"</title> 11 <script src="/resources/testharness.js"></script> 12 <script src="/resources/testharnessreport.js"></script> 13 <script src="/fetch/metadata/resources/helper.sub.js"></script> 14 <body> 15 <script> 16 'use strict'; 17 18 const params = { 19 body: ` 20 <svg xmlns="http://www.w3.org/2000/svg" width="123" height="123"> 21 <rect fill="lime" width="123" height="123"/> 22 </svg> 23 `, 24 mime: 'image/svg+xml' 25 }; 26 27 /** 28 * The `link` element supports a `load` event. That event would reliably 29 * indicate that the browser had received the request. Multiple major 30 * browsers do not implement the event, however, so in order to promote the 31 * visibility of this test, a less efficient polling-based detection 32 * mechanism is used. 33 * 34 * https://bugzilla.mozilla.org/show_bug.cgi?id=1638188 35 * https://bugs.chromium.org/p/chromium/issues/detail?id=1083034 36 */ 37 function induceRequest(t, url, attributes) { 38 const link = document.createElement('link'); 39 link.setAttribute('rel', 'icon'); 40 link.setAttribute('href', url); 41 42 for (const [ name, value ] of Object.entries(attributes)) { 43 link.setAttribute(name, value); 44 } 45 46 document.head.appendChild(link); 47 t.add_cleanup(() => link.remove()); 48 } 49 50 {%- for subtest in subtests %} 51 52 promise_test((t) => { 53 const key = '{{uuid()}}'; 54 55 induceRequest( 56 t, 57 makeRequestURL(key, [% subtest.origins %], params), 58 [%subtest.elementAttrs | default({}) | tojson%] 59 ); 60 61 return retrieve(key, {poll:true}) 62 .then((headers) => { 63 {%- if subtest.expected == none %} 64 assert_not_own_property(headers, '[%subtest.headerName%]'); 65 {%- else %} 66 assert_own_property(headers, '[%subtest.headerName%]'); 67 assert_array_equals(headers['[%subtest.headerName%]'], ['[%subtest.expected%]']); 68 {%- endif %} 69 }); 70 }, '[%subtest.headerName%][%subtest.description | pad("start", " - ")%] [%subtest.elementAttrs | collection("attributes")%]'); 71 72 {%- endfor %} 73 </script> 74 </body> 75 </html>