summaryrefslogtreecommitdiffstats
path: root/toolkit/components/passwordmgr/test/mochitest/test_autofill_autocomplete_types.html
blob: c44d5a25efe81c21c9186b91f95910fad154f59a (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
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <title>Test autofilling with autocomplete types (username, off, cc-type, etc.)</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>
Test autofilling with autocomplete types (username, off, cc-type, etc.)

<p id="display"></p>
<div id="content"></div>
<pre id="test">
<script class="testbody" type="text/javascript">
/*
  Test for Login Manager: Skip over inappropriate autcomplete types when finding username field
 */

const win = window.open("about:blank");
const loadPromise = loadFormIntoWindow(location.origin, `
  <form id="form0" action="https://autocomplete">
    <input  type="text" name="uname">
    <input  type="text" autocomplete="">
    <input  type="password" name="pword">
    <button type="submit">Submit</button>
  </form>

  <form id="form1" action="https://autocomplete">
    <input  type="text" name="uname">
    <input  type="text" autocomplete="username">
    <input  type="password" name="pword">
    <button type="submit">Submit</button>
  </form>

  <form id="form2" action="https://autocomplete">
    <input  type="text" name="uname">
    <input  type="text" autocomplete="off" name="acfield">
    <input  type="password" name="pword">
    <button type="submit">Submit</button>
  </form>

  <form id="form3" action="https://autocomplete">
    <input  type="text" name="uname">
    <input  type="text" autocomplete="on" name="acfield">
    <input  type="password" name="pword">
    <button type="submit">Submit</button>
  </form>

  <form id="form4" action="https://autocomplete">
    <input  type="text" name="uname">
    <input  type="text" autocomplete="nosuchtype" name="acfield">
    <input  type="password" name="pword">
    <button type="submit">Submit</button>
  </form>

  <form id="form5" action="https://autocomplete">
    <input  type="text" name="uname">
    <input  type="text" autocomplete="email" name="acfield">
    <input  type="password" name="pword">
    <button type="submit">Submit</button>
  </form>

  <form id="form6" action="https://autocomplete">
    <input  type="text" name="uname">
    <input  type="text" autocomplete="tel" name="acfield">
    <input  type="password" name="pword">
    <button type="submit">Submit</button>
  </form>

  <form id="form7" action="https://autocomplete">
    <input  type="text" name="uname">
    <input  type="text" autocomplete="tel-national" name="acfield">
    <input  type="password" name="pword">
    <button type="submit">Submit</button>
  </form>

  <!-- Begin forms where the first field is skipped for the username -->

  <form id="form101" action="https://autocomplete">
    <input  type="text" name="uname">
    <input  type="text" autocomplete="cc-number" name="acfield">
    <input  type="password" name="pword">
    <button type="submit">Submit</button>
  </form>`, win, 8);

add_setup(async () => {
  await setStoredLoginsAsync(
    [window.location.origin, "https://autocomplete", null, "testuser@example.com", "testpass1", "", ""]
  );
  SimpleTest.registerCleanupFunction(() => win.close());
});

/* Tests for autofill of single-user forms with various autocomplete types */
add_task(async function test_autofill_autocomplete_types() {
  await loadPromise;
  await checkLoginFormInFrameWithElementValues(win, 0, null, "testuser@example.com", "testpass1");
  await checkLoginFormInFrameWithElementValues(win, 1, null, "testuser@example.com", "testpass1");
  await checkLoginFormInFrameWithElementValues(win, 2, null, "testuser@example.com", "testpass1");
  await checkLoginFormInFrameWithElementValues(win, 3, null, "testuser@example.com", "testpass1");
  await checkLoginFormInFrameWithElementValues(win, 4, null, "testuser@example.com", "testpass1");
  await checkLoginFormInFrameWithElementValues(win, 5, null, "testuser@example.com", "testpass1");
  await checkLoginFormInFrameWithElementValues(win, 6, null, "testuser@example.com", "testpass1");
  await checkLoginFormInFrameWithElementValues(win, 7, null, "testuser@example.com", "testpass1");
  await checkLoginFormInFrameWithElementValues(win, 101, "testuser@example.com", null, "testpass1");
});

</script>
</pre>
</body>
</html>