use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.
the class FocusableElement2Test method bodySwitchFromBodyToNotFocusable.
/**
* @throws Exception if the test fails
*/
@Test
@Alerts(DEFAULT = { "onfocus:[object Window]", "active: body", "before", "active: body", "after", "active: body" }, CHROME = { "before", "active: body", "after", "active: body" }, EDGE = { "before", "active: body", "after", "active: body" }, IE = { "onfocusin:body", "active: body", "onfocus:[object Window]", "active: body", "before", "active: body", "after", "active: body" })
@HtmlUnitNYI(FF = { "before", "active: body", "after", "active: body" }, FF_ESR = { "before", "active: body", "after", "active: body" }, IE = { "before", "active: body", "after", "active: body" })
public // TODO FF & FF68 fail due to wrong body vs. window event handling
void bodySwitchFromBodyToNotFocusable() throws Exception {
final String html = "<html>\n" + " <head>\n" + " <script>\n" + logger() + " function test() {\n" + " log('before');\n" + " document.getElementById('focusId').focus();\n" + " document.getElementById('focusId').blur();\n" + " log('after');\n" + " }\n" + " </script>\n" + " </head>\n" + " <body id='body' onload='setTimeout(test, 10)' " + logEvents("") + ">\n" + " <div id='focusId' " + logEvents("F") + ">div</div>\n" + " </body>\n" + "</html>\n";
final WebDriver driver = loadPage2(html);
assertTitle(driver, String.join(";", getExpectedAlerts()) + (getExpectedAlerts().length > 0 ? ";" : ""));
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.
the class FocusableElement2Test method bodySwitchFromBodyToFocusable.
/**
* @throws Exception if the test fails
*/
@Test
@Alerts(DEFAULT = { "onfocus:[object Window]", "active: body", "before", "active: body", "onfocusF:focusId", "active: focusId", "onfocusinF:focusId", "active: focusId", "onfocusin:focusId", "active: focusId", "onblurF:focusId", "active: body", "onfocusoutF:focusId", "active: body", "onfocusout:focusId", "active: body", "after", "active: body" }, CHROME = { "before", "active: body", "onfocusF:focusId", "active: focusId", "onfocusinF:focusId", "active: focusId", "onfocusin:focusId", "active: focusId", "onblurF:focusId", "active: body", "onfocusoutF:focusId", "active: body", "onfocusout:focusId", "active: body", "after", "active: body" }, EDGE = { "before", "active: body", "onfocusF:focusId", "active: focusId", "onfocusinF:focusId", "active: focusId", "onfocusin:focusId", "active: focusId", "onblurF:focusId", "active: body", "onfocusoutF:focusId", "active: body", "onfocusout:focusId", "active: body", "after", "active: body" }, IE = { "onfocusin:body", "active: body", "onfocus:[object Window]", "active: body", "before", "active: body", "onfocusout:body", "active: focusId", "onfocusinF:focusId", "active: focusId", "onfocusin:focusId", "active: focusId", "onfocusoutF:focusId", "active: body", "onfocusout:focusId", "active: body", "onfocusin:body", "active: body", "after", "active: body", "onfocusF:focusId", "active: body", "onblurF:focusId", "active: body" })
@HtmlUnitNYI(FF = { "before", "active: body", "onfocusF:focusId", "active: focusId", "onfocusinF:focusId", "active: focusId", "onfocusin:focusId", "active: focusId", "onblurF:focusId", "active: body", "onfocusoutF:focusId", "active: body", "onfocusout:focusId", "active: body", "after", "active: body" }, FF_ESR = { "before", "active: body", "onfocusF:focusId", "active: focusId", "onfocusinF:focusId", "active: focusId", "onfocusin:focusId", "active: focusId", "onblurF:focusId", "active: body", "onfocusoutF:focusId", "active: body", "onfocusout:focusId", "active: body", "after", "active: body" }, IE = { "before", "active: body", "onfocusout:body", "active: body", "onfocusinF:focusId", "active: body", "onfocusin:focusId", "active: body", "onfocusF:focusId", "active: focusId", "onfocusoutF:focusId", "active: body", "onfocusout:focusId", "active: body", "onblurF:focusId", "active: body", "after", "active: body" })
public // TODO FF & FF68 fail due to wrong body vs. window event handling
void bodySwitchFromBodyToFocusable() throws Exception {
final String html = "<html>\n" + " <head>\n" + " <script>\n" + logger() + " function test() {\n" + " log('before');\n" + " document.getElementById('focusId').focus();\n" + " document.getElementById('focusId').blur();\n" + " log('after');\n" + " }\n" + " </script>\n" + " </head>\n" + " <body id='body' onload='setTimeout(test, 10)' " + logEvents("") + ">\n" + " <input type='text' id='focusId' " + logEvents("F") + ">\n" + " </body>\n" + "</html>\n";
final WebDriver driver = loadPage2(html);
assertTitle(driver, String.join(";", getExpectedAlerts()) + (getExpectedAlerts().length > 0 ? ";" : ""));
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.
the class FocusableElement2Test method body.
/**
* @throws Exception if the test fails
*/
@Test
@Alerts(DEFAULT = { "onfocus:[object Window]", "active: focusId", "before", "active: focusId", "after", "active: focusId" }, CHROME = { "before", "active: focusId", "after", "active: focusId" }, EDGE = { "before", "active: focusId", "after", "active: focusId" }, IE = { "onfocusin:focusId", "active: focusId", "onfocus:[object Window]", "active: focusId", "before", "active: focusId", "after", "active: focusId" })
@HtmlUnitNYI(FF = { "before", "active: focusId", "after", "active: focusId" }, FF_ESR = { "before", "active: focusId", "after", "active: focusId" }, IE = { "before", "active: focusId", "onfocusout:focusId", "active: focusId", "after", "active: focusId" })
public // TODO FF & FF68 fail due to wrong body vs. window event handling
void body() throws Exception {
final String html = "<html>\n" + " <head>\n" + " <script>\n" + logger() + " function test() {\n" + " log('before');\n" + " document.getElementById('focusId').focus();\n" + " document.getElementById('focusId').focus();\n" + " document.getElementById('focusId').blur();\n" + " document.getElementById('focusId').blur();\n" + " log('after');\n" + " }\n" + " </script>\n" + " </head>\n" + " <body id='focusId' onload='setTimeout(test, 10)' " + logEvents("") + ">\n" + " </body>\n" + "</html>\n";
final WebDriver driver = loadPage2(html);
assertTitle(driver, String.join(";", getExpectedAlerts()) + (getExpectedAlerts().length > 0 ? ";" : ""));
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.
the class HtmlAnchor2Test method clickWithDownloadAttributeDataUrl.
/**
* Not testable with Selenium.
*
* @exception Exception If the test fails
*/
@Test
@Alerts(DEFAULT = { "1", "First", "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAAL" + "GPC/xhBQAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9YGARc5KB0XV+IAAAAddEVYdENvbW1l" + "bnQAQ3JlYXRlZCB3aXRoIFRoZSBHSU1Q72QlbgAAAF1JREFUGNO9zL0NglAAxPEfdLTs4BZM4DIO4C" + "7OwQg2JoQ9LE1exdlYvBBeZ7jqch9//q1uH4TLzw4d6+ErXMMcXuHWxId3KOETnnXXV6MJpcq2MLaI" + "97CER3N0vr4MkhoXe0rZigAAAABJRU5ErkJggg==" }, IE = { "0", "First", "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAAL" + "GPC/xhBQAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9YGARc5KB0XV+IAAAAddEVYdENvbW1l" + "bnQAQ3JlYXRlZCB3aXRoIFRoZSBHSU1Q72QlbgAAAF1JREFUGNO9zL0NglAAxPEfdLTs4BZM4DIO4C" + "7OwQg2JoQ9LE1exdlYvBBeZ7jqch9//q1uH4TLzw4d6+ErXMMcXuHWxId3KOETnnXXV6MJpcq2MLaI" + "97CER3N0vr4MkhoXe0rZigAAAABJRU5ErkJggg==" })
@HtmlUnitNYI(IE = { "1", "First", "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAAL" + "GPC/xhBQAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9YGARc5KB0XV+IAAAAddEVYdENvbW1l" + "bnQAQ3JlYXRlZCB3aXRoIFRoZSBHSU1Q72QlbgAAAF1JREFUGNO9zL0NglAAxPEfdLTs4BZM4DIO4C" + "7OwQg2JoQ9LE1exdlYvBBeZ7jqch9//q1uH4TLzw4d6+ErXMMcXuHWxId3KOETnnXXV6MJpcq2MLaI" + "97CER3N0vr4MkhoXe0rZigAAAABJRU5ErkJggg==" })
public void clickWithDownloadAttributeDataUrl() throws Exception {
final String html = "<html>\n" + "<head>\n" + " <title>First</title>\n" + "</head>\n" + "<body>\n" + " <a id='clickMe' href='data:image/png;base64," + "iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGP" + "C/xhBQAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9YGARc5KB0XV+IA" + "AAAddEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIFRoZSBHSU1Q72QlbgAAAF1J" + "REFUGNO9zL0NglAAxPEfdLTs4BZM4DIO4C7OwQg2JoQ9LE1exdlYvBBeZ7jq" + "ch9//q1uH4TLzw4d6+ErXMMcXuHWxId3KOETnnXXV6MJpcq2MLaI97CER3N0" + "vr4MkhoXe0rZigAAAABJRU5ErkJggg==' download='lora.html'>Click Me</a>\n" + "</body></html>";
getMockWebConnection().setResponse(URL_SECOND, "<head><title>Second</title>");
final int windowsSize = getWebClient().getWebWindows().size();
final HtmlPage page = loadPage(html);
page.getElementById("clickMe").click();
assertEquals("Should have opened a new window", windowsSize + Integer.parseInt(getExpectedAlerts()[0]), getWebClient().getWebWindows().size());
assertEquals("Should not have navigated away", getExpectedAlerts()[1], page.getTitleText());
final WebWindow dataWindow = getWebClient().getWebWindows().get(getWebClient().getWebWindows().size() - 1);
final Page dataPage = dataWindow.getEnclosedPage();
assertTrue("Should be an UnexpectedPage", dataPage instanceof UnexpectedPage);
try (InputStream resultInputStream = ((UnexpectedPage) dataPage).getInputStream()) {
final ImageInputStream resultImageIS = ImageIO.createImageInputStream(resultInputStream);
final BufferedImage resultBufferedIIS = ImageIO.read(resultImageIS);
compareImages(getExpectedAlerts()[2], null, resultBufferedIIS);
}
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.
the class HtmlBaseTest method simpleScriptable.
/**
* @throws Exception if the test fails
*/
@Test
@Alerts("[object HTMLBaseElement]")
public void simpleScriptable() throws Exception {
final String html = "<html><head>\n" + "<base id='myId' target='MyNewWindow'>\n" + "<script>\n" + LOG_TITLE_FUNCTION + " function test() {\n" + " log(document.getElementById('myId'));\n" + " }\n" + "</script>\n" + "</head><body onload='test()'>\n" + "</body></html>";
final WebDriver driver = loadPageVerifyTitle2(html);
if (driver instanceof HtmlUnitDriver) {
final HtmlPage page = (HtmlPage) getWebWindowOf((HtmlUnitDriver) driver).getEnclosedPage();
assertTrue(HtmlBase.class.isInstance(page.getHtmlElementById("myId")));
}
}
Aggregations