|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 const REDIRECT_FROM = "https://example.com/browser/browser/base/content/test/general/" + |
|
5 "redirect_bug623155.sjs"; |
|
6 |
|
7 const REDIRECT_TO = "https://www.bank1.com/"; // Bad-cert host. |
|
8 |
|
9 function isRedirectedURISpec(aURISpec) { |
|
10 return isRedirectedURI(Services.io.newURI(aURISpec, null, null)); |
|
11 } |
|
12 |
|
13 function isRedirectedURI(aURI) { |
|
14 // Compare only their before-hash portion. |
|
15 return Services.io.newURI(REDIRECT_TO, null, null) |
|
16 .equalsExceptRef(aURI); |
|
17 } |
|
18 |
|
19 /* |
|
20 Test. |
|
21 |
|
22 1. Load |
|
23 https://example.com/browser/browser/base/content/test/general/redirect_bug623155.sjs#BG |
|
24 in a background tab. |
|
25 |
|
26 2. The redirected URI is <https://www.bank1.com/#BG>, which displayes a cert |
|
27 error page. |
|
28 |
|
29 3. Switch the tab to foreground. |
|
30 |
|
31 4. Check the URLbar's value, expecting <https://www.bank1.com/#BG> |
|
32 |
|
33 5. Load |
|
34 https://example.com/browser/browser/base/content/test/general/redirect_bug623155.sjs#FG |
|
35 in the foreground tab. |
|
36 |
|
37 6. The redirected URI is <https://www.bank1.com/#FG>. And this is also |
|
38 a cert-error page. |
|
39 |
|
40 7. Check the URLbar's value, expecting <https://www.bank1.com/#FG> |
|
41 |
|
42 8. End. |
|
43 |
|
44 */ |
|
45 |
|
46 var gNewTab; |
|
47 |
|
48 function test() { |
|
49 waitForExplicitFinish(); |
|
50 |
|
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 } |
|
59 |
|
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 }, |
|
68 |
|
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 //---------------------------------------------------------------------------- |
|
77 |
|
78 onLocationChange: function(aWebProgress, aRequest, aLocation, aFlags) { |
|
79 if (!aRequest) { |
|
80 // This is bug 673752, or maybe initial "about:blank". |
|
81 return; |
|
82 } |
|
83 |
|
84 ok(gNewTab, "There is a new tab."); |
|
85 ok(isRedirectedURI(aLocation), |
|
86 "onLocationChange catches only redirected URI."); |
|
87 |
|
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 } |
|
99 |
|
100 let isSelectedTab = gNewTab.selected; |
|
101 setTimeout(delayed, 0, isSelectedTab); |
|
102 } |
|
103 }; |
|
104 |
|
105 function delayed(aIsSelectedTab) { |
|
106 // Switch tab and confirm URL bar. |
|
107 if (!aIsSelectedTab) { |
|
108 gBrowser.selectedTab = gNewTab; |
|
109 } |
|
110 |
|
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); |
|
115 |
|
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 } |
|
125 |
|
126 /* Cleanup */ |
|
127 registerCleanupFunction(function() { |
|
128 if (gNewTab) { |
|
129 gBrowser.getBrowserForTab(gNewTab) |
|
130 .webProgress |
|
131 .removeProgressListener(gWebProgressListener); |
|
132 |
|
133 gBrowser.removeTab(gNewTab); |
|
134 } |
|
135 gNewTab = null; |
|
136 }); |