use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.
the class HtmlAreaTest method thisInJavascriptHref.
/**
* In action "this" should be the window and not the area.
* @throws Exception if the test fails
*/
@Test
@Alerts("true")
@BuggyWebDriver(FF = "Todo", FF_ESR = "Todo")
public void thisInJavascriptHref() throws Exception {
try (InputStream is = getClass().getClassLoader().getResourceAsStream("testfiles/tiny-jpg.img")) {
final byte[] directBytes = IOUtils.toByteArray(is);
final URL urlImage = new URL(URL_FIRST, "img.jpg");
final List<NameValuePair> emptyList = Collections.emptyList();
getMockWebConnection().setResponse(urlImage, directBytes, 200, "ok", "image/jpg", emptyList);
}
final String html = "<html><head><title>foo</title></head><body>\n" + "<img src='img.jpg' width='145' height='126' usemap='#somename'>\n" + "<map name='somename'>\n" + " <area href='javascript:alert(this == window)' id='a2' shape='rect' coords='0,0,30,30'/>\n" + "</map></body></html>";
final WebDriver driver = loadPage2(html);
final Page page;
if (driver instanceof HtmlUnitDriver) {
page = getWebWindowOf((HtmlUnitDriver) driver).getEnclosedPage();
} else {
page = null;
}
verifyAlerts(driver);
driver.findElement(By.id("a2")).click();
verifyAlerts(driver, getExpectedAlerts());
if (driver instanceof HtmlUnitDriver) {
final Page secondPage = getWebWindowOf((HtmlUnitDriver) driver).getEnclosedPage();
assertSame(page, secondPage);
}
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.
the class HtmlAreaTest method click_javascriptUrlMixedCase.
/**
* @throws Exception if the test fails
*/
@Test
@Alerts("clicked")
@BuggyWebDriver(FF = "Todo", FF_ESR = "Todo")
public void click_javascriptUrlMixedCase() throws Exception {
try (InputStream is = getClass().getClassLoader().getResourceAsStream("testfiles/tiny-jpg.img")) {
final byte[] directBytes = IOUtils.toByteArray(is);
final URL urlImage = new URL(URL_FIRST, "img.jpg");
final List<NameValuePair> emptyList = Collections.emptyList();
getMockWebConnection().setResponse(urlImage, directBytes, 200, "ok", "image/jpg", emptyList);
}
final String html = "<html><head><title>foo</title></head><body>\n" + "<img src='img.jpg' width='145' height='126' usemap='#somename'>\n" + "<map name='somename'>\n" + " <area href='javasCRIpT:alert(\"clicked\")' id='a2' shape='rect' coords='0,0,30,30'/>\n" + "</map>\n" + "</body></html>";
final WebDriver driver = loadPage2(html);
final Page page;
if (driver instanceof HtmlUnitDriver) {
page = getWebWindowOf((HtmlUnitDriver) driver).getEnclosedPage();
} else {
page = null;
}
verifyAlerts(driver);
driver.findElement(By.id("a2")).click();
verifyAlerts(driver, getExpectedAlerts());
if (driver instanceof HtmlUnitDriver) {
final Page secondPage = getWebWindowOf((HtmlUnitDriver) driver).getEnclosedPage();
assertSame(page, secondPage);
}
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.
the class HtmlAreaTest method isDisplayedEmptyCircle.
/**
* @throws Exception if an error occurs
*/
@Test
@Alerts(DEFAULT = { "false", "false", "true" }, IE = { "false", "false", "false" })
@HtmlUnitNYI(IE = { "false", "false", "true" })
public void isDisplayedEmptyCircle() throws Exception {
final String html = "<html><head><title>Page A</title></head>\n" + "<body>\n" + " <img id='myImg' usemap='#imgmap'" + " src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAA" + "HElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='>\n" + " <map id='myMap' name='imgmap'>\n" + " <area id='myArea1' shape='circle' coords='0,0,0'>\n" + " <area id='myArea2' shape='circle' >\n" + " <area id='myArea3' shape='circle' coords='0,0,0.8'>\n" + " </map>\n" + "</body></html>";
final String[] expected = getExpectedAlerts();
setExpectedAlerts(new String[] {});
final WebDriver driver = loadPage2(html);
boolean displayed = driver.findElement(By.id("myArea1")).isDisplayed();
assertEquals(Boolean.parseBoolean(expected[0]), displayed);
displayed = driver.findElement(By.id("myArea2")).isDisplayed();
assertEquals(Boolean.parseBoolean(expected[1]), displayed);
displayed = driver.findElement(By.id("myArea3")).isDisplayed();
assertEquals(Boolean.parseBoolean(expected[2]), displayed);
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.
the class HtmlBackgroundSoundTest method simpleScriptable.
/**
* @throws Exception if the test fails
*/
@Test
@Alerts(DEFAULT = "[object HTMLUnknownElement]", IE = "[object HTMLBGSoundElement]")
public void simpleScriptable() throws Exception {
final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head>\n" + "<script>\n" + LOG_TITLE_FUNCTION + " function test() {\n" + " log(document.getElementById('myId'));\n" + " }\n" + "</script>\n" + "</head><body onload='test()'>\n" + " <bgsound id='myId'/>\n" + "</body></html>";
final WebDriver driver = loadPageVerifyTitle2(html);
if (driver instanceof HtmlUnitDriver && getExpectedAlerts()[0].contains("Sound")) {
assertTrue(HtmlBackgroundSound.class.isInstance(toHtmlElement(driver.findElement(By.id("myId")))));
}
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.
the class FocusableElement2Test method bodyLoad.
/**
* @throws Exception if the test fails
*/
@Test
@Alerts(DEFAULT = { "body", "active: body", "onload", "active: body", "onfocus:[object Window]", "active: body" }, CHROME = { "body", "active: body", "onload", "active: body" }, EDGE = { "body", "active: body", "onload", "active: body" }, IE = { "body", "active: null", "onfocusin:body", "active: body", "onload", "active: body", "onfocus:[object Window]", "active: body" })
@HtmlUnitNYI(FF = { "body", "active: body", "onload", "active: body" }, FF_ESR = { "body", "active: body", "onload", "active: body" }, IE = { "body", "active: body", "onload", "active: body" })
public // TODO FF & FF68 fail due to wrong body vs. window event handling
void bodyLoad() throws Exception {
final String html = "<html>\n" + " <head>\n" + " <script>\n" + logger() + " function test() {\n" + " log('onload');\n" + " }\n" + " </script>\n" + " </head>\n" + " <body id='body' onload='test()' " + logEvents("") + ">\n" + " <script>\n" + " log('body');" + " </script>\n" + " </body>\n" + "</html>\n";
final WebDriver driver = loadPage2(html);
assertTitle(driver, String.join(";", getExpectedAlerts()) + (getExpectedAlerts().length > 0 ? ";" : ""));
}
Aggregations