Search in sources :

Example 11 with StatusHandler

use of com.gargoylesoftware.htmlunit.StatusHandler in project htmlunit by HtmlUnit.

the class HtmlObjectTest method checkAppletParams.

/**
 * Tests the handling of parameters.
 * @throws Exception if the test fails
 */
@Test
public void checkAppletParams() 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);
    final HtmlPage page = webClient.getPage(url);
    HtmlButton button = page.getHtmlElementById("buttonParam1");
    button.click();
    button = page.getHtmlElementById("buttonParam2");
    button.click();
    button = page.getHtmlElementById("buttonParamCodebase");
    button.click();
    button = page.getHtmlElementById("buttonParamArchive");
    button.click();
    assertEquals(4, collectedStatus.size());
    assertEquals("param1: 'value1'", collectedStatus.get(0));
    assertEquals("param2: 'value2'", collectedStatus.get(1));
    assertEquals("codebase: 'null'", collectedStatus.get(2));
    assertEquals("archive: 'simpleAppletDoIt.jar'", collectedStatus.get(3));
}
Also used : 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)

Example 12 with StatusHandler

use of com.gargoylesoftware.htmlunit.StatusHandler in project htmlunit by HtmlUnit.

the class HtmlObjectTest method checkAppletOverwriteArchive.

/**
 * Tests the handling of parameters.
 * @throws Exception if the test fails
 */
@Test
public void checkAppletOverwriteArchive() throws Exception {
    Assume.assumeFalse(SKIP_);
    if (getBrowserVersion().isChrome()) {
        return;
    }
    final URL url = getClass().getResource("/objects/subdir/codebaseParamApplet.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);
    final HtmlPage page = webClient.getPage(url);
    HtmlButton button = page.getHtmlElementById("buttonParam1");
    button.click();
    button = page.getHtmlElementById("buttonParam2");
    button.click();
    button = page.getHtmlElementById("buttonParamCodebase");
    button.click();
    button = page.getHtmlElementById("buttonParamArchive");
    button.click();
    assertEquals(4, collectedStatus.size());
    assertEquals("param1: 'value1'", collectedStatus.get(0));
    assertEquals("param2: 'value2'", collectedStatus.get(1));
    assertEquals("codebase: '..'", collectedStatus.get(2));
    assertEquals("archive: 'simpleAppletDoIt.jar'", collectedStatus.get(3));
}
Also used : 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)

Example 13 with StatusHandler

use of com.gargoylesoftware.htmlunit.StatusHandler in project htmlunit by HtmlUnit.

the class HtmlObjectTest method appletConfirmHandlerPermit.

/**
 * @throws Exception if the test fails
 */
@Test
public void appletConfirmHandlerPermit() throws Exception {
    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 true;
        }

        @Override
        public boolean confirm(final HtmlObject applet) {
            assertEquals("simpleAppletDoIt.jar", applet.getArchiveAttribute());
            return false;
        }
    });
    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)

Example 14 with StatusHandler

use of com.gargoylesoftware.htmlunit.StatusHandler in project htmlunit by HtmlUnit.

the class HtmlObjectTest method setMember.

/**
 * @throws Exception if the test fails
 */
@Test
public void setMember() 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);
    final HtmlPage page = webClient.getPage(url);
    final HtmlButton button = page.getHtmlElementById("setValueAttribute");
    button.click();
    assertEquals(1, collectedStatus.size());
    assertEquals("value set for 'myInput' to 'HtmlUnit'", collectedStatus.get(0));
    final String value = page.getElementById("myInput").getAttribute("value");
    assertEquals("HtmlUnit", value);
}
Also used : 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)

Example 15 with StatusHandler

use of com.gargoylesoftware.htmlunit.StatusHandler in project htmlunit by HtmlUnit.

the class HtmlObjectTest method checkAppletUnknownArchive.

/**
 * Tests the processing of an applet definition with wrong archive.
 * @throws Exception if the test fails
 */
@Test
public void checkAppletUnknownArchive() throws Exception {
    if (getBrowserVersion().isChrome()) {
        return;
    }
    final URL url = getClass().getResource("/objects/unknownArchiveApplet.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);
    final HtmlPage page = webClient.getPage(url);
    final DomNodeList<DomElement> objects = page.getElementsByTagName("object");
    assertEquals(1, objects.size());
    final HtmlObject htmlObject = (HtmlObject) objects.get(0);
    try {
        htmlObject.getApplet();
    } catch (final Exception e) {
        assertEquals("java.lang.ClassNotFoundException: net.sourceforge.htmlunit.testapplets.EmptyApplet", e.getMessage());
    }
}
Also used : 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

StatusHandler (com.gargoylesoftware.htmlunit.StatusHandler)28 Page (com.gargoylesoftware.htmlunit.Page)27 WebClient (com.gargoylesoftware.htmlunit.WebClient)27 URL (java.net.URL)27 ArrayList (java.util.ArrayList)27 Test (org.junit.Test)27 ActiveXObjectTest (com.gargoylesoftware.htmlunit.javascript.host.ActiveXObjectTest)12 AppletConfirmHandler (com.gargoylesoftware.htmlunit.AppletConfirmHandler)4 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)2 CollectingAlertHandler (com.gargoylesoftware.htmlunit.CollectingAlertHandler)1 MockWebConnection (com.gargoylesoftware.htmlunit.MockWebConnection)1 HtmlButton (com.gargoylesoftware.htmlunit.html.HtmlButton)1 JsxSetter (com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter)1