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 HTMLProgressElement}.
23   *
24   * @author Ahmed Ashour
25   * @author Ronald Brill
26   */
27  public class HTMLProgressElementTest extends WebDriverTestCase {
28  
29      /**
30       * @throws Exception if an error occurs
31       */
32      @Test
33      @Alerts({"0", "2", "1", "2", "1", "1"})
34      public void labels() throws Exception {
35          final String html = DOCTYPE_HTML
36              + "<html><head>\n"
37              + "  <script>\n"
38              + LOG_TITLE_FUNCTION
39              + "    function test() {\n"
40              + "      debug(document.getElementById('e1'));\n"
41              + "      debug(document.getElementById('e2'));\n"
42              + "      debug(document.getElementById('e3'));\n"
43              + "      debug(document.getElementById('e4'));\n"
44              + "      var labels = document.getElementById('e4').labels;\n"
45              + "      document.body.removeChild(document.getElementById('l4'));\n"
46              + "      debug(document.getElementById('e4'));\n"
47              + "      log(labels ? labels.length : labels);\n"
48              + "    }\n"
49              + "    function debug(e) {\n"
50              + "      log(e.labels ? e.labels.length : e.labels);\n"
51              + "    }\n"
52              + "  </script>\n"
53              + "</head>\n"
54              + "<body onload='test()'>\n"
55              + "  <progress id='e1'>e 1</progress><br>\n"
56              + "  <label>something <label> click here <progress id='e2'>e 2</progress></label></label><br>\n"
57              + "  <label for='e3'> and here</label>\n"
58              + "  <progress id='e3'>e 3</progress><br>\n"
59              + "  <label id='l4' for='e4'> what about</label>\n"
60              + "  <label> this<progress id='e4'>e 4</progress></label><br>\n"
61              + "</body></html>";
62  
63          loadPageVerifyTitle2(html);
64      }
65  
66      /**
67       * @throws Exception if an error occurs
68       */
69      @Test
70      @Alerts({"0", "number"})
71      public void value() throws Exception {
72          final String html = DOCTYPE_HTML
73              + "<html><head>\n"
74              + "  <script>\n"
75              + LOG_TITLE_FUNCTION
76              + "    function test() {\n"
77              + "      var e1 = document.getElementById('e1');\n"
78              + "      log(e1.value);\n"
79              + "      log(typeof e1.value);\n"
80              + "    }\n"
81              + "  </script>\n"
82              + "</head>\n"
83              + "<body onload='test()'>\n"
84              + "  <progress id='e1'>e 1</progress>\n"
85              + "</body></html>";
86  
87          loadPageVerifyTitle2(html);
88      }
89  }