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   * Unit tests for {@link HTMLPreElement}.
25   *
26   * @author Ronald Brill
27   */
28  @RunWith(BrowserRunner.class)
29  public class HTMLPreElementTest extends WebDriverTestCase {
30  
31      /**
32       * @throws Exception if an error occurs
33       */
34      @Test
35      @Alerts({"0", "number", "100", "77", "number", "123"})
36      public void width() throws Exception {
37          final String html = DOCTYPE_HTML
38              + "<html>\n"
39              + "  <head>\n"
40              + "    <script>\n"
41              + LOG_TITLE_FUNCTION
42              + "      function test() {\n"
43              + "        var testPre = document.getElementById('testPre');\n"
44              + "        log(testPre.width);\n"
45              + "        log(typeof testPre.width);\n"
46              + "        testPre.width = 100;\n"
47              + "        log(testPre.width);\n"
48  
49              + "        var testPre = document.getElementById('testPreWidth');\n"
50              + "        log(testPreWidth.width);\n"
51              + "        log(typeof testPreWidth.width);\n"
52              + "        testPreWidth.width = 123;\n"
53              + "        log(testPreWidth.width);\n"
54              + "      }\n"
55              + "    </script>\n"
56              + "  </head>\n"
57              + "  <body onload='test()'>\n"
58              + "    <pre id='testPre'>pre content</pre>\n"
59              + "    <pre id='testPreWidth' width='77'>pre content</pre>\n"
60              + "  </body>\n"
61              + "</html>";
62  
63          loadPageVerifyTitle2(html);
64      }
65  
66      /**
67       * @throws Exception if an error occurs
68       */
69      @Test
70      @Alerts({"undefined", "undefined", "undefined", "undefined", "undefined", "undefined",
71               "undefined", "left", "none", "right", "all", "2", "abc", "8"})
72      public void clear() throws Exception {
73          final String html = DOCTYPE_HTML
74              + "<html><body>\n"
75              + "<pre id='p1'>pre1</pre>\n"
76              + "<pre id='p2' clear='left'>pre2</pre>\n"
77              + "<pre id='p3' clear='all'>pre3</pre>\n"
78              + "<pre id='p4' clear='right'>pre4</pre>\n"
79              + "<pre id='p5' clear='none'>pre5</pre>\n"
80              + "<pre id='p6' clear='2'>pre6</pre>\n"
81              + "<pre id='p7' clear='foo'>pre7</pre>\n"
82              + "<script>\n"
83              + LOG_TITLE_FUNCTION
84              + "function set(p, value) {\n"
85              + "  try {\n"
86              + "    p.clear = value;\n"
87              + "  } catch(e) {\n"
88              + "    log('!');\n"
89              + "  }\n"
90              + "}\n"
91              + "var p1 = document.getElementById('p1');\n"
92              + "var p2 = document.getElementById('p2');\n"
93              + "var p3 = document.getElementById('p3');\n"
94              + "var p4 = document.getElementById('p4');\n"
95              + "var p5 = document.getElementById('p5');\n"
96              + "var p6 = document.getElementById('p6');\n"
97              + "var p7 = document.getElementById('p7');\n"
98              + "log(p1.clear);\n"
99              + "log(p2.clear);\n"
100             + "log(p3.clear);\n"
101             + "log(p4.clear);\n"
102             + "log(p5.clear);\n"
103             + "log(p6.clear);\n"
104             + "log(p7.clear);\n"
105             + "set(p1, 'left');\n"
106             + "set(p2, 'none');\n"
107             + "set(p3, 'right');\n"
108             + "set(p4, 'all');\n"
109             + "set(p5, 2);\n"
110             + "set(p6, 'abc');\n"
111             + "set(p7, '8');\n"
112             + "log(p1.clear);\n"
113             + "log(p2.clear);\n"
114             + "log(p3.clear);\n"
115             + "log(p4.clear);\n"
116             + "log(p5.clear);\n"
117             + "log(p6.clear);\n"
118             + "log(p7.clear);\n"
119             + "</script>\n"
120             + "</body></html>";
121 
122         loadPageVerifyTitle2(html);
123     }
124 }