Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id=248970 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Test for Bug 248970</title> |
michael@0 | 8 | <script type="application/javascript" |
michael@0 | 9 | src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 10 | <script type="text/javascript" src="notification_common.js"></script> |
michael@0 | 11 | <link rel="stylesheet" type="text/css" |
michael@0 | 12 | href="chrome://mochikit/content/tests/SimpleTest/test.css"> |
michael@0 | 13 | </head> |
michael@0 | 14 | <body> |
michael@0 | 15 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=248970">Mozilla Bug 248970</a> |
michael@0 | 16 | <p id="display"></p> |
michael@0 | 17 | <pre id="test"> |
michael@0 | 18 | <script class="testbody" type="text/javascript"> |
michael@0 | 19 | |
michael@0 | 20 | /** Test for Bug 248970 **/ |
michael@0 | 21 | // based on test_notifications.html |
michael@0 | 22 | |
michael@0 | 23 | const Ci = SpecialPowers.Ci; |
michael@0 | 24 | const Cc = SpecialPowers.Cc; |
michael@0 | 25 | const Cr = SpecialPowers.Cr; |
michael@0 | 26 | |
michael@0 | 27 | Components.utils.import("resource://gre/modules/Services.jsm"); |
michael@0 | 28 | |
michael@0 | 29 | var testpath = "/tests/toolkit/components/passwordmgr/test/"; |
michael@0 | 30 | var prefix = "http://test2.example.com" + testpath; |
michael@0 | 31 | var subtests = [ |
michael@0 | 32 | "subtst_privbrowsing_1.html", // 1 |
michael@0 | 33 | "subtst_privbrowsing_1.html", // 2 |
michael@0 | 34 | "subtst_privbrowsing_1.html", // 3 |
michael@0 | 35 | "subtst_privbrowsing_2.html", // 4 |
michael@0 | 36 | "subtst_privbrowsing_2.html", // 5 |
michael@0 | 37 | "subtst_privbrowsing_2.html", // 6 |
michael@0 | 38 | "subtst_privbrowsing_3.html", // 7 |
michael@0 | 39 | "subtst_privbrowsing_3.html", // 8 |
michael@0 | 40 | "subtst_privbrowsing_4.html", // 9 |
michael@0 | 41 | "subtst_privbrowsing_3.html" // 10 |
michael@0 | 42 | ]; |
michael@0 | 43 | |
michael@0 | 44 | var testNum = 0; |
michael@0 | 45 | function loadNextTest() { |
michael@0 | 46 | // run the initialization code for each test |
michael@0 | 47 | switch (++ testNum) { |
michael@0 | 48 | case 1: |
michael@0 | 49 | popupNotifications = normalWindowPopupNotifications; |
michael@0 | 50 | iframe = normalWindowIframe; |
michael@0 | 51 | break; |
michael@0 | 52 | |
michael@0 | 53 | case 2: |
michael@0 | 54 | popupNotifications = privateWindowPopupNotifications; |
michael@0 | 55 | iframe = privateWindowIframe; |
michael@0 | 56 | break; |
michael@0 | 57 | |
michael@0 | 58 | case 3: |
michael@0 | 59 | popupNotifications = normalWindowPopupNotifications; |
michael@0 | 60 | iframe = normalWindowIframe; |
michael@0 | 61 | break; |
michael@0 | 62 | |
michael@0 | 63 | case 4: |
michael@0 | 64 | pwmgr.addLogin(login); |
michael@0 | 65 | break; |
michael@0 | 66 | |
michael@0 | 67 | case 5: |
michael@0 | 68 | popupNotifications = privateWindowPopupNotifications; |
michael@0 | 69 | iframe = privateWindowIframe; |
michael@0 | 70 | break; |
michael@0 | 71 | |
michael@0 | 72 | case 6: |
michael@0 | 73 | popupNotifications = normalWindowPopupNotifications; |
michael@0 | 74 | iframe = normalWindowIframe; |
michael@0 | 75 | break; |
michael@0 | 76 | |
michael@0 | 77 | case 7: |
michael@0 | 78 | pwmgr.addLogin(login); |
michael@0 | 79 | break; |
michael@0 | 80 | |
michael@0 | 81 | case 8: |
michael@0 | 82 | popupNotifications = privateWindowPopupNotifications; |
michael@0 | 83 | iframe = privateWindowIframe; |
michael@0 | 84 | break; |
michael@0 | 85 | |
michael@0 | 86 | case 9: |
michael@0 | 87 | break; |
michael@0 | 88 | |
michael@0 | 89 | case 10: |
michael@0 | 90 | popupNotifications = normalWindowPopupNotifications; |
michael@0 | 91 | iframe = normalWindowIframe; |
michael@0 | 92 | break; |
michael@0 | 93 | |
michael@0 | 94 | default: |
michael@0 | 95 | ok(false, "Unexpected call to loadNextTest for test #" + testNum); |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | ok(true, "Starting test #" + testNum); |
michael@0 | 99 | iframe.src = prefix + subtests[testNum-1]; |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | |
michael@0 | 103 | function checkTest() { |
michael@0 | 104 | var popup; |
michael@0 | 105 | |
michael@0 | 106 | switch (testNum) { |
michael@0 | 107 | case 1: |
michael@0 | 108 | // run outside of private mode, popup notification should appear |
michael@0 | 109 | popup = getPopup(popupNotifications, "password-save"); |
michael@0 | 110 | ok(popup, "got popup notification"); |
michael@0 | 111 | popup.remove(); |
michael@0 | 112 | break; |
michael@0 | 113 | |
michael@0 | 114 | case 2: |
michael@0 | 115 | // run inside of private mode, popup notification should not appear |
michael@0 | 116 | popup = getPopup(popupNotifications, "password-save"); |
michael@0 | 117 | ok(!popup, "checking for no popup notification"); |
michael@0 | 118 | break; |
michael@0 | 119 | |
michael@0 | 120 | case 3: |
michael@0 | 121 | // run outside of private mode, popup notification should appear |
michael@0 | 122 | popup = getPopup(popupNotifications, "password-save"); |
michael@0 | 123 | ok(popup, "got popup notification"); |
michael@0 | 124 | popup.remove(); |
michael@0 | 125 | break; |
michael@0 | 126 | |
michael@0 | 127 | case 4: |
michael@0 | 128 | // run outside of private mode, popup notification should appear |
michael@0 | 129 | popup = getPopup(popupNotifications, "password-change"); |
michael@0 | 130 | ok(popup, "got popup notification"); |
michael@0 | 131 | popup.remove(); |
michael@0 | 132 | break; |
michael@0 | 133 | |
michael@0 | 134 | case 5: |
michael@0 | 135 | // run inside of private mode, popup notification should not appear |
michael@0 | 136 | popup = getPopup(popupNotifications, "password-change"); |
michael@0 | 137 | ok(!popup, "checking for no popup notification"); |
michael@0 | 138 | break; |
michael@0 | 139 | |
michael@0 | 140 | case 6: |
michael@0 | 141 | // run outside of private mode, popup notification should appear |
michael@0 | 142 | popup = getPopup(popupNotifications, "password-change"); |
michael@0 | 143 | ok(popup, "got popup notification"); |
michael@0 | 144 | popup.remove(); |
michael@0 | 145 | pwmgr.removeLogin(login); |
michael@0 | 146 | break; |
michael@0 | 147 | |
michael@0 | 148 | case 7: |
michael@0 | 149 | // verify that the user/pass pair was autofilled |
michael@0 | 150 | var gotUser = iframe.contentDocument.getElementById("user").textContent; |
michael@0 | 151 | var gotPass = iframe.contentDocument.getElementById("pass").textContent; |
michael@0 | 152 | is(gotUser, "notifyu1", "Checking submitted username"); |
michael@0 | 153 | is(gotPass, "notifyp1", "Checking submitted password"); |
michael@0 | 154 | break; |
michael@0 | 155 | |
michael@0 | 156 | case 8: |
michael@0 | 157 | // verify that the user/pass pair was not autofilled |
michael@0 | 158 | var gotUser = iframe.contentDocument.getElementById("user").textContent; |
michael@0 | 159 | var gotPass = iframe.contentDocument.getElementById("pass").textContent; |
michael@0 | 160 | is(gotUser, "", "Checking submitted username"); |
michael@0 | 161 | is(gotPass, "", "Checking submitted password"); |
michael@0 | 162 | break; |
michael@0 | 163 | |
michael@0 | 164 | case 9: |
michael@0 | 165 | // verify that the user/pass pair was available for autocomplete |
michael@0 | 166 | var gotUser = iframe.contentDocument.getElementById("user").textContent; |
michael@0 | 167 | var gotPass = iframe.contentDocument.getElementById("pass").textContent; |
michael@0 | 168 | is(gotUser, "notifyu1", "Checking submitted username"); |
michael@0 | 169 | is(gotPass, "notifyp1", "Checking submitted password"); |
michael@0 | 170 | break; |
michael@0 | 171 | |
michael@0 | 172 | case 10: |
michael@0 | 173 | // verify that the user/pass pair was autofilled |
michael@0 | 174 | var gotUser = iframe.contentDocument.getElementById("user").textContent; |
michael@0 | 175 | var gotPass = iframe.contentDocument.getElementById("pass").textContent; |
michael@0 | 176 | is(gotUser, "notifyu1", "Checking submitted username"); |
michael@0 | 177 | is(gotPass, "notifyp1", "Checking submitted password"); |
michael@0 | 178 | pwmgr.removeLogin(login); |
michael@0 | 179 | break; |
michael@0 | 180 | |
michael@0 | 181 | default: |
michael@0 | 182 | ok(false, "Unexpected call to checkTest for test #" + testNum); |
michael@0 | 183 | |
michael@0 | 184 | } |
michael@0 | 185 | } |
michael@0 | 186 | |
michael@0 | 187 | var mainWindow = window.QueryInterface(Ci.nsIInterfaceRequestor) |
michael@0 | 188 | .getInterface(Ci.nsIWebNavigation) |
michael@0 | 189 | .QueryInterface(Ci.nsIDocShellTreeItem) |
michael@0 | 190 | .rootTreeItem |
michael@0 | 191 | .QueryInterface(Ci.nsIInterfaceRequestor) |
michael@0 | 192 | .getInterface(Ci.nsIDOMWindow); |
michael@0 | 193 | var contentPage = "http://mochi.test:8888/tests/toolkit/components/passwordmgr/test/privbrowsing_perwindowpb_iframe.html"; |
michael@0 | 194 | var testWindows = []; |
michael@0 | 195 | |
michael@0 | 196 | function whenDelayedStartupFinished(aWindow, aCallback) { |
michael@0 | 197 | Services.obs.addObserver(function observer(aSubject, aTopic) { |
michael@0 | 198 | if (aWindow == aSubject) { |
michael@0 | 199 | Services.obs.removeObserver(observer, aTopic); |
michael@0 | 200 | setTimeout(aCallback, 0); |
michael@0 | 201 | } |
michael@0 | 202 | }, "browser-delayed-startup-finished", false); |
michael@0 | 203 | } |
michael@0 | 204 | |
michael@0 | 205 | function testOnWindow(aIsPrivate, aCallback) { |
michael@0 | 206 | var win = mainWindow.OpenBrowserWindow({private: aIsPrivate}); |
michael@0 | 207 | win.addEventListener("load", function onLoad() { |
michael@0 | 208 | win.removeEventListener("load", onLoad, false); |
michael@0 | 209 | whenDelayedStartupFinished(win, function() { |
michael@0 | 210 | win.addEventListener("DOMContentLoaded", function onInnerLoad() { |
michael@0 | 211 | if (win.content.location.href != contentPage) { |
michael@0 | 212 | win.gBrowser.loadURI(contentPage); |
michael@0 | 213 | return; |
michael@0 | 214 | } |
michael@0 | 215 | win.removeEventListener("DOMContentLoaded", onInnerLoad, true); |
michael@0 | 216 | |
michael@0 | 217 | win.content.addEventListener('load', function innerLoad2() { |
michael@0 | 218 | win.content.removeEventListener('load', innerLoad2, false); |
michael@0 | 219 | testWindows.push(win); |
michael@0 | 220 | SimpleTest.executeSoon(function() { aCallback(win); }); |
michael@0 | 221 | }, false, true); |
michael@0 | 222 | }, true); |
michael@0 | 223 | SimpleTest.executeSoon(function() { win.gBrowser.loadURI(contentPage); }); |
michael@0 | 224 | }); |
michael@0 | 225 | }, true); |
michael@0 | 226 | } |
michael@0 | 227 | |
michael@0 | 228 | var ignoreLoad = false; |
michael@0 | 229 | function handleLoad(aEvent) { |
michael@0 | 230 | // ignore every other load event ... We get one for loading the subtest (which |
michael@0 | 231 | // we want to ignore), and another when the subtest's form submits itself |
michael@0 | 232 | // (which we want to handle, to start the next test). |
michael@0 | 233 | ignoreLoad = !ignoreLoad; |
michael@0 | 234 | if (ignoreLoad) { |
michael@0 | 235 | ok(true, "Ignoring load of subtest #" + testNum); |
michael@0 | 236 | return; |
michael@0 | 237 | } |
michael@0 | 238 | ok(true, "Processing submission of subtest #" + testNum); |
michael@0 | 239 | |
michael@0 | 240 | checkTest(); |
michael@0 | 241 | |
michael@0 | 242 | if (testNum < subtests.length) { |
michael@0 | 243 | loadNextTest(); |
michael@0 | 244 | } else { |
michael@0 | 245 | ok(true, "private browsing notification tests finished."); |
michael@0 | 246 | |
michael@0 | 247 | testWindows.forEach(function(aWin) { |
michael@0 | 248 | aWin.close(); |
michael@0 | 249 | }); |
michael@0 | 250 | |
michael@0 | 251 | SimpleTest.finish(); |
michael@0 | 252 | } |
michael@0 | 253 | } |
michael@0 | 254 | |
michael@0 | 255 | var pwmgr = Cc["@mozilla.org/login-manager;1"]. |
michael@0 | 256 | getService(Ci.nsILoginManager); |
michael@0 | 257 | ok(pwmgr != null, "Access pwmgr"); |
michael@0 | 258 | |
michael@0 | 259 | // We need to make sure no logins have been stored by previous tests |
michael@0 | 260 | // for forms in |url|, otherwise the change password notification |
michael@0 | 261 | // would turn into a prompt, and the test will fail. |
michael@0 | 262 | var url = "http://test2.example.com"; |
michael@0 | 263 | is(pwmgr.countLogins(url, "", null), 0, "No logins should be stored for " + url); |
michael@0 | 264 | |
michael@0 | 265 | var nsLoginInfo = new SpecialPowers.wrap(SpecialPowers.Components).Constructor("@mozilla.org/login-manager/loginInfo;1", |
michael@0 | 266 | Ci.nsILoginInfo, "init"); |
michael@0 | 267 | var login = new nsLoginInfo(url, url, null, "notifyu1", "notifyp1", "user", "pass"); |
michael@0 | 268 | |
michael@0 | 269 | var normalWindow; |
michael@0 | 270 | var privateWindow; |
michael@0 | 271 | |
michael@0 | 272 | var iframe; |
michael@0 | 273 | var normalWindowIframe; |
michael@0 | 274 | var privateWindowIframe; |
michael@0 | 275 | |
michael@0 | 276 | var popupNotifications; |
michael@0 | 277 | var normalWindowPopupNotifications; |
michael@0 | 278 | var privateWindowPopupNotifications; |
michael@0 | 279 | |
michael@0 | 280 | testOnWindow(false, function(aWin) { |
michael@0 | 281 | var selectedBrowser = aWin.gBrowser.selectedBrowser; |
michael@0 | 282 | normalWindowIframe = selectedBrowser.contentDocument.getElementById("iframe"); |
michael@0 | 283 | normalWindowIframe.onload = handleLoad; |
michael@0 | 284 | selectedBrowser.focus(); |
michael@0 | 285 | |
michael@0 | 286 | normalWindowPopupNotifications = getPopupNotifications(selectedBrowser.contentWindow.top); |
michael@0 | 287 | ok(normalWindowPopupNotifications, "Got popupNotifications in normal window"); |
michael@0 | 288 | // ignore the first load for this window; |
michael@0 | 289 | ignoreLoad = false; |
michael@0 | 290 | |
michael@0 | 291 | testOnWindow(true, function(aPrivateWin) { |
michael@0 | 292 | selectedBrowser = aPrivateWin.gBrowser.selectedBrowser; |
michael@0 | 293 | privateWindowIframe = selectedBrowser.contentDocument.getElementById("iframe"); |
michael@0 | 294 | privateWindowIframe.onload = handleLoad; |
michael@0 | 295 | selectedBrowser.focus(); |
michael@0 | 296 | |
michael@0 | 297 | privateWindowPopupNotifications = getPopupNotifications(selectedBrowser.contentWindow.top); |
michael@0 | 298 | ok(privateWindowPopupNotifications, "Got popupNotifications in private window"); |
michael@0 | 299 | // ignore the first load for this window; |
michael@0 | 300 | ignoreLoad = false; |
michael@0 | 301 | |
michael@0 | 302 | SimpleTest.executeSoon(loadNextTest); |
michael@0 | 303 | }); |
michael@0 | 304 | }); |
michael@0 | 305 | |
michael@0 | 306 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 307 | </script> |
michael@0 | 308 | </pre> |
michael@0 | 309 | </body> |
michael@0 | 310 | </html> |
michael@0 | 311 |