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
|
<!DOCTYPE HTML>
<title>Dynamic change to readonly doesn't prevent datalist to keep working</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<script src="/tests/SimpleTest/AddTask.js"></script>
<script src="satchel_common.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css" />
<input readonly list="suggest" type="text" name="field1">
<datalist id="suggest">
<option value="First"></option>
<option value="Second"></option>
<option value="Secomundo"></option>
</datalist>
<pre id="test">
<script class="testbody">
const input = document.querySelector("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);
}
}
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);
}
}
function oneTick() {
return new Promise(resolve => SimpleTest.executeSoon(resolve));
}
async function runTests() {
input.focus();
ok(input.readOnly, "Input should be readonly");
is(document.activeElement, input, "Input should be focused");
input.removeAttribute("readonly");
await oneTick(); // AttributeChanged takes control of the input again off a runnable...
isnot(input.readOnly, "Input should not be readonly");
is(document.activeElement, input, "Should still be focused");
synthesizeKey("KEY_ArrowDown");
await expectPopup();
checkMenuEntries(["First", "Second", "Secomundo"]);
synthesizeKey("KEY_ArrowDown");
synthesizeKey("KEY_Enter");
is(input.value, "First");
SimpleTest.finish();
}
SimpleTest.waitForFocus(runTests);
</script>
</pre>
|