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