docshell/test/chrome/bug311007_window.xul

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:a8194abcdd8d
1 <?xml version="1.0"?>
2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
3
4 <window id="311007Test"
5 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
6 width="600"
7 height="600"
8 onload="startup();"
9 title="bug 311007 test">
10
11 <script type="application/javascript" src="docshell_helpers.js"></script>
12 <script type="application/javascript"><![CDATA[
13 /*
14 Regression test for bug 283733 and bug 307027.
15
16 Bug 283733
17 "accessing a relative anchor in a secure page removes the
18 locked icon and yellow background UI"
19
20 Bug 307027
21 "Going back from secure page to error page does not clear yellow bar"
22
23 And enhancements:
24
25 Bug 478927
26 onLocationChange should notify whether or not loading an error page.
27
28 */
29
30 const kDNSErrorURI = "https://example/err.html";
31 const kSecureURI =
32 "https://example.com/tests/docshell/test/navigation/blank.html";
33
34 /*
35 Step 1: load a network error page. <err.html> Not Secure
36 Step 2: load a secure page. <blank.html> Secure
37 Step 3: a secure page + hashchange. <blank.html#foo> Secure (bug 283733)
38 Step 4: go back to the error page. <err.html> Not Secure (bug 307027)
39 */
40
41 var gListener = null;
42
43 function WebProgressListener() {
44 this._callback = null;
45 }
46
47 WebProgressListener.prototype = {
48 QueryInterface: function(aIID) {
49 if (aIID.equals(Components.interfaces.nsIWebProgressListener) ||
50 aIID.equals(Components.interfaces.nsISupportsWeakReference) ||
51 aIID.equals(Components.interfaces.nsISupports))
52 return this;
53 throw Components.results.NS_NOINTERFACE;
54 },
55
56 onLocationChange: function(aWebProgress, aRequest, aLocation, aFlags) {
57 setTimeout(this._callback, 0, aWebProgress, aRequest, aLocation, aFlags);
58 },
59
60 set callback(aVal) {
61 this._callback = aVal;
62 }
63 };
64
65 function startup() {
66 gListener = new WebProgressListener();
67
68 document.getElementById("content")
69 .webProgress
70 .addProgressListener(gListener,
71 Components.interfaces.nsIWebProgress
72 .NOTIFY_LOCATION);
73
74 setTimeout(step1A, 0);
75 }
76
77 /******************************************************************************
78 * Step 1: Load an error page, and confirm UA knows it's insecure.
79 ******************************************************************************/
80
81 function step1A() {
82 gListener.callback = step1B;
83 content.location = kDNSErrorURI;
84 }
85
86 function step1B(aWebProgress, aRequest, aLocation, aFlags) {
87 is(aLocation.spec, kDNSErrorURI, "Error page's URI (1)");
88
89 ok(!(aFlags & Components.interfaces.nsIWebProgressListener
90 .LOCATION_CHANGE_SAME_DOCUMENT),
91 "DocShell loaded a document (1)");
92
93 ok((aFlags & Components.interfaces.nsIWebProgressListener
94 .LOCATION_CHANGE_ERROR_PAGE),
95 "This page is an error page.");
96
97 ok(!(aWebProgress.QueryInterface(Components.interfaces.nsIDocShell)
98 .securityUI.state &
99 Components.interfaces.nsIWebProgressListener.STATE_IS_SECURE),
100 "This is not a secure page (1)");
101
102 /* Go to step 2. */
103 setTimeout(step2A, 0);
104 }
105
106 /******************************************************************************
107 * Step 2: Load a HTTPS page, and confirm it's secure.
108 ******************************************************************************/
109
110 function step2A() {
111 gListener.callback = step2B;
112 content.location = kSecureURI;
113 }
114
115 function step2B(aWebProgress, aRequest, aLocation, aFlags) {
116 is(aLocation.spec, kSecureURI, "A URI on HTTPS (2)");
117
118 ok(!(aFlags & Components.interfaces.nsIWebProgressListener
119 .LOCATION_CHANGE_SAME_DOCUMENT),
120 "DocShell loaded a document (2)");
121
122 ok(!(aFlags & Components.interfaces.nsIWebProgressListener
123 .LOCATION_CHANGE_ERROR_PAGE),
124 "This page is not an error page.");
125
126 ok((aWebProgress.QueryInterface(Components.interfaces.nsIDocShell)
127 .securityUI.state &
128 Components.interfaces.nsIWebProgressListener.STATE_IS_SECURE),
129 "This is a secure page (2)");
130
131 /* Go to step 3. */
132 setTimeout(step3A, 0);
133 }
134
135 /*****************************************************************************
136 * Step 3: Trigger hashchange within a secure page, and confirm UA knows
137 * it's secure. (Bug 283733)
138 *****************************************************************************/
139
140 function step3A() {
141 gListener.callback = step3B;
142 content.location += "#foo";
143 }
144
145 function step3B(aWebProgress, aRequest, aLocation, aFlags) {
146 is(aLocation.spec, kSecureURI + "#foo", "hashchange on HTTPS (3)");
147
148 ok((aFlags & Components.interfaces.nsIWebProgressListener
149 .LOCATION_CHANGE_SAME_DOCUMENT),
150 "We are in the same document as before (3)");
151
152 ok(!(aFlags & Components.interfaces.nsIWebProgressListener
153 .LOCATION_CHANGE_ERROR_PAGE),
154 "This page is not an error page.");
155
156 ok((aWebProgress.QueryInterface(Components.interfaces.nsIDocShell)
157 .securityUI.state &
158 Components.interfaces.nsIWebProgressListener.STATE_IS_SECURE),
159 "This is a secure page (3)");
160
161 /* Go to step 4. */
162 setTimeout(step4A, 0);
163 }
164
165 /*****************************************************************************
166 * Step 4: Go back from a secure page to an error page, and confirm UA knows
167 * it's not secure. (Bug 307027)
168 *****************************************************************************/
169
170 function step4A() {
171 gListener.callback = step4B;
172 content.history.go(-2);
173 }
174
175 function step4B(aWebProgress, aRequest, aLocation, aFlags) {
176 is(aLocation.spec, kDNSErrorURI, "Go back to the error URI (4)");
177
178 ok(!(aFlags & Components.interfaces.nsIWebProgressListener
179 .LOCATION_CHANGE_SAME_DOCUMENT),
180 "DocShell loaded a document (4)");
181
182 ok((aFlags & Components.interfaces.nsIWebProgressListener
183 .LOCATION_CHANGE_ERROR_PAGE),
184 "This page is an error page.");
185
186 ok(!(aWebProgress.QueryInterface(Components.interfaces.nsIDocShell)
187 .securityUI.state &
188 Components.interfaces.nsIWebProgressListener.STATE_IS_SECURE),
189 "This is not a secure page (4)");
190
191 /* End. */
192 aWebProgress.removeProgressListener(gListener);
193 delete(gListener);
194 finish();
195 }
196 ]]></script>
197
198 <browser type="content-primary" flex="1" id="content" src="about:blank"/>
199 </window>

mercurial