summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/forms/select/optgroup-disabled.html
blob: 57b7f181ab3ba45a33c53761437aa04e136347e9 (plain)
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
<!DOCTYPE html>
<html>
<body>
<script src="../../js/resources/js-test-pre.js"></script>
<script src="../resources/common.js"></script>

<form id="form">
<select size="10" id="listbox">
<optgroup label="Enabled" id="listbox_optgroup_enabled">
    <option value="listbox_e1" id="listbox_option_enabled">One</option>
    <option value="listbox_e2">Two</option>
    <option value="listbox_e3">Three</option>
    <option value="listbox_e4">Four</option>
</optgroup>
<optgroup label="Disabled" disabled id="listbox_optgroup_disabled">
    <option value="listbox_d1" id="listbox_option_disabled">One</option>
    <option value="listbox_d2">Two</option>
    <option value="listbox_d3">Three</option>
    <option value="listbox_d4">Four</option>
</optgroup>
</select>
<br />
<select size="1" id="menulist">
<optgroup label="Enabled" id="menulist_optgroup_enabled">
    <option value="listbox_e1" id="menulist_option_enabled">One</option>
    <option value="listbox_e2">Two</option>
    <option value="listbox_e3">Three</option>
    <option value="listbox_e4">Four</option>
</optgroup>
<optgroup label="Disabled" disabled id="menulist_optgroup_disabled">
    <option value="menulist_d1" id="menulist_option_disabled">One</option>
    <option value="menulist_d2">Two</option>
    <option value="menulist_d3">Three</option>
    <option value="menulist_d4">Four</option>
</optgroup>
</select>
</form>
<script>
description('Test disabled attribute of optgroup element');

var disabledSet;
var enabledSet;

function querySelectorAll(selector)
{
    var set = {};
    var elements = document.querySelectorAll(selector);
    for (var i = 0; i < elements.length; ++i) {
        var element = elements[i];
        set[element.value || element.id] = true;
    }
    return set;
}

debug('Check :disabled pseudo-class');
disabledSet = querySelectorAll(":disabled");

shouldBeTrue('disabledSet["listbox_optgroup_disabled"]');
shouldBeTrue('disabledSet["listbox_d1"]');
shouldBeTrue('disabledSet["listbox_d2"]');
shouldBeTrue('disabledSet["listbox_d3"]');
shouldBeTrue('disabledSet["listbox_d4"]');

shouldBeTrue('disabledSet["menulist_optgroup_disabled"]');
shouldBeTrue('disabledSet["menulist_d1"]');
shouldBeTrue('disabledSet["menulist_d2"]');
shouldBeTrue('disabledSet["menulist_d3"]');
shouldBeTrue('disabledSet["menulist_d4"]');

enabledSet = querySelectorAll(':enabled');
shouldBeTrue('enabledSet["listbox_optgroup_enabled"]');
shouldBeTrue('enabledSet["menulist_optgroup_enabled"]');

debug('Check IDL attribute');
shouldBeTrue('$("listbox_optgroup_disabled").disabled');
shouldBeFalse('$("listbox_optgroup_enabled").disabled');
shouldBeTrue('$("menulist_optgroup_disabled").disabled');
shouldBeFalse('$("menulist_optgroup_enabled").disabled');

debug("select.disabled doesn't affect optgroup.disabled");
$("listbox").disabled = true;
$("menulist").disabled = true;
shouldBeTrue('$("listbox_optgroup_disabled").disabled');
shouldBeFalse('$("listbox_optgroup_enabled").disabled');
shouldBeTrue('$("menulist_optgroup_disabled").disabled');
shouldBeFalse('$("menulist_optgroup_enabled").disabled');

debug("select.disabled doesn't affect pseudo-class :disabled");
disabledSet = querySelectorAll(':disabled');
shouldBeTrue('disabledSet["listbox_optgroup_disabled"]');
shouldBeTrue('disabledSet["menulist_optgroup_disabled"]');
shouldBeUndefined('disabledSet["listbox_optgroup_enabled"]');
shouldBeUndefined('disabledSet["menulist_optgroup_enabled"]');

debug("form.disabled doesn't affect optgroup.disabled");
$("form").disabled = true;
shouldBeTrue('$("listbox_optgroup_disabled").disabled');
shouldBeFalse('$("listbox_optgroup_enabled").disabled');
shouldBeTrue('$("menulist_optgroup_disabled").disabled');
shouldBeFalse('$("menulist_optgroup_enabled").disabled');
$("form").disabled = false;

debug("form.disabled doesn't affect pseudo-class :disabled");
disabledSet = querySelectorAll(':disabled');
shouldBeTrue('disabledSet["listbox_optgroup_disabled"]');
shouldBeTrue('disabledSet["menulist_optgroup_disabled"]');
shouldBeUndefined('disabledSet["listbox_optgroup_enabled"]');
shouldBeUndefined('disabledSet["menulist_optgroup_enabled"]');

debug("Check IDL [Reflect]");
$("listbox_optgroup_disabled").removeAttribute("disabled");
$("menulist_optgroup_disabled").removeAttribute("disabled");

shouldBeFalse('$("listbox_optgroup_disabled").disabled');
shouldBeFalse('$("menulist_optgroup_disabled").disabled');

$("listbox_optgroup_disabled").setAttribute("disabled", "");
$("menulist_optgroup_disabled").setAttribute("disabled", "");
shouldBeTrue('$("listbox_optgroup_disabled").disabled');
shouldBeTrue('$("menulist_optgroup_disabled").disabled');

debug("optgroup.disabled doesn't affect option.selected");
$("listbox_option_enabled").selected = true;
shouldBe('$("listbox").selectedIndex', '0');

$("listbox_option_disabled").selected = true;
shouldBe('$("listbox").selectedIndex', '4');

$("menulist_option_enabled").selected = true;
shouldBe('$("menulist").selectedIndex', '0');

$("menulist_option_disabled").selected = true;
shouldBe('$("menulist").selectedIndex', '4');

</script>
</body>
</html>