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