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
31 @RunWith(BrowserRunner.class)
32 public class ActiveXObject2Test extends WebDriverTestCase {
33
34
35
36
37 @Test
38 @Alerts({"undefined", "undefined", "NaN", "false", "No", "No", "No", "No"})
39 public void browserDetection() throws Exception {
40 final String html = DOCTYPE_HTML
41 + "<html>\n"
42 + "<head>\n"
43 + "<script>\n"
44 + LOG_TITLE_FUNCTION_NORMALIZE
45 + " function test() {\n"
46 + " log(typeof window.ActiveXObject);\n"
47 + " log(String(window.ActiveXObject));\n"
48 + " log(Number(window.ActiveXObject));\n"
49 + " log(Boolean(window.ActiveXObject));\n"
50 + " log(window.ActiveXObject ? 'Yes' : 'No');\n"
51 + " if (window.ActiveXObject) { log('Yes') } else { log('No') }\n"
52 + " log(('ActiveXObject' in window) ? 'Yes' : 'No');\n"
53 + " if ('ActiveXObject' in window) { log('Yes') } else { log('No') }\n"
54 + " }\n"
55 + "</script>\n"
56 + "</head>\n"
57 + "<body onload='test()'>\n"
58 + "</body></html>";
59 loadPageVerifyTitle2(html);
60 }
61
62
63
64
65 @Test
66 @Alerts("ReferenceError")
67 public void xmlDocument() throws Exception {
68 final String html = DOCTYPE_HTML
69 + "<html>\n"
70 + "<head>\n"
71 + "<script>\n"
72 + LOG_TITLE_FUNCTION
73 + " function test() {\n"
74 + " try {\n"
75 + " var doc = new ActiveXObject('Microsoft.XMLDOM');\n"
76 + " log(typeof doc);\n"
77 + " } catch(e) { logEx(e); }\n"
78 + " }\n"
79 + "</script></head>\n"
80 + "<body onload='test()'>\n"
81 + "</body></html>";
82
83 loadPageVerifyTitle2(html);
84 }
85
86
87
88
89 @Test
90 @Alerts("ActiveXObject undefined")
91 public void activex() throws Exception {
92 final String html = DOCTYPE_HTML
93 + "<html>\n"
94 + "<head>\n"
95 + "<script>\n"
96 + LOG_TITLE_FUNCTION
97 + " function test() {\n"
98 + " try {\n"
99 + " if ('ActiveXObject' in window) {\n"
100 + " new ActiveXObject('InternetExplorer.Application');\n"
101 + " } else {\n"
102 + " log('ActiveXObject undefined');\n"
103 + " }\n"
104 + " } catch(e) {logEx(e);}\n"
105 + " }\n"
106 + "</script></head><body onload='test()'>\n"
107 + "</body></html>";
108
109 loadPageVerifyTitle2(html);
110 }
111 }