use of ghostdriver.server.HttpRequestCallback in project ghostdriver by detro.
the class AuthBasicTest method canSendKeysAndClickOnPageWithCSP.
// we should be able to interact with pages that have content security policies
// @Ignore
@Test
public void canSendKeysAndClickOnPageWithCSP() {
server.setHttpHandler("GET", new HttpRequestCallback() {
@Override
public void call(HttpServletRequest req, HttpServletResponse res) throws IOException {
res.addHeader("Content-Security-Policy", "default-src 'self'; script-src 'self';");
res.getOutputStream().println("<html>\n" + "<head>\n" + "</head>\n" + "<body>\n" + "<input id='username' />\n" + "</body>\n" + "</html>");
}
});
// Get Driver Instance
WebDriver d = getDriver();
d.get(server.getBaseUrl());
WebElement element = d.findElement(By.id("username"));
element.sendKeys("jesg");
element.click();
try {
((JavascriptExecutor) d).executeScript("1+1");
fail("we should not be able to eval javascript on csp page");
} catch (WebDriverException e) {
}
}
Aggregations