use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.
the class HistoryTest method historyCache.
/**
* Tests going in history {@link History#back()} with {@code POST} request.
*
* @throws Exception if an error occurs
*/
@Test
@Alerts("49")
public // limit varies for IE
void historyCache() throws Exception {
final Map<String, Class<? extends Servlet>> servlets = new HashMap<>();
final int testDeep = 70;
for (int i = 0; i < testDeep; i++) {
servlets.put("/post" + i, Post1Servlet.class);
}
startWebServer("./", new String[0], servlets);
final WebDriver driver = getWebDriver();
int count = Post1Servlet.Count_;
for (int i = 0; i < testDeep; i++) {
driver.get(URL_FIRST + "post" + i);
assertTrue(driver.getPageSource(), driver.getPageSource().contains("Call: " + (i + count)));
}
count = Post1Servlet.Count_;
for (int i = 0; i < testDeep - 1; i++) {
driver.navigate().back();
if (!driver.getPageSource().contains("Call: " + (count - i - 2))) {
assertEquals(Integer.parseInt(getExpectedAlerts()[0]), i);
return;
}
if (count != Post1Servlet.Count_) {
Assert.fail("Server called for " + i);
break;
}
}
assertEquals(getExpectedAlerts()[0], "done");
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.
the class HttpWebConnection3Test method acceptEncoding.
/**
* @throws Exception if the test fails
*/
@Test
@Alerts(DEFAULT = "gzip, deflate", CHROME = "gzip, deflate, br", EDGE = "gzip, deflate, br")
public void acceptEncoding() throws Exception {
final String response = "HTTP/1.1 200 OK\r\n" + "Content-Length: 2\r\n" + "Content-Type: text/plain\r\n" + "\r\n" + "Hi";
shutDownAll();
try (PrimitiveWebServer primitiveWebServer = new PrimitiveWebServer(null, response, null)) {
final WebDriver driver = getWebDriver();
driver.get("http://localhost:" + primitiveWebServer.getPort());
final String request = primitiveWebServer.getRequests().get(0);
final String[] headers = request.split("\\r\\n");
for (int i = 0; i < headers.length; i++) {
final String header = headers[i];
if (StringUtils.startsWithIgnoreCase(header, HttpHeader.ACCEPT_ENCODING_LC)) {
final String value = header.substring(header.indexOf(':') + 1);
assertEquals(getExpectedAlerts()[0], value.trim());
return;
}
}
fail("No accept-encoding header found.");
}
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.
the class HttpWebConnection3Test method locationUTF.
/**
* Test for bug #1898.
*
* @throws Exception if an error occurs
*/
@Test
@Alerts("§§URL§§?????")
public // seems to work only when running alone
void locationUTF() throws Exception {
final String url = "http://localhost:" + PORT_PRIMITIVE_SERVER + "/";
final String response = "HTTP/1.1 302 Found\r\n" + "Content-Length: 0\r\n" + "Location: " + url + "\u0623\u0647\u0644\u0627\u064b" + "\r\n" + "\r\n";
final String response2 = "HTTP/1.1 200 OK\r\n" + "Content-Length: 2\r\n" + "Content-Type: text/html\r\n" + "\r\n" + "Hi";
expandExpectedAlertsVariables(new URL(url));
shutDownAll();
try (PrimitiveWebServer primitiveWebServer = new PrimitiveWebServer(null, response, response2)) {
final WebDriver driver = getWebDriver();
driver.get(url);
assertEquals(getExpectedAlerts()[0], driver.getCurrentUrl());
assertTrue(driver.getPageSource().contains("Hi"));
assertEquals(2, primitiveWebServer.getRequests().size());
}
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.
the class CookieManagerTest method setCookieExpires_twoDigits2.
/**
* Two digits years should be interpreted as 20xx if before 1970 and as 19xx otherwise.
* Same as the test before, only different formating was used.
* @throws Exception if the test fails
*/
@Test
@Alerts(DEFAULT = "cookie1=1; cookie2=2; cookie3=3", IE = "cookie1=1; cookie2=2; cookie3=3; cookie4=4; cookie5=5; cookie6=6")
public void setCookieExpires_twoDigits2() throws Exception {
final List<NameValuePair> responseHeader1 = new ArrayList<>();
responseHeader1.add(new NameValuePair("Set-Cookie", "cookie1=1;expires=Sun,01 Dec 68 16:00:00 GMT"));
responseHeader1.add(new NameValuePair("Set-Cookie", "cookie2=2;expires=Thu,01 Dec 69 16:00:00 GMT"));
responseHeader1.add(new NameValuePair("Set-Cookie", "cookie3=3;expires=Mon,31 Dec 69 16:00:00 GMT"));
responseHeader1.add(new NameValuePair("Set-Cookie", "cookie4=4;expires=Thu,01 Jan 70 16:00:00 GMT"));
responseHeader1.add(new NameValuePair("Set-Cookie", "cookie5=5;expires=Tue,01 Dec 70 16:00:00 GMT"));
responseHeader1.add(new NameValuePair("Set-Cookie", "cookie6=6;expires=Wed,01 Dec 71 16:00:00 GMT"));
getMockWebConnection().setResponse(URL_FIRST, HTML_ALERT_COOKIE, 200, "OK", MimeType.TEXT_HTML, responseHeader1);
loadPageWithAlerts2(URL_FIRST);
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.
the class CookieManagerTest method emptyCookieName.
/**
* @throws Exception if the test fails
*/
@Test
@Alerts("value1")
public void emptyCookieName() throws Exception {
final List<NameValuePair> responseHeader = new ArrayList<>();
responseHeader.add(new NameValuePair("Set-Cookie", "=value1"));
getMockWebConnection().setDefaultResponse(HTML_ALERT_COOKIE, 200, "OK", MimeType.TEXT_HTML, responseHeader);
loadPageWithAlerts2(URL_FIRST);
}
Aggregations