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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Tom Schuster 2019-01-08 12:28:32 +00:00
Родитель 8dd6c6adf7
Коммит 82d1aa2207
6 изменённых файлов: 40 добавлений и 1 удалений

Просмотреть файл

@ -134,6 +134,9 @@ support-files =
test-network-exceptions.html test-network-exceptions.html
test-network-request.html test-network-request.html
test-network.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-observe-http-ajax.html
test-own-console.html test-own-console.html
test-property-provider.html test-property-provider.html
@ -344,6 +347,7 @@ skip-if = true # Bug 1438979
[browser_webconsole_network_reset_filter.js] [browser_webconsole_network_reset_filter.js]
[browser_webconsole_nodes_highlight.js] [browser_webconsole_nodes_highlight.js]
[browser_webconsole_nodes_select.js] [browser_webconsole_nodes_select.js]
[browser_webconsole_non_javascript_mime_warning.js]
[browser_webconsole_object_ctrl_click.js] [browser_webconsole_object_ctrl_click.js]
[browser_webconsole_object_in_sidebar_keyboard_nav.js] [browser_webconsole_object_in_sidebar_keyboard_nav.js]
[browser_webconsole_object_inspector.js] [browser_webconsole_object_inspector.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");
});

Просмотреть файл

@ -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>

Просмотреть файл

@ -0,0 +1 @@
// Not empty. The ^headers^ file is important for this test.

Просмотреть файл

@ -0,0 +1 @@
Content-Type: text/plain

Просмотреть файл

@ -1528,7 +1528,7 @@ void WarnWrongMIMEOfScript(nsHttpChannel *aChannel, nsIURI *aURI,
NS_ConvertUTF8toUTF16 typeString(contentType); NS_ConvertUTF8toUTF16 typeString(contentType);
if (!nsContentUtils::IsJavascriptMIMEType(typeString)) { if (!nsContentUtils::IsJavascriptMIMEType(typeString)) {
ReportMimeTypeMismatch(aChannel, "WarnScriptWithWrongMimeType", aURI, ReportMimeTypeMismatch(aChannel, "WarnScriptWithWrongMimeType", aURI,
contentType, Report::Error); contentType, Report::Warning);
} }
} }