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 HTMLBRElement}.
23   *
24   * @author Daniel Gredler
25   * @author Ahmed Ashour
26   * @author Ronald Brill
27   * @author Frank Danek
28   */
29  public class HTMLBRElementTest extends WebDriverTestCase {
30  
31      /**
32       * @throws Exception if an error occurs
33       */
34      @Test
35      @Alerts({"", "left", "all", "right", "none", "2", "foo", "left",
36               "none", "right", "all", "2", "abc", "8"})
37      public void clear() throws Exception {
38          final String html = DOCTYPE_HTML
39              + "<html><body>\n"
40              + "<br id='br1'/>\n"
41              + "<br id='br2' clear='left'/>\n"
42              + "<br id='br3' clear='all'/>\n"
43              + "<br id='br4' clear='right'/>\n"
44              + "<br id='br5' clear='none'/>\n"
45              + "<br id='br6' clear='2'/>\n"
46              + "<br id='br7' clear='foo'/>\n"
47              + "<script>\n"
48              + LOG_TITLE_FUNCTION
49              + "function set(br, value) {\n"
50              + "  try {\n"
51              + "    br.clear = value;\n"
52              + "  } catch(e) {\n"
53              + "    log('!');\n"
54              + "  }\n"
55              + "}\n"
56              + "var br1 = document.getElementById('br1');\n"
57              + "var br2 = document.getElementById('br2');\n"
58              + "var br3 = document.getElementById('br3');\n"
59              + "var br4 = document.getElementById('br4');\n"
60              + "var br5 = document.getElementById('br5');\n"
61              + "var br6 = document.getElementById('br6');\n"
62              + "var br7 = document.getElementById('br7');\n"
63              + "log(br1.clear);\n"
64              + "log(br2.clear);\n"
65              + "log(br3.clear);\n"
66              + "log(br4.clear);\n"
67              + "log(br5.clear);\n"
68              + "log(br6.clear);\n"
69              + "log(br7.clear);\n"
70              + "set(br1, 'left');\n"
71              + "set(br2, 'none');\n"
72              + "set(br3, 'right');\n"
73              + "set(br4, 'all');\n"
74              + "set(br5, 2);\n"
75              + "set(br6, 'abc');\n"
76              + "set(br7, '8');\n"
77              + "log(br1.clear);\n"
78              + "log(br2.clear);\n"
79              + "log(br3.clear);\n"
80              + "log(br4.clear);\n"
81              + "log(br5.clear);\n"
82              + "log(br6.clear);\n"
83              + "log(br7.clear);\n"
84              + "</script></body></html>";
85  
86          loadPageVerifyTitle2(html);
87      }
88  
89      /**
90       * @throws Exception if the test fails
91       */
92      @Test
93      @Alerts("<br id=\"myId\">")
94      public void outerHTML() throws Exception {
95          final String html = DOCTYPE_HTML
96              + "<html><head><script>\n"
97              + LOG_TITLE_FUNCTION
98              + "function doTest() {\n"
99              + "  log(document.getElementById('myId').outerHTML);\n"
100             + "}\n"
101             + "</script></head><body onload='doTest()'>\n"
102             + "  <br id='myId'>\n"
103             + "</body></html>";
104 
105         loadPageVerifyTitle2(html);
106     }
107 }