-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
disabled-elements-01.html
84 lines (69 loc) · 3.11 KB
/
disabled-elements-01.html
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
<!DOCTYPE html>
<title>HTMLFormElement: the disabled attribute</title>
<link rel="author" title="Eric Casler" href="mailto:ericorange@gmail.com">
<link rel="help" href="https://html.spec.whatwg.org/multipage/#enabling-and-disabling-form-controls:-the-disabled-attribute">
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<div id="log"></div>
<div id="root"></div>
<script>
// Elements tested for in this file
var types = ["button", "input", "select", "textarea"];
// no tests for: optgroup, option, fieldset
var root = document.getElementById("root");
for (var element_type = 0; element_type < types.length; element_type++) {
test(function() {
root.innerHTML = "<"+types[element_type]+" + id='elem'></"+types[element_type]+">";
var elem = document.getElementById("elem");
assert_false(elem.disabled);
},
"Test ["+types[element_type]+"]: default behaviour is NOT disabled");
test(function() {
var formats = ["disabled",
"disabled=disabled", "disabled='disabled'",
"disabled='true'", "disabled=true",
"disabled='false'", "disabled=false"];
for (var f = 0; f < formats.length; f++) {
root.innerHTML = "<"+types[element_type]+" id='elem' " + formats[f] + "></"+types[element_type]+">";
var elem = document.getElementById("elem");
assert_true(elem.disabled);
}
},
"Test ["+types[element_type]+"]: verify disabled acts as boolean attribute");
test(function() {
root.innerHTML = "<"+types[element_type]+" id='elem'></"+types[element_type]+"><input id='other' value='no event dispatched'></input>";
var elem = document.getElementById("elem"),
other = document.getElementById("other");
assert_equals(other.value, "no event dispatched");
elem.disabled = true;
assert_true(elem.disabled);
elem.onclick = function () {
// change value of other element, to avoid *.value returning "" for disabled elements
document.getElementById("other").value = "event dispatched";
};
// Check if dispatched event executes
var evObj = document.createEvent('Events');
evObj.initEvent("click", true, false);
elem.dispatchEvent(evObj);
assert_equals(other.value, "event dispatched");
},
"Test ["+types[element_type]+"]: synthetic click events should be dispatched");
test(function() {
root.innerHTML = "<"+types[element_type]+" id='elem'></"+types[element_type]+"><input id='other' value='no event dispatched'></input>";
var elem = document.getElementById("elem"),
other = document.getElementById("other");
assert_equals(other.value, "no event dispatched");
elem.disabled = true;
assert_true(elem.disabled);
elem.onclick = function () {
// change value of other element, to avoid *.value returning "" for disabled elements
document.getElementById("other").value = "event dispatched";
};
// Check that click() on a disabled element doesn't dispatch a click event.
elem.click();
assert_equals(other.value, "no event dispatched");
},
"Test ["+types[element_type]+"]: click() should not dispatch a click event");
}
root.innerHTML = "";
</script>