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