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;
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 FontFaceSet}.
23   *
24   * @author Ronald Brill
25   */
26  public class FontFaceSetTest extends WebDriverTestCase {
27  
28      /**
29       * @throws Exception if the test fails
30       */
31      @Test
32      @Alerts(DEFAULT = "undefined",
33              FF = "function FontFaceSet() { [native code] }",
34              FF_ESR = "function FontFaceSet() { [native code] }")
35      public void window() throws Exception {
36          final String html = DOCTYPE_HTML
37              + "<html>\n"
38              + "<body>\n"
39              + "<script>\n"
40              + LOG_TITLE_FUNCTION
41              + "  log(window.FontFaceSet);\n"
42              + "</script>\n"
43              + "</body></html>";
44  
45          loadPageVerifyTitle2(html);
46      }
47  
48      /**
49       * @throws Exception if the test fails
50       */
51      @Test
52      @Alerts("[object FontFaceSet]")
53      public void documentFonts() throws Exception {
54          final String html = DOCTYPE_HTML
55              + "<html>\n"
56              + "<body>\n"
57              + "<script>\n"
58              + LOG_TITLE_FUNCTION
59              + "  log(document.fonts);\n"
60              + "</script>\n"
61              + "</body></html>";
62  
63          loadPageVerifyTitle2(html);
64      }
65  
66      /**
67       * @throws Exception if the test fails
68       */
69      @Test
70      @Alerts("then: ")
71      public void load() throws Exception {
72          final String html = DOCTYPE_HTML
73              + "<html>\n"
74              + "<body>\n"
75              + "<script>\n"
76              + LOG_TITLE_FUNCTION
77              + "  if (document.fonts) {\n"
78              + "    document.fonts.load('12px Arial', 'HtmlUnit').then(function(value) {\n"
79              + "        log('then: ' + value);"
80              + "      });\n"
81              + "  } else {\n"
82              + "    log('document.fonts is undefined');\n"
83              + "  }"
84              + "</script>\n"
85              + "</body></html>";
86  
87          loadPage2(html);
88          verifyTitle2(DEFAULT_WAIT_TIME, getWebDriver(), getExpectedAlerts());
89      }
90  
91      /**
92       * @throws Exception if the test fails
93       */
94      @Test
95      @Alerts(DEFAULT = {"false", "undefined", "ReferenceError", "ReferenceError", "ReferenceError",
96                         "false", "undefined", "ReferenceError", "ReferenceError", "ReferenceError"},
97              FF = {"false", "undefined", "ReferenceError", "ReferenceError", "ReferenceError",
98                    "true", "function FontFaceSet() { [native code] }", "function FontFaceSet() { [native code] }",
99                    "[object FontFaceSet]", "function EventTarget() { [native code] }"},
100             FF_ESR = {"false", "undefined", "ReferenceError", "ReferenceError", "ReferenceError",
101                       "true", "function FontFaceSet() { [native code] }", "function FontFaceSet() { [native code] }",
102                       "[object FontFaceSet]", "function EventTarget() { [native code] }"})
103     public void windowScope() throws Exception {
104         final String html = DOCTYPE_HTML
105             + "<html></body>\n"
106             + "<script>\n"
107             + LOG_TITLE_FUNCTION
108             + "  log('fontFaceSet' in window);\n"
109             + "  log(window.fontFaceSet);\n"
110             + "  try { log(fontFaceSet); } catch(e) { logEx(e); };\n"
111             + "  try { log(fontFaceSet.prototype); } catch(e) { logEx(e); };\n"
112             + "  try { log(fontFaceSet.__proto__); } catch(e) { logEx(e); };\n"
113 
114             + "  log('FontFaceSet' in window);\n"
115             + "  log(window.FontFaceSet);\n"
116             + "  try { log(FontFaceSet); } catch(e) { logEx(e); };\n"
117             + "  try { log(FontFaceSet.prototype); } catch(e) { logEx(e); };\n"
118             + "  try { log(FontFaceSet.__proto__); } catch(e) { logEx(e); };\n"
119             + "</script>\n"
120             + "</body></html>";
121 
122         loadPageVerifyTitle2(html);
123     }
124 }