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 HTMLDataElement}.
23   * @author Ronald Brill
24   */
25  public class HTMLDataElementTest extends WebDriverTestCase {
26  
27      /**
28       * @throws Exception if an error occurs
29       */
30      @Test
31      @Alerts("[object HTMLDataElement]")
32      public void tag() throws Exception {
33          final String html = DOCTYPE_HTML
34              + "<html><body>\n"
35              + "  <data id='it' value='1234'>onetwothreefour</data>\n"
36              + "<script>\n"
37              + LOG_TITLE_FUNCTION
38              + "  log(document.getElementById('it'));\n"
39              + "</script></body></html>";
40  
41          loadPageVerifyTitle2(html);
42      }
43  
44      /**
45       * @throws Exception if an error occurs
46       */
47      @Test
48      @Alerts({"1234", "#12o", "", "#12o"})
49      public void value() throws Exception {
50          final String html = DOCTYPE_HTML
51              + "<html><body>\n"
52              + "  <data id='d1' value='1234'>onetwothreefour</data>\n"
53              + "  <data id='d2' >onetwothreefour</data>\n"
54              + "<script>\n"
55              + LOG_TITLE_FUNCTION
56              + "  var dat = document.getElementById('d1');\n"
57              + "  log(dat.value);\n"
58              + "  dat.value = '#12o';\n"
59              + "  log(dat.value);\n"
60  
61              + "  dat = document.getElementById('d2');\n"
62              + "  log(dat.value);\n"
63              + "  dat.value = '#12o';\n"
64              + "  log(dat.value);\n"
65              + "</script></body></html>";
66          loadPageVerifyTitle2(html);
67      }
68  }