bug311007_window.xhtml (6440B)
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 src="chrome://mochikit/content/chrome-harness.js" /> 12 <script type="application/javascript" src="docshell_helpers.js"></script> 13 <script type="application/javascript"><![CDATA[ 14 // `content` is the id of the browser element used for the test. 15 /* global content */ 16 /* 17 Regression test for bug 283733 and bug 307027. 18 19 Bug 283733 20 "accessing a relative anchor in a secure page removes the 21 locked icon and yellow background UI" 22 23 Bug 307027 24 "Going back from secure page to error page does not clear yellow bar" 25 26 And enhancements: 27 28 Bug 478927 29 onLocationChange should notify whether or not loading an error page. 30 31 */ 32 33 const kDNSErrorURI = "https://example/err.html"; 34 const kSecureURI = 35 "https://example.com/tests/docshell/test/navigation/blank.html"; 36 37 /* 38 Step 1: load a network error page. <err.html> Not Secure 39 Step 2: load a secure page. <blank.html> Secure 40 Step 3: a secure page + hashchange. <blank.html#foo> Secure (bug 283733) 41 Step 4: go back to the error page. <err.html> Not Secure (bug 307027) 42 */ 43 44 var gListener = null; 45 46 function WebProgressListener() { 47 this._callback = null; 48 } 49 50 WebProgressListener.prototype = { 51 QueryInterface: ChromeUtils.generateQI([ 52 "nsIWebProgressListener", 53 "nsISupportsWeakReference", 54 ]), 55 56 onLocationChange(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 Ci.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 & Ci.nsIWebProgressListener 90 .LOCATION_CHANGE_SAME_DOCUMENT), 91 "DocShell loaded a document (1)"); 92 93 ok((aFlags & Ci.nsIWebProgressListener 94 .LOCATION_CHANGE_ERROR_PAGE), 95 "This page is an error page."); 96 97 ok(!(document.getElementById("content") 98 .browsingContext 99 .secureBrowserUI.state & 100 Ci.nsIWebProgressListener.STATE_IS_SECURE), 101 "This is not a secure page (1)"); 102 103 /* Go to step 2. */ 104 setTimeout(step2A, 0); 105 } 106 107 /****************************************************************************** 108 * Step 2: Load a HTTPS page, and confirm it's secure. 109 ******************************************************************************/ 110 111 function step2A() { 112 gListener.callback = step2B; 113 content.location = kSecureURI; 114 } 115 116 function step2B(aWebProgress, aRequest, aLocation, aFlags) { 117 content.addEventListener( 118 'load', 119 () => step2C(aWebProgress, aRequest, aLocation, aFlags), 120 {once: true}); 121 } 122 123 function step2C(aWebProgress, aRequest, aLocation, aFlags) { 124 is(aLocation.spec, kSecureURI, "A URI on HTTPS (2)"); 125 126 ok(!(aFlags & Ci.nsIWebProgressListener 127 .LOCATION_CHANGE_SAME_DOCUMENT), 128 "DocShell loaded a document (2)"); 129 130 ok(!(aFlags & Ci.nsIWebProgressListener 131 .LOCATION_CHANGE_ERROR_PAGE), 132 "This page is not an error page."); 133 134 ok((document.getElementById("content") 135 .browsingContext 136 .secureBrowserUI.state & 137 Ci.nsIWebProgressListener.STATE_IS_SECURE), 138 "This is a secure page (2)"); 139 140 /* Go to step 3. */ 141 setTimeout(step3A, 0); 142 } 143 144 /***************************************************************************** 145 * Step 3: Trigger hashchange within a secure page, and confirm UA knows 146 * it's secure. (Bug 283733) 147 *****************************************************************************/ 148 149 function step3A() { 150 gListener.callback = step3B; 151 content.location += "#foo"; 152 } 153 154 function step3B(aWebProgress, aRequest, aLocation, aFlags) { 155 is(aLocation.spec, kSecureURI + "#foo", "hashchange on HTTPS (3)"); 156 157 ok((aFlags & Ci.nsIWebProgressListener 158 .LOCATION_CHANGE_SAME_DOCUMENT), 159 "We are in the same document as before (3)"); 160 161 ok(!(aFlags & Ci.nsIWebProgressListener 162 .LOCATION_CHANGE_ERROR_PAGE), 163 "This page is not an error page."); 164 165 ok((document.getElementById("content") 166 .browsingContext 167 .secureBrowserUI.state & 168 Ci.nsIWebProgressListener.STATE_IS_SECURE), 169 "This is a secure page (3)"); 170 171 /* Go to step 4. */ 172 setTimeout(step4A, 0); 173 } 174 175 /***************************************************************************** 176 * Step 4: Go back from a secure page to an error page, and confirm UA knows 177 * it's not secure. (Bug 307027) 178 *****************************************************************************/ 179 180 function step4A() { 181 gListener.callback = step4B; 182 content.history.go(-2); 183 } 184 185 function step4B(aWebProgress, aRequest, aLocation, aFlags) { 186 is(aLocation.spec, kDNSErrorURI, "Go back to the error URI (4)"); 187 188 ok(!(aFlags & Ci.nsIWebProgressListener 189 .LOCATION_CHANGE_SAME_DOCUMENT), 190 "DocShell loaded a document (4)"); 191 192 ok((aFlags & Ci.nsIWebProgressListener 193 .LOCATION_CHANGE_ERROR_PAGE), 194 "This page is an error page."); 195 196 ok(!(document.getElementById("content") 197 .browsingContext 198 .secureBrowserUI.state & 199 Ci.nsIWebProgressListener.STATE_IS_SECURE), 200 "This is not a secure page (4)"); 201 202 /* End. */ 203 document.getElementById("content") 204 .webProgress.removeProgressListener(gListener); 205 gListener = null; 206 finish(); 207 } 208 ]]></script> 209 210 <browser type="content" primary="true" flex="1" id="content" src="about:blank"/> 211 </window>