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);
}
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'"));
}
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);
}
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);
}
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'"));
}
Aggregations