Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | const REDIRECT_FROM = "https://example.com/browser/browser/base/content/test/general/" + |
michael@0 | 5 | "redirect_bug623155.sjs"; |
michael@0 | 6 | |
michael@0 | 7 | const REDIRECT_TO = "https://www.bank1.com/"; // Bad-cert host. |
michael@0 | 8 | |
michael@0 | 9 | function isRedirectedURISpec(aURISpec) { |
michael@0 | 10 | return isRedirectedURI(Services.io.newURI(aURISpec, null, null)); |
michael@0 | 11 | } |
michael@0 | 12 | |
michael@0 | 13 | function isRedirectedURI(aURI) { |
michael@0 | 14 | // Compare only their before-hash portion. |
michael@0 | 15 | return Services.io.newURI(REDIRECT_TO, null, null) |
michael@0 | 16 | .equalsExceptRef(aURI); |
michael@0 | 17 | } |
michael@0 | 18 | |
michael@0 | 19 | /* |
michael@0 | 20 | Test. |
michael@0 | 21 | |
michael@0 | 22 | 1. Load |
michael@0 | 23 | https://example.com/browser/browser/base/content/test/general/redirect_bug623155.sjs#BG |
michael@0 | 24 | in a background tab. |
michael@0 | 25 | |
michael@0 | 26 | 2. The redirected URI is <https://www.bank1.com/#BG>, which displayes a cert |
michael@0 | 27 | error page. |
michael@0 | 28 | |
michael@0 | 29 | 3. Switch the tab to foreground. |
michael@0 | 30 | |
michael@0 | 31 | 4. Check the URLbar's value, expecting <https://www.bank1.com/#BG> |
michael@0 | 32 | |
michael@0 | 33 | 5. Load |
michael@0 | 34 | https://example.com/browser/browser/base/content/test/general/redirect_bug623155.sjs#FG |
michael@0 | 35 | in the foreground tab. |
michael@0 | 36 | |
michael@0 | 37 | 6. The redirected URI is <https://www.bank1.com/#FG>. And this is also |
michael@0 | 38 | a cert-error page. |
michael@0 | 39 | |
michael@0 | 40 | 7. Check the URLbar's value, expecting <https://www.bank1.com/#FG> |
michael@0 | 41 | |
michael@0 | 42 | 8. End. |
michael@0 | 43 | |
michael@0 | 44 | */ |
michael@0 | 45 | |
michael@0 | 46 | var gNewTab; |
michael@0 | 47 | |
michael@0 | 48 | function test() { |
michael@0 | 49 | waitForExplicitFinish(); |
michael@0 | 50 | |
michael@0 | 51 | // Load a URI in the background. |
michael@0 | 52 | gNewTab = gBrowser.addTab(REDIRECT_FROM + "#BG"); |
michael@0 | 53 | gBrowser.getBrowserForTab(gNewTab) |
michael@0 | 54 | .webProgress |
michael@0 | 55 | .addProgressListener(gWebProgressListener, |
michael@0 | 56 | Components.interfaces.nsIWebProgress |
michael@0 | 57 | .NOTIFY_LOCATION); |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | var gWebProgressListener = { |
michael@0 | 61 | QueryInterface: function(aIID) { |
michael@0 | 62 | if (aIID.equals(Components.interfaces.nsIWebProgressListener) || |
michael@0 | 63 | aIID.equals(Components.interfaces.nsISupportsWeakReference) || |
michael@0 | 64 | aIID.equals(Components.interfaces.nsISupports)) |
michael@0 | 65 | return this; |
michael@0 | 66 | throw Components.results.NS_NOINTERFACE; |
michael@0 | 67 | }, |
michael@0 | 68 | |
michael@0 | 69 | // --------------------------------------------------------------------------- |
michael@0 | 70 | // NOTIFY_LOCATION mode should work fine without these methods. |
michael@0 | 71 | // |
michael@0 | 72 | //onStateChange: function() {}, |
michael@0 | 73 | //onStatusChange: function() {}, |
michael@0 | 74 | //onProgressChange: function() {}, |
michael@0 | 75 | //onSecurityChange: function() {}, |
michael@0 | 76 | //---------------------------------------------------------------------------- |
michael@0 | 77 | |
michael@0 | 78 | onLocationChange: function(aWebProgress, aRequest, aLocation, aFlags) { |
michael@0 | 79 | if (!aRequest) { |
michael@0 | 80 | // This is bug 673752, or maybe initial "about:blank". |
michael@0 | 81 | return; |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | ok(gNewTab, "There is a new tab."); |
michael@0 | 85 | ok(isRedirectedURI(aLocation), |
michael@0 | 86 | "onLocationChange catches only redirected URI."); |
michael@0 | 87 | |
michael@0 | 88 | if (aLocation.ref == "BG") { |
michael@0 | 89 | // This is background tab's request. |
michael@0 | 90 | isnot(gNewTab, gBrowser.selectedTab, "This is a background tab."); |
michael@0 | 91 | } else if (aLocation.ref == "FG") { |
michael@0 | 92 | // This is foreground tab's request. |
michael@0 | 93 | is(gNewTab, gBrowser.selectedTab, "This is a foreground tab."); |
michael@0 | 94 | } |
michael@0 | 95 | else { |
michael@0 | 96 | // We shonuld not reach here. |
michael@0 | 97 | ok(false, "This URI hash is not expected:" + aLocation.ref); |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | let isSelectedTab = gNewTab.selected; |
michael@0 | 101 | setTimeout(delayed, 0, isSelectedTab); |
michael@0 | 102 | } |
michael@0 | 103 | }; |
michael@0 | 104 | |
michael@0 | 105 | function delayed(aIsSelectedTab) { |
michael@0 | 106 | // Switch tab and confirm URL bar. |
michael@0 | 107 | if (!aIsSelectedTab) { |
michael@0 | 108 | gBrowser.selectedTab = gNewTab; |
michael@0 | 109 | } |
michael@0 | 110 | |
michael@0 | 111 | ok(isRedirectedURISpec(content.location.href), |
michael@0 | 112 | "The content area is redirected. aIsSelectedTab:" + aIsSelectedTab); |
michael@0 | 113 | is(gURLBar.value, content.location.href, |
michael@0 | 114 | "The URL bar shows the content URI. aIsSelectedTab:" + aIsSelectedTab); |
michael@0 | 115 | |
michael@0 | 116 | if (!aIsSelectedTab) { |
michael@0 | 117 | // If this was a background request, go on a foreground request. |
michael@0 | 118 | content.location = REDIRECT_FROM + "#FG"; |
michael@0 | 119 | } |
michael@0 | 120 | else { |
michael@0 | 121 | // Othrewise, nothing to do remains. |
michael@0 | 122 | finish(); |
michael@0 | 123 | } |
michael@0 | 124 | } |
michael@0 | 125 | |
michael@0 | 126 | /* Cleanup */ |
michael@0 | 127 | registerCleanupFunction(function() { |
michael@0 | 128 | if (gNewTab) { |
michael@0 | 129 | gBrowser.getBrowserForTab(gNewTab) |
michael@0 | 130 | .webProgress |
michael@0 | 131 | .removeProgressListener(gWebProgressListener); |
michael@0 | 132 | |
michael@0 | 133 | gBrowser.removeTab(gNewTab); |
michael@0 | 134 | } |
michael@0 | 135 | gNewTab = null; |
michael@0 | 136 | }); |