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