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