1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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"
);
});
|