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
|
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="timeout" content="long">
<meta name="variant" content="?textcontrol=text">
<meta name="variant" content="?textcontrol=password">
<meta name="variant" content="?textcontrol=textarea">
<title>Check whether a text control element handles user input when it's an editing host</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="/resources/testdriver-actions.js"></script>
</head>
<body>
<div></div>
<script>
const searchParams = new URLSearchParams(document.location.search);
const textControlType = searchParams.get("textcontrol");
const textControlDescription =
textControlType == "textarea"
? "<textarea contenteditable>"
: `<input type="${textControlType}" contenteditable>`;
const div = document.querySelector("div");
function createTextControl() {
const textControl = document.createElement(
textControlType == "textarea" ? "textarea" : "input"
);
if (textControlType != "textarea") {
textControl.type = textControlType;
}
return textControl;
}
promise_test(async t => {
const textControl = createTextControl();
div.appendChild(textControl);
textControl.setAttribute("contenteditable", "");
textControl.focus();
await (new test_driver.Actions()
.keyDown("a")
.keyUp("a")
.keyDown("b")
.keyUp("b")
.keyDown("c")
.keyUp("c")
.send());
assert_equals(
textControl.value,
"abc",
`${t.name}: The text control value should be updated`
);
assert_equals(
document.querySelector("div").textContent.trim(),
"",
`${t.name}: No text should be inserted as a child of the text control`
);
textControl.remove();
}, `User typing in ${textControlDescription} should update the value`);
promise_test(async t => {
const textControl = createTextControl();
div.appendChild(textControl);
textControl.setAttribute("contenteditable", "");
textControl.focus();
document.execCommand("insertText", false, "abc");
assert_equals(
textControl.value,
"abc",
`${t.name}: The text control value should be updated`
);
assert_equals(
div.textContent.trim(),
"",
`${t.name}: No text should be inserted as a child of the text control`
);
textControl.remove();
}, `execCommand("insertText") in ${textControlDescription} should update the value`);
promise_test(async t => {
const textControl = createTextControl();
div.appendChild(textControl);
textControl.focus();
textControl.setAttribute("contenteditable", "");
await (new test_driver.Actions()
.keyDown("a")
.keyUp("a")
.keyDown("b")
.keyUp("b")
.keyDown("c")
.keyUp("c")
.send());
assert_equals(
textControl.value,
"abc",
`${t.name}: The text control value should be updated`
);
assert_equals(
div.textContent.trim(),
"",
`${t.name}: No text should be inserted as a child of the text control`
);
textControl.remove();
}, `User typing in ${textControlDescription} should update the value (became an editing host during focused)`);
promise_test(async t => {
const textControl = createTextControl();
div.appendChild(textControl);
textControl.focus();
textControl.setAttribute("contenteditable", "");
document.execCommand("insertText", false, "abc");
assert_equals(
textControl.value,
"abc",
`${t.name}: The text control value should be updated`
);
assert_equals(
div.textContent.trim(),
"",
`${t.name}: No text should be inserted as a child of the text control`
);
textControl.remove();
}, `execCommand("insertText") in ${textControlDescription} should update the value (became an editing host during focused)`);
if (textControlType != "textarea") {
promise_test(async t => {
const textControl = createTextControl();
textControl.type = "button";
div.appendChild(textControl);
textControl.setAttribute("contenteditable", "");
textControl.focus();
textControl.type = textControlType;
await (new test_driver.Actions()
.keyDown("a")
.keyUp("a")
.keyDown("b")
.keyUp("b")
.keyDown("c")
.keyUp("c")
.send());
assert_equals(
textControl.value,
"abc",
`${t.name}: The text control value should be updated`
);
assert_equals(
document.querySelector("div").textContent.trim(),
"",
`${t.name}: No text should be inserted as a child of the text control`
);
textControl.remove();
}, `User typing in ${
textControlDescription
} should update the value (became an editing host during focused and different type)`);
promise_test(async t => {
const textControl = createTextControl();
textControl.type = "button";
div.appendChild(textControl);
textControl.setAttribute("contenteditable", "");
textControl.focus();
textControl.type = textControlType;
document.execCommand("insertText", false, "abc");
assert_equals(
textControl.value,
"abc",
`${t.name}: The text control value should be updated`
);
assert_equals(
div.textContent.trim(),
"",
`${t.name}: No text should be inserted as a child of the text control`
);
textControl.remove();
}, `execCommand("insertText") in ${
textControlDescription
} should update the value (became an editing host during focused and different type)`);
}
</script>
</body>
</html>
|