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
|
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test autofill on username-form</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 autofill on username-form
<script>
add_setup(async () => {
await setStoredLoginsAsync(
[window.location.origin, "https://autofill", null, "user1", "pass1"]
);
});
add_task(async function test_autofill_username_only_form() {
await loadRecipes({
siteRecipes: [{
hosts: ["mochi.test:8888"],
notUsernameSelector: "input[name='shouldnotfill']",
}],
});
let win = window.open("about:blank");
SimpleTest.registerCleanupFunction(() => win.close());
// 5 out of the 7 forms should be autofilled
await loadFormIntoWindow(window.location.origin, `
<!-- no password field, 1 username field -->
<form id='form1' action='https://autofill'> 1
<input type='text' name='uname' autocomplete='username' value=''>
<button type='submit'>Submit</button>
<button type='reset'> Reset </button>
</form>
<!-- no password field, 1 username field, with a value set -->
<form id='form2' action='https://autofill'> 2
<input type='text' name='uname' autocomplete='username' value='someuser'>
<button type='submit'>Submit</button>
<button type='reset'> Reset </button>
</form>
<!-- no password field, 2 username fields, should be ignored -->
<form id='form3' action='https://autofill'> 3
<input type='text' name='uname1' autocomplete='username' value=''>
<input type='text' name='uname2' autocomplete='username' value=''>
<button type='submit'>Submit</button>
<button type='reset'> Reset </button>
</form>
<!-- no password field, 1 username field, too small for the username login -->
<form id='form4' action='https://autofill'> 4
<input type='text' name='uname' value='' maxlength="4" autocomplete='username'>
<button type='submit'>Submit</button>
<button type='reset'> Reset </button>
</form>
<!-- no password field, 1 username field, too small for the username login -->
<form id='form5' action='https://autofill'> 5
<input type='text' name='uname' value='' maxlength="0" autocomplete='username'>
<button type='submit'>Submit</button>
<button type='reset'> Reset </button>
</form>
<!-- no password field, 1 text input field (not a username-only form), should be ignored -->
<form id='form6' action='https://autofill'> 6
<input type='text' name='uname' value=''>
<button type='submit'>Submit</button>
<button type='reset'> Reset </button>
</form>
<!-- no password field, 1 username field that matches notUsernameSelector recipe -->
<form id='form7' action='https://autofill'> 7
<input type='text' name='shouldnotfill' autocomplete='username' value=''>
<button type='submit'>Submit</button>
<button type='reset'> Reset </button>
</form>`, win, 5);
await checkLoginFormInFrameWithElementValues(win, 1, "user1");
await checkLoginFormInFrameWithElementValues(win, 2, "someuser");
await checkUnmodifiedFormInFrame(win, 3);
await checkUnmodifiedFormInFrame(win, 4);
await checkUnmodifiedFormInFrame(win, 5);
await checkUnmodifiedFormInFrame(win, 6);
await checkUnmodifiedFormInFrame(win, 7);
await resetRecipes();
});
</script>
<p id="display"></p>
<div id="content"></div>
<pre id="test"></pre>
</pre>
</body>
</html>
|