Search in sources :

Example 6 with AppletConfirmHandler

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);
}
Also used : AppletConfirmHandler(com.gargoylesoftware.htmlunit.AppletConfirmHandler) StatusHandler(com.gargoylesoftware.htmlunit.StatusHandler) ArrayList(java.util.ArrayList) Page(com.gargoylesoftware.htmlunit.Page) WebClient(com.gargoylesoftware.htmlunit.WebClient) URL(java.net.URL) Test(org.junit.Test) ActiveXObjectTest(com.gargoylesoftware.htmlunit.javascript.host.ActiveXObjectTest)

Aggregations

AppletConfirmHandler (com.gargoylesoftware.htmlunit.AppletConfirmHandler)6 WebClient (com.gargoylesoftware.htmlunit.WebClient)6 URL (java.net.URL)6 ArrayList (java.util.ArrayList)6 Page (com.gargoylesoftware.htmlunit.Page)4 StatusHandler (com.gargoylesoftware.htmlunit.StatusHandler)4 Test (org.junit.Test)4 FailingHttpStatusCodeException (com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException)2 WebRequest (com.gargoylesoftware.htmlunit.WebRequest)2 WebResponse (com.gargoylesoftware.htmlunit.WebResponse)2 AppletClassLoader (com.gargoylesoftware.htmlunit.html.applets.AppletClassLoader)2 AppletStubImpl (com.gargoylesoftware.htmlunit.html.applets.AppletStubImpl)2 ActiveXObjectTest (com.gargoylesoftware.htmlunit.javascript.host.ActiveXObjectTest)2 Applet (java.applet.Applet)2 HashMap (java.util.HashMap)2