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