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.intl;
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 Intl}.
23   *
24   * @author Ahmed Ashour
25   * @author Ronald Brill
26   */
27  public class IntlTest extends WebDriverTestCase {
28  
29      /**
30       * @throws Exception if the test fails
31       */
32      @Test
33      @Alerts("[object Intl]")
34      public void intl() throws Exception {
35          test("Intl");
36      }
37  
38      private void test(final String string) throws Exception {
39          final String html = DOCTYPE_HTML
40              + "<html><head>\n"
41              + "<script>\n"
42              + LOG_TITLE_FUNCTION
43              + "  function test() {\n"
44              + "    try {\n"
45              + "      log(" + string + ");\n"
46              + "    } catch(e) { logEx(e) }\n"
47              + "  }\n"
48              + "</script>\n"
49              + "</head><body onload='test()'>\n"
50              + "</body></html>";
51  
52          loadPageVerifyTitle2(html);
53      }
54  
55      /**
56       * @throws Exception if the test fails
57       */
58      @Test
59      @Alerts("function Collator() { [native code] }")
60      public void collator() throws Exception {
61          test("Intl.Collator");
62      }
63  
64      /**
65       * @throws Exception if the test fails
66       */
67      @Test
68      @Alerts("function DateTimeFormat() { [native code] }")
69      public void dateTimeFormat() throws Exception {
70          test("Intl.DateTimeFormat");
71      }
72  
73      /**
74       * @throws Exception if the test fails
75       */
76      @Test
77      @Alerts("function NumberFormat() { [native code] }")
78      public void numberFormat() throws Exception {
79          test("Intl.NumberFormat");
80      }
81  
82      /**
83       * @throws Exception if the test fails
84       */
85      @Test
86      @Alerts(DEFAULT = "undefined",
87              CHROME = "function v8BreakIterator() { [native code] }",
88              EDGE = "function v8BreakIterator() { [native code] }")
89      public void v8BreakIterator() throws Exception {
90          test("Intl.v8BreakIterator");
91      }
92  
93  }