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.css;
16  
17  import org.htmlunit.WebDriverTestCase;
18  import org.htmlunit.junit.annotation.Alerts;
19  import org.junit.jupiter.api.Test;
20  
21  /**
22   * Tests for {@link CSSFontFaceRule}.
23   *
24   * @author Marc Guillemot
25   * @author Frank Danek
26   * @author Ronald Brill
27   */
28  public class CSSFontFaceRuleTest extends WebDriverTestCase {
29  
30      /**
31       * @throws Exception if an error occurs
32       */
33      @Test
34      @Alerts("TypeError")
35      public void ctor() throws Exception {
36          final String html = DOCTYPE_HTML
37              + "<html><body>\n"
38              + LOG_TEXTAREA
39              + "<script>\n"
40              + LOG_TEXTAREA_FUNCTION
41              + "try {\n"
42              + "  var rule = new CSSFontFaceRule();\n"
43              + "  log(rule);\n"
44              + "} catch(e) { logEx(e); }\n"
45              + "</script></body></html>";
46  
47          loadPageVerifyTextArea2(html);
48      }
49  
50      /**
51       * @throws Exception if an error occurs
52       */
53      @Test
54      @Alerts({"[object CSSFontFaceRule]", "5",
55               "@font-face { font-family: Delicious; src: url(\"Delicious-Bold.otf\"); }"})
56      public void simple() throws Exception {
57          final String html = DOCTYPE_HTML
58              + "<html><body>\n"
59              + LOG_TEXTAREA
60              + "<style>\n"
61              + "  @font-face { font-family: Delicious; src: url('Delicious-Bold.otf'); }\n"
62              + "  h3 { font-family: Delicious;  }\n"
63              + "</style>\n"
64              + "<script>\n"
65              + LOG_TEXTAREA_FUNCTION
66              + "try {\n"
67              + "  var styleSheet = document.styleSheets[0];\n"
68              + "  var rule = styleSheet.cssRules[0];\n"
69              + "  log(rule);\n"
70              + "  log(rule.type);\n"
71              + "  log(rule.cssText);\n"
72              + "}\n"
73              + "catch(e) { logEx(e); }\n"
74              + "</script></body></html>";
75  
76          loadPageVerifyTextArea2(html);
77      }
78  
79      /**
80       * @throws Exception if an error occurs
81       */
82      @Test
83      @Alerts("@font-face { font-family: Delicious; src: url(\"//:\"); }")
84      public void urlSlashSlashColon() throws Exception {
85          final String html = DOCTYPE_HTML
86              + "<html><body>\n"
87              + LOG_TEXTAREA
88              + "<style>\n"
89              + "  @font-face { font-family: Delicious; src: url(//:); }\n"
90              + "  h3 { font-family: Delicious;  }\n"
91              + "</style>\n"
92              + "<script>\n"
93              + LOG_TEXTAREA_FUNCTION
94              + "try {\n"
95              + "  var styleSheet = document.styleSheets[0];\n"
96              + "  var rule = styleSheet.cssRules[0];\n"
97              + "  log(rule.cssText);\n"
98              + "}\n"
99              + "catch(e) { logEx(e); }\n"
100             + "</script></body></html>";
101 
102         loadPageVerifyTextArea2(html);
103     }
104 
105     /**
106      * @throws Exception if an error occurs
107      */
108     @Test
109     @Alerts("@font-face { font-family: Delicious; src: url(\"/:\"); }")
110     public void urlSlashColon() throws Exception {
111         final String html = DOCTYPE_HTML
112             + "<html><body>\n"
113             + LOG_TEXTAREA
114             + "<style>\n"
115             + "  @font-face { font-family: Delicious; src: url(/:); }\n"
116             + "  h3 { font-family: Delicious;  }\n"
117             + "</style>\n"
118             + "<script>\n"
119             + LOG_TEXTAREA_FUNCTION
120             + "try {\n"
121             + "  var styleSheet = document.styleSheets[0];\n"
122             + "  var rule = styleSheet.cssRules[0];\n"
123             + "  log(rule.cssText);\n"
124             + "}\n"
125             + "catch(e) { logEx(e); }\n"
126             + "</script></body></html>";
127 
128         loadPageVerifyTextArea2(html);
129     }
130 
131     /**
132      * @throws Exception if an error occurs
133      */
134     @Test
135     @Alerts("@font-face { font-family: Delicious; src: url(\"//\"); }")
136     public void urlSlashSlash() throws Exception {
137         final String html = DOCTYPE_HTML
138             + "<html><body>\n"
139             + LOG_TEXTAREA
140             + "<style>\n"
141             + "  @font-face { font-family: Delicious; src: url(//); }\n"
142             + "  h3 { font-family: Delicious;  }\n"
143             + "</style>\n"
144             + "<script>\n"
145             + LOG_TEXTAREA_FUNCTION
146             + "try {\n"
147             + "  var styleSheet = document.styleSheets[0];\n"
148             + "  var rule = styleSheet.cssRules[0];\n"
149             + "  log(rule.cssText);\n"
150             + "}\n"
151             + "catch(e) { logEx(e); }\n"
152             + "</script></body></html>";
153 
154         loadPageVerifyTextArea2(html);
155     }
156 }