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  import org.w3c.dom.html.HTMLBaseFontElement;
21  
22  /**
23   * Tests for {@link HTMLBaseFontElement}.
24   * @author Ronald Brill
25   * @author Frank Danek
26   * @author Ahmed Ashour
27   */
28  public class HTMLBaseFontElementTest extends WebDriverTestCase {
29  
30      /**
31       * @throws Exception if an error occurs
32       */
33      @Test
34      @Alerts({"[object HTMLElement]", "undefined", "undefined", "undefined"})
35      public void defaults() throws Exception {
36          final String html = DOCTYPE_HTML
37              + "<html>\n"
38              + "  <head>\n"
39              + "    <basefont id='base' />\n"
40              + "    <script>\n"
41              + LOG_TITLE_FUNCTION
42              + "      function test() {\n"
43              + "        var base = document.getElementById('base');\n"
44              + "        log(base);\n"
45              + "        log(base.face);\n"
46              + "        log(base.size);\n"
47              + "        log(base.color);\n"
48              + "      }\n"
49              + "    </script>\n"
50              + "  </head>\n"
51              + "  <body onload='test()'>foo</body>\n"
52              + "</html>";
53  
54          loadPageVerifyTitle2(html);
55      }
56  
57      /**
58       * @throws Exception if an error occurs
59       */
60      @Test
61      @Alerts({"undefined", "42"})
62      public void size() throws Exception {
63          final String html = DOCTYPE_HTML
64              + "<html>\n"
65              + "  <head>\n"
66              + "    <basefont id='base' color='red' face='swiss' size='4' />\n"
67              + "    <script>\n"
68              + LOG_TITLE_FUNCTION
69              + "      function test() {\n"
70              + "        var base = document.getElementById('base');\n"
71              + "        log(base.size);\n"
72              + "        try {\n"
73              + "          base.size = 42;\n"
74              + "          log(base.size);\n"
75              + "        } catch(e) {\n"
76              + "          logEx(e);\n"
77              + "        }\n"
78              + "      }\n"
79              + "    </script>\n"
80              + "  </head>\n"
81              + "  <body onload='test()'>foo</body>\n"
82              + "</html>";
83  
84          loadPageVerifyTitle2(html);
85      }
86  
87      /**
88       * @throws Exception if an error occurs
89       */
90      @Test
91      @Alerts({"undefined", "helvetica"})
92      public void face() throws Exception {
93          final String html = DOCTYPE_HTML
94              + "<html>\n"
95              + "  <head>\n"
96              + "    <basefont id='base' color='red' face='swiss' size='5' />\n"
97              + "    <script>\n"
98              + LOG_TITLE_FUNCTION
99              + "      function test() {\n"
100             + "        var base = document.getElementById('base');\n"
101             + "        log(base.face);\n"
102             + "        try {\n"
103             + "          base.face = 'helvetica';\n"
104             + "          log(base.face);\n"
105             + "        } catch(e) {\n"
106             + "          logEx(e);\n"
107             + "        }\n"
108             + "      }\n"
109             + "    </script>\n"
110             + "  </head>\n"
111             + "  <body onload='test()'>foo</body>\n"
112             + "</html>";
113 
114         loadPageVerifyTitle2(html);
115     }
116 
117     /**
118      * @throws Exception if an error occurs
119      */
120     @Test
121     @Alerts({"undefined", "blue"})
122     public void color() throws Exception {
123         final String html = DOCTYPE_HTML
124             + "<html>\n"
125             + "  <head>\n"
126             + "    <basefont id='base' color='red' face='swiss' size='4' />\n"
127             + "    <script>\n"
128             + LOG_TITLE_FUNCTION
129             + "      function test() {\n"
130             + "        var base = document.getElementById('base');\n"
131             + "        log(base.color);\n"
132             + "        try {\n"
133             + "          base.color = 'blue';\n"
134             + "          log(base.color);\n"
135             + "        } catch(e) {\n"
136             + "          logEx(e);\n"
137             + "        }\n"
138             + "      }\n"
139             + "    </script>\n"
140             + "  </head>\n"
141             + "  <body onload='test()'>foo</body>\n"
142             + "</html>";
143 
144         loadPageVerifyTitle2(html);
145     }
146 
147     /**
148      * @throws Exception if the test fails
149      */
150     @Test
151     @Alerts({"[object HTMLElement]", "ReferenceError"})
152     public void type() throws Exception {
153         final String html = DOCTYPE_HTML
154             + "<html><head>\n"
155             + "<script>\n"
156             + LOG_TITLE_FUNCTION
157             + "  function test() {\n"
158             + "  var elem = document.getElementById('b1');\n"
159             + "    try {\n"
160             + "      log(elem);\n"
161             + "      log(HTMLBaseFontElement);\n"
162             + "    } catch(e) { logEx(e); }\n"
163             + "  }\n"
164             + "</script>\n"
165             + "</head>\n"
166             + "<body onload='test()'>\n"
167             + "  <basefont id='b1' color='red' face='swiss' size='4' />\n"
168             + "</body></html>";
169 
170         loadPageVerifyTitle2(html);
171     }
172 }