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.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 HtmlTemplate}.
23   *
24   * @author Ronald Brill
25   */
26  public class HtmlTemplateTest extends WebDriverTestCase {
27  
28      /**
29       * @throws Exception if the test fails
30       */
31      @Test
32      @Alerts({"2", "null", "null"})
33      public void noChilds() throws Exception {
34          final String html = DOCTYPE_HTML
35              + "<html><head>\n"
36              + "<script>\n"
37              + LOG_TITLE_FUNCTION
38              + "  function test() {\n"
39              + "    log(document.querySelectorAll('form input[type=radio][name=\"rad\"]').length);\n"
40              + "    log(document.querySelector('form input[type=radio][name=\"rad\"][value=\"3\"]'));\n"
41              + "    log(document.querySelector('form input[type=radio][name=\"rad\"][value=\"4\"]'));\n"
42              + "  }\n"
43              + "</script>\n"
44              + "</head>\n"
45              + "<body onload='test()'>\n"
46              + "<form>\n"
47              + "  <input type='radio' id='radio1' name='rad' value='1' checked/>\n"
48              + "  <input type='radio' name='rad' value='2'/>\n"
49              + "  <template>\n"
50              + "    <input type='radio' name='rad' value='3' checked/>\n"
51              + "    <input type='radio' name='rad' value='4'/>\n"
52              + "  </template>\n"
53              + "</body></html>";
54  
55          loadPageVerifyTitle2(html);
56      }
57  
58      /**
59       * @throws Exception if the test fails
60       */
61      @Test
62      @Alerts("true")
63      public void ignoreContent() throws Exception {
64          final String html = DOCTYPE_HTML
65              + "<html><head>\n"
66              + "<script>\n"
67              + LOG_TITLE_FUNCTION
68              + "  function test() {\n"
69              + "    log(document.getElementById('radio1').checked);\n"
70              + "  }\n"
71              + "</script>\n"
72              + "</head>\n"
73              + "<body onload='test()'>\n"
74              + "<form>\n"
75              + "  <input type='radio' id='radio1' name='rad' value='1' checked/>\n"
76              + "  <input type='radio' name='rad' value='2'/>\n"
77              + "  <template>\n"
78              + "    <input type='radio' name='rad' value='3' checked/>\n"
79              + "    <input type='radio' name='rad' value='4'/>\n"
80              + "  </template>\n"
81              + "</body></html>";
82  
83          loadPageVerifyTitle2(html);
84      }
85  }