|
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: forms and logins without a username. |
|
11 <script> |
|
12 commonInit(); |
|
13 SimpleTest.waitForExplicitFinish(); |
|
14 |
|
15 var pwmgr = SpecialPowers.Cc["@mozilla.org/login-manager;1"] |
|
16 .getService(SpecialPowers.Ci.nsILoginManager); |
|
17 |
|
18 var nsLoginInfo = new SpecialPowers.wrap(SpecialPowers.Components).Constructor("@mozilla.org/login-manager/loginInfo;1", SpecialPowers.Ci.nsILoginInfo); |
|
19 ok(nsLoginInfo != null, "nsLoginInfo constructor"); |
|
20 |
|
21 // pwlogin1 uses a unique formSubmitURL, to check forms where no other logins |
|
22 // will apply. pwlogin2 uses the normal formSubmitURL, so that we can test |
|
23 // forms with a mix of username and non-username logins that might apply. |
|
24 // |
|
25 // Note: pwlogin2 is deleted at the end of the test. |
|
26 |
|
27 pwlogin1 = new nsLoginInfo(); |
|
28 pwlogin2 = new nsLoginInfo(); |
|
29 |
|
30 pwlogin1.init("http://mochi.test:8888", "http://mochi.test:1111", null, |
|
31 "", "1234", "uname", "pword"); |
|
32 |
|
33 pwlogin2.init("http://mochi.test:8888", "http://mochi.test:8888", null, |
|
34 "", "1234", "uname", "pword"); |
|
35 |
|
36 try { |
|
37 pwmgr.addLogin(pwlogin1); |
|
38 pwmgr.addLogin(pwlogin2); |
|
39 } catch (e) { |
|
40 ok(false, "addLogin threw: " + e); |
|
41 } |
|
42 |
|
43 </script> |
|
44 <p id="display"></p> |
|
45 |
|
46 <div id="content" style="display: none"> |
|
47 |
|
48 |
|
49 <!-- simple form: no username field, 1 password field --> |
|
50 <form id='form1' action='http://mochi.test:1111/formtest.js'> 1 |
|
51 <input type='password' name='pname' value=''> |
|
52 |
|
53 <button type='submit'>Submit</button> |
|
54 <button type='reset'> Reset </button> |
|
55 </form> |
|
56 |
|
57 <!-- simple form: no username field, 2 password fields --> |
|
58 <form id='form2' action='http://mochi.test:1111/formtest.js'> 2 |
|
59 <input type='password' name='pname1' value=''> |
|
60 <input type='password' name='pname2' value=''> |
|
61 |
|
62 <button type='submit'>Submit</button> |
|
63 <button type='reset'> Reset </button> |
|
64 </form> |
|
65 |
|
66 <!-- simple form: no username field, 3 password fields --> |
|
67 <form id='form3' action='http://mochi.test:1111/formtest.js'> 3 |
|
68 <input type='password' name='pname1' value=''> |
|
69 <input type='password' name='pname2' value=''> |
|
70 <input type='password' name='pname3' value=''> |
|
71 |
|
72 <button type='submit'>Submit</button> |
|
73 <button type='reset'> Reset </button> |
|
74 </form> |
|
75 |
|
76 <!-- 4 password fields, should be ignored. --> |
|
77 <form id='form4' action='http://mochi.test:1111/formtest.js'> 4 |
|
78 <input type='password' name='pname1' value=''> |
|
79 <input type='password' name='pname2' value=''> |
|
80 <input type='password' name='pname3' value=''> |
|
81 <input type='password' name='pname4' value=''> |
|
82 |
|
83 <button type='submit'>Submit</button> |
|
84 <button type='reset'> Reset </button> |
|
85 </form> |
|
86 |
|
87 |
|
88 |
|
89 <!-- 1 username field --> |
|
90 <form id='form5' action='http://mochi.test:1111/formtest.js'> 5 |
|
91 <input type='text' name='uname' value=''> |
|
92 <input type='password' name='pname' value=''> |
|
93 |
|
94 <button type='submit'>Submit</button> |
|
95 <button type='reset'> Reset </button> |
|
96 </form> |
|
97 |
|
98 |
|
99 <!-- 1 username field, with a value set --> |
|
100 <form id='form6' action='http://mochi.test:1111/formtest.js'> 6 |
|
101 <input type='text' name='uname' value='someuser'> |
|
102 <input type='password' name='pname' value=''> |
|
103 |
|
104 <button type='submit'>Submit</button> |
|
105 <button type='reset'> Reset </button> |
|
106 </form> |
|
107 |
|
108 |
|
109 |
|
110 <!-- |
|
111 (The following forms have 2 potentially-matching logins, on is |
|
112 password-only, the other is username+password) |
|
113 --> |
|
114 |
|
115 |
|
116 |
|
117 <!-- 1 username field, with value set. Fill in the matching U+P login --> |
|
118 <form id='form7' action='formtest.js'> 7 |
|
119 <input type='text' name='uname' value='testuser'> |
|
120 <input type='password' name='pname' value=''> |
|
121 |
|
122 <button type='submit'>Submit</button> |
|
123 <button type='reset'> Reset </button> |
|
124 </form> |
|
125 |
|
126 <!-- 1 username field, with value set. Don't fill in U+P login--> |
|
127 <form id='form8' action='formtest.js'> 8 |
|
128 <input type='text' name='uname' value='someuser'> |
|
129 <input type='password' name='pname' value=''> |
|
130 |
|
131 <button type='submit'>Submit</button> |
|
132 <button type='reset'> Reset </button> |
|
133 </form> |
|
134 |
|
135 |
|
136 |
|
137 <!-- 1 username field, too small for U+P login --> |
|
138 <form id='form9' action='formtest.js'> 9 |
|
139 <input type='text' name='uname' value='' maxlength="4"> |
|
140 <input type='password' name='pname' value=''> |
|
141 |
|
142 <button type='submit'>Submit</button> |
|
143 <button type='reset'> Reset </button> |
|
144 </form> |
|
145 |
|
146 <!-- 1 username field, too small for U+P login --> |
|
147 <form id='form10' action='formtest.js'> 10 |
|
148 <input type='text' name='uname' value='' maxlength="0"> |
|
149 <input type='password' name='pname' value=''> |
|
150 |
|
151 <button type='submit'>Submit</button> |
|
152 <button type='reset'> Reset </button> |
|
153 </form> |
|
154 |
|
155 <!-- 1 username field, too small for U+P login --> |
|
156 <form id='form11' action='formtest.js'> 11 |
|
157 <input type='text' name='uname' value=''> |
|
158 <input type='password' name='pname' value='' maxlength="4"> |
|
159 |
|
160 <button type='submit'>Submit</button> |
|
161 <button type='reset'> Reset </button> |
|
162 </form> |
|
163 |
|
164 <!-- 1 username field, too small for either login --> |
|
165 <form id='form12' action='formtest.js'> 12 |
|
166 <input type='text' name='uname' value=''> |
|
167 <input type='password' name='pname' value='' maxlength="1"> |
|
168 |
|
169 <button type='submit'>Submit</button> |
|
170 <button type='reset'> Reset </button> |
|
171 </form> |
|
172 |
|
173 <!-- 1 username field, too small for either login --> |
|
174 <form id='form13' action='formtest.js'> 13 |
|
175 <input type='text' name='uname' value=''> |
|
176 <input type='password' name='pname' value='' maxlength="0"> |
|
177 |
|
178 <button type='submit'>Submit</button> |
|
179 <button type='reset'> Reset </button> |
|
180 </form> |
|
181 |
|
182 |
|
183 |
|
184 </div> |
|
185 |
|
186 <pre id="test"> |
|
187 <script class="testbody" type="text/javascript"> |
|
188 |
|
189 /** Test for Login Manager: password-only logins **/ |
|
190 function startTest() { |
|
191 |
|
192 checkForm(1, "1234"); |
|
193 checkForm(2, "1234", ""); |
|
194 checkForm(3, "1234", "", ""); |
|
195 checkUnmodifiedForm(4); |
|
196 |
|
197 checkForm(5, "", "1234"); |
|
198 checkForm(6, "someuser", ""); |
|
199 |
|
200 checkForm(7, "testuser", "testpass"); |
|
201 checkForm(8, "someuser", ""); |
|
202 |
|
203 checkForm(9, "", "1234"); |
|
204 checkForm(10, "", "1234"); |
|
205 checkForm(11, "", "1234"); |
|
206 |
|
207 checkUnmodifiedForm(12); |
|
208 checkUnmodifiedForm(13); |
|
209 |
|
210 pwmgr.removeLogin(pwlogin2); |
|
211 SimpleTest.finish(); |
|
212 } |
|
213 |
|
214 window.onload = startTest; |
|
215 </script> |
|
216 </pre> |
|
217 </body> |
|
218 </html> |
|
219 |