test_bug551846.html (5227B)
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"> 25 26 /** Test for Bug 551846 */ 27 28 function checkSizeReflection(element, defaultValue) 29 { 30 is(element.size, defaultValue, "Default size should be " + defaultValue); 31 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"); 37 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"); 43 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"); 49 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"); 55 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"); 61 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"); 67 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"); 73 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"); 78 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"); 85 } 86 87 function checkSetSizeException(element) 88 { 89 var caught = false; 90 91 try { 92 element.size = 1; 93 } catch(e) { 94 caught = true; 95 } 96 ok(!caught, "Setting a positive size shouldn't throw an exception"); 97 98 caught = false; 99 try { 100 element.size = 0; 101 } catch(e) { 102 caught = true; 103 } 104 ok(!caught, "Setting a size to 0 from the IDL shouldn't throw an exception"); 105 106 element.size = 1; 107 108 caught = false; 109 try { 110 element.size = -1; 111 } catch(e) { 112 caught = true; 113 } 114 ok(!caught, "Setting a negative size from the IDL shouldn't throw an exception"); 115 116 is(element.size, 0, "The size should now be equal to the minimum non-negative value"); 117 118 caught = false; 119 try { 120 element.setAttribute('size', -10); 121 } catch(e) { 122 caught = true; 123 } 124 ok(!caught, "Setting an invalid size in the content attribute shouldn't throw an exception"); 125 126 // reverting to defalut 127 element.removeAttribute('size'); 128 } 129 130 function checkSizeWhenChangeMultiple(element, aDefaultNonMultiple, aDefaultMultiple) 131 { 132 s.setAttribute('size', -1) 133 is(s.size, aDefaultNonMultiple, "Size IDL attribute should be 1"); 134 135 s.multiple = true; 136 is(s.size, aDefaultMultiple, "Size IDL attribute should be 4"); 137 138 is(s.getAttribute('size'), "-1", "Size content attribute should be -1"); 139 140 s.setAttribute('size', -2); 141 is(s.size, aDefaultMultiple, "Size IDL attribute should be 4"); 142 143 s.multiple = false; 144 is(s.size, aDefaultNonMultiple, "Size IDL attribute should be 1"); 145 146 is(s.getAttribute('size'), "-2", "Size content attribute should be -2"); 147 } 148 149 var s = document.getElementById('s'); 150 151 checkSizeReflection(s, 0); 152 checkSetSizeException(s); 153 154 s.setAttribute('multiple', 'true'); 155 checkSizeReflection(s, 0); 156 checkSetSizeException(s); 157 s.removeAttribute('multiple'); 158 159 checkSizeWhenChangeMultiple(s, 0, 0); 160 161 </script> 162 </pre> 163 </body> 164 </html>