1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/passwordmgr/test/test_bug_227640.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,243 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<head> 1.7 + <title>Test for Login Manager</title> 1.8 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.9 + <script type="text/javascript" src="pwmgr_common.js"></script> 1.10 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.11 +</head> 1.12 +<body> 1.13 +Login Manager test: 227640 1.14 +<script> 1.15 +commonInit(); 1.16 +SimpleTest.waitForExplicitFinish(); 1.17 + 1.18 +var pwmgr = SpecialPowers.Cc["@mozilla.org/login-manager;1"] 1.19 + .getService(SpecialPowers.Ci.nsILoginManager); 1.20 +</script> 1.21 + 1.22 +<p id="display"></p> 1.23 +<div id="content" style="display: none"> 1.24 + 1.25 + <!-- no autocomplete for password field --> 1.26 + <form id="form1" onsubmit="return checkSubmit(1)" method="get"> 1.27 + <input type="text" name="uname" value=""> 1.28 + <input type="password" name="pword" value="" autocomplete=off> 1.29 + 1.30 + <button type="submit">Submit</button> 1.31 + <button type="reset"> Reset </button> 1.32 + </form> 1.33 + 1.34 + <!-- no autocomplete for username field --> 1.35 + <form id="form2" onsubmit="return checkSubmit(2);" method="get"> 1.36 + <input type="text" name="uname" value="" autocomplete=off> 1.37 + <input type="password" name="pword" value=""> 1.38 + 1.39 + <button type="submit">Submit</button> 1.40 + <button type="reset"> Reset </button> 1.41 + </form> 1.42 + 1.43 + <!-- no autocomplete for username or password fields --> 1.44 + <form id="form3" onsubmit="return checkSubmit(3);" method="get"> 1.45 + <input type="text" name="uname" value="" autocomplete=off> 1.46 + <input type="password" name="pword" value="" autocomplete=off> 1.47 + 1.48 + <button type="submit">Submit</button> 1.49 + <button type="reset"> Reset </button> 1.50 + </form> 1.51 + 1.52 + <!-- no autocomplete for entire form --> 1.53 + <form id="form4" onsubmit="return checkSubmit(4);" method="get" autocomplete=off> 1.54 + <input type="text" name="uname" value=""> 1.55 + <input type="password" name="pword" value=""> 1.56 + 1.57 + <button type="submit">Submit</button> 1.58 + <button type="reset"> Reset </button> 1.59 + </form> 1.60 + 1.61 + <!-- no autocomplete for entire form and password field --> 1.62 + <form id="form5" onsubmit="return checkSubmit(5);" method="get"> 1.63 + <input type="text" name="uname" value=""> 1.64 + <input type="password" name="pword" value="" autocomplete=off> 1.65 + 1.66 + <button type="submit">Submit</button> 1.67 + <button type="reset"> Reset </button> 1.68 + </form> 1.69 + 1.70 + <!-- no autocomplete for entire form and username field --> 1.71 + <form id="form6" onsubmit="return checkSubmit(6);" method="get"> 1.72 + <input type="text" name="uname" value="" autocomplete=off> 1.73 + <input type="password" name="pword" value=""> 1.74 + 1.75 + <button type="submit">Submit</button> 1.76 + <button type="reset"> Reset </button> 1.77 + </form> 1.78 + 1.79 + <!-- no autocomplete for entire form, userfield, and password field --> 1.80 + <form id="form7" onsubmit="return checkSubmit(7);" method="get" autocomplete=off> 1.81 + <input type="text" name="uname" value="" autocomplete=off> 1.82 + <input type="password" name="pword" value="" autocomplete=off> 1.83 + 1.84 + <button type="submit">Submit</button> 1.85 + <button type="reset"> Reset </button> 1.86 + </form> 1.87 + 1.88 + 1.89 + <!-- ===== repeat, but with logins not previously stored ===== --> 1.90 + 1.91 + 1.92 + <!-- no autocomplete for password field --> 1.93 + <form id="form8" onsubmit="return checkSubmit(8);" method="get"> 1.94 + <input type="text" name="xxxuname" value="newuser"> 1.95 + <input type="password" name="xxxpword" value="newpass" autocomplete=off> 1.96 + 1.97 + <button type="submit">Submit</button> 1.98 + <button type="reset"> Reset </button> 1.99 + </form> 1.100 + 1.101 + <!-- no autocomplete for username field --> 1.102 + <form id="form9" onsubmit="return checkSubmit(9);" method="get"> 1.103 + <input type="text" name="xxxuname" value="newuser" autocomplete=off> 1.104 + <input type="password" name="xxxpword" value="newpass"> 1.105 + 1.106 + <button type="submit">Submit</button> 1.107 + <button type="reset"> Reset </button> 1.108 + </form> 1.109 + 1.110 + <!-- no autocomplete for username or password fields --> 1.111 + <form id="form10" onsubmit="return checkSubmit(10);" method="get"> 1.112 + <input type="text" name="xxxuname" value="newuser" autocomplete=off> 1.113 + <input type="password" name="xxxpword" value="newpass" autocomplete=off> 1.114 + 1.115 + <button type="submit">Submit</button> 1.116 + <button type="reset"> Reset </button> 1.117 + </form> 1.118 + 1.119 + <!-- no autocomplete for entire form --> 1.120 + <form id="form11" onsubmit="return checkSubmit(11);" method="get" autocomplete=off> 1.121 + <input type="text" name="xxxuname" value="newuser"> 1.122 + <input type="password" name="xxxpword" value="newpass"> 1.123 + 1.124 + <button type="submit">Submit</button> 1.125 + <button type="reset"> Reset </button> 1.126 + </form> 1.127 + 1.128 + <!-- no autocomplete for entire form and password field --> 1.129 + <form id="form12" onsubmit="return checkSubmit(12);" method="get"> 1.130 + <input type="text" name="xxxuname" value="newuser"> 1.131 + <input type="password" name="xxxpword" value="newpass" autocomplete=off> 1.132 + 1.133 + <button type="submit">Submit</button> 1.134 + <button type="reset"> Reset </button> 1.135 + </form> 1.136 + 1.137 + <!-- no autocomplete for entire form and username field --> 1.138 + <form id="form13" onsubmit="return checkSubmit(13);" method="get"> 1.139 + <input type="text" name="xxxuname" value="newuser" autocomplete=off> 1.140 + <input type="password" name="xxxpword" value="newpass"> 1.141 + 1.142 + <button type="submit">Submit</button> 1.143 + <button type="reset"> Reset </button> 1.144 + </form> 1.145 + 1.146 + <!-- no autocomplete for entire form, userfield, and password field --> 1.147 + <form id="form14" onsubmit="return checkSubmit(14);" method="get" autocomplete=off> 1.148 + <input type="text" name="xxxuname" value="newuser" autocomplete=off> 1.149 + <input type="password" name="xxxpword" value="newpass" autocomplete=off> 1.150 + 1.151 + <button type="submit">Submit</button> 1.152 + <button type="reset"> Reset </button> 1.153 + </form> 1.154 + 1.155 +</div> 1.156 +<pre id="test"> 1.157 +<script class="testbody" type="text/javascript"> 1.158 + 1.159 +/** Test for Login Manager: 227640 (password is saved even when the 1.160 + password field has autocomplete="off") **/ 1.161 + 1.162 +// This test ensures that pwmgr does not save a username or password when 1.163 +// autocomplete=off is present. 1.164 + 1.165 +var numStartingLogins = 0; 1.166 +var numSubmittedForms = 0; 1.167 + 1.168 +function startTest() { 1.169 + // Get current number of logins, so we can know if some accidently get 1.170 + // added during the test. 1.171 + numStartingLogins = countLogins(); 1.172 + ok(numStartingLogins > 0, "counting logins at start"); 1.173 + 1.174 + // Check first set of forms, which should not be filled by pwmgr. 1.175 + for (var i = 1; i <= 7; i++) { 1.176 + is($_(i, "uname").value, "", "Checking for unfilled username " + i); 1.177 + is($_(i, "pword").value, "", "Checking for unfilled password " + i); 1.178 + // Set the field values to that of an existing login 1.179 + $_(i, "uname").value = "testuser"; 1.180 + $_(i, "pword").value = "testpass"; 1.181 + } 1.182 + 1.183 + // Check second set of forms, which should have preset values (and are unknown to pwmgr). 1.184 + for (var i = 8; i <= 14; i++) { 1.185 + is($_(i, "xxxuname").value, "newuser", "Checking unmodified username " + i); 1.186 + is($_(i, "xxxpword").value, "newpass", "Checking unmodified password " + i); 1.187 + } 1.188 + 1.189 + var button = getFormSubmitButton(1); 1.190 + 1.191 + // submit the first form. 1.192 + button.click(); 1.193 +} 1.194 + 1.195 + 1.196 +// Called by each form's onsubmit handler. 1.197 +function checkSubmit(formNum) { 1.198 + numSubmittedForms++; 1.199 + 1.200 + // End the test at the last form. 1.201 + if (formNum == 14) { 1.202 + is(numSubmittedForms, 14, "Ensuring all forms were submitted.");; 1.203 + 1.204 + var numEndingLogins = countLogins(); 1.205 + ok(numEndingLogins > 0, "counting logins at end"); 1.206 + 1.207 + is(numStartingLogins, numEndingLogins, "counting logins at end"); 1.208 + 1.209 + SimpleTest.finish(); 1.210 + return false; // return false to cancel current form submission 1.211 + } 1.212 + 1.213 + var button = getFormSubmitButton(formNum + 1); 1.214 + 1.215 + // submit the next form. 1.216 + button.click(); 1.217 + 1.218 + return false; // return false to cancel current form submission 1.219 +} 1.220 + 1.221 + 1.222 +function getFormSubmitButton(formNum) { 1.223 + var form = $("form" + formNum); // by id, not name 1.224 + ok(form != null, "getting form " + formNum); 1.225 + 1.226 + // we can't just call form.submit(), because that doesn't seem to 1.227 + // invoke the form onsubmit handler. 1.228 + var button = form.firstChild; 1.229 + while (button && button.type != "submit") { button = button.nextSibling; } 1.230 + ok(button != null, "getting form submit button"); 1.231 + 1.232 + return button; 1.233 +} 1.234 + 1.235 +// Counts the number of logins currently stored by password manager. 1.236 +function countLogins() { 1.237 + var logins = pwmgr.getAllLogins(); 1.238 + 1.239 + return logins.length; 1.240 +} 1.241 +window.onload = startTest; 1.242 +</script> 1.243 +</pre> 1.244 +</body> 1.245 +</html> 1.246 +