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.SimpleWebTestCase;
18 import org.junit.jupiter.api.Test;
19
20
21
22
23
24
25
26 public class Navigator2Test extends SimpleWebTestCase {
27
28
29
30
31
32 @Test
33 public void cookieEnabled() throws Exception {
34 cookieEnabled(true);
35 cookieEnabled(false);
36 }
37
38 private void cookieEnabled(final boolean cookieEnabled) throws Exception {
39 final String html = DOCTYPE_HTML
40 + "<html><head>\n"
41 + "<script>\n"
42 + "function test() {\n"
43 + " alert(navigator.cookieEnabled);\n"
44 + "}\n"
45 + "</script>\n"
46 + "</head>\n"
47 + "<body onload='test()'></body>\n"
48 + "</html>";
49
50 setExpectedAlerts(Boolean.toString(cookieEnabled));
51 if (!cookieEnabled) {
52 getWebClient().getCookieManager().setCookiesEnabled(cookieEnabled);
53 }
54
55 loadPageWithAlerts(html);
56 }
57
58
59
60
61
62 @Test
63 public void javaEnabled() throws Exception {
64 attribute("javaEnabled()", "false");
65 }
66
67
68
69
70
71
72
73 void attribute(final String name, final String value) throws Exception {
74 final String html = DOCTYPE_HTML
75 + "<html>\n"
76 + "<head>\n"
77 + " <title>test</title>\n"
78 + " <script>\n"
79 + " function doTest() {\n"
80 + " alert('" + name + " = ' + window.navigator." + name + ");\n"
81 + " }\n"
82 + " </script>\n"
83 + "</head>\n"
84 + "<body onload=\'doTest()\'>\n"
85 + "</body>\n"
86 + "</html>";
87
88 setExpectedAlerts(name + " = " + value);
89 loadPageWithAlerts(html);
90 }
91 }