Skip to content

Commit c00c143

Browse files
committed
more robust tests
1 parent 122d468 commit c00c143

File tree

1 file changed

+77
-40
lines changed

1 file changed

+77
-40
lines changed

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

Lines changed: 77 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -82,28 +82,36 @@ public void opener() throws Exception {
8282
final URL urlThird = new URL(URL_FIRST, "third/");
8383

8484
final String firstContent = DOCTYPE_HTML
85-
+ "<html><head><title>First</title><script>\n"
85+
+ "<html><head>\n"
86+
+ "<title>First</title>\n"
87+
+ "<script>\n"
88+
+ LOG_WINDOW_NAME_FUNCTION
8689
+ "function test() {\n"
87-
+ " alert(window.opener);\n"
88-
+ " alert('one');\n"
90+
+ " log(window.opener);\n"
91+
+ " log('one');\n"
8992
+ " open('" + URL_SECOND + "', 'foo');\n"
9093
+ "}\n"
9194
+ "function calllog(text) {\n"
92-
+ " alert(text);\n"
95+
+ " log(text);\n"
9396
+ "}\n"
9497
+ "</script></head><body onload='test()'>\n"
9598
+ "</body></html>";
9699
final String secondContent = DOCTYPE_HTML
97-
+ "<html><head><title>Second</title><script>\n"
100+
+ "<html><head>\n"
101+
+ "<title>Second</title>\n"
102+
+ "<script>\n"
98103
+ "function test() {\n"
99104
+ " opener.calllog('two');\n"
100105
+ " document.form1.submit();\n"
101106
+ "}\n"
102-
+ "</script></head><body onload='test()'>\n"
107+
+ "</script></head>\n"
108+
+ "<body onload='test()'>\n"
103109
+ "<form name='form1' action='" + urlThird + "' method='post'><input type='submit'></form>\n"
104110
+ "</body></html>";
105111
final String thirdContent = DOCTYPE_HTML
106-
+ "<html><head><title>Third</title><script>\n"
112+
+ "<html><head>\n"
113+
+ "<title>Third</title>\n"
114+
+ "<script>\n"
107115
+ "function test() {\n"
108116
+ " opener.calllog('three');\n"
109117
+ "}\n"
@@ -113,8 +121,9 @@ public void opener() throws Exception {
113121
getMockWebConnection().setResponse(URL_SECOND, secondContent);
114122
getMockWebConnection().setResponse(urlThird, thirdContent);
115123

116-
final WebDriver driver = loadPageWithAlerts2(firstContent);
124+
final WebDriver driver = loadPage2(firstContent);
117125
assertTitle(driver, "First");
126+
verifyWindowName2(DEFAULT_WAIT_TIME, driver, getExpectedAlerts());
118127
}
119128

120129
/**
@@ -166,31 +175,41 @@ public void javascriptVariableFromTopAndParentFrame() throws Exception {
166175
final URL urlThird = new URL(URL_FIRST, "third/");
167176

168177
final String firstContent = DOCTYPE_HTML
169-
+ "<html><head><title>First</title></head><body><script>\n"
170-
+ "myVariable = 'first'"
171-
+ " </script><iframe name='left' src='" + URL_SECOND + "'></iframe>\n"
178+
+ "<html><head>\n"
179+
+ "<title>First</title>\n"
180+
+ "</head><body>\n"
181+
+ "<script>myVariable = 'first'</script>\n"
182+
+ "<iframe name='left' src='" + URL_SECOND + "'></iframe>\n"
172183
+ "</body></html>";
173184

174185
final String secondContent = DOCTYPE_HTML
175-
+ "<html><head><title>Second</title></head><body><script>\n"
176-
+ "myVariable = 'second'"
177-
+ " </script><iframe name='innermost' src='" + urlThird + "'></iframe>\n"
186+
+ "<html><head>\n"
187+
+ "<title>Second</title>\n"
188+
+ "</head>\n"
189+
+ "<body>\n"
190+
+ "<script>myVariable = 'second'</script>\n"
191+
+ "<iframe name='innermost' src='" + urlThird + "'></iframe>\n"
178192
+ "</body></html>";
179193
getMockWebConnection().setResponse(URL_SECOND, secondContent);
180194

181195
final String thirdContent = DOCTYPE_HTML
182-
+ "<html><head><title>Third</title><script>\n"
196+
+ "<html><head>\n"
197+
+ "<title>Third</title>\n"
198+
+ "<script>\n"
183199
+ "myVariable = 'third';\n"
200+
201+
+ LOG_WINDOW_NAME_FUNCTION
184202
+ "function doTest() {\n"
185-
+ "alert('parent.myVariable = ' + parent.myVariable);\n"
186-
+ "alert('top.myVariable = ' + top.myVariable);\n"
203+
+ " log('parent.myVariable = ' + parent.myVariable);\n"
204+
+ " log('top.myVariable = ' + top.myVariable);\n"
187205
+ "}\n"
188206
+ "</script></head>\n"
189207
+ "<body onload='doTest()'></body></html>";
190208
getMockWebConnection().setResponse(urlThird, thirdContent);
191209

192-
final WebDriver driver = loadPageWithAlerts2(firstContent);
210+
final WebDriver driver = loadPage2(firstContent);
193211
assertTitle(driver, "First");
212+
verifyWindowName2(driver, getExpectedAlerts());
194213
}
195214

196215
/**
@@ -215,29 +234,40 @@ public void javascriptVariableFromNamedFrame() throws Exception {
215234
+ "</frameset></html>";
216235

217236
final String secondContent = DOCTYPE_HTML
218-
+ "<html><head><title>second</title></head><body><script>\n"
219-
+ "myVariable = 'second';\n"
220-
+ "</script><p>second</p></body></html>";
237+
+ "<html><head>\n"
238+
+ "<title>second</title>\n"
239+
+ "</head><body>\n"
240+
+ "<script>myVariable = 'second';</script>\n"
241+
+ "<p>second</p></body></html>";
221242
getMockWebConnection().setResponse(URL_SECOND, secondContent);
222243

223244
final String thirdContent = DOCTYPE_HTML
224-
+ "<html><head><title>third</title></head><body><script>\n"
225-
+ "myVariable = 'third';\n"
226-
+ "</script><p>third</p></body></html>";
245+
+ "<html><head>\n"
246+
+ "<title>third</title>\n"
247+
+ "</head>\n"
248+
+ "<body>\n"
249+
+ "<script>myVariable = 'third';</script>\n"
250+
+ "<p>third</p></body></html>";
227251
getMockWebConnection().setResponse(urlThird, thirdContent);
228252

229253
final String fourthContent = DOCTYPE_HTML
230-
+ "<html><head><title>fourth</title></head><body onload='doTest()'><script>\n"
231-
+ "myVariable = 'fourth';\n"
232-
+ "function doTest() {\n"
233-
+ "alert('parent.second.myVariable = ' + parent.second.myVariable);\n"
234-
+ "alert('parent.third.myVariable = ' + parent.third.myVariable);\n"
254+
+ "<html><head>\n"
255+
+ "<title>fourth</title>\n"
256+
+ "</head>\n"
257+
+ "<body onload='doTest()'>\n"
258+
+ "<script>\n"
259+
+ " myVariable = 'fourth';\n"
260+
+ LOG_WINDOW_NAME_FUNCTION
261+
+ " function doTest() {\n"
262+
+ " log('parent.second.myVariable = ' + parent.second.myVariable);\n"
263+
+ " log('parent.third.myVariable = ' + parent.third.myVariable);\n"
235264
+ "}\n"
236265
+ "</script></body></html>";
237266
getMockWebConnection().setResponse(urlFourth, fourthContent);
238267

239-
final WebDriver driver = loadPageWithAlerts2(firstContent);
268+
final WebDriver driver = loadPage2(firstContent);
240269
assertTitle(driver, "first");
270+
verifyWindowName2(driver, getExpectedAlerts());
241271
}
242272

243273
/**
@@ -287,10 +317,14 @@ public void getFrameByName() throws Exception {
287317
getMockWebConnection().setResponse(urlThird, thirdContent);
288318

289319
final String fourthContent = DOCTYPE_HTML
290-
+ "<html><head><title>fourth</title></head><body onload='doTest()'><script>\n"
291-
+ "function doTest() {\n"
292-
+ "alert('fourth-second='+parent.second.document.location);\n"
293-
+ "alert('fourth-third='+parent.third.document.location);\n"
320+
+ "<html><head>\n"
321+
+ "<title>fourth</title>\n"
322+
+ "</head>\n"
323+
+ "<body onload='doTest()'><script>\n"
324+
+ LOG_WINDOW_NAME_FUNCTION
325+
+ " function doTest() {\n"
326+
+ " log('fourth-second='+parent.second.document.location);\n"
327+
+ " log('fourth-third='+parent.third.document.location);\n"
294328
+ "}\n"
295329
+ "</script></body></html>";
296330
getMockWebConnection().setResponse(urlFourth, fourthContent);
@@ -302,8 +336,9 @@ public void getFrameByName() throws Exception {
302336
}
303337
setExpectedAlerts(expectedAlerts);
304338

305-
final WebDriver driver = loadPageWithAlerts2(firstContent);
339+
final WebDriver driver = loadPage2(firstContent);
306340
assertTitle(driver, "first");
341+
verifyWindowName2(driver, expectedAlerts);
307342
}
308343

309344
/**
@@ -1267,13 +1302,15 @@ public void evalScopeOtherWindow() throws Exception {
12671302
final String iframe = DOCTYPE_HTML
12681303
+ "<html><body>\n"
12691304
+ "<script>\n"
1305+
+ LOG_WINDOW_NAME_FUNCTION
12701306
+ " window.parent.eval('var foo = 1');\n"
1271-
+ " alert(window.parent.foo);\n"
1307+
+ " log(window.parent.foo);\n"
12721308
+ "</script>\n"
12731309
+ "</body></html>";
12741310

12751311
getMockWebConnection().setDefaultResponse(iframe);
1276-
loadPageWithAlerts2(html);
1312+
loadPage2(html);
1313+
verifyWindowName2(getWebDriver(), getExpectedAlerts());
12771314
}
12781315

12791316
/**
@@ -1401,17 +1438,17 @@ public void eval() throws Exception {
14011438
+ "<html><body>\n"
14021439
+ "<input type='button' id='myButton' value='Click Me' onclick='test(this)'>\n"
14031440
+ "<script>\n"
1441+
+ LOG_TITLE_FUNCTION
14041442
+ "function test(f) {\n"
1405-
+ " alert(eval('f.tagName'));\n"
1443+
+ " log(eval('f.tagName'));\n"
14061444
+ "}\n"
14071445
+ "</script>\n"
14081446
+ "</body></html>";
14091447

14101448
final WebDriver driver = loadPage2(content);
14111449

14121450
driver.findElement(By.id("myButton")).click();
1413-
1414-
verifyAlerts(driver, getExpectedAlerts());
1451+
verifyTitle2(driver, getExpectedAlerts());
14151452
}
14161453

14171454
/**

0 commit comments

Comments
 (0)