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
|
"use strict";
const { UrlbarTestUtils } = ChromeUtils.importESModule(
"resource://testing-common/UrlbarTestUtils.sys.mjs"
);
const REDIRECTURL =
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
"http://www.example.com/browser/docshell/test/browser/redirect_to_example.sjs";
add_task(async function () {
// Test both directly setting a value and pressing enter, or setting the
// value through input events, like the user would do.
const setValueFns = [
value => {
gURLBar.value = value;
},
value => {
return UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
waitForFocus,
value,
});
},
];
for (let setValueFn of setValueFns) {
let tab = await BrowserTestUtils.openNewForegroundTab(
gBrowser,
"about:blank"
);
// Enter search terms and start a search.
gURLBar.focus();
await setValueFn(REDIRECTURL);
let errorPageLoaded = BrowserTestUtils.waitForErrorPage(tab.linkedBrowser);
EventUtils.synthesizeKey("KEY_Enter");
await errorPageLoaded;
let [contentURL, originalURL] = await SpecialPowers.spawn(
tab.linkedBrowser,
[],
() => {
return [
content.document.documentURI,
content.document.mozDocumentURIIfNotForErrorPages.spec,
];
}
);
info("Page that loaded: " + contentURL);
const errorURI = "about:neterror?";
ok(contentURL.startsWith(errorURI), "Should be on an error page");
const contentPrincipal = tab.linkedBrowser.contentPrincipal;
ok(
contentPrincipal.spec.startsWith(errorURI),
"Principal should be for the error page"
);
originalURL = new URL(originalURL);
is(
originalURL.host,
"example",
"Should be an error for http://example, not http://www.example.com/"
);
BrowserTestUtils.removeTab(tab);
}
});
|