summaryrefslogtreecommitdiffstats
path: root/toolkit/components/passwordmgr/test/mochitest/test_basic_form_pwonly.html
blob: 40fec8c462b7607b0ffb805e319fd3337d86e660 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <title>Test forms and logins without a username</title>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript" src="pwmgr_common.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
Login Manager test: forms and logins without a username.
<script>
runChecksAfterCommonInit(() => startTest());
runInParent(() => {
  const { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components;
  var pwmgr = Cc["@mozilla.org/login-manager;1"]
              .getService(Ci.nsILoginManager);

  var nsLoginInfo = Components.Constructor("@mozilla.org/login-manager/loginInfo;1", Ci.nsILoginInfo);

  // pwlogin1 uses a unique formSubmitURL, to check forms where no other logins
  // will apply. pwlogin2 uses the normal formSubmitURL, so that we can test
  // forms with a mix of username and non-username logins that might apply.
  //
  // Note: pwlogin2 is deleted at the end of the test.

  pwlogin1 = new nsLoginInfo();
  pwlogin2 = new nsLoginInfo();

  pwlogin1.init("http://mochi.test:8888", "http://mochi.test:1111", null,
                "", "1234", "uname", "pword");

  pwlogin2.init("http://mochi.test:8888", "http://mochi.test:8888", null,
                "", "1234", "uname", "pword");


  pwmgr.addLogin(pwlogin1);
  pwmgr.addLogin(pwlogin2);
});
</script>
<p id="display"></p>

<div id="content" style="display: none">


<!-- simple form: no username field, 1 password field -->
<form id='form1' action='http://mochi.test:1111/formtest.js'> 1
    <input type='password' name='pname' value=''>

    <button type='submit'>Submit</button>
    <button type='reset'> Reset </button>
</form>

<!-- simple form: no username field, 2 password fields -->
<form id='form2' action='http://mochi.test:1111/formtest.js'> 2
    <input type='password' name='pname1' value=''>
    <input type='password' name='pname2' value=''>

    <button type='submit'>Submit</button>
    <button type='reset'> Reset </button>
</form>

<!-- simple form: no username field, 3 password fields -->
<form id='form3' action='http://mochi.test:1111/formtest.js'> 3
    <input type='password' name='pname1' value=''>
    <input type='password' name='pname2' value=''>
    <input type='password' name='pname3' value=''>

    <button type='submit'>Submit</button>
    <button type='reset'> Reset </button>
</form>

<!-- 4 password fields, should be ignored. -->
<form id='form4' action='http://mochi.test:1111/formtest.js'> 4
    <input type='password' name='pname1' value=''>
    <input type='password' name='pname2' value=''>
    <input type='password' name='pname3' value=''>
    <input type='password' name='pname4' value=''>

    <button type='submit'>Submit</button>
    <button type='reset'> Reset </button>
</form>



<!-- 1 username field -->
<form id='form5' action='http://mochi.test:1111/formtest.js'> 5
    <input type='text'     name='uname' value=''>
    <input type='password' name='pname' value=''>

    <button type='submit'>Submit</button>
    <button type='reset'> Reset </button>
</form>


<!-- 1 username field, with a value set -->
<form id='form6' action='http://mochi.test:1111/formtest.js'> 6
    <input type='text'     name='uname' value='someuser'>
    <input type='password' name='pname' value=''>

    <button type='submit'>Submit</button>
    <button type='reset'> Reset </button>
</form>



<!--
(The following forms have 2 potentially-matching logins, on is
password-only, the other is username+password)
-->



<!-- 1 username field, with value set. Fill in the matching U+P login -->
<form id='form7' action='formtest.js'> 7
    <input type='text'     name='uname' value='testuser'>
    <input type='password' name='pname' value=''>

    <button type='submit'>Submit</button>
    <button type='reset'> Reset </button>
</form>

<!-- 1 username field, with value set. Don't fill in U+P login-->
<form id='form8' action='formtest.js'> 8
    <input type='text'     name='uname' value='someuser'>
    <input type='password' name='pname' value=''>

    <button type='submit'>Submit</button>
    <button type='reset'> Reset </button>
</form>



<!-- 1 username field, too small for U+P login -->
<form id='form9' action='formtest.js'> 9
    <input type='text'     name='uname' value='' maxlength="4">
    <input type='password' name='pname' value=''>

    <button type='submit'>Submit</button>
    <button type='reset'> Reset </button>
</form>

<!-- 1 username field, too small for U+P login -->
<form id='form10' action='formtest.js'> 10
    <input type='text'     name='uname' value='' maxlength="0">
    <input type='password' name='pname' value=''>

    <button type='submit'>Submit</button>
    <button type='reset'> Reset </button>
</form>

<!-- 1 username field, too small for U+P login -->
<form id='form11' action='formtest.js'> 11
    <input type='text'     name='uname' value=''>
    <input type='password' name='pname' value='' maxlength="4">

    <button type='submit'>Submit</button>
    <button type='reset'> Reset </button>
</form>

<!-- 1 username field, too small for either login -->
<form id='form12' action='formtest.js'> 12
    <input type='text'     name='uname' value=''>
    <input type='password' name='pname' value='' maxlength="1">

    <button type='submit'>Submit</button>
    <button type='reset'> Reset </button>
</form>

<!-- 1 username field, too small for either login -->
<form id='form13' action='formtest.js'> 13
    <input type='text'     name='uname' value=''>
    <input type='password' name='pname' value='' maxlength="0">

    <button type='submit'>Submit</button>
    <button type='reset'> Reset </button>
</form>



</div>

<pre id="test">
<script class="testbody" type="text/javascript">

/** Test for Login Manager: password-only logins **/
function startTest() {

    checkForm(1, "1234");
    checkForm(2, "1234", "");
    checkForm(3, "1234", "", "");
    checkUnmodifiedForm(4);

    checkForm(5, "", "1234");
    checkForm(6, "someuser", "");

    checkForm(7, "testuser", "testpass");
    checkForm(8, "someuser", "");

    checkForm(9, "", "1234");
    checkForm(10, "", "1234");
    checkForm(11, "", "1234");

    checkUnmodifiedForm(12);
    checkUnmodifiedForm(13);

    SimpleTest.finish();
}
</script>
</pre>
</body>
</html>