use of com.gargoylesoftware.htmlunit.StatusHandler in project htmlunit by HtmlUnit.
the class HtmlObjectTest method checkAppletParams.
/**
* Tests the handling of parameters.
* @throws Exception if the test fails
*/
@Test
public void checkAppletParams() 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("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: 'null'", collectedStatus.get(2));
assertEquals("archive: 'simpleAppletDoIt.jar'", collectedStatus.get(3));
}
use of com.gargoylesoftware.htmlunit.StatusHandler in project htmlunit by HtmlUnit.
the class HtmlObjectTest method checkAppletOverwriteArchive.
/**
* Tests the handling of parameters.
* @throws Exception if the test fails
*/
@Test
public void checkAppletOverwriteArchive() throws Exception {
Assume.assumeFalse(SKIP_);
if (getBrowserVersion().isChrome()) {
return;
}
final URL url = getClass().getResource("/objects/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));
}
use of com.gargoylesoftware.htmlunit.StatusHandler in project htmlunit by HtmlUnit.
the class HtmlObjectTest method appletConfirmHandlerPermit.
/**
* @throws Exception if the test fails
*/
@Test
public void appletConfirmHandlerPermit() throws Exception {
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 true;
}
@Override
public boolean confirm(final HtmlObject applet) {
assertEquals("simpleAppletDoIt.jar", applet.getArchiveAttribute());
return false;
}
});
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);
}
use of com.gargoylesoftware.htmlunit.StatusHandler in project htmlunit by HtmlUnit.
the class HtmlObjectTest method setMember.
/**
* @throws Exception if the test fails
*/
@Test
public void setMember() 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("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 HtmlObjectTest method checkAppletUnknownArchive.
/**
* Tests the processing of an applet definition with wrong archive.
* @throws Exception if the test fails
*/
@Test
public void checkAppletUnknownArchive() throws Exception {
if (getBrowserVersion().isChrome()) {
return;
}
final URL url = getClass().getResource("/objects/unknownArchiveApplet.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);
try {
htmlObject.getApplet();
} catch (final Exception e) {
assertEquals("java.lang.ClassNotFoundException: net.sourceforge.htmlunit.testapplets.EmptyApplet", e.getMessage());
}
}
Aggregations