importscripts_mime.any.js (1426B)
1 // META: global=worker 2 // 3 // Tentative test for https://github.com/whatwg/html/issues/3255 4 5 let test_cases = [ 6 // Supported mimetypes: 7 ["text/javascript", true], 8 ["application/javascript", true], 9 ["text/ecmascript", true], 10 11 // Blocked mimetpyes: 12 ["image/png", false], 13 ["text/csv", false], 14 ["video/mpeg", false], 15 16 // Legacy mimetypes: 17 ["text/html", false], 18 ["text/plain", false], 19 ["application/xml", false], 20 ["application/octet-stream", false], 21 22 // Potato mimetypes: 23 ["text/potato", false], 24 ["potato/text", false], 25 ["aaa/aaa", false], 26 ["zzz/zzz", false], 27 28 // Parameterized mime types: 29 ["text/javascript; charset=utf-8", true], 30 ["text/javascript;charset=utf-8", true], 31 ["text/javascript;bla;bla", true], 32 ["text/csv; charset=utf-8", false], 33 ["text/csv;charset=utf-8", false], 34 ["text/csv;bla;bla", false], 35 36 // Funky capitalization: 37 ["Text/html", false], 38 ["text/Html", false], 39 ["TeXt/HtMl", false], 40 ["TEXT/HTML", false], 41 ]; 42 43 for (const [mimeType, isScriptType] of test_cases) { 44 test(t => { 45 let import_url = "/workers/support/imported_script.py?mime=" + mimeType; 46 if (isScriptType) { 47 assert_equals(undefined, importScripts(import_url)); 48 } else { 49 assert_throws_dom("NetworkError", _ => { importScripts(import_url) }) 50 } 51 }, "importScripts() requires scripty MIME types: " + mimeType + " is " + (isScriptType ? "allowed" : "blocked") + "."); 52 }