The following test case works in Chrome, Firefox, and Internet Explorer, but htmlunit does not correctly load all javascript and results in an incorrect dom. Any javascript following the spurious </script> tag is not executed.
/**
* @throws Exception if the test fails
*/
@Test
public void shouldHandleFunkyDocumentWriteScriptTag() throws Exception {
final String content = "<html>\n"
+ "<head>\n"
+ " <title>test</title>\n"
+ " <script language=\"JavaScript1.1\">\n"
+ " <!--\n"
+ "document.write('<SCRIPT LANGUAGE=JavaScript1.1 SRC=\"
http://bogus.destination.com/fakescript.js\">');\n"
+ "//--></script>\n"
+ "</SCRIPT>\n"
+ "</head>\n"
+ "<body>\n"
+ "<div>\n"
+ "alert('test');"
+ "</div>\n"
+ "</body>\n"
+ "</html>";
final List<String> collectedAlerts =
Collections.synchronizedList(new ArrayList<String>());
final HtmlPage page = loadPage(content, collectedAlerts);
final JavaScriptJobManager jobManager =
page.getEnclosingWindow().getJobManager();
assertNotNull(jobManager);
// Not perfect, but 100 chances to start should be enough for a
loaded system
Thread.sleep(500);
Assert.assertFalse("At least one alert should have fired by now",
collectedAlerts.isEmpty());
((TopLevelWindow) page.getEnclosingWindow()).close();
// 100 chances to stop
jobManager.waitForJobs(500);
final int finalValue = collectedAlerts.size();
// 100 chances to fail
jobManager.waitForJobs(500);
Assert.assertEquals("No new alerts should have happened",
finalValue, collectedAlerts.size());
}
Looks like I accidentally oversimplified my test case. I'll paste a better example below. I'm starting to think what I'm seeing may be a timing issue. I'm expecting the link to a js file at hosted2.ap.org, below, to print out a number of new DOM elements including a number of img tags pointed to a service reference ending with 'Image.svc'. What I see, instead, is the original script tag, unevaluated, in the DOM. If you want more js src locations to try (in case the one below stops working) you can find a number of them here: http://businessinsavannah.com/ssi/aggregator.shtml
Thanks again for your help. Let me know if there is any you might need from me.
Matt Walters
Any luck looking into the issue?
Let me know if you need any additional info from me.
Thanks,
Diff: