Search in sources :

Example 1 with StatusHandler

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

the class HtmlAppletTest method checkAppletBase.

/**
 * Tests the codebase and documentbase properties.
 * @throws Exception if the test fails
 */
@Test
public void checkAppletBase() throws Exception {
    Assume.assumeFalse(SKIP_);
    if (areAppletsNotSupported()) {
        return;
    }
    final URL url = getClass().getResource("/applets/codebaseApplet.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("buttonShowCodeBase");
    button.click();
    button = page.getHtmlElementById("buttonShowDocumentBase");
    button.click();
    assertEquals(2, collectedStatus.size());
    assertTrue(collectedStatus.get(0), collectedStatus.get(0).startsWith("CodeBase: 'file:"));
    assertTrue(collectedStatus.get(0), collectedStatus.get(0).endsWith("target/test-classes/applets/'"));
    assertTrue(collectedStatus.get(1), collectedStatus.get(1).startsWith("DocumentBase: 'file:"));
    assertTrue(collectedStatus.get(1), collectedStatus.get(1).endsWith("target/test-classes/applets/codebaseApplet.html'"));
}
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)

Example 2 with StatusHandler

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

the class HtmlAppletTest method checkAppletCall.

/**
 * @throws Exception if the test fails
 */
@Test
public void checkAppletCall() throws Exception {
    Assume.assumeFalse(SKIP_);
    if (areAppletsNotSupported()) {
        return;
    }
    final URL url = getClass().getResource("/applets/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 HtmlTextInput input = page.getHtmlElementById("myInput");
    HtmlButton button = page.getHtmlElementById("callWithoutParams");
    button.click();
    assertEquals(2, collectedStatus.size());
    assertEquals("call: 'callSample'", collectedStatus.get(0));
    assertEquals("  'done'", collectedStatus.get(1));
    assertEquals("undefined", input.asNormalizedText());
    button = page.getHtmlElementById("callWithStringParam");
    button.click();
    assertEquals(4, collectedStatus.size());
    assertEquals("call: 'callSample'", collectedStatus.get(2));
    assertEquals("HtmlUnit", input.asNormalizedText());
}
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)

Example 3 with StatusHandler

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

the class HtmlAppletTest method checkAppletParams.

/**
 * Tests the handling of parameters.
 * @throws Exception if the test fails
 */
@Test
public void checkAppletParams() throws Exception {
    Assume.assumeFalse(SKIP_);
    if (areAppletsNotSupported()) {
        return;
    }
    final URL url = getClass().getResource("/applets/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)

Example 4 with StatusHandler

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

the class HtmlAppletTest method checkAppletExecJs.

/**
 * @throws Exception if the test fails
 */
@Test
public void checkAppletExecJs() throws Exception {
    Assume.assumeFalse(SKIP_);
    if (areAppletsNotSupported()) {
        return;
    }
    final URL url = getClass().getResource("/applets/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("execJs7");
    button.click();
    assertEquals(2, collectedStatus.size());
    assertEquals("execJS: '7'", collectedStatus.get(0));
    assertEquals("  '7.0'", collectedStatus.get(1));
    button = page.getHtmlElementById("execJsOuterHtml");
    button.click();
    assertEquals(4, collectedStatus.size());
    assertEquals("execJS: 'document.getElementById('myInput').outerHTML'", collectedStatus.get(2));
    assertEquals("  '<input type=\"text\" id=\"myInput\">'", 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)

Example 5 with StatusHandler

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

the class HtmlAppletTest 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 (areAppletsNotSupported()) {
        return;
    }
    final URL url = getClass().getResource("/applets/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> applets = page.getElementsByTagName("applet");
    assertEquals(1, applets.size());
    final HtmlApplet htmlApplet = (HtmlApplet) applets.get(0);
    try {
        htmlApplet.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)

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