use of com.gargoylesoftware.htmlunit.UnexpectedPage in project htmlunit by HtmlUnit.
the class HtmlAnchor2Test method click_unexpectedPageDownloadAttributeAttachmentHandler.
/**
* @throws Exception if the test fails
*/
@Test
public void click_unexpectedPageDownloadAttributeAttachmentHandler() throws Exception {
final String html = "<html><head></head>\n" + "<body>\n" + " <a href='" + URL_SECOND + "' id='link' download='test.json'>link</a>\n" + "</body>\n" + "</html>";
getMockWebConnection().setResponse(URL_SECOND, "{name: \"Test\"};", MimeType.APPLICATION_JSON);
final LinkedList<Page> pages = new LinkedList<Page>();
getWebClient().setAttachmentHandler(new AttachmentHandler() {
@Override
public void handleAttachment(final Page page) {
pages.add(page);
}
});
try {
final HtmlPage page = loadPage(html);
assertEquals(1, getWebClient().getWebWindows().size());
page.getElementById("link").click();
assertEquals(2, getWebClient().getWebWindows().size());
final WebWindow newWindow = getWebClient().getWebWindows().get(getWebClient().getWebWindows().size() - 1);
assertTrue(newWindow.getEnclosedPage() instanceof UnexpectedPage);
assertEquals(1, pages.size());
assertTrue(pages.get(0) instanceof UnexpectedPage);
} finally {
getWebClient().setAttachmentHandler(null);
}
}
Aggregations