use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.
the class CookieManagerTest method cookieSetFromJSWithoutPathUsesCurrentLocation2.
/**
* A cookie set with document.cookie without path applies only for the current path.
* @throws Exception if the test fails
*/
@Test
@Alerts("first=1")
public void cookieSetFromJSWithoutPathUsesCurrentLocation2() throws Exception {
final List<NameValuePair> responseHeader1 = new ArrayList<>();
responseHeader1.add(new NameValuePair("Set-Cookie", "first=1; path=/c"));
final String html = "<html>\n" + "<head></head>\n" + "<body><script>\n" + " document.cookie = 'first=new';\n" + " location.replace('/c/test.html');\n" + "</script></body>\n" + "</html>";
getMockWebConnection().setDefaultResponse(HTML_ALERT_COOKIE);
final URL firstUrl = new URL(URL_FIRST, "/a/b");
getMockWebConnection().setResponse(firstUrl, html, 200, "Ok", MimeType.TEXT_HTML, responseHeader1);
loadPageWithAlerts2(firstUrl);
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.
the class CookieManagerTest method cookieExpires_GMT.
/**
* @throws Exception if the test fails
*/
@Test
@Alerts(DEFAULT = "cookie1=1", IE = "cookie1=1; cookie2=2")
@NotYetImplemented(IE)
public void cookieExpires_GMT() throws Exception {
final List<NameValuePair> responseHeader = new ArrayList<>();
responseHeader.add(new NameValuePair("Set-Cookie", "cookie1=1;expires=Sun Jan 20 2042 17:45:00 GMT+0800 (CST)"));
responseHeader.add(new NameValuePair("Set-Cookie", "cookie2=2;expires=Sun Jan 20 2004 17:45:00 GMT+0800 (CST)"));
getMockWebConnection().setResponse(URL_FIRST, HTML_ALERT_COOKIE, 200, "OK", MimeType.TEXT_HTML, responseHeader);
loadPageWithAlerts2(URL_FIRST);
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.
the class CookieManagerTest method issue270.
/**
* Test for issue #270.
* @throws Exception in case of error
*
* This requires an entry in your hosts file
* 127.0.0.1 host1.htmlunit.org
*/
@Test
@Alerts("JDSessionID=1234567890")
public void issue270() throws Exception {
final List<NameValuePair> responseHeader1 = new ArrayList<>();
responseHeader1.add(new NameValuePair("Set-Cookie", "first=1; path=/c"));
final String html = "<html>\n" + "<head></head>\n" + "<body><script>\n" + "function setCookie(name, value, expires, path, domain, secure) {\n" + " var curCookie = name + '=' + escape(value) +\n" + " ((expires) ? '; expires=' + expires.toGMTString() : '') +\n" + " ((path) ? '; path=' + path : '') +\n" + " ((domain) ? '; domain=' + domain : '') +\n" + " ((secure) ? '; secure' : '');\n" + " document.cookie = curCookie;\n" + "}\n" + "var now = new Date();\n" + "now.setTime(now.getTime() + 60 * 60 * 1000);\n" + "setCookie('JDSessionID', '1234567890', now, '/', 'htmlunit.org');\n" + "</script></body>\n" + "</html>";
// [IE] real IE waits for the page to load until infinity
if (useRealBrowser() && getBrowserVersion().isIE()) {
Assert.fail("Blocks real IE");
}
final URL firstUrl = new URL("http://host1.htmlunit.org:" + PORT + "/");
getMockWebConnection().setResponse(firstUrl, html);
loadPage2(html, firstUrl);
loadPageWithAlerts2(HTML_ALERT_COOKIE, firstUrl);
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.
the class CookieManagerTest method setCookieExpires_twoDigits.
/**
* Two digits years should be interpreted as 20xx if before 1970 and as 19xx otherwise.
* @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_twoDigits() 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 orderFromServer.
/**
* @throws Exception if the test fails
*/
@Test
@Alerts("a_key=helloA; b_key=helloB; c_key=helloC")
public void orderFromServer() throws Exception {
final List<NameValuePair> responseHeader = new ArrayList<>();
responseHeader.add(new NameValuePair("Set-Cookie", "c_key=helloC"));
responseHeader.add(new NameValuePair("Set-Cookie", "a_key=helloA"));
responseHeader.add(new NameValuePair("Set-Cookie", "b_key=helloB"));
getMockWebConnection().setDefaultResponse(HTML_ALERT_COOKIE, 200, "OK", MimeType.TEXT_HTML, responseHeader);
loadPageWithAlerts2(URL_FIRST);
}
Aggregations