1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/docshell/test/chrome/bug311007_window.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,199 @@ 1.4 +<?xml version="1.0"?> 1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?> 1.6 + 1.7 +<window id="311007Test" 1.8 + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 1.9 + width="600" 1.10 + height="600" 1.11 + onload="startup();" 1.12 + title="bug 311007 test"> 1.13 + 1.14 + <script type="application/javascript" src="docshell_helpers.js"></script> 1.15 + <script type="application/javascript"><![CDATA[ 1.16 +/* 1.17 + Regression test for bug 283733 and bug 307027. 1.18 + 1.19 + Bug 283733 1.20 + "accessing a relative anchor in a secure page removes the 1.21 + locked icon and yellow background UI" 1.22 + 1.23 + Bug 307027 1.24 + "Going back from secure page to error page does not clear yellow bar" 1.25 + 1.26 + And enhancements: 1.27 + 1.28 + Bug 478927 1.29 + onLocationChange should notify whether or not loading an error page. 1.30 + 1.31 + */ 1.32 + 1.33 +const kDNSErrorURI = "https://example/err.html"; 1.34 +const kSecureURI = 1.35 + "https://example.com/tests/docshell/test/navigation/blank.html"; 1.36 + 1.37 +/* 1.38 + Step 1: load a network error page. <err.html> Not Secure 1.39 + Step 2: load a secure page. <blank.html> Secure 1.40 + Step 3: a secure page + hashchange. <blank.html#foo> Secure (bug 283733) 1.41 + Step 4: go back to the error page. <err.html> Not Secure (bug 307027) 1.42 + */ 1.43 + 1.44 +var gListener = null; 1.45 + 1.46 +function WebProgressListener() { 1.47 + this._callback = null; 1.48 +} 1.49 + 1.50 +WebProgressListener.prototype = { 1.51 + QueryInterface: function(aIID) { 1.52 + if (aIID.equals(Components.interfaces.nsIWebProgressListener) || 1.53 + aIID.equals(Components.interfaces.nsISupportsWeakReference) || 1.54 + aIID.equals(Components.interfaces.nsISupports)) 1.55 + return this; 1.56 + throw Components.results.NS_NOINTERFACE; 1.57 + }, 1.58 + 1.59 + onLocationChange: function(aWebProgress, aRequest, aLocation, aFlags) { 1.60 + setTimeout(this._callback, 0, aWebProgress, aRequest, aLocation, aFlags); 1.61 + }, 1.62 + 1.63 + set callback(aVal) { 1.64 + this._callback = aVal; 1.65 + } 1.66 +}; 1.67 + 1.68 +function startup() { 1.69 + gListener = new WebProgressListener(); 1.70 + 1.71 + document.getElementById("content") 1.72 + .webProgress 1.73 + .addProgressListener(gListener, 1.74 + Components.interfaces.nsIWebProgress 1.75 + .NOTIFY_LOCATION); 1.76 + 1.77 + setTimeout(step1A, 0); 1.78 +} 1.79 + 1.80 +/****************************************************************************** 1.81 + * Step 1: Load an error page, and confirm UA knows it's insecure. 1.82 + ******************************************************************************/ 1.83 + 1.84 +function step1A() { 1.85 + gListener.callback = step1B; 1.86 + content.location = kDNSErrorURI; 1.87 +} 1.88 + 1.89 +function step1B(aWebProgress, aRequest, aLocation, aFlags) { 1.90 + is(aLocation.spec, kDNSErrorURI, "Error page's URI (1)"); 1.91 + 1.92 + ok(!(aFlags & Components.interfaces.nsIWebProgressListener 1.93 + .LOCATION_CHANGE_SAME_DOCUMENT), 1.94 + "DocShell loaded a document (1)"); 1.95 + 1.96 + ok((aFlags & Components.interfaces.nsIWebProgressListener 1.97 + .LOCATION_CHANGE_ERROR_PAGE), 1.98 + "This page is an error page."); 1.99 + 1.100 + ok(!(aWebProgress.QueryInterface(Components.interfaces.nsIDocShell) 1.101 + .securityUI.state & 1.102 + Components.interfaces.nsIWebProgressListener.STATE_IS_SECURE), 1.103 + "This is not a secure page (1)"); 1.104 + 1.105 + /* Go to step 2. */ 1.106 + setTimeout(step2A, 0); 1.107 +} 1.108 + 1.109 +/****************************************************************************** 1.110 + * Step 2: Load a HTTPS page, and confirm it's secure. 1.111 + ******************************************************************************/ 1.112 + 1.113 +function step2A() { 1.114 + gListener.callback = step2B; 1.115 + content.location = kSecureURI; 1.116 +} 1.117 + 1.118 +function step2B(aWebProgress, aRequest, aLocation, aFlags) { 1.119 + is(aLocation.spec, kSecureURI, "A URI on HTTPS (2)"); 1.120 + 1.121 + ok(!(aFlags & Components.interfaces.nsIWebProgressListener 1.122 + .LOCATION_CHANGE_SAME_DOCUMENT), 1.123 + "DocShell loaded a document (2)"); 1.124 + 1.125 + ok(!(aFlags & Components.interfaces.nsIWebProgressListener 1.126 + .LOCATION_CHANGE_ERROR_PAGE), 1.127 + "This page is not an error page."); 1.128 + 1.129 + ok((aWebProgress.QueryInterface(Components.interfaces.nsIDocShell) 1.130 + .securityUI.state & 1.131 + Components.interfaces.nsIWebProgressListener.STATE_IS_SECURE), 1.132 + "This is a secure page (2)"); 1.133 + 1.134 + /* Go to step 3. */ 1.135 + setTimeout(step3A, 0); 1.136 +} 1.137 + 1.138 +/***************************************************************************** 1.139 + * Step 3: Trigger hashchange within a secure page, and confirm UA knows 1.140 + * it's secure. (Bug 283733) 1.141 + *****************************************************************************/ 1.142 + 1.143 +function step3A() { 1.144 + gListener.callback = step3B; 1.145 + content.location += "#foo"; 1.146 +} 1.147 + 1.148 +function step3B(aWebProgress, aRequest, aLocation, aFlags) { 1.149 + is(aLocation.spec, kSecureURI + "#foo", "hashchange on HTTPS (3)"); 1.150 + 1.151 + ok((aFlags & Components.interfaces.nsIWebProgressListener 1.152 + .LOCATION_CHANGE_SAME_DOCUMENT), 1.153 + "We are in the same document as before (3)"); 1.154 + 1.155 + ok(!(aFlags & Components.interfaces.nsIWebProgressListener 1.156 + .LOCATION_CHANGE_ERROR_PAGE), 1.157 + "This page is not an error page."); 1.158 + 1.159 + ok((aWebProgress.QueryInterface(Components.interfaces.nsIDocShell) 1.160 + .securityUI.state & 1.161 + Components.interfaces.nsIWebProgressListener.STATE_IS_SECURE), 1.162 + "This is a secure page (3)"); 1.163 + 1.164 + /* Go to step 4. */ 1.165 + setTimeout(step4A, 0); 1.166 +} 1.167 + 1.168 +/***************************************************************************** 1.169 + * Step 4: Go back from a secure page to an error page, and confirm UA knows 1.170 + * it's not secure. (Bug 307027) 1.171 + *****************************************************************************/ 1.172 + 1.173 +function step4A() { 1.174 + gListener.callback = step4B; 1.175 + content.history.go(-2); 1.176 +} 1.177 + 1.178 +function step4B(aWebProgress, aRequest, aLocation, aFlags) { 1.179 + is(aLocation.spec, kDNSErrorURI, "Go back to the error URI (4)"); 1.180 + 1.181 + ok(!(aFlags & Components.interfaces.nsIWebProgressListener 1.182 + .LOCATION_CHANGE_SAME_DOCUMENT), 1.183 + "DocShell loaded a document (4)"); 1.184 + 1.185 + ok((aFlags & Components.interfaces.nsIWebProgressListener 1.186 + .LOCATION_CHANGE_ERROR_PAGE), 1.187 + "This page is an error page."); 1.188 + 1.189 + ok(!(aWebProgress.QueryInterface(Components.interfaces.nsIDocShell) 1.190 + .securityUI.state & 1.191 + Components.interfaces.nsIWebProgressListener.STATE_IS_SECURE), 1.192 + "This is not a secure page (4)"); 1.193 + 1.194 + /* End. */ 1.195 + aWebProgress.removeProgressListener(gListener); 1.196 + delete(gListener); 1.197 + finish(); 1.198 +} 1.199 + ]]></script> 1.200 + 1.201 + <browser type="content-primary" flex="1" id="content" src="about:blank"/> 1.202 +</window>