michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: const REDIRECT_FROM = "https://example.com/browser/browser/base/content/test/general/" + michael@0: "redirect_bug623155.sjs"; michael@0: michael@0: const REDIRECT_TO = "https://www.bank1.com/"; // Bad-cert host. michael@0: michael@0: function isRedirectedURISpec(aURISpec) { michael@0: return isRedirectedURI(Services.io.newURI(aURISpec, null, null)); michael@0: } michael@0: michael@0: function isRedirectedURI(aURI) { michael@0: // Compare only their before-hash portion. michael@0: return Services.io.newURI(REDIRECT_TO, null, null) michael@0: .equalsExceptRef(aURI); michael@0: } michael@0: michael@0: /* michael@0: Test. michael@0: michael@0: 1. Load michael@0: https://example.com/browser/browser/base/content/test/general/redirect_bug623155.sjs#BG michael@0: in a background tab. michael@0: michael@0: 2. The redirected URI is , which displayes a cert michael@0: error page. michael@0: michael@0: 3. Switch the tab to foreground. michael@0: michael@0: 4. Check the URLbar's value, expecting michael@0: michael@0: 5. Load michael@0: https://example.com/browser/browser/base/content/test/general/redirect_bug623155.sjs#FG michael@0: in the foreground tab. michael@0: michael@0: 6. The redirected URI is . And this is also michael@0: a cert-error page. michael@0: michael@0: 7. Check the URLbar's value, expecting michael@0: michael@0: 8. End. michael@0: michael@0: */ michael@0: michael@0: var gNewTab; michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: // Load a URI in the background. michael@0: gNewTab = gBrowser.addTab(REDIRECT_FROM + "#BG"); michael@0: gBrowser.getBrowserForTab(gNewTab) michael@0: .webProgress michael@0: .addProgressListener(gWebProgressListener, michael@0: Components.interfaces.nsIWebProgress michael@0: .NOTIFY_LOCATION); michael@0: } michael@0: michael@0: var gWebProgressListener = { michael@0: QueryInterface: function(aIID) { michael@0: if (aIID.equals(Components.interfaces.nsIWebProgressListener) || michael@0: aIID.equals(Components.interfaces.nsISupportsWeakReference) || michael@0: aIID.equals(Components.interfaces.nsISupports)) michael@0: return this; michael@0: throw Components.results.NS_NOINTERFACE; michael@0: }, michael@0: michael@0: // --------------------------------------------------------------------------- michael@0: // NOTIFY_LOCATION mode should work fine without these methods. michael@0: // michael@0: //onStateChange: function() {}, michael@0: //onStatusChange: function() {}, michael@0: //onProgressChange: function() {}, michael@0: //onSecurityChange: function() {}, michael@0: //---------------------------------------------------------------------------- michael@0: michael@0: onLocationChange: function(aWebProgress, aRequest, aLocation, aFlags) { michael@0: if (!aRequest) { michael@0: // This is bug 673752, or maybe initial "about:blank". michael@0: return; michael@0: } michael@0: michael@0: ok(gNewTab, "There is a new tab."); michael@0: ok(isRedirectedURI(aLocation), michael@0: "onLocationChange catches only redirected URI."); michael@0: michael@0: if (aLocation.ref == "BG") { michael@0: // This is background tab's request. michael@0: isnot(gNewTab, gBrowser.selectedTab, "This is a background tab."); michael@0: } else if (aLocation.ref == "FG") { michael@0: // This is foreground tab's request. michael@0: is(gNewTab, gBrowser.selectedTab, "This is a foreground tab."); michael@0: } michael@0: else { michael@0: // We shonuld not reach here. michael@0: ok(false, "This URI hash is not expected:" + aLocation.ref); michael@0: } michael@0: michael@0: let isSelectedTab = gNewTab.selected; michael@0: setTimeout(delayed, 0, isSelectedTab); michael@0: } michael@0: }; michael@0: michael@0: function delayed(aIsSelectedTab) { michael@0: // Switch tab and confirm URL bar. michael@0: if (!aIsSelectedTab) { michael@0: gBrowser.selectedTab = gNewTab; michael@0: } michael@0: michael@0: ok(isRedirectedURISpec(content.location.href), michael@0: "The content area is redirected. aIsSelectedTab:" + aIsSelectedTab); michael@0: is(gURLBar.value, content.location.href, michael@0: "The URL bar shows the content URI. aIsSelectedTab:" + aIsSelectedTab); michael@0: michael@0: if (!aIsSelectedTab) { michael@0: // If this was a background request, go on a foreground request. michael@0: content.location = REDIRECT_FROM + "#FG"; michael@0: } michael@0: else { michael@0: // Othrewise, nothing to do remains. michael@0: finish(); michael@0: } michael@0: } michael@0: michael@0: /* Cleanup */ michael@0: registerCleanupFunction(function() { michael@0: if (gNewTab) { michael@0: gBrowser.getBrowserForTab(gNewTab) michael@0: .webProgress michael@0: .removeProgressListener(gWebProgressListener); michael@0: michael@0: gBrowser.removeTab(gNewTab); michael@0: } michael@0: gNewTab = null; michael@0: });