Search in sources :

Example 26 with StatusHandler

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

the class HtmlObjectTest method checkAppletBase.

/**
 * Tests the codebase and documentbase properties.
 * @throws Exception if the test fails
 */
@Test
public void checkAppletBase() throws Exception {
    Assume.assumeFalse(SKIP_);
    if (getBrowserVersion().isChrome()) {
        return;
    }
    final URL url = getClass().getResource("/objects/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/objects/'"));
    assertTrue(collectedStatus.get(1), collectedStatus.get(1).startsWith("DocumentBase: 'file:"));
    assertTrue(collectedStatus.get(1), collectedStatus.get(1).endsWith("target/test-classes/objects/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) ActiveXObjectTest(com.gargoylesoftware.htmlunit.javascript.host.ActiveXObjectTest)

Example 27 with StatusHandler

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

the class HtmlObjectTest method checkAppletExecJs.

/**
 * @throws Exception if the test fails
 */
@Test
public void checkAppletExecJs() 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("execJs7");
    button.click();
    assertEquals(2, collectedStatus.size());
    assertEquals("execJS: '7'", collectedStatus.get(0));
    assertEquals("  '7.0'", collectedStatus.get(1));
}
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 28 with StatusHandler

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

the class HtmlObjectTest method checkSubdirAppletBase.

/**
 * Tests the codebase and documentbase properties.
 * @throws Exception if the test fails
 */
@Test
public void checkSubdirAppletBase() throws Exception {
    Assume.assumeFalse(SKIP_);
    if (getBrowserVersion().isChrome()) {
        return;
    }
    final URL url = getClass().getResource("/objects/subdir/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/objects/'"));
    assertTrue(collectedStatus.get(1), collectedStatus.get(1).startsWith("DocumentBase: 'file:"));
    assertTrue(collectedStatus.get(1), collectedStatus.get(1).endsWith("target/test-classes/objects/subdir/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) 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