Skip to content

Commit cb9dc19

Browse files
committed
more tests
1 parent bca4c02 commit cb9dc19

File tree

2 files changed

+102
-1
lines changed

2 files changed

+102
-1
lines changed

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

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ public void writeScriptInManyTimes() throws Exception {
896896
+ " document.write('<script>log(\"foo1\");</' + 'script>');\n"
897897

898898
+ " log('1');\n"
899-
+ " document.write('<script src=\"scriptA.js\">;</' + 'script>');\n"
899+
+ " document.write('<script src=\"scriptA.js\"></' + 'script>');\n"
900900
+ " log('2');\n"
901901

902902
+ " document.write('<script src=\"scriptB.js\">');\n"
@@ -920,6 +920,83 @@ public void writeScriptInManyTimes() throws Exception {
920920
loadPageVerifyTitle2(html);
921921
}
922922

923+
/**
924+
* @throws Exception if the test fails
925+
*/
926+
@Test
927+
@Alerts({"0", "foo1", "1", "foo2", "2", "3", "4", "A", "foo3"})
928+
public void writeScriptPostponed() throws Exception {
929+
final String html = "<html>\n"
930+
+ "<head>\n"
931+
+ "<script>\n"
932+
+ LOG_TITLE_FUNCTION
933+
+ " log('0');\n"
934+
+ "</script>\n"
935+
936+
+ "<script>log(\"foo1\");</script>'\n"
937+
938+
+ "<script>\n"
939+
+ " log('1');\n"
940+
+ " document.write('<script>log(\"foo2\");</' + 'script>');\n"
941+
+ " log('2');\n"
942+
+ " document.write('<script src=\"scriptA.js\"></' + 'script>');\n"
943+
+ " log('3');\n"
944+
+ " document.write('<script>log(\"foo3\");</' + 'script>');\n"
945+
+ " log('4');\n"
946+
+ "</script>\n"
947+
948+
+ "</head>\n"
949+
+ "<body>\n"
950+
+ "</body></html>";
951+
952+
final URL scriptUrlA = new URL(URL_FIRST, "scriptA.js");
953+
final URL scriptUrlB = new URL(URL_FIRST, "scriptB.js");
954+
955+
getMockWebConnection().setDefaultResponse(html);
956+
getMockWebConnection().setResponse(scriptUrlA, "log('A');\n", MimeType.TEXT_JAVASCRIPT);
957+
958+
loadPageVerifyTitle2(html);
959+
}
960+
961+
/**
962+
* @throws Exception if the test fails
963+
*/
964+
@Test
965+
@Alerts({"0", "A", "1", "foo2", "2", "3", "4", "B", "foo3"})
966+
public void writeScriptPostponedBeforeWrite() throws Exception {
967+
final String html = "<html>\n"
968+
+ "<head>\n"
969+
+ "<script>\n"
970+
+ LOG_TITLE_FUNCTION
971+
+ " log('0');\n"
972+
+ "</script>\n"
973+
974+
+ "<script src='scriptA.js'></script>'\n"
975+
976+
+ "<script>\n"
977+
+ " log('1');\n"
978+
+ " document.write('<script>log(\"foo2\");</' + 'script>');\n"
979+
+ " log('2');\n"
980+
+ " document.write('<script src=\"scriptB.js\"></' + 'script>');\n"
981+
+ " log('3');\n"
982+
+ " document.write('<script>log(\"foo3\");</' + 'script>');\n"
983+
+ " log('4');\n"
984+
+ "</script>\n"
985+
986+
+ "</head>\n"
987+
+ "<body>\n"
988+
+ "</body></html>";
989+
990+
final URL scriptUrlA = new URL(URL_FIRST, "scriptA.js");
991+
final URL scriptUrlB = new URL(URL_FIRST, "scriptB.js");
992+
993+
getMockWebConnection().setDefaultResponse(html);
994+
getMockWebConnection().setResponse(scriptUrlA, "log('A');\n", MimeType.TEXT_JAVASCRIPT);
995+
getMockWebConnection().setResponse(scriptUrlB, "log('B');\n", MimeType.TEXT_JAVASCRIPT);
996+
997+
loadPageVerifyTitle2(html);
998+
}
999+
9231000
/**
9241001
* Test for bug 1613119.
9251002
* @throws Exception if the test fails

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,30 @@ public void asyncLoadsAsync() throws Exception {
12951295
assertTitle(driver, getExpectedAlerts()[0]);
12961296
}
12971297

1298+
/**
1299+
* @throws Exception if the test fails
1300+
*/
1301+
@Test
1302+
@Alerts({"1", "2", "3"})
1303+
public void syncFromAsyncTask() throws Exception {
1304+
final String html = "<html><body><script>\n"
1305+
+ LOG_TITLE_FUNCTION
1306+
+ "function addScript() {\n"
1307+
+ " var script = document.createElement('script');\n"
1308+
+ " script.src = 'js.js';\n"
1309+
+ " document.head.appendChild(script);\n"
1310+
+ " log('2');\n"
1311+
+ "}\n"
1312+
+ "setTimeout(addScript, 5);\n"
1313+
+ " log('1');\n"
1314+
+ "</script></body></html>\n";
1315+
1316+
getMockWebConnection().setResponse(new URL(URL_FIRST, "js.js"), "log('3')");
1317+
1318+
final WebDriver driver = loadPage2(html);
1319+
verifyTitle2(DEFAULT_WAIT_TIME, driver, getExpectedAlerts());
1320+
}
1321+
12981322
/**
12991323
* @throws Exception if the test fails
13001324
*/

0 commit comments

Comments
 (0)