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.annotation.Alerts;
19  import org.junit.jupiter.api.Test;
20  
21  /**
22   * Tests for {@link HTMLMeterElement}.
23   *
24   * @author Marc Guillemot
25   * @author Frank Danek
26   * @author Ahmed Ashour
27   */
28  public class HTMLMeterElementTest extends WebDriverTestCase {
29  
30      /**
31       * @throws Exception if an error occurs
32       */
33      @Test
34      @Alerts("[object HTMLMeterElement]")
35      public void tag() throws Exception {
36          final String html = DOCTYPE_HTML
37              + "<html><body>\n"
38              + "<meter id='it' min='200' max='500' value='350'>\n"
39              + "<script>\n"
40              + LOG_TITLE_FUNCTION
41              + "  log(document.getElementById('it'));\n"
42              + "</script></body></html>";
43  
44          loadPageVerifyTitle2(html);
45      }
46  
47      /**
48       * @throws Exception if an error occurs
49       */
50      @Test
51      @Alerts({"number200", "number500", "number200", "number500", "number350", "number350"})
52      public void properties() throws Exception {
53          final String html = DOCTYPE_HTML
54              + "<html><body>\n"
55              + "<meter id='it' min='200' max='500' value='350'>\n"
56              + "<script>\n"
57              + LOG_TITLE_FUNCTION
58              + "var elt = document.getElementById('it');\n"
59              + "if (window.HTMLMeterElement) {\n"
60              + "  log(typeof(elt.min) + elt.min);\n"
61              + "  log(typeof(elt.max) + elt.max);\n"
62              + "  log(typeof(elt.low) + elt.low);\n"
63              + "  log(typeof(elt.high) + elt.high);\n"
64              + "  log(typeof(elt.value) + elt.value);\n"
65              + "  log(typeof(elt.optimum) + elt.optimum);\n"
66              + "}\n"
67              + "</script></body></html>";
68  
69          loadPageVerifyTitle2(html);
70      }
71  
72      /**
73       * @throws Exception if an error occurs
74       */
75      @Test
76      @Alerts({"0", "2", "1", "2", "1", "1"})
77      public void labels() throws Exception {
78          final String html = DOCTYPE_HTML
79              + "<html><head>\n"
80              + "  <script>\n"
81              + LOG_TITLE_FUNCTION
82              + "    function test() {\n"
83              + "      debug(document.getElementById('e1'));\n"
84              + "      debug(document.getElementById('e2'));\n"
85              + "      debug(document.getElementById('e3'));\n"
86              + "      debug(document.getElementById('e4'));\n"
87              + "      var labels = document.getElementById('e4').labels;\n"
88              + "      document.body.removeChild(document.getElementById('l4'));\n"
89              + "      debug(document.getElementById('e4'));\n"
90              + "      log(labels ? labels.length : labels);\n"
91              + "    }\n"
92              + "    function debug(e) {\n"
93              + "      log(e.labels ? e.labels.length : e.labels);\n"
94              + "    }\n"
95              + "  </script>\n"
96              + "</head>\n"
97              + "<body onload='test()'>\n"
98              + "  <meter id='e1'>e 1</meter><br>\n"
99              + "  <label>something <label> click here <meter id='e2'>e 2</meter></label></label><br>\n"
100             + "  <label for='e3'> and here</label>\n"
101             + "  <meter id='e3'>e 3</meter><br>\n"
102             + "  <label id='l4' for='e4'> what about</label>\n"
103             + "  <label> this<meter id='e4'>e 4</meter></label><br>\n"
104             + "</body></html>";
105 
106         loadPageVerifyTitle2(html);
107     }
108 }