Search in sources :

Example 21 with StatusHandler

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

the class HtmlAppletTest method checkAppletBaseWithoutCodebase.

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

Example 22 with StatusHandler

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

the class HTMLCollectionFrames method setStatus.

/**
 * Sets the text from the status line.
 * @param message the status line text
 */
@JsxSetter
public void setStatus(final String message) {
    status_ = message;
    final StatusHandler statusHandler = webWindow_.getWebClient().getStatusHandler();
    if (statusHandler != null) {
        statusHandler.statusMessageChanged(webWindow_.getEnclosedPage(), message);
    }
}
Also used : StatusHandler(com.gargoylesoftware.htmlunit.StatusHandler) JsxSetter(com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter)

Example 23 with StatusHandler

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

the class HTMLAppletElement2Test method callAppletMethodFromJS.

/**
 * Tests calling applet method from JavaScript code.
 * @throws Exception if the test fails
 */
@Test
public void callAppletMethodFromJS() throws Exception {
    Assume.assumeFalse(SKIP_);
    if (getBrowserVersion().isChrome() || getBrowserVersion().isEdge() || getBrowserVersion().isFirefox()) {
        return;
    }
    final URL url = getClass().getResource("/applets/simpleAppletDoIt.html");
    final WebClient webClient = getWebClientWithMockWebConnection();
    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 button1 = page.getHtmlElementById("button1");
    button1.click();
    final HtmlButton button2 = page.getHtmlElementById("button2");
    button2.click();
    final String[] expectedStatus = { "Called: doIt('hello')", "Called: doIt('12345')" };
    assertEquals(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) WebClient(com.gargoylesoftware.htmlunit.WebClient) URL(java.net.URL) HtmlButton(com.gargoylesoftware.htmlunit.html.HtmlButton) Test(org.junit.Test)

Example 24 with StatusHandler

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

the class HtmlObjectTest method checkAppletIgnoreUnknownArchive.

/**
 * Tests the processing of an applet definition with one valid and one wrong archive.
 * @throws Exception if the test fails
 */
@Test
public void checkAppletIgnoreUnknownArchive() throws Exception {
    Assume.assumeFalse(SKIP_);
    if (getBrowserVersion().isChrome()) {
        return;
    }
    final URL url = getClass().getResource("/objects/ignoreUnknownArchiveApplet.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);
    htmlObject.getApplet();
}
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 25 with StatusHandler

use of com.gargoylesoftware.htmlunit.StatusHandler 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

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