summaryrefslogtreecommitdiffstats
path: root/dom/security/test/https-first/browser_superfluos_auth.js
diff options
context:
space:
mode:
Diffstat (limited to 'dom/security/test/https-first/browser_superfluos_auth.js')
-rw-r--r--dom/security/test/https-first/browser_superfluos_auth.js67
1 files changed, 67 insertions, 0 deletions
diff --git a/dom/security/test/https-first/browser_superfluos_auth.js b/dom/security/test/https-first/browser_superfluos_auth.js
new file mode 100644
index 0000000000..961430a444
--- /dev/null
+++ b/dom/security/test/https-first/browser_superfluos_auth.js
@@ -0,0 +1,67 @@
+/* Any copyright is dedicated to the Public Domain.
+ * https://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+// This test checks the superfluos auth prompt when HTTPS-First is enabled (Bug 1858565).
+
+const TEST_URI = "https://www.mozilla.org@example.com/";
+
+const { MockRegistrar } = ChromeUtils.importESModule(
+ "resource://testing-common/MockRegistrar.sys.mjs"
+);
+
+let respondMockPromptWithYes = false;
+
+const gMockPromptService = {
+ firstTimeCalled: false,
+ confirmExBC() {
+ return respondMockPromptWithYes ? 0 : 1;
+ },
+
+ QueryInterface: ChromeUtils.generateQI(["nsIPromptService"]),
+};
+
+var gMockPromptServiceCID = MockRegistrar.register(
+ "@mozilla.org/prompter;1",
+ gMockPromptService
+);
+
+registerCleanupFunction(() => {
+ MockRegistrar.unregister(gMockPromptServiceCID);
+});
+
+function checkBrowserLoad(browser) {
+ return new Promise(resolve => {
+ BrowserTestUtils.browserLoaded(browser, false, null, true).then(() => {
+ resolve(true);
+ });
+ BrowserTestUtils.browserStopped(browser, false, null, true).then(() => {
+ resolve(false);
+ });
+ });
+}
+
+add_task(async function () {
+ await SpecialPowers.pushPrefEnv({
+ set: [["dom.security.https_first", true]],
+ });
+
+ respondMockPromptWithYes = false;
+ let didBrowserLoadPromise = checkBrowserLoad(gBrowser.selectedBrowser);
+ BrowserTestUtils.startLoadingURIString(gBrowser.selectedBrowser, TEST_URI);
+ let didBrowserLoad = await didBrowserLoadPromise;
+ ok(
+ !didBrowserLoad,
+ "The browser should stop the load when the user refuses to load a page with superfluos authentication"
+ );
+
+ respondMockPromptWithYes = true;
+ didBrowserLoadPromise = checkBrowserLoad(gBrowser.selectedBrowser);
+ BrowserTestUtils.startLoadingURIString(gBrowser.selectedBrowser, TEST_URI);
+ didBrowserLoad = await didBrowserLoadPromise;
+ ok(
+ didBrowserLoad,
+ "The browser should load when the user agrees to load a page with superfluos authentication"
+ );
+});