Bug 1799662 - Test https-first performs fallback and mixed content level 2 is not auto upgrading. r=freddyb

Differential Revision: https://phabricator.services.mozilla.com/D161595
This commit is contained in:
lyavor 2022-11-24 09:20:46 +00:00
parent 14fc57b869
commit bd299ebf6b
6 changed files with 98 additions and 0 deletions

View File

@ -25,3 +25,9 @@ support-files =
support-files =
file_slow_download.html
file_slow_download.sjs
[browser_downgrade_mixed_content_auto_upgrade_console.js]
support-files =
file_mixed_content_auto_upgrade.html
pass.png
test.ogv
test.wav

View File

@ -0,0 +1,80 @@
// Bug 1673574 - Improve Console logging for mixed content auto upgrading
"use strict";
const testPath = getRootDirectory(gTestPath).replace(
"chrome://mochitests/content",
"http://httpsfirst.com"
);
let tests = [
{
description: "Top-Level upgrade should get logged",
expectLogLevel: Ci.nsIConsoleMessage.warn,
expectIncludes: ["Upgrading insecure request", "to use", "httpsfirst.com"],
},
{
description: "Top-Level upgrade failure should get logged",
expectLogLevel: Ci.nsIConsoleMessage.warn,
expectIncludes: [
"Upgrading insecure request",
"failed",
"httpsfirst.com",
"Downgrading to",
],
},
];
const kTestURI = testPath + "file_mixed_content_auto_upgrade.html";
add_task(async function() {
// A longer timeout is necessary for this test than the plain mochitests
// due to opening a new tab with the web console.
requestLongerTimeout(4);
// Enable ML2 and HTTPS-First Mode and register console-listener
await SpecialPowers.pushPrefEnv({
set: [
["security.mixed_content.upgrade_display_content", true],
["dom.security.https_first", true],
],
});
Services.console.registerListener(on_new_message);
// 1. Upgrade page to https://
await BrowserTestUtils.loadURI(gBrowser.selectedBrowser, kTestURI);
await BrowserTestUtils.waitForCondition(() => tests.length === 0);
// Clean up
Services.console.unregisterListener(on_new_message);
});
function on_new_message(msgObj) {
const message = msgObj.message;
const logLevel = msgObj.logLevel;
// The console message is:
// Should only show HTTPS-First messages
if (message.includes("Mixed Content:")) {
ok(
!message.includes("Upgrading insecure display request"),
"msg included a mixed content upgrade"
);
}
if (message.includes("HTTPS-First Mode:")) {
for (let i = 0; i < tests.length; i++) {
const testCase = tests[i];
// Check if log-level matches
if (logLevel !== testCase.expectLogLevel) {
continue;
}
// Check if all substrings are included
if (testCase.expectIncludes.some(str => !message.includes(str))) {
continue;
}
ok(true, testCase.description);
tests.splice(i, 1);
break;
}
}
}

View File

@ -0,0 +1,12 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Bug 1673574 - Improve Console logging for mixed content auto upgrading</title>
</head>
<body>
<!--upgradeable resources--->
<img src="http://example.com/browser/dom/security/test/https-first/pass.png">
<video src="http://example.com/browser/dom/security/test/https-first/test.ogv">
<audio src="http://example.com/browser/dom/security/test/https-first/test.wav">
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Binary file not shown.