Skip to content

Commit 195101d

Browse files
committed
one more test
1 parent ce4a6d1 commit 195101d

1 file changed

Lines changed: 39 additions & 7 deletions

File tree

src/test/java/org/htmlunit/javascript/host/html/HTMLDocumentWrite2Test.java

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -233,31 +233,63 @@ public void open_FF() throws Exception {
233233
* @throws Exception if the test fails
234234
*/
235235
@Test
236-
@Alerts({" after-write Hello", " after-write Hello after-write Hello"})
236+
@Alerts({"after-write§js§Hello", "after-write§js§Hello"})
237237
public void writeExternalScriptAfterClick() throws Exception {
238238
shutDownAll();
239239

240240
final String html = DOCTYPE_HTML
241241
+ "<html><head>\n"
242242
+ "<script>\n"
243-
+ "document.write('<scr'+'ipt src=\"script.js\"></scr'+'ipt>');\n"
244-
+ "window.name += ' after-write ';\n"
243+
+ LOG_WINDOW_NAME_FUNCTION
244+
+ " document.write('<scr'+'ipt src=\"script.js\"></scr'+'ipt>');\n"
245+
+ " log('after-write');\n"
246+
+ "</script>\n"
247+
+ "<script>\n"
248+
+ " log(window.foo);\n"
249+
+ "</script>\n"
250+
+ "</head>\n"
251+
+ "<body>\n"
252+
+ "<a href='?again'>a link</a>\n"
253+
+ "</body>\n"
254+
+ "</html>";
255+
256+
getMockWebConnection().setDefaultResponse("log('js'); window.foo = 'Hello'", MimeType.TEXT_JAVASCRIPT);
257+
final WebDriver driver = loadPage2(html);
258+
verifyWindowName2(driver, getExpectedAlerts()[0]);
259+
260+
driver.findElement(By.linkText("a link")).click();
261+
verifyWindowName2(driver, getExpectedAlerts()[1]);
262+
}
263+
/**
264+
* @throws Exception if the test fails
265+
*/
266+
@Test
267+
@Alerts({"after-write§undefined§js", "after-write§undefined§js"})
268+
public void writeExternalAsyncScriptAfterClick() throws Exception {
269+
shutDownAll();
270+
271+
final String html = DOCTYPE_HTML
272+
+ "<html><head>\n"
273+
+ "<script>\n"
274+
+ LOG_WINDOW_NAME_FUNCTION
275+
+ " document.write('<scr'+'ipt async src=\"script.js\"></scr'+'ipt>');\n"
276+
+ " log('after-write');\n"
245277
+ "</script>\n"
246278
+ "<script>\n"
247-
+ "window.name += window.foo;\n"
279+
+ " log(window.foo);\n"
248280
+ "</script>\n"
249281
+ "</head>\n"
250282
+ "<body>\n"
251283
+ "<a href='?again'>a link</a>\n"
252284
+ "</body>\n"
253285
+ "</html>";
254286

255-
getMockWebConnection().setDefaultResponse("window.foo = 'Hello'", MimeType.TEXT_JAVASCRIPT);
287+
getMockWebConnection().setDefaultResponse("log('js'); window.foo = 'Hello'", MimeType.TEXT_JAVASCRIPT);
256288
final WebDriver driver = loadPage2(html);
257-
verifyJsVariable(driver, "window.top.name", getExpectedAlerts()[0]);
289+
verifyWindowName2(DEFAULT_WAIT_TIME, driver, getExpectedAlerts()[0]);
258290

259291
driver.findElement(By.linkText("a link")).click();
260-
verifyJsVariable(driver, "window.top.name", getExpectedAlerts()[1]);
292+
verifyWindowName2(DEFAULT_WAIT_TIME, driver, getExpectedAlerts()[1]);
261293
}
262294

263295
/**

0 commit comments

Comments
 (0)