summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/forms/select/select-selectedIndex-multiple.html
blob: 7bd414a804d1095cdd31974e612fd686b840614a (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
138
139
140
141
142
143
144
145
146
<select multiple id="test" size="3">
</select>
<div id="console"></div>
<script src="../../../resources/js-test.js"></script>
<script>
function reset(mySelect) {
    mySelect.length = 0;
    mySelect.options[mySelect.length] = new Option("one", "value", true, true);
    mySelect.options[mySelect.length] = new Option("two", "value", true, true);
}

var mySelect = document.getElementById("test");
reset(mySelect);
var i = 0;

debug((++i) + ") setting length to a negative length");
mySelect.options.length = -1;
shouldBe("mySelect.options.length", "2");
shouldBe("mySelect.selectedIndex", "0");

debug((++i) + ") setting length to a larger length");
mySelect.options.length = 5;
shouldBe("mySelect.options.length", "5");
shouldBe("mySelect.selectedIndex", "0");

debug((++i) + ") setting length to a smaller length");
mySelect.options.length = 2;
shouldBe("mySelect.options.length", "2");
shouldBe("mySelect.selectedIndex", "0");

mySelect.options.length = 1;
shouldBe("mySelect.options.length", "1");
shouldBe("mySelect.selectedIndex", "0");
reset(mySelect);

debug((++i) + ") setting length to the same length");
mySelect.options.length = 2;
shouldBe("mySelect.options.length", "2");
shouldBe("mySelect.selectedIndex", "0");

debug((++i) + ") setting length to non-integer value: null");
mySelect.options.length = null;
shouldBe("mySelect.options.length", "0");
shouldBe("mySelect.selectedIndex", "-1");
reset(mySelect);

debug((++i) + ") setting length to non-integer value: undefined");
mySelect.options.length = undefined;
shouldBe("mySelect.options.length", "0");
shouldBe("mySelect.selectedIndex", "-1");
reset(mySelect);

debug((++i) + ") setting length to non-integer value: true");
mySelect.options.length = true;
shouldBe("mySelect.options.length", "1");
shouldBe("mySelect.selectedIndex", "0");
reset(mySelect);

debug((++i) + ") setting length to non-integer value: false");
mySelect.options.length = false;
shouldBe("mySelect.options.length", "0");
shouldBe("mySelect.selectedIndex", "-1");
reset(mySelect);

debug((++i) + ") setting length to non-integer value: non-numeric string");
mySelect.options.length = "apple";
shouldBe("mySelect.options.length", "0");
shouldBe("mySelect.selectedIndex", "-1");
reset(mySelect);

debug((++i) + ") setting length to non-integer value: object");
mySelect.options.length = new Object();
shouldBe("mySelect.options.length", "0");
shouldBe("mySelect.selectedIndex", "-1");
reset(mySelect);

debug((++i) + ") setting length to non-integer value: negative infinity");
mySelect.options.length = -1/0;
shouldBe("mySelect.options.length", "0");
shouldBe("mySelect.selectedIndex", "-1");
reset(mySelect);

debug((++i) + ") setting length to non-integer value: NaN");
mySelect.options.length = 0/0;
shouldBe("mySelect.options.length", "0");
shouldBe("mySelect.selectedIndex", "-1");
reset(mySelect);

debug((++i) + ") setting length to non-integer value: positive infinity");
mySelect.options.length = 1/0;
shouldBe("mySelect.options.length", "0");
shouldBe("mySelect.selectedIndex", "-1");
reset(mySelect);

debug((++i) + ") setting length to non-integer value: floating point number");
mySelect.options.length = 2.1;
shouldBe("mySelect.options.length", "2");
shouldBe("mySelect.selectedIndex", "0");

debug((++i) + ") setting an element by index past the end of the current list");
mySelect.options[10] = new Option("ten", "value", true, true);
shouldBe("mySelect.options.length", "11");
shouldBe("mySelect.selectedIndex", "0");

debug((++i) + ") setting an existing element by index");
mySelect.options[10] = mySelect.options[10];
shouldBe("mySelect.options.length", "11");
shouldBe("mySelect.selectedIndex", "0");

debug((++i) + ") trying to set an element that's not an option: null");
mySelect.options[10] = null;
shouldBe("mySelect.options.length", "10");
shouldBe("mySelect.selectedIndex", "0");

debug((++i) + ") trying to set an element that's not an option: undefined");
mySelect.options[10] = undefined;
shouldBe("mySelect.options.length", "10");
shouldBe("mySelect.selectedIndex", "0");

debug((++i) + ") trying to set an element that's not an option: select element");
shouldThrow("mySelect.options[10] = mySelect;");
shouldBe("mySelect.options.length", "10");
shouldBe("mySelect.selectedIndex", "0");

debug((++i) + ") trying to set a option element using an invalid index: negative infinity");
mySelect.options[-1/0] = document.createElement("option");
shouldBe("mySelect.options.length", "10");
shouldBe("mySelect.selectedIndex", "0");

debug((++i) + ") trying to set a option element using an invalid index: NaN");
mySelect.options[0/0] = document.createElement("option");
shouldBe("mySelect.options.length", "10");
shouldBe("mySelect.selectedIndex", "0");

debug((++i) + ") trying to set a option element using an invalid index: positive infinity");
mySelect.options[1/0] = document.createElement("option");
shouldBe("mySelect.options.length", "10");
shouldBe("mySelect.selectedIndex", "0");

debug((++i) + ") setting length to a value greater than 2,147,483,647");
mySelect.options.length = 2147483648;
shouldBe("mySelect.options.length", "10");
shouldBe("mySelect.selectedIndex", "0");

debug("");
</script>