1
2
3
4
5
6
7
8
9
10
11
12
13
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
25
26
27
28
29
30 @RunWith(BrowserRunner.class)
31 public class NotificationTest extends WebDriverTestCase {
32
33
34
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
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
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
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 }