summaryrefslogtreecommitdiffstats
path: root/toolkit/components/passwordmgr/test/mochitest/test_username_focus.html
blob: 9c2f9d8e89d91a86052d56256537c0e7ee087584 (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
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <title>Test interaction between autocomplete and focus on username fields</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script src="/tests/SimpleTest/EventUtils.js"></script>
  <script type="text/javascript" src="../../../satchel/test/satchel_common.js"></script>
  <script type="text/javascript" src="pwmgr_common.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>
<div id="content"></div>
<pre id="test">
<script class="testbody" type="text/javascript">
const action1 = "http://username-focus-1";
const action2 = "http://username-focus-2";

add_setup(async () => {
  await setStoredLoginsAsync(
    [location.origin, action1, null, "testuser1A", "testpass1A", "", ""],
    [location.origin, action2, null, "testuser2A", "testpass2A", "", ""],
    [location.origin, action2, null, "testuser2B", "testpass2B", "", ""]
  );
});

add_task(async function autofilled() {
  const form = createLoginForm({ action: action1 });

  info("Username and password already filled so don't show autocomplete");
  await noPopupBy(() => form.uname.focus());

  form.submit.focus();
  form.uname.value = "testuser";
  info("Focus when we don't have an exact match");
  await popupBy(() => form.uname.focus());
});

add_task(async function autofilled_prefilled_un() {
  const form = createLoginForm({
    action: action1,
    username: {
      value: "testuser1A"
    }
  });

  info("Username and password already filled so don't show autocomplete");
  await noPopupBy(() => form.uname.focus());

  form.submit.focus();
  form.uname.value = "testuser";
  info("Focus when we don't have an exact match");
  await popupBy(() => form.uname.focus());
});

add_task(async function autofilled_focused_dynamic() {
  const form = createLoginForm({
    action: action1,
    password: {
      type: "not-yet-password"
    }
  });

  info("Username and password will be filled while username focused");
  await noPopupBy(() => form.uname.focus());

  info("triggering autofill");
  await noPopupBy(() => form.pword.type = "password");

  const popupState = await getPopupState();
  is(popupState.open, false, "Check popup is closed");

  form.submit.focus();
  form.pword.value = "test";
  info("Focus when we don't have an exact match");
  await popupBy(() => form.uname.focus());
});

// Begin testing forms that have multiple saved logins

add_task(async function multiple() {
  const form = createLoginForm({ action: action2 });

  info("Fields not filled due to multiple so autocomplete upon focus");
  await popupBy(() => form.uname.focus());
});

add_task(async function multiple_dynamic() {
  const form = createLoginForm({
    action: action2,
    password: {
      type: "not-yet-password"
    }
  });

  info("Fields not filled but username is focused upon marking so open");
  await noPopupBy(() => form.uname.focus());

  info("triggering _fillForm code");
  await popupBy(() => form.pword.type = "password");
});

add_task(async function multiple_prefilled_un1() {
  const form = createLoginForm({
    action: action2,
    username: {
      value: "testuser2A"
    }
  });

  info("Username and password already filled so don't show autocomplete");
  await noPopupBy(() => form.uname.focus());

  form.submit.focus();
  form.uname.value = "testuser";
  info("Focus when we don't have an exact match");
  await popupBy(() => form.uname.focus());
});

add_task(async function multiple_prefilled_un2() {
  const form = createLoginForm({
    action: action2,
    username: {
      value: "testuser2B"
    }
  });

  info("Username and password already filled so don't show autocomplete");
  await noPopupBy(() => form.uname.focus());

  form.submit.focus();
  form.uname.value = "testuser";
  info("Focus when we don't have an exact match");
  await popupBy(() => form.uname.focus());
});

add_task(async function multiple_prefilled_focused_dynamic() {
  const form = createLoginForm({
    action: action2,
    username: {
      value: "testuser2B"
    },
    password: {
      type: "not-yet-password"
    }
  });

  info("Username and password will be filled while username focused");
  await noPopupBy(() => form.uname.focus());
  info("triggering autofill");
  await noPopupBy(() => form.pword.type = "password");

  let popupState = await getPopupState();
  is(popupState.open, false, "Check popup is closed");

  form.submit.focus();
  form.pword.value = "test";
  info("Focus when we don't have an exact match");
  await popupBy(() => form.uname.focus());
});
</script>
</pre>
</body>
</html>