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
|
<!DOCTYPE HTML>
<html>
<head>
<title>Test for datalist in Shadow DOM</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<script type="text/javascript" src="satchel_common.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>
<div id="content">
<div id="host"></div>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
const host = document.getElementById("host");
host.attachShadow({ mode: "open" }).innerHTML = `
<form id="form1" onsubmit="return false;">
<input list="suggest" type="text" name="field1">
<button type="submit">Submit</button>
</form>
<datalist id="suggest">
<option value="First"></option>
<option value="Second"></option>
<option value="Secomundo"></option>
</datalist><Paste>
`;
let input = host.shadowRoot.querySelector("input");
function setForm(value) {
input.value = value;
input.focus();
}
// Restore the form to the default state.
function restoreForm() {
setForm("");
}
// Check for expected form data.
function checkForm(expectedValue) {
let formID = input.parentNode.id;
is(input.value, expectedValue, "Checking " + formID + " input");
}
SimpleTest.waitForExplicitFinish();
var expectingPopup = null;
function expectPopup() {
info("expecting a popup");
return new Promise(resolve => {
expectingPopup = resolve;
});
}
var testNum = 0;
function popupShownListener() {
info("popup shown for test " + testNum);
if (expectingPopup) {
expectingPopup();
expectingPopup = null;
} else {
ok(false, "Autocomplete popup not expected during test " + testNum);
}
}
function waitForMenuChange(expectedCount) {
return new Promise(resolve => {
notifyMenuChanged(expectedCount, null, resolve);
});
}
registerPopupShownListener(popupShownListener);
function checkMenuEntries(expectedValues) {
let actualValues = getMenuEntries();
is(actualValues.length, expectedValues.length, testNum + " Checking length of expected menu");
for (let i = 0; i < expectedValues.length; i++) {
is(actualValues[i], expectedValues[i], testNum + " Checking menu entry #" + i);
}
}
async function runTests() {
testNum++;
restoreForm();
synthesizeKey("KEY_ArrowDown");
await expectPopup();
checkMenuEntries(["First", "Second", "Secomundo"]);
synthesizeKey("KEY_ArrowDown");
synthesizeKey("KEY_Enter");
checkForm("First");
testNum++;
restoreForm();
sendString("Sec");
synthesizeKey("KEY_ArrowDown");
await expectPopup();
testNum++;
checkMenuEntries(["Second", "Secomundo"]);
sendString("o");
await waitForMenuChange(2);
testNum++;
checkMenuEntries(["Second", "Secomundo"]);
synthesizeKey("KEY_ArrowDown");
synthesizeKey("KEY_Enter");
checkForm("Second");
SimpleTest.finish();
}
window.onpageshow = runTests;
</script>
</pre>
</body>
</html>
|