Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test gets skipped with pattern: os == 'linux' && os_version == '18.04' && asan OR os == 'linux' && os_version == '18.04' && tsan OR win11_2009 && asan
- Manifest: browser/components/urlbar/tests/browser/browser.toml
/* Any copyright is dedicated to the Public Domain.
const REDIRECT_FROM = `${TEST_BASE_URL}redirect_error.sjs`;
function isRedirectedURISpec(aURISpec) {
return isRedirectedURI(Services.io.newURI(aURISpec));
}
function isRedirectedURI(aURI) {
// Compare only their before-hash portion.
return Services.io.newURI(REDIRECT_TO).equalsExceptRef(aURI);
}
/*
Test.
1. Load redirect_bug623155.sjs#BG in a background tab.
error page.
3. Switch the tab to foreground.
5. Load redirect_bug623155.sjs#FG in the foreground tab.
a cert-error page.
8. End.
*/
var gNewTab;
function test() {
waitForExplicitFinish();
// Load a URI in the background.
gNewTab = BrowserTestUtils.addTab(gBrowser, REDIRECT_FROM + "#BG");
gBrowser
.getBrowserForTab(gNewTab)
.webProgress.addProgressListener(
gWebProgressListener,
Ci.nsIWebProgress.NOTIFY_LOCATION
);
}
var gWebProgressListener = {
QueryInterface: ChromeUtils.generateQI([
"nsIWebProgressListener",
"nsISupportsWeakReference",
]),
// ---------------------------------------------------------------------------
// NOTIFY_LOCATION mode should work fine without these methods.
//
// onStateChange: function() {},
// onStatusChange: function() {},
// onProgressChange: function() {},
// onSecurityChange: function() {},
// ----------------------------------------------------------------------------
onLocationChange(aWebProgress, aRequest, aLocation) {
if (!aRequest) {
return;
}
ok(gNewTab, "There is a new tab.");
ok(
isRedirectedURI(aLocation),
"onLocationChange catches only redirected URI."
);
if (aLocation.ref == "BG") {
// This is background tab's request.
isnot(gNewTab, gBrowser.selectedTab, "This is a background tab.");
} else if (aLocation.ref == "FG") {
// This is foreground tab's request.
is(gNewTab, gBrowser.selectedTab, "This is a foreground tab.");
} else {
// We shonuld not reach here.
ok(false, "This URI hash is not expected:" + aLocation.ref);
}
let isSelectedTab = gNewTab.selected;
setTimeout(delayed, 0, isSelectedTab);
},
};
function delayed(aIsSelectedTab) {
// Switch tab and confirm URL bar.
if (!aIsSelectedTab) {
gBrowser.selectedTab = gNewTab;
}
let currentURI = gBrowser.selectedBrowser.currentURI.spec;
ok(
isRedirectedURISpec(currentURI),
"The content area is redirected. aIsSelectedTab:" + aIsSelectedTab
);
is(
gURLBar.value,
UrlbarTestUtils.trimURL(currentURI),
"The URL bar shows the content URI. aIsSelectedTab:" + aIsSelectedTab
);
if (!aIsSelectedTab) {
// If this was a background request, go on a foreground request.
BrowserTestUtils.startLoadingURIString(
gBrowser.selectedBrowser,
REDIRECT_FROM + "#FG"
);
} else {
// Othrewise, nothing to do remains.
finish();
}
}
/* Cleanup */
registerCleanupFunction(function () {
if (gNewTab) {
gBrowser
.getBrowserForTab(gNewTab)
.webProgress.removeProgressListener(gWebProgressListener);
gBrowser.removeTab(gNewTab);
}
gNewTab = null;
});