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