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 @RunWith(BrowserRunner.class)
31 public class NativeGlobalTest extends WebDriverTestCase {
32
33
34
35
36
37 @Test
38 @Alerts({"undefined", "NaN", "Infinity"})
39 public void assignConst() throws Exception {
40 final String html = DOCTYPE_HTML
41 + "<html><body><script>\n"
42 + LOG_TITLE_FUNCTION
43 + "undefined = 123;\n"
44 + "log(undefined);\n"
45 + "NaN = 123;\n"
46 + "log(NaN);\n"
47 + "Infinity = 123;\n"
48 + "log(Infinity);\n"
49 + "</script></body></html>";
50
51 loadPageVerifyTitle2(html);
52 }
53
54
55
56
57
58 @Test
59 @Alerts({"true", "undefined", "NaN", "Infinity"})
60 public void redeclareConst() throws Exception {
61 final String html = DOCTYPE_HTML
62 + "<html><body><script>\n"
63 + LOG_TITLE_FUNCTION
64 + "var undefined;\n"
65 + "var NaN;\n"
66 + "var Infinity;\n"
67 + "log(window.foo == undefined);\n"
68 + "undefined = 123;\n"
69 + "log(undefined);\n"
70 + "log(NaN);\n"
71 + "log(Infinity);\n"
72 + "</script></body></html>";
73
74 loadPageVerifyTitle2(html);
75 }
76 }