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
52 int i = 0;
53 for (final String parent : jsClassNames) {
54 if (predicate.test(parent)) {
55 for (final String child : jsClassNames) {
56 list.add(Arguments.of(parent, child));
57 }
58 if (++i > 100) {
59 return list;
60 }
61 }
62 }
63 return list;
64 }
65
66
67
68
69
70
71
72
73 @ParameterizedTest(name = "_{0}_{1}", quoteTextArguments = false)
74 @MethodSource("data")
75 @Alerts("false/false")
76 protected void test(final String parent, final String child) throws Exception {
77 final String html = DOCTYPE_HTML
78 + "<html>\n"
79 + "<head>\n"
80 + "<title>-</title>\n"
81 + "</head>\n"
82 + "<body>\n"
83 + "<script>\n"
84
85 + " function isParentOf(p, c) {\n"
86 + " detector = function() {};\n"
87 + " p.prototype.myCustomFunction = detector;\n"
88 + " return (c.prototype.myCustomFunction === detector) + '/'"
89 + " + (Object.getPrototypeOf(c) === p);\n"
90 + " }\n"
91
92 + " try {\n"
93 + " document.title = isParentOf(" + parent + ", " + child + ");\n"
94 + " } catch(e) { document.title = 'false/false'; }\n"
95 + "</script>\n"
96 + "</body></html>";
97
98 ServerRestartCount_++;
99 if (ServerRestartCount_ == 200) {
100 stopWebServers();
101 ServerRestartCount_ = 0;
102 }
103 final WebDriver driver = loadPage2(html);
104 assertTitle(driver, getExpectedAlerts()[0]);
105 }
106
107
108
109
110 @Override
111 protected boolean isWebClientCached() {
112 return true;
113 }
114 }