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 Notification}.
25   *
26   * @author Marc Guillemot
27   * @author Ronald Brill
28   * @author Ahmed Ashour
29   */
30  @RunWith(BrowserRunner.class)
31  public class NotificationTest extends WebDriverTestCase {
32  
33      /**
34       * @throws Exception if the test fails
35       */
36      @Test
37      @Alerts({"function", "true"})
38      public void prototype() throws Exception {
39          final String html = DOCTYPE_HTML
40              + "<html><body><script>\n"
41              + LOG_TITLE_FUNCTION
42              + "try {\n"
43              + "  log(typeof window.Notification);\n"
44              + "  log('Notification' in window);\n"
45              + "} catch(e) { logEx(e);}\n"
46              + "</script></body></html>";
47  
48          loadPageVerifyTitle2(html);
49      }
50  
51      /**
52       * @throws Exception if the test fails
53       */
54      @Test
55      @Alerts("default")
56      public void permission() throws Exception {
57          final String html = DOCTYPE_HTML
58              + "<html><body><script>\n"
59              + LOG_TITLE_FUNCTION
60              + "try {\n"
61              + "  log(Notification.permission);\n"
62              + "} catch(e) { logEx(e);}\n"
63              + "</script></body></html>";
64  
65          loadPageVerifyTitle2(html);
66      }
67  
68      /**
69       * @throws Exception if the test fails
70       */
71      @Test
72      @Alerts({})
73      public void minimalUsage() throws Exception {
74          final String html = DOCTYPE_HTML
75              + "<html><body><script>\n"
76              + LOG_TITLE_FUNCTION
77              + "try {\n"
78              + "  new Notification('Hello here');\n"
79              + "} catch(e) { logEx(e);}\n"
80              + "</script></body></html>";
81  
82          loadPageVerifyTitle2(html);
83      }
84  
85      /**
86       * @throws Exception if the test fails
87       */
88      @Test
89      @Alerts("function")
90      public void requestPermission() throws Exception {
91          final String html = DOCTYPE_HTML
92              + "<html><body><script>\n"
93              + LOG_TITLE_FUNCTION
94              + "try {\n"
95              + "  log(typeof Notification.requestPermission);\n"
96              + "} catch(e) { logEx(e);}\n"
97              + "</script></body></html>";
98  
99          loadPageVerifyTitle2(html);
100     }
101 }