summaryrefslogtreecommitdiffstats
path: root/toolkit/components/passwordmgr/test/mochitest/test_basic_form_1pw.html
blob: bb91d9cf3ece61a17d14af395c552965c55340fb (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
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <title>Test autofill for forms with 1 password field</title>
  <script 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 with 1 password field
<script>
gTestDependsOnDeprecatedLogin = true;
runChecksAfterCommonInit(() => startTest());

let DEFAULT_ORIGIN = window.location.origin;
</script>
<p id="display"></p>

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

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

/** Test for Login Manager: simple form fill **/

async function startTest() {
  let win = window.open("about:blank");
  SimpleTest.registerCleanupFunction(() => win.close());
  await loadFormIntoWindow(DEFAULT_ORIGIN, `
    <!-- no username fields -->

    <form id='form1' action='formtest.js'> 1
        <!-- Blank, so fill in the password -->
        <input type='password' name='pname' value=''>
        <button type='submit'>Submit</button>
    </form>

    <form id='form2' action='formtest.js'> 2
        <!-- Already contains the password, so nothing to do. -->
        <input type='password' name='pname' value='testpass'>
        <button type='submit'>Submit</button>
    </form>

    <form id='form3' action='formtest.js'> 3
        <!-- Contains unknown password, so don't change it -->
        <input type='password' name='pname' value='xxxxxxxx'>
        <button type='submit'>Submit</button>
    </form>


    <!-- username fields -->

    <form id='form4' action='formtest.js'> 4
        <!-- Blanks, so fill in login -->
        <input type='text'     name='uname' value=''>
        <input type='password' name='pname' value=''>
        <button type='submit'>Submit</button>
    </form>

    <form id='form5' action='formtest.js'> 5
        <!-- Username already set, so fill in password -->
        <input type='text'     name='uname' value='testuser'>
        <input type='password' name='pname' value=''>
        <button type='submit'>Submit</button>
    </form>

    <form id='form6' action='formtest.js'> 6
        <!-- Unknown username, so don't fill in password -->
        <input type='text'     name='uname' value='xxxxxxxx'>
        <input type='password' name='pname' value=''>
        <button type='submit'>Submit</button>
    </form>

    <form id='form7' action='formtest.js'> 7
        <!-- Password already set, could fill in username but that's weird so we don't -->
        <input type='text'     name='uname' value=''>
        <input type='password' name='pname' value='testpass'>
        <button type='submit'>Submit</button>
    </form>

    <form id='form8' action='formtest.js'> 8
        <!-- Unknown password, so don't fill in a username -->
        <input type='text'     name='uname' value=''>
        <input type='password' name='pname' value='xxxxxxxx'>
        <button type='submit'>Submit</button>
    </form>



    <!-- extra text fields -->

    <form id='form9' action='formtest.js'> 9
        <!-- text field _after_ password should never be treated as a username field -->
        <input type='password' name='pname' value=''>
        <input type='text'     name='uname' value=''>
        <button type='submit'>Submit</button>
    </form>

    <form id='form10' action='formtest.js'> 10
        <!-- only the first text field before the password should be for username -->
        <input type='text'     name='other' value=''>
        <input type='text'     name='uname' value=''>
        <input type='password' name='pname' value=''>
        <button type='submit'>Submit</button>
    </form>

    <form id='form11' action='formtest.js'> 11
        <!-- variation just to make sure extra text field is still ignored -->
        <input type='text'     name='uname' value=''>
        <input type='password' name='pname' value=''>
        <input type='text'     name='other' value=''>
        <button type='submit'>Submit</button>
    </form>



    <!-- same as last bunch, but with xxxx in the extra field. -->

    <form id='form12' action='formtest.js'> 12
        <!-- text field _after_ password should never be treated as a username field -->
        <input type='password' name='pname' value=''>
        <input type='text'     name='uname' value='xxxxxxxx'>
        <button type='submit'>Submit</button>
    </form>

    <form id='form13' action='formtest.js'> 13
        <!-- only the first text field before the password should be for username -->
        <input type='text'     name='other' value='xxxxxxxx'>
        <input type='text'     name='uname' value=''>
        <input type='password' name='pname' value=''>
        <button type='submit'>Submit</button>
    </form>

    <form id='form14' action='formtest.js'> 14
        <!-- variation just to make sure extra text field is still ignored -->
        <input type='text'     name='uname' value=''>
        <input type='password' name='pname' value=''>
        <input type='text'     name='other' value='xxxxxxxx'>
        <button type='submit'>Submit</button>
    </form>`, win, 14);

  var f = 1;

  // 1-3
  await checkLoginFormInFrameWithElementValues(win, f++, "testpass");
  await checkLoginFormInFrameWithElementValues(win, f++, "testpass");
  await checkLoginFormInFrameWithElementValues(win, f++, "xxxxxxxx");

  // 4-8
  await checkLoginFormInFrameWithElementValues(win, f++, "testuser", "testpass");
  await checkLoginFormInFrameWithElementValues(win, f++, "testuser", "testpass");
  await checkLoginFormInFrameWithElementValues(win, f++, "xxxxxxxx", "");
  await checkLoginFormInFrameWithElementValues(win, f++, "", "testpass");
  await checkLoginFormInFrameWithElementValues(win, f++, "", "xxxxxxxx");

  // 9-14
  await checkLoginFormInFrameWithElementValues(win, f++, "testpass", "");
  await checkLoginFormInFrameWithElementValues(win, f++, "", "testuser", "testpass");
  await checkLoginFormInFrameWithElementValues(win, f++, "testuser", "testpass", "");
  await checkLoginFormInFrameWithElementValues(win, f++, "testpass", "xxxxxxxx");
  await checkLoginFormInFrameWithElementValues(win, f++, "xxxxxxxx", "testuser", "testpass");
  await checkLoginFormInFrameWithElementValues(win, f++, "testuser", "testpass", "xxxxxxxx");

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