summaryrefslogtreecommitdiffstats
path: root/dom/html/test/forms/test_meter_pseudo-classes.html
blob: e317a584059966b61818dd736c9cd7c702f7552f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=660238
-->
<head>
  <title>Test for Bug 660238</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=770238">Mozilla Bug 660238</a>
<p id="display"></p>
<pre id="test">
<script type="application/javascript">

/** Test for Bug 660238 **/

function checkOptimum(aElement, aValue, aOptimum, expectedResult)
{
  var errorString = expectedResult
                      ? "value attribute should be in the optimum region"
                      : "value attribute should not be in the optimum region";

  aElement.setAttribute('value', aValue);
  aElement.setAttribute('optimum', aOptimum);
  is(aElement.matches(":-moz-meter-optimum"),
    expectedResult, errorString);
}

function checkSubOptimum(aElement, aValue, aOptimum, expectedResult)
{
  var errorString = "value attribute should be in the suboptimal region";
  if (!expectedResult) {
    errorString = "value attribute should not be in the suboptimal region";
  }
  aElement.setAttribute('value', aValue);
  aElement.setAttribute('optimum', aOptimum);
  is(aElement.matches(":-moz-meter-sub-optimum"),
    expectedResult, errorString);
}

function checkSubSubOptimum(aElement, aValue, aOptimum, expectedResult)
{
  var errorString = "value attribute should be in the sub-suboptimal region";
  if (!expectedResult) {
    errorString = "value attribute should not be in the sub-suboptimal region";
  }
  aElement.setAttribute('value', aValue);
  aElement.setAttribute('optimum', aOptimum);
  is(aElement.matches(":-moz-meter-sub-sub-optimum"),
    expectedResult, errorString);
}

function checkMozMatchesSelector()
{
  var element = document.createElement('meter');
  // all tests realised with default values for min and max (0 and 1)
  // low = 0.3 and high = 0.7
  element.setAttribute('low', 0.3);
  element.setAttribute('high', 0.7);

  var tests = [
    /*
     * optimum = 0.0 =>
     *     optimum region        = [ 0.0, 0.3 [
     *     suboptimal region     = [ 0.3, 0.7 ]
     *     sub-suboptimal region = ] 0.7, 1.0 ]
     */
    [ 0.0, 0.0, true, false, false ],
    [ 0.1, 0.0, true, false, false ],
    [ 0.3, 0.0, false, true, false ],
    [ 0.5, 0.0, false, true, false ],
    [ 0.7, 0.0, false, true, false ],
    [ 0.8, 0.0, false, false, true ],
    [ 1.0, 0.0, false, false, true ],
    /*
     * optimum = 0.1 =>
     *     optimum region        = [ 0.0, 0.3 [
     *     suboptimal region     = [ 0.3, 0.7 ]
     *     sub-suboptimal region = ] 0.7, 1.0 ]
     */
    [ 0.0, 0.1, true, false, false ],
    [ 0.1, 0.1, true, false, false ],
    [ 0.3, 0.1, false, true, false ],
    [ 0.5, 0.1, false, true, false ],
    [ 0.7, 0.1, false, true, false ],
    [ 0.8, 0.1, false, false, true ],
    [ 1.0, 0.1, false, false, true ],
    /*
     * optimum = 0.3 =>
     *     suboptimal region     = [ 0.0, 0.3 [
     *     optimum region        = [ 0.3, 0.7 ]
     *     suboptimal region     = ] 0.7, 1.0 ]
     */
    [ 0.0, 0.3, false, true, false ],
    [ 0.1, 0.3, false, true, false ],
    [ 0.3, 0.3, true, false, false ],
    [ 0.5, 0.3, true, false, false ],
    [ 0.7, 0.3, true, false, false ],
    [ 0.8, 0.3, false, true, false ],
    [ 1.0, 0.3, false, true, false ],
    /*
     * optimum = 0.5 =>
     *     suboptimal region     = [ 0.0, 0.3 [
     *     optimum region        = [ 0.3, 0.7 ]
     *     suboptimal region     = ] 0.7, 1.0 ]
     */
    [ 0.0, 0.5, false, true, false ],
    [ 0.1, 0.5, false, true, false ],
    [ 0.3, 0.5, true, false, false ],
    [ 0.5, 0.5, true, false, false ],
    [ 0.7, 0.5, true, false, false ],
    [ 0.8, 0.5, false, true, false ],
    [ 1.0, 0.5, false, true, false ],
    /*
     * optimum = 0.7 =>
     *     suboptimal region     = [ 0.0, 0.3 [
     *     optimum region        = [ 0.3, 0.7 ]
     *     suboptimal region     = ] 0.7, 1.0 ]
     */
    [ 0.0, 0.7, false, true, false ],
    [ 0.1, 0.7, false, true, false ],
    [ 0.3, 0.7, true, false, false ],
    [ 0.5, 0.7, true, false, false ],
    [ 0.7, 0.7, true, false, false ],
    [ 0.8, 0.7, false, true, false ],
    [ 1.0, 0.7, false, true, false ],
    /*
     * optimum = 0.8 =>
     *     sub-suboptimal region = [ 0.0, 0.3 [
     *     suboptimal region     = [ 0.3, 0.7 ]
     *     optimum region        = ] 0.7, 1.0 ]
     */
    [ 0.0, 0.8, false, false, true ],
    [ 0.1, 0.8, false, false, true ],
    [ 0.3, 0.8, false, true, false ],
    [ 0.5, 0.8, false, true, false ],
    [ 0.7, 0.8, false, true, false ],
    [ 0.8, 0.8, true, false, false ],
    [ 1.0, 0.8, true, false, false ],
    /*
     * optimum = 1.0 =>
     *     sub-suboptimal region = [ 0.0, 0.3 [
     *     suboptimal region     = [ 0.3, 0.7 ]
     *     optimum region        = ] 0.7, 1.0 ]
     */
    [ 0.0, 1.0, false, false, true ],
    [ 0.1, 1.0, false, false, true ],
    [ 0.3, 1.0, false, true, false ],
    [ 0.5, 1.0, false, true, false ],
    [ 0.7, 1.0, false, true, false ],
    [ 0.8, 1.0, true, false, false ],
    [ 1.0, 1.0, true, false, false ],
  ];

  for (var test of tests) {
    checkOptimum(element, test[0], test[1], test[2]);
    checkSubOptimum(element, test[0], test[1], test[3]);
    checkSubSubOptimum(element, test[0], test[1], test[4]);
  }
}

checkMozMatchesSelector();

</script>
</pre>
</body>
</html>