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