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   * Unit tests for {@link HTMLTimeElement}.
23   * @author Ronald Brill
24   */
25  public class HTMLTimeElementTest extends WebDriverTestCase {
26  
27      /**
28       * Text attribute is no longer supported.
29       *
30       * @throws Exception if the test fails
31       */
32      @Test
33      @Alerts({"undefined", "undefined"})
34      public void text() throws Exception {
35          final String html = DOCTYPE_HTML
36              + "<html>\n"
37              + "  <head>\n"
38              + "    <script>\n"
39              + LOG_TITLE_FUNCTION
40              + "      function test() {\n"
41              + "        var time1 = document.getElementById('time1');\n"
42              + "        log(time1.text);\n"
43              + "        var time2 = document.getElementById('time1');\n"
44              + "        log(time2.text);\n"
45              + "      }\n"
46              + "    </script>\n"
47              + "  </head>\n"
48              + "  <body onload='test()'>\n"
49              + "    <p>start <time id='time1'>20:00</time></p>\n"
50              + "    <p>start <time id='time2' datetime='2001-05-15 19:00'>15. Mai</time></p>\n"
51              + "  </body>\n"
52              + "</html>";
53  
54          loadPageVerifyTitle2(html);
55      }
56  
57      /**
58       * @throws Exception if the test fails
59       */
60      @Test
61      @Alerts({"", "20:40", "2001-05-15 19:00", ""})
62      public void datetime() throws Exception {
63          final String html = DOCTYPE_HTML
64              + "<html>\n"
65              + "  <head>\n"
66              + "    <script>\n"
67              + LOG_TITLE_FUNCTION
68              + "      function test() {\n"
69              + "        var time1 = document.getElementById('time1');\n"
70              + "        log(time1.dateTime);\n"
71              + "        time1.dateTime = '20:40';\n"
72              + "        log(time1.dateTime);\n"
73  
74              + "        var time2 = document.getElementById('time2');\n"
75              + "        log(time2.dateTime);\n"
76              + "        time2.dateTime = '';\n"
77              + "        log(time2.dateTime);\n"
78              + "      }\n"
79              + "    </script>\n"
80              + "  </head>\n"
81              + "  <body onload='test()'>\n"
82              + "    <p>start <time id='time1'>20:00</time></p>\n"
83              + "    <p>start <time id='time2' datetime='2001-05-15 19:00'>15. Mai</time></p>\n"
84              + "  </body>\n"
85              + "</html>";
86  
87          loadPageVerifyTitle2(html);
88      }
89  }