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.BrowserRunner;
19  import org.htmlunit.junit.annotation.Alerts;
20  import org.junit.Test;
21  import org.junit.runner.RunWith;
22  
23  /**
24   * Tests for {@link FontFaceSet}.
25   *
26   * @author Ronald Brill
27   */
28  @RunWith(BrowserRunner.class)
29  public class FontFaceSetTest extends WebDriverTestCase {
30  
31      /**
32       * @throws Exception if the test fails
33       */
34      @Test
35      @Alerts(DEFAULT = "undefined",
36              FF = "function FontFaceSet() { [native code] }",
37              FF_ESR = "function FontFaceSet() { [native code] }")
38      public void window() throws Exception {
39          final String html = DOCTYPE_HTML
40              + "<html>\n"
41              + "<body>\n"
42              + "<script>\n"
43              + LOG_TITLE_FUNCTION
44              + "  log(window.FontFaceSet);\n"
45              + "</script>\n"
46              + "</body></html>";
47  
48          loadPageVerifyTitle2(html);
49      }
50  
51      /**
52       * @throws Exception if the test fails
53       */
54      @Test
55      @Alerts("[object FontFaceSet]")
56      public void documentFonts() throws Exception {
57          final String html = DOCTYPE_HTML
58              + "<html>\n"
59              + "<body>\n"
60              + "<script>\n"
61              + LOG_TITLE_FUNCTION
62              + "  log(document.fonts);\n"
63              + "</script>\n"
64              + "</body></html>";
65  
66          loadPageVerifyTitle2(html);
67      }
68  
69      /**
70       * @throws Exception if the test fails
71       */
72      @Test
73      @Alerts("then: ")
74      public void load() throws Exception {
75          final String html = DOCTYPE_HTML
76              + "<html>\n"
77              + "<body>\n"
78              + "<script>\n"
79              + LOG_TITLE_FUNCTION
80              + "  if (document.fonts) {\n"
81              + "    document.fonts.load('12px Arial', 'HtmlUnit').then(function(value) {\n"
82              + "        log('then: ' + value);"
83              + "      });\n"
84              + "  } else {\n"
85              + "    log('document.fonts is undefined');\n"
86              + "  }"
87              + "</script>\n"
88              + "</body></html>";
89  
90          loadPage2(html);
91          verifyTitle2(DEFAULT_WAIT_TIME, getWebDriver(), getExpectedAlerts());
92      }
93  }