4 https://bugzilla.mozilla.org/show_bug.cgi?id=551846
7 <title>Test for Bug
551846</title>
8 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
9 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css"/>
12 <a target=
"_blank" href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=551846">Mozilla Bug
551846</a>
14 <div id=
"content" style=
"display: none">
16 <option>Tulip
</option>
18 <option>Gagea
</option>
19 <option>Snowflake
</option>
20 <option>Ismene
</option>
24 <script type=
"application/javascript">
26 /** Test for Bug
551846 **/
28 function checkSizeReflection(element, defaultValue)
30 is(element.size, defaultValue,
"Default size should be " + defaultValue);
32 element.setAttribute('size', -
15);
33 is(element.size, defaultValue,
34 "The reflecting IDL attribute should return the default value when content attribute value is invalid");
35 is(element.getAttribute('size'),
"-15",
36 "The content attribute should containt the previously set value");
38 element.setAttribute('size',
0);
40 "0 should be considered as a valid value");
41 is(element.getAttribute('size'),
"0",
42 "The content attribute should containt the previously set value");
44 element.setAttribute('size',
2147483647); /* PR_INT32_MAX */
45 is(element.size,
2147483647,
46 "PR_INT32_MAX should be considered as a valid value");
47 is(element.getAttribute('size'),
"2147483647",
48 "The content attribute should containt the previously set value");
50 element.setAttribute('size', -
2147483648); /* PR_INT32_MIN */
51 is(element.size, defaultValue,
52 "The reflecting IDL attribute should return the default value when content attribute value is invalid");
53 is(element.getAttribute('size'),
"-2147483648",
54 "The content attribute should containt the previously set value");
56 element.setAttribute('size', 'non-numerical-value');
57 is(element.size, defaultValue,
58 "The reflecting IDL attribute should return the default value when content attribute value is invalid");
59 is(element.getAttribute('size'), 'non-numerical-value',
60 "The content attribute should containt the previously set value");
62 element.setAttribute('size',
4294967294); /* PR_INT32_MAX *
2 */
63 is(element.size, defaultValue,
64 "Value greater than PR_INT32_MAX should be considered as invalid");
65 is(element.getAttribute('size'),
"4294967294",
66 "The content attribute should containt the previously set value");
68 element.setAttribute('size', -
4294967296); /* PR_INT32_MIN *
2 */
69 is(element.size, defaultValue,
70 "The reflecting IDL attribute should return the default value when content attribute value is invalid");
71 is(element.getAttribute('size'),
"-4294967296",
72 "The content attribute should containt the previously set value");
74 element.size = defaultValue +
1;
75 element.removeAttribute('size');
76 is(element.size, defaultValue,
77 "When the attribute is removed, the size should be the default size");
79 element.setAttribute('size', 'foobar');
80 is(element.size, defaultValue,
81 "The reflecting IDL attribute should return the default value when content attribute value is invalid");
82 element.removeAttribute('size');
83 is(element.size, defaultValue,
84 "When the attribute is removed, the size should be the default size");
87 function checkSetSizeException(element)
96 ok(!caught,
"Setting a positive size shouldn't throw an exception");
104 ok(!caught,
"Setting a size to 0 from the IDL shouldn't throw an exception");
114 ok(!caught,
"Setting a negative size from the IDL shouldn't throw an exception");
116 is(element.size,
0,
"The size should now be equal to the minimum non-negative value");
120 element.setAttribute('size', -
10);
124 ok(!caught,
"Setting an invalid size in the content attribute shouldn't throw an exception");
126 // reverting to defalut
127 element.removeAttribute('size');
130 function checkSizeWhenChangeMultiple(element, aDefaultNonMultiple, aDefaultMultiple)
132 s.setAttribute('size', -
1)
133 is(s.size, aDefaultNonMultiple,
"Size IDL attribute should be 1");
136 is(s.size, aDefaultMultiple,
"Size IDL attribute should be 4");
138 is(s.getAttribute('size'),
"-1",
"Size content attribute should be -1");
140 s.setAttribute('size', -
2);
141 is(s.size, aDefaultMultiple,
"Size IDL attribute should be 4");
144 is(s.size, aDefaultNonMultiple,
"Size IDL attribute should be 1");
146 is(s.getAttribute('size'),
"-2",
"Size content attribute should be -2");
149 var s = document.getElementById('s');
151 checkSizeReflection(s,
0);
152 checkSetSizeException(s);
154 s.setAttribute('multiple', 'true');
155 checkSizeReflection(s,
0);
156 checkSetSizeException(s);
157 s.removeAttribute('multiple');
159 checkSizeWhenChangeMultiple(s,
0,
0);