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