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 | <head> |
michael@0 | 4 | <title>Test for Login Manager</title> |
michael@0 | 5 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 6 | <script type="text/javascript" src="pwmgr_common.js"></script> |
michael@0 | 7 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 8 | </head> |
michael@0 | 9 | <body> |
michael@0 | 10 | Login Manager test: 227640 |
michael@0 | 11 | <script> |
michael@0 | 12 | commonInit(); |
michael@0 | 13 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 14 | |
michael@0 | 15 | var pwmgr = SpecialPowers.Cc["@mozilla.org/login-manager;1"] |
michael@0 | 16 | .getService(SpecialPowers.Ci.nsILoginManager); |
michael@0 | 17 | </script> |
michael@0 | 18 | |
michael@0 | 19 | <p id="display"></p> |
michael@0 | 20 | <div id="content" style="display: none"> |
michael@0 | 21 | |
michael@0 | 22 | <!-- no autocomplete for password field --> |
michael@0 | 23 | <form id="form1" onsubmit="return checkSubmit(1)" method="get"> |
michael@0 | 24 | <input type="text" name="uname" value=""> |
michael@0 | 25 | <input type="password" name="pword" value="" autocomplete=off> |
michael@0 | 26 | |
michael@0 | 27 | <button type="submit">Submit</button> |
michael@0 | 28 | <button type="reset"> Reset </button> |
michael@0 | 29 | </form> |
michael@0 | 30 | |
michael@0 | 31 | <!-- no autocomplete for username field --> |
michael@0 | 32 | <form id="form2" onsubmit="return checkSubmit(2);" method="get"> |
michael@0 | 33 | <input type="text" name="uname" value="" autocomplete=off> |
michael@0 | 34 | <input type="password" name="pword" value=""> |
michael@0 | 35 | |
michael@0 | 36 | <button type="submit">Submit</button> |
michael@0 | 37 | <button type="reset"> Reset </button> |
michael@0 | 38 | </form> |
michael@0 | 39 | |
michael@0 | 40 | <!-- no autocomplete for username or password fields --> |
michael@0 | 41 | <form id="form3" onsubmit="return checkSubmit(3);" method="get"> |
michael@0 | 42 | <input type="text" name="uname" value="" autocomplete=off> |
michael@0 | 43 | <input type="password" name="pword" value="" autocomplete=off> |
michael@0 | 44 | |
michael@0 | 45 | <button type="submit">Submit</button> |
michael@0 | 46 | <button type="reset"> Reset </button> |
michael@0 | 47 | </form> |
michael@0 | 48 | |
michael@0 | 49 | <!-- no autocomplete for entire form --> |
michael@0 | 50 | <form id="form4" onsubmit="return checkSubmit(4);" method="get" autocomplete=off> |
michael@0 | 51 | <input type="text" name="uname" value=""> |
michael@0 | 52 | <input type="password" name="pword" value=""> |
michael@0 | 53 | |
michael@0 | 54 | <button type="submit">Submit</button> |
michael@0 | 55 | <button type="reset"> Reset </button> |
michael@0 | 56 | </form> |
michael@0 | 57 | |
michael@0 | 58 | <!-- no autocomplete for entire form and password field --> |
michael@0 | 59 | <form id="form5" onsubmit="return checkSubmit(5);" method="get"> |
michael@0 | 60 | <input type="text" name="uname" value=""> |
michael@0 | 61 | <input type="password" name="pword" value="" autocomplete=off> |
michael@0 | 62 | |
michael@0 | 63 | <button type="submit">Submit</button> |
michael@0 | 64 | <button type="reset"> Reset </button> |
michael@0 | 65 | </form> |
michael@0 | 66 | |
michael@0 | 67 | <!-- no autocomplete for entire form and username field --> |
michael@0 | 68 | <form id="form6" onsubmit="return checkSubmit(6);" method="get"> |
michael@0 | 69 | <input type="text" name="uname" value="" autocomplete=off> |
michael@0 | 70 | <input type="password" name="pword" value=""> |
michael@0 | 71 | |
michael@0 | 72 | <button type="submit">Submit</button> |
michael@0 | 73 | <button type="reset"> Reset </button> |
michael@0 | 74 | </form> |
michael@0 | 75 | |
michael@0 | 76 | <!-- no autocomplete for entire form, userfield, and password field --> |
michael@0 | 77 | <form id="form7" onsubmit="return checkSubmit(7);" method="get" autocomplete=off> |
michael@0 | 78 | <input type="text" name="uname" value="" autocomplete=off> |
michael@0 | 79 | <input type="password" name="pword" value="" autocomplete=off> |
michael@0 | 80 | |
michael@0 | 81 | <button type="submit">Submit</button> |
michael@0 | 82 | <button type="reset"> Reset </button> |
michael@0 | 83 | </form> |
michael@0 | 84 | |
michael@0 | 85 | |
michael@0 | 86 | <!-- ===== repeat, but with logins not previously stored ===== --> |
michael@0 | 87 | |
michael@0 | 88 | |
michael@0 | 89 | <!-- no autocomplete for password field --> |
michael@0 | 90 | <form id="form8" onsubmit="return checkSubmit(8);" method="get"> |
michael@0 | 91 | <input type="text" name="xxxuname" value="newuser"> |
michael@0 | 92 | <input type="password" name="xxxpword" value="newpass" autocomplete=off> |
michael@0 | 93 | |
michael@0 | 94 | <button type="submit">Submit</button> |
michael@0 | 95 | <button type="reset"> Reset </button> |
michael@0 | 96 | </form> |
michael@0 | 97 | |
michael@0 | 98 | <!-- no autocomplete for username field --> |
michael@0 | 99 | <form id="form9" onsubmit="return checkSubmit(9);" method="get"> |
michael@0 | 100 | <input type="text" name="xxxuname" value="newuser" autocomplete=off> |
michael@0 | 101 | <input type="password" name="xxxpword" value="newpass"> |
michael@0 | 102 | |
michael@0 | 103 | <button type="submit">Submit</button> |
michael@0 | 104 | <button type="reset"> Reset </button> |
michael@0 | 105 | </form> |
michael@0 | 106 | |
michael@0 | 107 | <!-- no autocomplete for username or password fields --> |
michael@0 | 108 | <form id="form10" onsubmit="return checkSubmit(10);" method="get"> |
michael@0 | 109 | <input type="text" name="xxxuname" value="newuser" autocomplete=off> |
michael@0 | 110 | <input type="password" name="xxxpword" value="newpass" autocomplete=off> |
michael@0 | 111 | |
michael@0 | 112 | <button type="submit">Submit</button> |
michael@0 | 113 | <button type="reset"> Reset </button> |
michael@0 | 114 | </form> |
michael@0 | 115 | |
michael@0 | 116 | <!-- no autocomplete for entire form --> |
michael@0 | 117 | <form id="form11" onsubmit="return checkSubmit(11);" method="get" autocomplete=off> |
michael@0 | 118 | <input type="text" name="xxxuname" value="newuser"> |
michael@0 | 119 | <input type="password" name="xxxpword" value="newpass"> |
michael@0 | 120 | |
michael@0 | 121 | <button type="submit">Submit</button> |
michael@0 | 122 | <button type="reset"> Reset </button> |
michael@0 | 123 | </form> |
michael@0 | 124 | |
michael@0 | 125 | <!-- no autocomplete for entire form and password field --> |
michael@0 | 126 | <form id="form12" onsubmit="return checkSubmit(12);" method="get"> |
michael@0 | 127 | <input type="text" name="xxxuname" value="newuser"> |
michael@0 | 128 | <input type="password" name="xxxpword" value="newpass" autocomplete=off> |
michael@0 | 129 | |
michael@0 | 130 | <button type="submit">Submit</button> |
michael@0 | 131 | <button type="reset"> Reset </button> |
michael@0 | 132 | </form> |
michael@0 | 133 | |
michael@0 | 134 | <!-- no autocomplete for entire form and username field --> |
michael@0 | 135 | <form id="form13" onsubmit="return checkSubmit(13);" method="get"> |
michael@0 | 136 | <input type="text" name="xxxuname" value="newuser" autocomplete=off> |
michael@0 | 137 | <input type="password" name="xxxpword" value="newpass"> |
michael@0 | 138 | |
michael@0 | 139 | <button type="submit">Submit</button> |
michael@0 | 140 | <button type="reset"> Reset </button> |
michael@0 | 141 | </form> |
michael@0 | 142 | |
michael@0 | 143 | <!-- no autocomplete for entire form, userfield, and password field --> |
michael@0 | 144 | <form id="form14" onsubmit="return checkSubmit(14);" method="get" autocomplete=off> |
michael@0 | 145 | <input type="text" name="xxxuname" value="newuser" autocomplete=off> |
michael@0 | 146 | <input type="password" name="xxxpword" value="newpass" autocomplete=off> |
michael@0 | 147 | |
michael@0 | 148 | <button type="submit">Submit</button> |
michael@0 | 149 | <button type="reset"> Reset </button> |
michael@0 | 150 | </form> |
michael@0 | 151 | |
michael@0 | 152 | </div> |
michael@0 | 153 | <pre id="test"> |
michael@0 | 154 | <script class="testbody" type="text/javascript"> |
michael@0 | 155 | |
michael@0 | 156 | /** Test for Login Manager: 227640 (password is saved even when the |
michael@0 | 157 | password field has autocomplete="off") **/ |
michael@0 | 158 | |
michael@0 | 159 | // This test ensures that pwmgr does not save a username or password when |
michael@0 | 160 | // autocomplete=off is present. |
michael@0 | 161 | |
michael@0 | 162 | var numStartingLogins = 0; |
michael@0 | 163 | var numSubmittedForms = 0; |
michael@0 | 164 | |
michael@0 | 165 | function startTest() { |
michael@0 | 166 | // Get current number of logins, so we can know if some accidently get |
michael@0 | 167 | // added during the test. |
michael@0 | 168 | numStartingLogins = countLogins(); |
michael@0 | 169 | ok(numStartingLogins > 0, "counting logins at start"); |
michael@0 | 170 | |
michael@0 | 171 | // Check first set of forms, which should not be filled by pwmgr. |
michael@0 | 172 | for (var i = 1; i <= 7; i++) { |
michael@0 | 173 | is($_(i, "uname").value, "", "Checking for unfilled username " + i); |
michael@0 | 174 | is($_(i, "pword").value, "", "Checking for unfilled password " + i); |
michael@0 | 175 | // Set the field values to that of an existing login |
michael@0 | 176 | $_(i, "uname").value = "testuser"; |
michael@0 | 177 | $_(i, "pword").value = "testpass"; |
michael@0 | 178 | } |
michael@0 | 179 | |
michael@0 | 180 | // Check second set of forms, which should have preset values (and are unknown to pwmgr). |
michael@0 | 181 | for (var i = 8; i <= 14; i++) { |
michael@0 | 182 | is($_(i, "xxxuname").value, "newuser", "Checking unmodified username " + i); |
michael@0 | 183 | is($_(i, "xxxpword").value, "newpass", "Checking unmodified password " + i); |
michael@0 | 184 | } |
michael@0 | 185 | |
michael@0 | 186 | var button = getFormSubmitButton(1); |
michael@0 | 187 | |
michael@0 | 188 | // submit the first form. |
michael@0 | 189 | button.click(); |
michael@0 | 190 | } |
michael@0 | 191 | |
michael@0 | 192 | |
michael@0 | 193 | // Called by each form's onsubmit handler. |
michael@0 | 194 | function checkSubmit(formNum) { |
michael@0 | 195 | numSubmittedForms++; |
michael@0 | 196 | |
michael@0 | 197 | // End the test at the last form. |
michael@0 | 198 | if (formNum == 14) { |
michael@0 | 199 | is(numSubmittedForms, 14, "Ensuring all forms were submitted.");; |
michael@0 | 200 | |
michael@0 | 201 | var numEndingLogins = countLogins(); |
michael@0 | 202 | ok(numEndingLogins > 0, "counting logins at end"); |
michael@0 | 203 | |
michael@0 | 204 | is(numStartingLogins, numEndingLogins, "counting logins at end"); |
michael@0 | 205 | |
michael@0 | 206 | SimpleTest.finish(); |
michael@0 | 207 | return false; // return false to cancel current form submission |
michael@0 | 208 | } |
michael@0 | 209 | |
michael@0 | 210 | var button = getFormSubmitButton(formNum + 1); |
michael@0 | 211 | |
michael@0 | 212 | // submit the next form. |
michael@0 | 213 | button.click(); |
michael@0 | 214 | |
michael@0 | 215 | return false; // return false to cancel current form submission |
michael@0 | 216 | } |
michael@0 | 217 | |
michael@0 | 218 | |
michael@0 | 219 | function getFormSubmitButton(formNum) { |
michael@0 | 220 | var form = $("form" + formNum); // by id, not name |
michael@0 | 221 | ok(form != null, "getting form " + formNum); |
michael@0 | 222 | |
michael@0 | 223 | // we can't just call form.submit(), because that doesn't seem to |
michael@0 | 224 | // invoke the form onsubmit handler. |
michael@0 | 225 | var button = form.firstChild; |
michael@0 | 226 | while (button && button.type != "submit") { button = button.nextSibling; } |
michael@0 | 227 | ok(button != null, "getting form submit button"); |
michael@0 | 228 | |
michael@0 | 229 | return button; |
michael@0 | 230 | } |
michael@0 | 231 | |
michael@0 | 232 | // Counts the number of logins currently stored by password manager. |
michael@0 | 233 | function countLogins() { |
michael@0 | 234 | var logins = pwmgr.getAllLogins(); |
michael@0 | 235 | |
michael@0 | 236 | return logins.length; |
michael@0 | 237 | } |
michael@0 | 238 | window.onload = startTest; |
michael@0 | 239 | </script> |
michael@0 | 240 | </pre> |
michael@0 | 241 | </body> |
michael@0 | 242 | </html> |
michael@0 | 243 |