test_bug551846.html 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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 type="application/javascript" 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. /** Test for Bug 551846 **/
  26. function checkSizeReflection(element, defaultValue)
  27. {
  28. is(element.size, defaultValue, "Default size should be " + defaultValue);
  29. element.setAttribute('size', -15);
  30. is(element.size, defaultValue,
  31. "The reflecting IDL attribute should return the default value when content attribute value is invalid");
  32. is(element.getAttribute('size'), "-15",
  33. "The content attribute should containt the previously set value");
  34. element.setAttribute('size', 0);
  35. is(element.size, 0,
  36. "0 should be considered as a valid value");
  37. is(element.getAttribute('size'), "0",
  38. "The content attribute should containt the previously set value");
  39. element.setAttribute('size', 2147483647); /* PR_INT32_MAX */
  40. is(element.size, 2147483647,
  41. "PR_INT32_MAX should be considered as a valid value");
  42. is(element.getAttribute('size'), "2147483647",
  43. "The content attribute should containt the previously set value");
  44. element.setAttribute('size', -2147483648); /* PR_INT32_MIN */
  45. is(element.size, defaultValue,
  46. "The reflecting IDL attribute should return the default value when content attribute value is invalid");
  47. is(element.getAttribute('size'), "-2147483648",
  48. "The content attribute should containt the previously set value");
  49. element.setAttribute('size', 'non-numerical-value');
  50. is(element.size, defaultValue,
  51. "The reflecting IDL attribute should return the default value when content attribute value is invalid");
  52. is(element.getAttribute('size'), 'non-numerical-value',
  53. "The content attribute should containt the previously set value");
  54. element.setAttribute('size', 4294967294); /* PR_INT32_MAX * 2 */
  55. is(element.size, defaultValue,
  56. "Value greater than PR_INT32_MAX should be considered as invalid");
  57. is(element.getAttribute('size'), "4294967294",
  58. "The content attribute should containt the previously set value");
  59. element.setAttribute('size', -4294967296); /* PR_INT32_MIN * 2 */
  60. is(element.size, defaultValue,
  61. "The reflecting IDL attribute should return the default value when content attribute value is invalid");
  62. is(element.getAttribute('size'), "-4294967296",
  63. "The content attribute should containt the previously set value");
  64. element.size = defaultValue + 1;
  65. element.removeAttribute('size');
  66. is(element.size, defaultValue,
  67. "When the attribute is removed, the size should be the default size");
  68. element.setAttribute('size', 'foobar');
  69. is(element.size, defaultValue,
  70. "The reflecting IDL attribute should return the default value when content attribute value is invalid");
  71. element.removeAttribute('size');
  72. is(element.size, defaultValue,
  73. "When the attribute is removed, the size should be the default size");
  74. }
  75. function checkSetSizeException(element)
  76. {
  77. var caught = false;
  78. try {
  79. element.size = 1;
  80. } catch(e) {
  81. caught = true;
  82. }
  83. ok(!caught, "Setting a positive size shouldn't throw an exception");
  84. caught = false;
  85. try {
  86. element.size = 0;
  87. } catch(e) {
  88. caught = true;
  89. }
  90. ok(!caught, "Setting a size to 0 from the IDL shouldn't throw an exception");
  91. element.size = 1;
  92. caught = false;
  93. try {
  94. element.size = -1;
  95. } catch(e) {
  96. caught = true;
  97. }
  98. ok(!caught, "Setting a negative size from the IDL shouldn't throw an exception");
  99. is(element.size, 0, "The size should now be equal to the minimum non-negative value");
  100. caught = false;
  101. try {
  102. element.setAttribute('size', -10);
  103. } catch(e) {
  104. caught = true;
  105. }
  106. ok(!caught, "Setting an invalid size in the content attribute shouldn't throw an exception");
  107. // reverting to defalut
  108. element.removeAttribute('size');
  109. }
  110. function checkSizeWhenChangeMultiple(element, aDefaultNonMultiple, aDefaultMultiple)
  111. {
  112. s.setAttribute('size', -1)
  113. is(s.size, aDefaultNonMultiple, "Size IDL attribute should be 1");
  114. s.multiple = true;
  115. is(s.size, aDefaultMultiple, "Size IDL attribute should be 4");
  116. is(s.getAttribute('size'), "-1", "Size content attribute should be -1");
  117. s.setAttribute('size', -2);
  118. is(s.size, aDefaultMultiple, "Size IDL attribute should be 4");
  119. s.multiple = false;
  120. is(s.size, aDefaultNonMultiple, "Size IDL attribute should be 1");
  121. is(s.getAttribute('size'), "-2", "Size content attribute should be -2");
  122. }
  123. var s = document.getElementById('s');
  124. checkSizeReflection(s, 0);
  125. checkSetSizeException(s);
  126. s.setAttribute('multiple', 'true');
  127. checkSizeReflection(s, 0);
  128. checkSetSizeException(s);
  129. s.removeAttribute('multiple');
  130. checkSizeWhenChangeMultiple(s, 0, 0);
  131. </script>
  132. </pre>
  133. </body>
  134. </html>