Search in sources :

Example 16 with StatusHandler

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

the class HtmlObjectTest method checkSubdirRelativeAppletBase.

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

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

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

Example 18 with StatusHandler

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

the class HtmlAppletTest method checkAppletOverwriteArchive.

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

Example 19 with StatusHandler

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

the class HtmlAppletTest method appletConfirmHandlerPermit.

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

        @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 20 with StatusHandler

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

the class HtmlAppletTest method checkSubdirRelativeAppletBase.

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

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