View Javadoc
1   /*
2    * Copyright (c) 2002-2025 Gargoyle Software Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * https://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  package org.htmlunit.javascript.host.html;
16  
17  import org.htmlunit.WebDriverTestCase;
18  import org.htmlunit.junit.BrowserRunner;
19  import org.htmlunit.junit.annotation.Alerts;
20  import org.junit.Test;
21  import org.junit.runner.RunWith;
22  
23  /**
24   * Tests for {@link HTMLMeterElement}.
25   *
26   * @author Marc Guillemot
27   * @author Frank Danek
28   * @author Ahmed Ashour
29   */
30  @RunWith(BrowserRunner.class)
31  public class HTMLMeterElementTest extends WebDriverTestCase {
32  
33      /**
34       * @throws Exception if an error occurs
35       */
36      @Test
37      @Alerts("[object HTMLMeterElement]")
38      public void tag() throws Exception {
39          final String html = DOCTYPE_HTML
40              + "<html><body>\n"
41              + "<meter id='it' min='200' max='500' value='350'>\n"
42              + "<script>\n"
43              + LOG_TITLE_FUNCTION
44              + "  log(document.getElementById('it'));\n"
45              + "</script></body></html>";
46  
47          loadPageVerifyTitle2(html);
48      }
49  
50      /**
51       * @throws Exception if an error occurs
52       */
53      @Test
54      @Alerts({"number200", "number500", "number200", "number500", "number350", "number350"})
55      public void properties() throws Exception {
56          final String html = DOCTYPE_HTML
57              + "<html><body>\n"
58              + "<meter id='it' min='200' max='500' value='350'>\n"
59              + "<script>\n"
60              + LOG_TITLE_FUNCTION
61              + "var elt = document.getElementById('it');\n"
62              + "if (window.HTMLMeterElement) {\n"
63              + "  log(typeof(elt.min) + elt.min);\n"
64              + "  log(typeof(elt.max) + elt.max);\n"
65              + "  log(typeof(elt.low) + elt.low);\n"
66              + "  log(typeof(elt.high) + elt.high);\n"
67              + "  log(typeof(elt.value) + elt.value);\n"
68              + "  log(typeof(elt.optimum) + elt.optimum);\n"
69              + "}\n"
70              + "</script></body></html>";
71  
72          loadPageVerifyTitle2(html);
73      }
74  
75      /**
76       * @throws Exception if an error occurs
77       */
78      @Test
79      @Alerts({"0", "2", "1", "2", "1", "1"})
80      public void labels() throws Exception {
81          final String html = DOCTYPE_HTML
82              + "<html><head>\n"
83              + "  <script>\n"
84              + LOG_TITLE_FUNCTION
85              + "    function test() {\n"
86              + "      debug(document.getElementById('e1'));\n"
87              + "      debug(document.getElementById('e2'));\n"
88              + "      debug(document.getElementById('e3'));\n"
89              + "      debug(document.getElementById('e4'));\n"
90              + "      var labels = document.getElementById('e4').labels;\n"
91              + "      document.body.removeChild(document.getElementById('l4'));\n"
92              + "      debug(document.getElementById('e4'));\n"
93              + "      log(labels ? labels.length : labels);\n"
94              + "    }\n"
95              + "    function debug(e) {\n"
96              + "      log(e.labels ? e.labels.length : e.labels);\n"
97              + "    }\n"
98              + "  </script>\n"
99              + "</head>\n"
100             + "<body onload='test()'>\n"
101             + "  <meter id='e1'>e 1</meter><br>\n"
102             + "  <label>something <label> click here <meter id='e2'>e 2</meter></label></label><br>\n"
103             + "  <label for='e3'> and here</label>\n"
104             + "  <meter id='e3'>e 3</meter><br>\n"
105             + "  <label id='l4' for='e4'> what about</label>\n"
106             + "  <label> this<meter id='e4'>e 4</meter></label><br>\n"
107             + "</body></html>";
108 
109         loadPageVerifyTitle2(html);
110     }
111 }