1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.javascript;
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 IEConditionalCompilationTest extends WebDriverTestCase {
30
31
32
33
34 @Test
35 public void simple() throws Exception {
36 final String script = "/*@cc_on log('testing @cc_on'); @*/";
37 testScript(script);
38 }
39
40
41
42
43 @Test
44 @Alerts("3")
45 public void simple2() throws Exception {
46 final String script = "var a={b:/*@cc_on!@*/false,c:/*@cc_on!@*/false};\n"
47 + "var foo = (1 + 2/*V*/);\n"
48 + "log(foo)";
49 testScript(script);
50 }
51
52
53
54
55 @Test
56 public void simple3() throws Exception {
57 final String script = "/*@cc_on @*/\n"
58 + "/*@if (@_win32)\n"
59 + "log('testing @cc_on');\n"
60 + "/*@end @*/";
61 testScript(script);
62 }
63
64
65
66
67 @Test
68 public void simple4() throws Exception {
69 final String script = "/*@cc_on log(1) @*/\n"
70 + "/*@if (@_win32)\n"
71 + "log('testing @cc_on');\n"
72 + "/*@end @*/";
73 testScript(script);
74 }
75
76
77
78
79 @Test
80 public void ifTest() throws Exception {
81 final String script = "/*@cc_on@if(@_jscript_version>=5){log(@_jscript_version)}@end@*/";
82 testScript(script);
83 }
84
85
86
87
88 @Test
89 public void variables_jscript_version() throws Exception {
90 final String script = "/*@cc_on log(@_jscript_version) @*/";
91 testScript(script);
92 }
93
94
95
96
97 @Test
98 public void variables_jscript_build() throws Exception {
99 final String script = "/*@cc_on log(@_jscript_build) @*/";
100 testScript(script);
101 }
102
103
104
105
106 @Test
107 public void reservedString() throws Exception {
108 final String script = "/*@cc_on log('testing /*@cc_on'); @*/";
109 testScript(script);
110 }
111
112
113
114
115 @Test
116 public void set() throws Exception {
117 final String script = "/*@cc_on @set @mine = 12 log(@mine); @*/";
118 testScript(script);
119 }
120
121
122
123
124 @Test
125 public void elif() throws Exception {
126 final String script = "/*@cc_on @if(@_win32)type='win';@elif(@_mac)type='mac';@end log(type); @*/";
127 testScript(script);
128 }
129
130
131
132
133 @Test
134 public void dollar_single_quote_in_string() throws Exception {
135 final String script = "/*@cc_on var test='$2'; log(test);@*/";
136 testScript(script);
137 }
138
139
140
141
142 @Test
143 public void dollar_double_quote_in_string() throws Exception {
144 final String script = "/*@cc_on var test=\"$2\"; log(test);@*/";
145 testScript(script);
146 }
147
148
149
150
151 @Test
152 public void slashes_in_single_quotes() throws Exception {
153 final String script = "/*@cc_on var test='\\\\\'; log(test);@*/";
154 testScript(script);
155 }
156
157
158
159
160 @Test
161 public void slash_dollar_in_single_quotes() throws Exception {
162 final String script = "/*@cc_on var test='\\$\'; log(test);@*/";
163 testScript(script);
164 }
165
166 private void testScript(final String script) throws Exception {
167 final String html
168 = "<html><head>\n"
169 + "<script>\n"
170 + LOG_TITLE_FUNCTION
171 + script + "\n"
172 + "</script>\n"
173 + "</head><body>\n"
174 + "</body></html>";
175
176 loadPageVerifyTitle2(html);
177 }
178
179
180
181
182 @Test
183 @Alerts("false")
184 public void escaping() throws Exception {
185 final String script = "var isMSIE=eval('false;/*@cc_on@if(@\\x5fwin32)isMSIE=true@end@*/');\n"
186 + "log(isMSIE);";
187 testScript(script);
188 }
189
190
191
192
193 @Test
194 @Alerts("false")
195 public void eval() throws Exception {
196 final String script =
197 "var isMSIE;\n"
198 + "eval('function f() { isMSIE=eval(\"false;/*@cc_on@if(@' + '_win32)isMSIE=true@end@*/\") }');\n"
199 + "f();\n"
200 + "log(isMSIE);";
201 testScript(script);
202 }
203
204
205
206
207
208 @Test
209 public void bug3076667() throws Exception {
210 final String script =
211 "/*@cc_on @*/\n"
212 + "/*@if (true) log('Alert');\n"
213 + "@end @*/ ";
214 testScript(script);
215 }
216
217
218
219
220
221 @Test
222 public void escapedDoubleQuote() throws Exception {
223 final String script =
224 "/*@cc_on\n"
225 + "document.write(\"\\\"\\\"\");\n"
226 + "log(1);\n"
227 + "@*/\n"
228 + "</script></html>";
229
230 testScript(script);
231 }
232 }