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