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 HTMLHRElement}.
25   *
26   * @author Ronald Brill
27   * @author Frank Danek
28   */
29  @RunWith(BrowserRunner.class)
30  public class HTMLHRElementTest extends WebDriverTestCase {
31  
32      /**
33       * @throws Exception if an error occurs
34       */
35      @Test
36      @Alerts({"left", "right", "center", "wrong", ""})
37      public void getAlign() throws Exception {
38          final String html = DOCTYPE_HTML
39              + "<html><body>\n"
40              + "  <hr id='h1' align='left' />\n"
41              + "  <hr id='h2' align='right' />\n"
42              + "  <hr id='h3' align='center' />\n"
43              + "  <hr id='h4' align='wrong' />\n"
44              + "  <hr id='h5' />\n"
45  
46              + "<script>\n"
47              + LOG_TITLE_FUNCTION
48              + "  for (var i = 1; i <= 5; i++) {\n"
49              + "    log(document.getElementById('h' + i).align);\n"
50              + "  }\n"
51              + "</script>\n"
52              + "</body></html>";
53  
54          loadPageVerifyTitle2(html);
55      }
56  
57      /**
58       * @throws Exception if an error occurs
59       */
60      @Test
61      @Alerts({"CenTer", "8", "foo", "left", "right", "center"})
62      public void setAlign() throws Exception {
63          final String html = DOCTYPE_HTML
64              + "<html><body>\n"
65              + "  <hr id='h1' align='left' />\n"
66  
67              + "<script>\n"
68              + LOG_TITLE_FUNCTION
69              + "  function setAlign(elem, value) {\n"
70              + "    try {\n"
71              + "      elem.align = value;\n"
72              + "    } catch(e) { logEx(e); }\n"
73              + "    log(elem.align);\n"
74              + "  }\n"
75  
76              + "  var elem = document.getElementById('h1');\n"
77              + "  setAlign(elem, 'CenTer');\n"
78  
79              + "  setAlign(elem, '8');\n"
80              + "  setAlign(elem, 'foo');\n"
81  
82              + "  setAlign(elem, 'left');\n"
83              + "  setAlign(elem, 'right');\n"
84              + "  setAlign(elem, 'center');\n"
85              + "</script>\n"
86              + "</body></html>";
87          loadPageVerifyTitle2(html);
88      }
89  }