use of com.gargoylesoftware.htmlunit.AppletConfirmHandler in project htmlunit by HtmlUnit.
the class HtmlObjectTest method appletConfirmHandler.
/**
* @throws Exception if the test fails
*/
@Test
public void appletConfirmHandler() throws Exception {
Assume.assumeFalse(SKIP_);
if (getBrowserVersion().isChrome()) {
return;
}
final URL url = getClass().getResource("/objects/simpleAppletDoIt.html");
final WebClient webClient = getWebClient();
final List<String> collectedStatus = new ArrayList<>();
final StatusHandler statusHandler = new StatusHandler() {
@Override
public void statusMessageChanged(final Page page, final String message) {
collectedStatus.add(message);
}
};
webClient.setStatusHandler(statusHandler);
webClient.getOptions().setAppletEnabled(true);
webClient.setAppletConfirmHandler(new AppletConfirmHandler() {
@Override
public boolean confirm(final HtmlApplet applet) {
return false;
}
@Override
public boolean confirm(final HtmlObject applet) {
assertEquals("simpleAppletDoIt.jar", applet.getArchiveAttribute());
return true;
}
});
final HtmlPage page = webClient.getPage(url);
final DomNodeList<DomElement> objects = page.getElementsByTagName("object");
assertEquals(1, objects.size());
final HtmlObject htmlObject = (HtmlObject) objects.get(0);
assertTrue(htmlObject.getApplet() != null);
}
Aggregations