Skip to content

Commit 69047ce

Browse files
committed
more tests
1 parent 726ba40 commit 69047ce

5 files changed

Lines changed: 185 additions & 0 deletions

File tree

src/test/java/org/htmlunit/javascript/host/ExternalTest.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,37 @@ public void isSearchProviderInstalled() throws Exception {
124124
+ "</body></html>";
125125
loadPageVerifyTitle2(html);
126126
}
127+
128+
/**
129+
* @throws Exception if the test fails
130+
*/
131+
@Test
132+
@Alerts(DEFAULT = {"true", "[object External]", "[object External]", "undefined", "[object External]",
133+
"true", "function External() { [native code] }", "function External() { [native code] }",
134+
"[object External]", "function () { [native code] }"},
135+
FF = {"true", "[object External]", "[object External]", "undefined", "[object External]",
136+
"false", "undefined", "ReferenceError", "ReferenceError", "ReferenceError"},
137+
FF_ESR = {"true", "[object External]", "[object External]", "undefined", "[object External]",
138+
"false", "undefined", "ReferenceError", "ReferenceError", "ReferenceError"})
139+
public void windowScope() throws Exception {
140+
final String html = DOCTYPE_HTML
141+
+ "<html></body>\n"
142+
+ "<script>\n"
143+
+ LOG_TITLE_FUNCTION
144+
+ " log('external' in window);\n"
145+
+ " log(window.external);\n"
146+
+ " try { log(external); } catch(e) { logEx(e); };\n"
147+
+ " try { log(external.prototype); } catch(e) { logEx(e); };\n"
148+
+ " try { log(external.__proto__); } catch(e) { logEx(e); };\n"
149+
150+
+ " log('External' in window);\n"
151+
+ " log(window.External);\n"
152+
+ " try { log(External); } catch(e) { logEx(e); };\n"
153+
+ " try { log(External.prototype); } catch(e) { logEx(e); };\n"
154+
+ " try { log(External.__proto__); } catch(e) { logEx(e); };\n"
155+
+ "</script>\n"
156+
+ "</body></html>";
157+
158+
loadPageVerifyTitle2(html);
159+
}
127160
}

src/test/java/org/htmlunit/javascript/host/FontFaceSetTest.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,38 @@ public void load() throws Exception {
8787
loadPage2(html);
8888
verifyTitle2(DEFAULT_WAIT_TIME, getWebDriver(), getExpectedAlerts());
8989
}
90+
91+
/**
92+
* @throws Exception if the test fails
93+
*/
94+
@Test
95+
@Alerts(DEFAULT = {"false", "undefined", "ReferenceError", "ReferenceError", "ReferenceError",
96+
"false", "undefined", "ReferenceError", "ReferenceError", "ReferenceError"},
97+
FF = {"false", "undefined", "ReferenceError", "ReferenceError", "ReferenceError",
98+
"true", "function FontFaceSet() { [native code] }", "function FontFaceSet() { [native code] }",
99+
"[object FontFaceSet]", "function EventTarget() { [native code] }"},
100+
FF_ESR = {"false", "undefined", "ReferenceError", "ReferenceError", "ReferenceError",
101+
"true", "function FontFaceSet() { [native code] }", "function FontFaceSet() { [native code] }",
102+
"[object FontFaceSet]", "function EventTarget() { [native code] }"})
103+
public void windowScope() throws Exception {
104+
final String html = DOCTYPE_HTML
105+
+ "<html></body>\n"
106+
+ "<script>\n"
107+
+ LOG_TITLE_FUNCTION
108+
+ " log('fontFaceSet' in window);\n"
109+
+ " log(window.fontFaceSet);\n"
110+
+ " try { log(fontFaceSet); } catch(e) { logEx(e); };\n"
111+
+ " try { log(fontFaceSet.prototype); } catch(e) { logEx(e); };\n"
112+
+ " try { log(fontFaceSet.__proto__); } catch(e) { logEx(e); };\n"
113+
114+
+ " log('FontFaceSet' in window);\n"
115+
+ " log(window.FontFaceSet);\n"
116+
+ " try { log(FontFaceSet); } catch(e) { logEx(e); };\n"
117+
+ " try { log(FontFaceSet.prototype); } catch(e) { logEx(e); };\n"
118+
+ " try { log(FontFaceSet.__proto__); } catch(e) { logEx(e); };\n"
119+
+ "</script>\n"
120+
+ "</body></html>";
121+
122+
loadPageVerifyTitle2(html);
123+
}
90124
}

src/test/java/org/htmlunit/javascript/host/css/StyleMediaTest.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* Tests for {@link StyleMedia}.
2323
*
2424
* @author Ahmed Ashour
25+
* @author Ronald Brill
2526
*/
2627
public class StyleMediaTest extends WebDriverTestCase {
2728

@@ -74,4 +75,36 @@ public void matchMedium() throws Exception {
7475

7576
loadPageVerifyTitle2(html);
7677
}
78+
79+
/**
80+
* @throws Exception if the test fails
81+
*/
82+
@Test
83+
@Alerts(DEFAULT = {"true", "[object StyleMedia]", "[object StyleMedia]", "undefined", "[object StyleMedia]",
84+
"false", "undefined", "ReferenceError", "ReferenceError", "ReferenceError"},
85+
FF = {"false", "undefined", "ReferenceError", "ReferenceError", "ReferenceError",
86+
"false", "undefined", "ReferenceError", "ReferenceError", "ReferenceError"},
87+
FF_ESR = {"false", "undefined", "ReferenceError", "ReferenceError", "ReferenceError",
88+
"false", "undefined", "ReferenceError", "ReferenceError", "ReferenceError"})
89+
public void windowScope() throws Exception {
90+
final String html = DOCTYPE_HTML
91+
+ "<html></body>\n"
92+
+ "<script>\n"
93+
+ LOG_TITLE_FUNCTION
94+
+ " log('styleMedia' in window);\n"
95+
+ " log(window.styleMedia);\n"
96+
+ " try { log(styleMedia); } catch(e) { logEx(e); };\n"
97+
+ " try { log(styleMedia.prototype); } catch(e) { logEx(e); };\n"
98+
+ " try { log(styleMedia.__proto__); } catch(e) { logEx(e); };\n"
99+
100+
+ " log('StyleMedia' in window);\n"
101+
+ " log(window.StyleMedia);\n"
102+
+ " try { log(StyleMedia); } catch(e) { logEx(e); };\n"
103+
+ " try { log(StyleMedia.prototype); } catch(e) { logEx(e); };\n"
104+
+ " try { log(StyleMedia.__proto__); } catch(e) { logEx(e); };\n"
105+
+ "</script>\n"
106+
+ "</body></html>";
107+
108+
loadPageVerifyTitle2(html);
109+
}
77110
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) 2002-2025 Gargoyle Software Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* https://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
package org.htmlunit.javascript.host.dom;
16+
17+
import org.htmlunit.WebDriverTestCase;
18+
import org.htmlunit.junit.annotation.Alerts;
19+
import org.junit.jupiter.api.Test;
20+
21+
/**
22+
* Tests for {@link XPathNSResolver}.
23+
*
24+
* @author Ronald Brill
25+
*/
26+
public class XPathNSResolverTest extends WebDriverTestCase {
27+
28+
/**
29+
* @throws Exception if the test fails
30+
*/
31+
@Test
32+
@Alerts({"false", "undefined", "ReferenceError", "ReferenceError", "ReferenceError",
33+
"false", "undefined", "ReferenceError", "ReferenceError", "ReferenceError"})
34+
public void windowScope() throws Exception {
35+
final String html = DOCTYPE_HTML
36+
+ "<html></body>\n"
37+
+ "<script>\n"
38+
+ LOG_TITLE_FUNCTION
39+
+ " log('xPathNSResolver' in window);\n"
40+
+ " log(window.xPathNSResolver);\n"
41+
+ " try { log(xPathNSResolver); } catch(e) { logEx(e); };\n"
42+
+ " try { log(xPathNSResolver.prototype); } catch(e) { logEx(e); };\n"
43+
+ " try { log(xPathNSResolver.__proto__); } catch(e) { logEx(e); };\n"
44+
45+
+ " log('XPathNSResolver' in window);\n"
46+
+ " log(window.XPathNSResolver);\n"
47+
+ " try { log(XPathNSResolver); } catch(e) { logEx(e); };\n"
48+
+ " try { log(XPathNSResolver.prototype); } catch(e) { logEx(e); };\n"
49+
+ " try { log(XPathNSResolver.__proto__); } catch(e) { logEx(e); };\n"
50+
+ "</script>\n"
51+
+ "</body></html>";
52+
53+
loadPageVerifyTitle2(html);
54+
}
55+
}

src/test/java/org/htmlunit/javascript/host/event/MutationEventTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,5 +295,35 @@ public void createEvent() throws Exception {
295295
+ "</body></html>";
296296
loadPageVerifyTitle2(html);
297297
}
298+
/**
299+
* @throws Exception if the test fails
300+
*/
301+
@Test
302+
@Alerts(DEFAULT = {"false", "undefined", "ReferenceError", "ReferenceError", "ReferenceError",
303+
"false", "undefined", "ReferenceError", "ReferenceError", "ReferenceError"},
304+
FF_ESR = {"false", "undefined", "ReferenceError", "ReferenceError", "ReferenceError",
305+
"true", "function MutationEvent() { [native code] }",
306+
"function MutationEvent() { [native code] }",
307+
"[object MutationEvent]", "function Event() { [native code] }"})
308+
public void windowScope() throws Exception {
309+
final String html = DOCTYPE_HTML
310+
+ "<html></body>\n"
311+
+ "<script>\n"
312+
+ LOG_TITLE_FUNCTION
313+
+ " log('mutationEvent' in window);\n"
314+
+ " log(window.mutationEvent);\n"
315+
+ " try { log(mutationEvent); } catch(e) { logEx(e); };\n"
316+
+ " try { log(mutationEvent.prototype); } catch(e) { logEx(e); };\n"
317+
+ " try { log(mutationEvent.__proto__); } catch(e) { logEx(e); };\n"
318+
319+
+ " log('MutationEvent' in window);\n"
320+
+ " log(window.MutationEvent);\n"
321+
+ " try { log(MutationEvent); } catch(e) { logEx(e); };\n"
322+
+ " try { log(MutationEvent.prototype); } catch(e) { logEx(e); };\n"
323+
+ " try { log(MutationEvent.__proto__); } catch(e) { logEx(e); };\n"
324+
+ "</script>\n"
325+
+ "</body></html>";
298326

327+
loadPageVerifyTitle2(html);
328+
}
299329
}

0 commit comments

Comments
 (0)