browser_uriFixupAlternateRedirects.js (1888B)
1 "use strict"; 2 3 const { UrlbarTestUtils } = ChromeUtils.importESModule( 4 "resource://testing-common/UrlbarTestUtils.sys.mjs" 5 ); 6 7 const REDIRECTURL = 8 // eslint-disable-next-line @microsoft/sdl/no-insecure-url 9 "http://www.example.com/browser/docshell/test/browser/redirect_to_example.sjs"; 10 11 add_task(async function () { 12 // Test both directly setting a value and pressing enter, or setting the 13 // value through input events, like the user would do. 14 const setValueFns = [ 15 value => { 16 gURLBar.value = value; 17 }, 18 value => { 19 return UrlbarTestUtils.promiseAutocompleteResultPopup({ 20 window, 21 waitForFocus, 22 value, 23 }); 24 }, 25 ]; 26 for (let setValueFn of setValueFns) { 27 let tab = await BrowserTestUtils.openNewForegroundTab( 28 gBrowser, 29 "about:blank" 30 ); 31 // Enter search terms and start a search. 32 gURLBar.focus(); 33 await setValueFn(REDIRECTURL); 34 let errorPageLoaded = BrowserTestUtils.waitForErrorPage(tab.linkedBrowser); 35 EventUtils.synthesizeKey("KEY_Enter"); 36 await errorPageLoaded; 37 let [contentURL, originalURL] = await SpecialPowers.spawn( 38 tab.linkedBrowser, 39 [], 40 () => { 41 return [ 42 content.document.documentURI, 43 content.document.mozDocumentURIIfNotForErrorPages.spec, 44 ]; 45 } 46 ); 47 info("Page that loaded: " + contentURL); 48 const errorURI = "about:neterror?"; 49 ok(contentURL.startsWith(errorURI), "Should be on an error page"); 50 51 const contentPrincipal = tab.linkedBrowser.contentPrincipal; 52 ok( 53 contentPrincipal.spec.startsWith(errorURI), 54 "Principal should be for the error page" 55 ); 56 57 originalURL = new URL(originalURL); 58 is( 59 originalURL.host, 60 "example", 61 "Should be an error for http://example, not http://www.example.com/" 62 ); 63 64 BrowserTestUtils.removeTab(tab); 65 } 66 });