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