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