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.BrowserParameterizedRunner.Default;
26 import org.htmlunit.junit.annotation.Alerts;
27 import org.junit.After;
28 import org.junit.Test;
29 import org.junit.runners.Parameterized.Parameter;
30 import org.openqa.selenium.WebDriver;
31
32
33
34
35
36
37
38 public abstract class HostParentOf extends WebDriverTestCase {
39
40 private static int ServerRestartCount_ = 0;
41
42
43
44
45
46
47
48 protected static Collection<Object[]> data(final Predicate<String> predicate) throws Exception {
49 final Set<String> jsClassNames = TestCaseTest.getAllConfiguredJsConstructorNames();
50
51 final List<Object[]> list = new ArrayList<>(jsClassNames.size() * jsClassNames.size() / 10);
52 for (final String parent : jsClassNames) {
53 if (predicate.test(parent)) {
54 for (final String child : jsClassNames) {
55 list.add(new Object[] {parent, child});
56 }
57 }
58 }
59 return list;
60 }
61
62
63
64
65 @Parameter
66 public String parent_;
67
68
69
70
71 @Parameter(1)
72 public String child_;
73
74
75
76
77
78 @Test
79 @Alerts("false")
80 @Default
81 public void isParentOf() throws Exception {
82 test(parent_, child_);
83 }
84
85
86
87
88
89
90
91
92 protected void test(final String parent, final String child) throws Exception {
93 final String html = DOCTYPE_HTML
94 + "<html>\n"
95 + "<head>\n"
96 + "<title>-</title>\n"
97 + "</head>\n"
98 + "<body>\n"
99 + "<script>\n"
100
101 + " function isParentOf(o1, o2) {"
102 + " detector = function() {};\n"
103 + " o1.prototype.myCustomFunction = detector;\n"
104 + " return o2.prototype.myCustomFunction === detector;\n"
105 + " }\n"
106
107 + " try {\n"
108 + " document.title = isParentOf(" + parent + ", " + child + ");\n"
109 + " } catch(e) { document.title = 'false'; }\n"
110 + "</script>\n"
111 + "</body></html>";
112
113 ServerRestartCount_++;
114 if (ServerRestartCount_ == 200) {
115 stopWebServers();
116 ServerRestartCount_ = 0;
117 }
118 final WebDriver driver = loadPage2(html);
119 assertTitle(driver, getExpectedAlerts()[0]);
120 }
121
122
123
124
125 @Override
126 protected boolean isWebClientCached() {
127 return true;
128 }
129
130
131
132
133 @After
134 public void after() {
135 parent_ = null;
136 child_ = null;
137 }
138 }