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({})
70      public void minimalUsage() throws Exception {
71          final String html = DOCTYPE_HTML
72              + "<html><body><script>\n"
73              + LOG_TITLE_FUNCTION
74              + "try {\n"
75              + "  new Notification('Hello here');\n"
76              + "} catch(e) { logEx(e);}\n"
77              + "</script></body></html>";
78  
79          loadPageVerifyTitle2(html);
80      }
81  
82      /**
83       * @throws Exception if the test fails
84       */
85      @Test
86      @Alerts("function")
87      public void requestPermission() throws Exception {
88          final String html = DOCTYPE_HTML
89              + "<html><body><script>\n"
90              + LOG_TITLE_FUNCTION
91              + "try {\n"
92              + "  log(typeof Notification.requestPermission);\n"
93              + "} catch(e) { logEx(e);}\n"
94              + "</script></body></html>";
95  
96          loadPageVerifyTitle2(html);
97      }
98  }