1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/base/content/test/general/browser_bug623155.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,136 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +const REDIRECT_FROM = "https://example.com/browser/browser/base/content/test/general/" + 1.8 + "redirect_bug623155.sjs"; 1.9 + 1.10 +const REDIRECT_TO = "https://www.bank1.com/"; // Bad-cert host. 1.11 + 1.12 +function isRedirectedURISpec(aURISpec) { 1.13 + return isRedirectedURI(Services.io.newURI(aURISpec, null, null)); 1.14 +} 1.15 + 1.16 +function isRedirectedURI(aURI) { 1.17 + // Compare only their before-hash portion. 1.18 + return Services.io.newURI(REDIRECT_TO, null, null) 1.19 + .equalsExceptRef(aURI); 1.20 +} 1.21 + 1.22 +/* 1.23 + Test. 1.24 + 1.25 +1. Load 1.26 +https://example.com/browser/browser/base/content/test/general/redirect_bug623155.sjs#BG 1.27 + in a background tab. 1.28 + 1.29 +2. The redirected URI is <https://www.bank1.com/#BG>, which displayes a cert 1.30 + error page. 1.31 + 1.32 +3. Switch the tab to foreground. 1.33 + 1.34 +4. Check the URLbar's value, expecting <https://www.bank1.com/#BG> 1.35 + 1.36 +5. Load 1.37 +https://example.com/browser/browser/base/content/test/general/redirect_bug623155.sjs#FG 1.38 + in the foreground tab. 1.39 + 1.40 +6. The redirected URI is <https://www.bank1.com/#FG>. And this is also 1.41 + a cert-error page. 1.42 + 1.43 +7. Check the URLbar's value, expecting <https://www.bank1.com/#FG> 1.44 + 1.45 +8. End. 1.46 + 1.47 + */ 1.48 + 1.49 +var gNewTab; 1.50 + 1.51 +function test() { 1.52 + waitForExplicitFinish(); 1.53 + 1.54 + // Load a URI in the background. 1.55 + gNewTab = gBrowser.addTab(REDIRECT_FROM + "#BG"); 1.56 + gBrowser.getBrowserForTab(gNewTab) 1.57 + .webProgress 1.58 + .addProgressListener(gWebProgressListener, 1.59 + Components.interfaces.nsIWebProgress 1.60 + .NOTIFY_LOCATION); 1.61 +} 1.62 + 1.63 +var gWebProgressListener = { 1.64 + QueryInterface: function(aIID) { 1.65 + if (aIID.equals(Components.interfaces.nsIWebProgressListener) || 1.66 + aIID.equals(Components.interfaces.nsISupportsWeakReference) || 1.67 + aIID.equals(Components.interfaces.nsISupports)) 1.68 + return this; 1.69 + throw Components.results.NS_NOINTERFACE; 1.70 + }, 1.71 + 1.72 + // --------------------------------------------------------------------------- 1.73 + // NOTIFY_LOCATION mode should work fine without these methods. 1.74 + // 1.75 + //onStateChange: function() {}, 1.76 + //onStatusChange: function() {}, 1.77 + //onProgressChange: function() {}, 1.78 + //onSecurityChange: function() {}, 1.79 + //---------------------------------------------------------------------------- 1.80 + 1.81 + onLocationChange: function(aWebProgress, aRequest, aLocation, aFlags) { 1.82 + if (!aRequest) { 1.83 + // This is bug 673752, or maybe initial "about:blank". 1.84 + return; 1.85 + } 1.86 + 1.87 + ok(gNewTab, "There is a new tab."); 1.88 + ok(isRedirectedURI(aLocation), 1.89 + "onLocationChange catches only redirected URI."); 1.90 + 1.91 + if (aLocation.ref == "BG") { 1.92 + // This is background tab's request. 1.93 + isnot(gNewTab, gBrowser.selectedTab, "This is a background tab."); 1.94 + } else if (aLocation.ref == "FG") { 1.95 + // This is foreground tab's request. 1.96 + is(gNewTab, gBrowser.selectedTab, "This is a foreground tab."); 1.97 + } 1.98 + else { 1.99 + // We shonuld not reach here. 1.100 + ok(false, "This URI hash is not expected:" + aLocation.ref); 1.101 + } 1.102 + 1.103 + let isSelectedTab = gNewTab.selected; 1.104 + setTimeout(delayed, 0, isSelectedTab); 1.105 + } 1.106 +}; 1.107 + 1.108 +function delayed(aIsSelectedTab) { 1.109 + // Switch tab and confirm URL bar. 1.110 + if (!aIsSelectedTab) { 1.111 + gBrowser.selectedTab = gNewTab; 1.112 + } 1.113 + 1.114 + ok(isRedirectedURISpec(content.location.href), 1.115 + "The content area is redirected. aIsSelectedTab:" + aIsSelectedTab); 1.116 + is(gURLBar.value, content.location.href, 1.117 + "The URL bar shows the content URI. aIsSelectedTab:" + aIsSelectedTab); 1.118 + 1.119 + if (!aIsSelectedTab) { 1.120 + // If this was a background request, go on a foreground request. 1.121 + content.location = REDIRECT_FROM + "#FG"; 1.122 + } 1.123 + else { 1.124 + // Othrewise, nothing to do remains. 1.125 + finish(); 1.126 + } 1.127 +} 1.128 + 1.129 +/* Cleanup */ 1.130 +registerCleanupFunction(function() { 1.131 + if (gNewTab) { 1.132 + gBrowser.getBrowserForTab(gNewTab) 1.133 + .webProgress 1.134 + .removeProgressListener(gWebProgressListener); 1.135 + 1.136 + gBrowser.removeTab(gNewTab); 1.137 + } 1.138 + gNewTab = null; 1.139 +});