use of com.gargoylesoftware.htmlunit.StatusHandler in project htmlunit by HtmlUnit.
the class HtmlAppletTest method checkAppletBase.
/**
* Tests the codebase and documentbase properties.
* @throws Exception if the test fails
*/
@Test
public void checkAppletBase() throws Exception {
Assume.assumeFalse(SKIP_);
if (areAppletsNotSupported()) {
return;
}
final URL url = getClass().getResource("/applets/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/codebaseApplet.html'"));
}
use of com.gargoylesoftware.htmlunit.StatusHandler in project htmlunit by HtmlUnit.
the class HtmlAppletTest method checkAppletCall.
/**
* @throws Exception if the test fails
*/
@Test
public void checkAppletCall() 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 HtmlTextInput input = page.getHtmlElementById("myInput");
HtmlButton button = page.getHtmlElementById("callWithoutParams");
button.click();
assertEquals(2, collectedStatus.size());
assertEquals("call: 'callSample'", collectedStatus.get(0));
assertEquals(" 'done'", collectedStatus.get(1));
assertEquals("undefined", input.asNormalizedText());
button = page.getHtmlElementById("callWithStringParam");
button.click();
assertEquals(4, collectedStatus.size());
assertEquals("call: 'callSample'", collectedStatus.get(2));
assertEquals("HtmlUnit", input.asNormalizedText());
}
use of com.gargoylesoftware.htmlunit.StatusHandler in project htmlunit by HtmlUnit.
the class HtmlAppletTest method checkAppletParams.
/**
* Tests the handling of parameters.
* @throws Exception if the test fails
*/
@Test
public void checkAppletParams() 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("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 HtmlAppletTest method checkAppletExecJs.
/**
* @throws Exception if the test fails
*/
@Test
public void checkAppletExecJs() 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("execJs7");
button.click();
assertEquals(2, collectedStatus.size());
assertEquals("execJS: '7'", collectedStatus.get(0));
assertEquals(" '7.0'", collectedStatus.get(1));
button = page.getHtmlElementById("execJsOuterHtml");
button.click();
assertEquals(4, collectedStatus.size());
assertEquals("execJS: 'document.getElementById('myInput').outerHTML'", collectedStatus.get(2));
assertEquals(" '<input type=\"text\" id=\"myInput\">'", collectedStatus.get(3));
}
use of com.gargoylesoftware.htmlunit.StatusHandler in project htmlunit by HtmlUnit.
the class HtmlAppletTest 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 (areAppletsNotSupported()) {
return;
}
final URL url = getClass().getResource("/applets/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> applets = page.getElementsByTagName("applet");
assertEquals(1, applets.size());
final HtmlApplet htmlApplet = (HtmlApplet) applets.get(0);
try {
htmlApplet.getApplet();
} catch (final Exception e) {
assertEquals("java.lang.ClassNotFoundException: net.sourceforge.htmlunit.testapplets.EmptyApplet", e.getMessage());
}
}
Aggregations