Search in sources :

Example 6 with StatusHandler

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

the class HtmlAppletTest method setMember.

/**
 * @throws Exception if the test fails
 */
@Test
public void setMember() 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 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)

Example 7 with StatusHandler

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

the class HtmlAppletTest method checkSubdirAppletBase.

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

Example 8 with StatusHandler

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

the class HtmlAppletTest method appletConfirmHandler.

/**
 * @throws Exception if the test fails
 */
@Test
public void appletConfirmHandler() 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);
    webClient.setAppletConfirmHandler(new AppletConfirmHandler() {

        @Override
        public boolean confirm(final HtmlApplet applet) {
            assertEquals("simpleAppletDoIt.jar", applet.getArchiveAttribute());
            return true;
        }

        @Override
        public boolean confirm(final HtmlObject applet) {
            return false;
        }
    });
    final HtmlPage page = webClient.getPage(url);
    final DomNodeList<DomElement> applets = page.getElementsByTagName("applet");
    assertEquals(1, applets.size());
    final HtmlApplet htmlApplet = (HtmlApplet) applets.get(0);
    assertTrue(htmlApplet.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)

Example 9 with StatusHandler

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

the class WindowTest method status.

/**
 * @throws Exception if the test fails
 */
@Test
public void status() throws Exception {
    final WebClient webClient = getWebClient();
    final MockWebConnection webConnection = new MockWebConnection();
    final String firstContent = "<html><head><title>First</title><script>\n" + "function doTest() {\n" + "  alert(window.status);\n" + "  window.status = 'newStatus';\n" + "  alert(window.status);\n" + "}\n" + "</script></head><body onload='doTest()'>\n" + "</body></html>";
    final URL url = URL_FIRST;
    webConnection.setResponse(url, firstContent);
    webClient.setWebConnection(webConnection);
    final List<String> collectedAlerts = new ArrayList<>();
    webClient.setAlertHandler(new CollectingAlertHandler(collectedAlerts));
    final List<String> collectedStatus = new ArrayList<>();
    webClient.setStatusHandler(new StatusHandler() {

        @Override
        public void statusMessageChanged(final Page page, final String message) {
            collectedStatus.add(message);
        }
    });
    final HtmlPage firstPage = webClient.getPage(URL_FIRST);
    assertEquals("First", firstPage.getTitleText());
    final String[] expectedAlerts = { "", "newStatus" };
    assertEquals("alerts", expectedAlerts, collectedAlerts);
    final String[] expectedStatus = { "newStatus" };
    assertEquals("status", expectedStatus, collectedStatus);
}
Also used : StatusHandler(com.gargoylesoftware.htmlunit.StatusHandler) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) ArrayList(java.util.ArrayList) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) Page(com.gargoylesoftware.htmlunit.Page) MockWebConnection(com.gargoylesoftware.htmlunit.MockWebConnection) CollectingAlertHandler(com.gargoylesoftware.htmlunit.CollectingAlertHandler) WebClient(com.gargoylesoftware.htmlunit.WebClient) URL(java.net.URL) Test(org.junit.Test)

Example 10 with StatusHandler

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

the class HtmlObjectTest method checkAppletBaseWithoutCodebase.

/**
 * Tests the codebase and documentbase properties.
 * @throws Exception if the test fails
 */
@Test
public void checkAppletBaseWithoutCodebase() 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("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/simpleAppletDoIt.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