use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.
the class HtmlAnchorTest method href_js_escaping.
/**
* @throws Exception if an error occurs
*/
@Test
@Alerts({ "hi", "%28%29" })
public void href_js_escaping() throws Exception {
final String html = "<html><head>\n<script>\n" + " function sayHello(text) {\n" + " alert(text);\n" + " }\n" + "</script></head>\n" + "<body>\n" + " <a id='myAnchor' href=\"javascript:sayHello%28'hi'%29\">My Link</a>\n" + " <input id='myButton' type=button onclick=\"javascript:sayHello('%28%29')\" value='My Button'>\n" + "</body></html>";
final WebDriver driver = loadPage2(html);
driver.findElement(By.id("myAnchor")).click();
verifyAlerts(driver, getExpectedAlerts()[0]);
driver.findElement(By.id("myButton")).click();
verifyAlerts(driver, getExpectedAlerts()[1]);
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.
the class HtmlAnchorTest method clickNestedButtonElement.
/**
* @throws Exception if an error occurs
*/
@Test
@Alerts("§§URL§§page2.html")
public void clickNestedButtonElement() throws Exception {
final String html = "<html>\n" + "<body>\n" + " <a href='page2.html'>\n" + " <button id='theButton'></button>\n" + " </a>\n" + "</body></html>";
expandExpectedAlertsVariables(URL_FIRST);
getMockWebConnection().setDefaultResponse("");
final WebDriver driver = loadPage2(html);
final WebElement button = driver.findElement(By.id("theButton"));
assertEquals("button", button.getTagName());
button.click();
assertEquals(getExpectedAlerts()[0], driver.getCurrentUrl());
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.
the class HtmlAnchorTest method clickNestedSubmitElement.
/**
* @throws Exception if an error occurs
*/
@Test
@Alerts("page2.html")
public void clickNestedSubmitElement() throws Exception {
final String html = "<html>\n" + "<body>\n" + " <a href='page2.html'>\n" + " <input type='submit' id='theInput' />\n" + " </a>\n" + "</body></html>";
getMockWebConnection().setDefaultResponse("");
final WebDriver driver = loadPage2(html);
final WebElement input = driver.findElement(By.id("theInput"));
assertEquals("input", input.getTagName());
input.click();
assertEquals(URL_FIRST + getExpectedAlerts()[0], driver.getCurrentUrl());
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.
the class HtmlAnchorTest method click_refererHeader.
/**
* Tests the 'Referer' HTTP header.
* @throws Exception on test failure
*/
@Test
@Alerts("§§URL§§index.html?test")
public void click_refererHeader() throws Exception {
final String firstContent = "<html><head><title>Page A</title></head>\n" + "<body><a href='" + URL_SECOND + "' id='link'>link</a></body>\n" + "</html>";
final String secondContent = "<html><head><title>Page B</title></head>\n" + "<body></body>\n" + "</html>";
expandExpectedAlertsVariables(URL_FIRST);
final URL indexUrl = new URL(URL_FIRST.toString() + "index.html");
getMockWebConnection().setResponse(indexUrl, firstContent);
getMockWebConnection().setResponse(URL_SECOND, secondContent);
final WebDriver driver = loadPage2(firstContent, new URL(URL_FIRST.toString() + "index.html?test#ref"));
driver.findElement(By.id("link")).click();
assertEquals(2, getMockWebConnection().getRequestCount());
final Map<String, String> lastAdditionalHeaders = getMockWebConnection().getLastAdditionalHeaders();
assertEquals(getExpectedAlerts()[0], lastAdditionalHeaders.get(HttpHeader.REFERER));
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.
the class HtmlAnchorTest method controlClick_refererHeader.
/**
* @throws Exception if the test fails
*/
@Test
@Alerts("§§URL§§index.html?test")
public void controlClick_refererHeader() throws Exception {
final String firstContent = "<html><head><title>Page A</title></head>\n" + "<body>\n" + " <a href='" + URL_SECOND + "' id='link'>link</a>\n" + "</body>\n" + "</html>";
final String secondContent = "<html><head><title>Page B</title></head>\n" + "<body></body>\n" + "</html>";
expandExpectedAlertsVariables(URL_FIRST);
final URL indexUrl = new URL(URL_FIRST.toString() + "index.html");
getMockWebConnection().setResponse(indexUrl, firstContent);
getMockWebConnection().setResponse(URL_SECOND, secondContent);
final WebDriver driver = loadPage2(firstContent, new URL(URL_FIRST.toString() + "index.html?test#ref"));
new Actions(driver).keyDown(Keys.CONTROL).click(driver.findElement(By.id("link"))).keyUp(Keys.CONTROL).build().perform();
Thread.sleep(DEFAULT_WAIT_TIME / 10);
assertEquals(2, getMockWebConnection().getRequestCount());
final Map<String, String> lastAdditionalHeaders = getMockWebConnection().getLastAdditionalHeaders();
assertEquals(getExpectedAlerts()[0], lastAdditionalHeaders.get(HttpHeader.REFERER));
}
Aggregations