Bug 1880216 - Migrate Fenix docs into Sphinx. r=owlish,geckoview-reviewers,android...
[gecko.git] / dom / html / test / test_bug551846.html
blob4950b1e452e5d164c477003500c9fa1c8e692bc8
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=551846
5 -->
6 <head>
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"/>
10 </head>
11 <body>
12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=551846">Mozilla Bug 551846</a>
13 <p id="display"></p>
14 <div id="content" style="display: none">
15 <select id='s'>
16 <option>Tulip</option>
17 <option>Lily</option>
18 <option>Gagea</option>
19 <option>Snowflake</option>
20 <option>Ismene</option>
21 </select>
22 </div>
23 <pre id="test">
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);
39 is(element.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)
89 var caught = false;
91 try {
92 element.size = 1;
93 } catch(e) {
94 caught = true;
96 ok(!caught, "Setting a positive size shouldn't throw an exception");
98 caught = false;
99 try {
100 element.size = 0;
101 } catch(e) {
102 caught = true;
104 ok(!caught, "Setting a size to 0 from the IDL shouldn't throw an exception");
106 element.size = 1;
108 caught = false;
109 try {
110 element.size = -1;
111 } catch(e) {
112 caught = true;
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");
118 caught = false;
119 try {
120 element.setAttribute('size', -10);
121 } catch(e) {
122 caught = true;
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");
135 s.multiple = true;
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");
143 s.multiple = false;
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);
161 </script>
162 </pre>
163 </body>
164 </html>