test_meter_pseudo-classes.html 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=660238
  5. -->
  6. <head>
  7. <title>Test for Bug 660238</title>
  8. <script type="application/javascript" src="/MochiKit/packed.js"></script>
  9. <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  10. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  11. </head>
  12. <body>
  13. <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=770238">Mozilla Bug 660238</a>
  14. <p id="display"></p>
  15. <pre id="test">
  16. <script type="application/javascript">
  17. /** Test for Bug 660238 **/
  18. function checkOptimum(aElement, aValue, aOptimum, expectedResult)
  19. {
  20. var errorString = expectedResult
  21. ? "value attribute should be in the optimum region"
  22. : "value attribute should not be in the optimum region";
  23. aElement.setAttribute('value', aValue);
  24. aElement.setAttribute('optimum', aOptimum);
  25. is(aElement.matches(":-moz-meter-optimum"),
  26. expectedResult, errorString);
  27. }
  28. function checkSubOptimum(aElement, aValue, aOptimum, expectedResult)
  29. {
  30. var errorString = "value attribute should be in the suboptimal region";
  31. if (!expectedResult) {
  32. errorString = "value attribute should not be in the suboptimal region";
  33. }
  34. aElement.setAttribute('value', aValue);
  35. aElement.setAttribute('optimum', aOptimum);
  36. is(aElement.matches(":-moz-meter-sub-optimum"),
  37. expectedResult, errorString);
  38. }
  39. function checkSubSubOptimum(aElement, aValue, aOptimum, expectedResult)
  40. {
  41. var errorString = "value attribute should be in the sub-suboptimal region";
  42. if (!expectedResult) {
  43. errorString = "value attribute should not be in the sub-suboptimal region";
  44. }
  45. aElement.setAttribute('value', aValue);
  46. aElement.setAttribute('optimum', aOptimum);
  47. is(aElement.matches(":-moz-meter-sub-sub-optimum"),
  48. expectedResult, errorString);
  49. }
  50. function checkMozMatchesSelector()
  51. {
  52. var element = document.createElement('meter');
  53. // all tests realised with default values for min and max (0 and 1)
  54. // low = 0.3 and high = 0.7
  55. element.setAttribute('low', 0.3);
  56. element.setAttribute('high', 0.7);
  57. var tests = [
  58. /*
  59. * optimum = 0.0 =>
  60. * optimum region = [ 0.0, 0.3 [
  61. * suboptimal region = [ 0.3, 0.7 ]
  62. * sub-suboptimal region = ] 0.7, 1.0 ]
  63. */
  64. [ 0.0, 0.0, true, false, false ],
  65. [ 0.1, 0.0, true, false, false ],
  66. [ 0.3, 0.0, false, true, false ],
  67. [ 0.5, 0.0, false, true, false ],
  68. [ 0.7, 0.0, false, true, false ],
  69. [ 0.8, 0.0, false, false, true ],
  70. [ 1.0, 0.0, false, false, true ],
  71. /*
  72. * optimum = 0.1 =>
  73. * optimum region = [ 0.0, 0.3 [
  74. * suboptimal region = [ 0.3, 0.7 ]
  75. * sub-suboptimal region = ] 0.7, 1.0 ]
  76. */
  77. [ 0.0, 0.1, true, false, false ],
  78. [ 0.1, 0.1, true, false, false ],
  79. [ 0.3, 0.1, false, true, false ],
  80. [ 0.5, 0.1, false, true, false ],
  81. [ 0.7, 0.1, false, true, false ],
  82. [ 0.8, 0.1, false, false, true ],
  83. [ 1.0, 0.1, false, false, true ],
  84. /*
  85. * optimum = 0.3 =>
  86. * suboptimal region = [ 0.0, 0.3 [
  87. * optimum region = [ 0.3, 0.7 ]
  88. * suboptimal region = ] 0.7, 1.0 ]
  89. */
  90. [ 0.0, 0.3, false, true, false ],
  91. [ 0.1, 0.3, false, true, false ],
  92. [ 0.3, 0.3, true, false, false ],
  93. [ 0.5, 0.3, true, false, false ],
  94. [ 0.7, 0.3, true, false, false ],
  95. [ 0.8, 0.3, false, true, false ],
  96. [ 1.0, 0.3, false, true, false ],
  97. /*
  98. * optimum = 0.5 =>
  99. * suboptimal region = [ 0.0, 0.3 [
  100. * optimum region = [ 0.3, 0.7 ]
  101. * suboptimal region = ] 0.7, 1.0 ]
  102. */
  103. [ 0.0, 0.5, false, true, false ],
  104. [ 0.1, 0.5, false, true, false ],
  105. [ 0.3, 0.5, true, false, false ],
  106. [ 0.5, 0.5, true, false, false ],
  107. [ 0.7, 0.5, true, false, false ],
  108. [ 0.8, 0.5, false, true, false ],
  109. [ 1.0, 0.5, false, true, false ],
  110. /*
  111. * optimum = 0.7 =>
  112. * suboptimal region = [ 0.0, 0.3 [
  113. * optimum region = [ 0.3, 0.7 ]
  114. * suboptimal region = ] 0.7, 1.0 ]
  115. */
  116. [ 0.0, 0.7, false, true, false ],
  117. [ 0.1, 0.7, false, true, false ],
  118. [ 0.3, 0.7, true, false, false ],
  119. [ 0.5, 0.7, true, false, false ],
  120. [ 0.7, 0.7, true, false, false ],
  121. [ 0.8, 0.7, false, true, false ],
  122. [ 1.0, 0.7, false, true, false ],
  123. /*
  124. * optimum = 0.8 =>
  125. * sub-suboptimal region = [ 0.0, 0.3 [
  126. * suboptimal region = [ 0.3, 0.7 ]
  127. * optimum region = ] 0.7, 1.0 ]
  128. */
  129. [ 0.0, 0.8, false, false, true ],
  130. [ 0.1, 0.8, false, false, true ],
  131. [ 0.3, 0.8, false, true, false ],
  132. [ 0.5, 0.8, false, true, false ],
  133. [ 0.7, 0.8, false, true, false ],
  134. [ 0.8, 0.8, true, false, false ],
  135. [ 1.0, 0.8, true, false, false ],
  136. /*
  137. * optimum = 1.0 =>
  138. * sub-suboptimal region = [ 0.0, 0.3 [
  139. * suboptimal region = [ 0.3, 0.7 ]
  140. * optimum region = ] 0.7, 1.0 ]
  141. */
  142. [ 0.0, 1.0, false, false, true ],
  143. [ 0.1, 1.0, false, false, true ],
  144. [ 0.3, 1.0, false, true, false ],
  145. [ 0.5, 1.0, false, true, false ],
  146. [ 0.7, 1.0, false, true, false ],
  147. [ 0.8, 1.0, true, false, false ],
  148. [ 1.0, 1.0, true, false, false ],
  149. ];
  150. for (var test of tests) {
  151. checkOptimum(element, test[0], test[1], test[2]);
  152. checkSubOptimum(element, test[0], test[1], test[3]);
  153. checkSubSubOptimum(element, test[0], test[1], test[4]);
  154. }
  155. }
  156. checkMozMatchesSelector();
  157. </script>
  158. </pre>
  159. </body>
  160. </html>