importscripts_mime_local.any.js (1937B)
1 // META: global=dedicatedworker,sharedworker 2 // 3 // Tests for https://github.com/whatwg/html/issues/8869 4 5 importScripts("/resources/testharness.js"); 6 7 let test_cases = [ 8 // Supported mimetypes: 9 ["text/javascript", true], 10 ["application/javascript", true], 11 ["text/ecmascript", true], 12 13 // Blocked mimetpyes: 14 ["image/png", false], 15 ["text/csv", false], 16 ["video/mpeg", false], 17 18 // Legacy mimetypes: 19 ["text/html", false], 20 ["text/plain", false], 21 ["application/xml", false], 22 ["application/octet-stream", false], 23 24 // Potato mimetypes: 25 ["text/potato", false], 26 ["potato/text", false], 27 ["aaa/aaa", false], 28 ["zzz/zzz", false], 29 30 // Parameterized mime types: 31 ["text/javascript; charset=utf-8", true], 32 ["text/javascript;charset=utf-8", true], 33 ["text/javascript;bla;bla", true], 34 ["text/csv; charset=utf-8", false], 35 ["text/csv;charset=utf-8", false], 36 ["text/csv;bla;bla", false], 37 38 // Funky capitalization: 39 ["Text/html", false], 40 ["text/Html", false], 41 ["TeXt/HtMl", false], 42 ["TEXT/HTML", false], 43 ]; 44 45 for (const [mimeType, isScriptType] of test_cases) { 46 test(t => { 47 let import_url = `data:${ mimeType },`; 48 if (isScriptType) { 49 assert_equals(undefined, importScripts(import_url)); 50 } else { 51 assert_throws_dom("NetworkError", _ => { importScripts(import_url) }) 52 } 53 }, "importScripts() requires scripty MIME types for data: URLs: " + mimeType + " is " + (isScriptType ? "allowed" : "blocked") + "."); 54 } 55 56 for (const [mimeType, isScriptType] of test_cases) { 57 test(t => { 58 let import_url = URL.createObjectURL(new Blob([""], { type: mimeType })); 59 if (isScriptType) { 60 assert_equals(undefined, importScripts(import_url)); 61 } else { 62 assert_throws_dom("NetworkError", _ => { importScripts(import_url) }) 63 } 64 }, "importScripts() requires scripty MIME types for blob: URLs: " + mimeType + " is " + (isScriptType ? "allowed" : "blocked") + "."); 65 } 66 done();