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