1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.javascript;
16
17 import org.htmlunit.ScriptException;
18 import org.htmlunit.WebDriverTestCase;
19 import org.htmlunit.junit.BrowserRunner;
20 import org.junit.Test;
21 import org.junit.runner.RunWith;
22
23
24
25
26
27
28
29 @RunWith(BrowserRunner.class)
30 public class IEWeirdSyntaxTest extends WebDriverTestCase {
31
32
33
34
35 @Test
36 public void semicolon_before_finally() throws Exception {
37 doTestTryCatchFinally("", ";");
38 doTestTryCatchFinally("", "\n;\n");
39 doTestTryCatchFinally("", "\n;");
40 }
41
42
43
44
45 @Test
46 public void semicolon_before_catch() throws Exception {
47 doTestTryCatchFinally(";", "");
48 doTestTryCatchFinally("\n;\n", "");
49 }
50
51
52
53
54 @Test
55 public void semicolonAndComment_before_catchAndFinally() throws Exception {
56 doTestTryCatchFinally("// comment\n;\n", "");
57 doTestTryCatchFinally("", "// comment\n;\n");
58 doTestTryCatchFinally("", "// comment\n // other comment\n;\n");
59 doTestTryCatchFinally("", "// comment\n ; // other comment\n");
60 }
61
62 private void doTestTryCatchFinally(final String beforeCatch, final String beforeFinally) throws Exception {
63 final String html = "<html>\n"
64 + "<script>\n"
65 + " try {\n"
66 + " alert('1');\n"
67 + " }" + beforeCatch
68 + " catch(e) {\n"
69 + " alert('2');\n"
70 + " }" + beforeFinally
71 + " finally {\n"
72 + " alert('3');\n"
73 + " }\n"
74 + "</script>\n"
75 + "</html>";
76 doTestWithEvaluatorExceptionExcept(html);
77 }
78
79
80
81
82 @Test
83 public void windowDotHandlerFunction() throws Exception {
84 final String html = "<html>\n"
85 + "<head>\n"
86 + "<script>\n"
87 + " function window.onload() {\n"
88 + " alert(1);\n"
89 + " }\n"
90 + "</script>\n"
91 + "</head>\n"
92 + "<body></body></html>";
93 doTestWithEvaluatorExceptionExcept(html);
94 }
95
96 private void doTestWithEvaluatorExceptionExcept(final String html) throws Exception {
97 try {
98 loadPageWithAlerts2(html);
99 }
100 catch (final Exception e) {
101 if (!(e.getCause() instanceof ScriptException)) {
102 throw e;
103 }
104 }
105 }
106 }