browser_webconsole_json_mime.js (2950B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Tests that <script> loads with JSON MIME types produce a warning. 7 // See Bug 1916351. 8 add_task(async function script_load_with_json_mime_produce_warning() { 9 const TEST_URI = 10 "https://example.com/browser/devtools/client/webconsole/" + 11 "test/browser/" + 12 "test-script-json-mime.html"; 13 const MIME_WARNING_MSG = 14 "The script from “https://example.com/browser/devtools/client/webconsole/test/browser/test-json-mime.json” was loaded even though its MIME type (“application/json”) is not a valid JavaScript MIME type."; 15 const hud = await openNewTabAndConsole(TEST_URI); 16 await waitFor(() => findWarningMessage(hud, MIME_WARNING_MSG), "", 100); 17 ok(true, "JSON MIME type warning displayed"); 18 }); 19 20 // Tests that <script type=module> loads with JSON MIME types produce an error. 21 add_task(async function script_module_load_with_json_mime_produce_error() { 22 const TEST_URI = 23 "https://example.com/browser/devtools/client/webconsole/" + 24 "test/browser/" + 25 "test-script-json-module-mime.html"; 26 const MIME_ERROR_MSG = 27 "Loading module from “https://example.com/browser/devtools/client/webconsole/test/browser/test-json-mime.json” was blocked because of a disallowed MIME type (“application/json”)"; 28 const hud = await openNewTabAndConsole(TEST_URI); 29 await waitFor(() => findErrorMessage(hud, MIME_ERROR_MSG), "", 100); 30 ok(true, "JSON MIME type error displayed"); 31 }); 32 33 // Tests that JSON module loads with invalid MIME types produce an error. 34 add_task(async function json_module_import_with_invalid_mime_produce_error() { 35 const TEST_URI = 36 "https://example.com/browser/devtools/client/webconsole/" + 37 "test/browser/" + 38 "test-json-module-mime.html"; 39 const MIME_ERROR_MSG = 40 "Loading JSON module from “https://example.com/browser/devtools/client/webconsole/test/browser/test-non-javascript-mime.mjs” was blocked because of a disallowed MIME type (“text/html”)"; 41 const hud = await openNewTabAndConsole(TEST_URI); 42 await waitFor(() => findErrorMessage(hud, MIME_ERROR_MSG), "", 100); 43 ok(true, "JSON MIME type error displayed"); 44 }); 45 46 // Tests that JSON module loads with text/javascript MIME types produce an error. 47 add_task( 48 async function json_module_import_with_javascript_mime_produce_error() { 49 const TEST_URI = 50 "https://example.com/browser/devtools/client/webconsole/" + 51 "test/browser/" + 52 "test-js-json-module-mime.html"; 53 const MIME_ERROR_MSG = 54 "Loading JSON module from “https://example.com/browser/devtools/client/webconsole/test/browser/test-js-mime.mjs” was blocked because of a disallowed MIME type (“text/javascript”)"; 55 const hud = await openNewTabAndConsole(TEST_URI); 56 await waitFor(() => findErrorMessage(hud, MIME_ERROR_MSG), "", 100); 57 ok(true, "JSON MIME type error displayed"); 58 } 59 );