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