test_accept_header.html (2587B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title>Accept header</title> 5 <script src="/tests/SimpleTest/SimpleTest.js"></script> 6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 7 </head> 8 <body> 9 <script> 10 SimpleTest.requestCompleteLog(); 11 12 // All the requests are sent to test_accept_header.sjs which will return 13 // different content based on the queryString. When the queryString is 'get', 14 // test_accept_header.sjs returns a JSON object with the latest request and its 15 // accept header value. 16 17 function test_last_request_and_continue(query, expected) { 18 fetch("test_accept_header.sjs?get").then(r => r.json()).then(json => { 19 is(json.type, query, "Expected: " + query); 20 is(json.accept, expected, "Accept header: " + expected); 21 next(); 22 }); 23 } 24 25 function test_iframe() { 26 let ifr = document.createElement("iframe"); 27 ifr.src = "test_accept_header.sjs?iframe"; 28 ifr.onload = () => { 29 test_last_request_and_continue("iframe", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); 30 }; 31 document.body.appendChild(ifr); 32 } 33 34 function test_image() { 35 let i = new Image(); 36 i.src = "test_accept_header.sjs?image"; 37 i.onload = function() { 38 // Fetch spec says we should have: "image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5" 39 test_last_request_and_continue("image", "image/avif,image/webp,image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5"); 40 } 41 } 42 43 function test_style() { 44 let head = document.getElementsByTagName("head")[0]; 45 let link = document.createElement("link"); 46 link.rel = "stylesheet"; 47 link.type = "text/css"; 48 link.href = "test_accept_header.sjs?style"; 49 link.onload = () => { 50 test_last_request_and_continue("style", "text/css,*/*;q=0.1"); 51 }; 52 head.appendChild(link); 53 } 54 55 function test_worker() { 56 let w = new Worker("test_accept_header.sjs?worker"); 57 w.onmessage = function() { 58 test_last_request_and_continue("worker", "*/*"); 59 } 60 } 61 62 function test_json_modules() { 63 let script = document.createElement("script"); 64 script.src = "test_import_json_module.mjs"; 65 script.type = "module"; 66 script.onload = () => { 67 test_last_request_and_continue("json", "application/json,*/*;q=0.5"); 68 } 69 document.body.appendChild(script); 70 } 71 72 let tests = [ 73 test_iframe, 74 test_image, 75 test_style, 76 test_worker, 77 test_json_modules, 78 ]; 79 80 function next() { 81 if (!tests.length) { 82 SimpleTest.finish(); 83 return; 84 } 85 86 let test = tests.shift(); 87 test(); 88 } 89 90 SimpleTest.waitForExplicitFinish(); 91 92 SpecialPowers.pushPrefEnv({ "set": [ 93 [ "dom.enable_performance_observer", true ] 94 ]}, next); 95 96 </script> 97 </body> 98 </html>