Bug 1510223 - Test for MIME type warning. r=ckerschb,nchevobbe
authorTom Schuster <evilpies@gmail.com>
Tue, 08 Jan 2019 12:28:32 +0000
changeset 509984 3e906dc0b1e81089d1c65e0c7e23db8d8923f704
parent 509983 dfdec6abcc4d52fbb7ab10617209c13fd29f78bd
child 509985 587eb607c9ad7116c3827eaa1b34d707d73a3352
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersckerschb, nchevobbe
bugs1510223
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1510223 - Test for MIME type warning. r=ckerschb,nchevobbe Turns out we also produced an error instead of a warnings. Good that we added those test \o/ Differential Revision: https://phabricator.services.mozilla.com/D15659
devtools/client/webconsole/test/mochitest/browser.ini
devtools/client/webconsole/test/mochitest/browser_webconsole_non_javascript_mime_warning.js
devtools/client/webconsole/test/mochitest/test-non-javascript-mime.html
devtools/client/webconsole/test/mochitest/test-non-javascript-mime.js
devtools/client/webconsole/test/mochitest/test-non-javascript-mime.js^headers^
netwerk/protocol/http/nsHttpChannel.cpp
--- a/devtools/client/webconsole/test/mochitest/browser.ini
+++ b/devtools/client/webconsole/test/mochitest/browser.ini
@@ -129,16 +129,19 @@ support-files =
   test-message-categories-svg.xhtml
   test-message-categories-workers.html
   test-message-categories-workers.js
   test-mixedcontent-securityerrors.html
   test-mutation.html
   test-network-exceptions.html
   test-network-request.html
   test-network.html
+  test-non-javascript-mime.html
+  test-non-javascript-mime.js
+  test-non-javascript-mime.js^headers^
   test-observe-http-ajax.html
   test-own-console.html
   test-property-provider.html
   test-reopen-closed-tab.html
   test-result-format-as-string.html
   test-sourcemap-error-01.html
   test-sourcemap-error-01.js
   test-sourcemap-error-02.html
@@ -339,16 +342,17 @@ skip-if = true #	Bug 1404382
 [browser_webconsole_network_messages_expand.js]
 skip-if = true  # Bug 1438979
 [browser_webconsole_network_messages_openinnet.js]
 [browser_webconsole_network_messages_status_code.js]
 [browser_webconsole_network_requests_from_chrome.js]
 [browser_webconsole_network_reset_filter.js]
 [browser_webconsole_nodes_highlight.js]
 [browser_webconsole_nodes_select.js]
+[browser_webconsole_non_javascript_mime_warning.js]
 [browser_webconsole_object_ctrl_click.js]
 [browser_webconsole_object_in_sidebar_keyboard_nav.js]
 [browser_webconsole_object_inspector.js]
 [browser_webconsole_object_inspector__proto__.js]
 [browser_webconsole_object_inspector_entries.js]
 [browser_webconsole_object_inspector_getters.js]
 [browser_webconsole_object_inspector_getters_prototype.js]
 [browser_webconsole_object_inspector_key_sorting.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/webconsole/test/mochitest/browser_webconsole_non_javascript_mime_warning.js
@@ -0,0 +1,20 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+// Tests that <script> loads with non-JavaScript MIME types produce a warning.
+// See Bug 1510223.
+
+"use strict";
+
+const TEST_URI = "http://example.com/browser/devtools/client/webconsole/" +
+                 "test/mochitest/" +
+                 "test-non-javascript-mime.html";
+const MIME_WARNING_MSG = "The script from “http://example.com/browser/devtools/client/webconsole/test/mochitest/test-non-javascript-mime.js” was loaded even though its MIME type (“text/plain”) is not a valid JavaScript MIME type";
+
+add_task(async function() {
+  const hud = await openNewTabAndConsole(TEST_URI);
+  await waitFor(()=> findMessage(hud, MIME_WARNING_MSG, ".message.warn"), "", 100);
+  ok(true, "MIME type warning displayed");
+});
new file mode 100644
--- /dev/null
+++ b/devtools/client/webconsole/test/mochitest/test-non-javascript-mime.html
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html lang="en">
+  <head>
+    <meta charset="utf-8">
+    <title>Web Console test for script with non-JavaScript MIME type</title>
+<!-- Any copyright is dedicated to the Public Domain.
+     http://creativecommons.org/publicdomain/zero/1.0/ -->
+    <script type="text/javascript" src="test-non-javascript-mime.js"></script>
+  </head>
+  <body>
+    <p>Web Console test for script with non-JavaScript MIME type.</p>
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/devtools/client/webconsole/test/mochitest/test-non-javascript-mime.js
@@ -0,0 +1,1 @@
+// Not empty. The ^headers^ file is important for this test.
new file mode 100644
--- /dev/null
+++ b/devtools/client/webconsole/test/mochitest/test-non-javascript-mime.js^headers^
@@ -0,0 +1,1 @@
+Content-Type: text/plain
\ No newline at end of file
--- a/netwerk/protocol/http/nsHttpChannel.cpp
+++ b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -1523,17 +1523,17 @@ void WarnWrongMIMEOfScript(nsHttpChannel
     return;
   }
 
   nsAutoCString contentType;
   aResponseHead->ContentType(contentType);
   NS_ConvertUTF8toUTF16 typeString(contentType);
   if (!nsContentUtils::IsJavascriptMIMEType(typeString)) {
     ReportMimeTypeMismatch(aChannel, "WarnScriptWithWrongMimeType", aURI,
-                           contentType, Report::Error);
+                           contentType, Report::Warning);
   }
 }
 
 nsresult nsHttpChannel::CallOnStartRequest() {
   LOG(("nsHttpChannel::CallOnStartRequest [this=%p]", this));
 
   MOZ_RELEASE_ASSERT(!mRequireCORSPreflight || mIsCorsPreflightDone,
                      "CORS preflight must have been finished by the time we "