1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.general.huge;
16
17 import java.util.ArrayList;
18 import java.util.Collection;
19 import java.util.List;
20 import java.util.Set;
21 import java.util.function.Predicate;
22
23 import org.htmlunit.TestCaseTest;
24 import org.htmlunit.WebDriverTestCase;
25 import org.htmlunit.junit.annotation.Alerts;
26 import org.junit.jupiter.params.ParameterizedTest;
27 import org.junit.jupiter.params.provider.Arguments;
28 import org.junit.jupiter.params.provider.MethodSource;
29 import org.openqa.selenium.WebDriver;
30
31
32
33
34
35
36
37 public abstract class HostParentOf extends WebDriverTestCase {
38
39 private static int ServerRestartCount_ = 0;
40
41
42
43
44
45
46
47 protected static Collection<Arguments> data(final Predicate<String> predicate) throws Exception {
48 final Set<String> jsClassNames = TestCaseTest.getAllConfiguredJsConstructorNames();
49
50 final List<Arguments> list = new ArrayList<>(jsClassNames.size() * jsClassNames.size() / 10);
51 for (final String parent : jsClassNames) {
52 if (predicate.test(parent)) {
53 for (final String child : jsClassNames) {
54 list.add(Arguments.of(parent, child));
55 }
56 }
57 }
58 return list;
59 }
60
61
62
63
64
65
66
67
68 @ParameterizedTest(name = "_{0}_{1}")
69 @MethodSource("data")
70 @Alerts("false/false")
71 protected void test(final String parent, final String child) throws Exception {
72 final String html = DOCTYPE_HTML
73 + "<html>\n"
74 + "<head>\n"
75 + "<title>-</title>\n"
76 + "</head>\n"
77 + "<body>\n"
78 + "<script>\n"
79
80 + " function isParentOf(p, c) {\n"
81 + " detector = function() {};\n"
82 + " p.prototype.myCustomFunction = detector;\n"
83 + " return (c.prototype.myCustomFunction === detector) + '/'"
84 + " + (Object.getPrototypeOf(c) === p);\n"
85 + " }\n"
86
87 + " try {\n"
88 + " document.title = isParentOf(" + parent + ", " + child + ");\n"
89 + " } catch(e) { document.title = 'false/false'; }\n"
90 + "</script>\n"
91 + "</body></html>";
92
93 ServerRestartCount_++;
94 if (ServerRestartCount_ == 200) {
95 stopWebServers();
96 ServerRestartCount_ = 0;
97 }
98 final WebDriver driver = loadPage2(html);
99 assertTitle(driver, getExpectedAlerts()[0]);
100 }
101
102
103
104
105 @Override
106 protected boolean isWebClientCached() {
107 return true;
108 }
109 }