From: <rb...@us...> - 2014-03-29 17:53:27
|
Revision: 9213 http://sourceforge.net/p/htmlunit/code/9213 Author: rbri Date: 2014-03-29 17:53:22 +0000 (Sat, 29 Mar 2014) Log Message: ----------- cleanup and one more test Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/CookieManager.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CookieManagerTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/CookieManager.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/CookieManager.java 2014-03-29 13:04:54 UTC (rev 9212) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/CookieManager.java 2014-03-29 17:53:22 UTC (rev 9213) @@ -27,7 +27,6 @@ import org.apache.commons.collections.set.ListOrderedSet; import org.apache.commons.lang3.StringUtils; -import org.apache.http.client.config.CookieSpecs; import org.apache.http.cookie.CookieOrigin; import org.apache.http.cookie.CookieSpec; import org.apache.http.impl.cookie.BrowserCompatSpecFactory; @@ -48,13 +47,6 @@ */ public class CookieManager implements Serializable { - /** - * HtmlUnit's cookie policy is to be browser-compatible. Code which requires access to - * HtmlUnit's cookie policy should use this constant, rather than making assumptions and using - * one of the HttpClient {@link CookieSpecs} constants directly. - */ - public static final String HTMLUNIT_COOKIE_POLICY = CookieSpecs.BROWSER_COMPATIBILITY; - /** Whether or not cookies are enabled. */ private boolean cookiesEnabled_; @@ -113,16 +105,16 @@ } final String host = url.getHost(); - final String path = url.getPath(); - final String protocol = url.getProtocol(); - final boolean secure = "https".equals(protocol); - // URLs like "about:blank" don't have cookies and we need to catch these // cases here before HttpClient complains if (host.isEmpty()) { return Collections.emptySet(); } + final String path = url.getPath(); + final String protocol = url.getProtocol(); + final boolean secure = "https".equals(protocol); + final int port = getPort(url); // discard expired cookies Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CookieManagerTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CookieManagerTest.java 2014-03-29 13:04:54 UTC (rev 9212) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CookieManagerTest.java 2014-03-29 17:53:22 UTC (rev 9213) @@ -23,6 +23,7 @@ import java.util.Map; import org.apache.http.Header; +import org.apache.http.client.utils.DateUtils; import org.apache.http.cookie.CookieOrigin; import org.apache.http.impl.cookie.BrowserCompatSpec; import org.apache.http.message.BasicHeader; @@ -51,7 +52,7 @@ @RunWith(BrowserRunner.class) public class CookieManagerTest extends WebDriverTestCase { /** HTML code with JS code <code>alert(document.cookie)</code>. */ - public static final String HTML_ALERT_COOKIE = "<html><head><script>\nalert(document.cookie);\n</script>" + public static final String HTML_ALERT_COOKIE = "<html><head><script>\nalert(document.cookie);\n</script></head>" + "<body></body></html>"; /** @@ -483,7 +484,41 @@ loadPageWithAlerts2(firstUrl); } + /** + * Test for document.cookie for cookies expiered after the page was loaded. + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = {"cookies: first=1", "cookies: " }) + public void setCookieTimeout() throws Exception { + final List<NameValuePair> responseHeader1 = new ArrayList<NameValuePair>(); + final String expires = DateUtils.formatDate(new Date(System.currentTimeMillis() + 10000)); + responseHeader1.add(new NameValuePair("Set-Cookie", "first=1; expires=" + expires + "; path=/foo")); + responseHeader1.add(new NameValuePair("Location", "/foo/content.html")); + final String html = "<html>\n" + + "<head>\n" + + "<script>\n" + + " function alertCookies() {\n" + + " alert('cookies: ' + document.cookie);\n" + + " }\n" + + "</script>" + + "</head>\n" + + "<body>\n" + + "<script>\n" + + " alertCookies();\n" + + " window.setTimeout(alertCookies, 11000);\n" + + "</script>" + + "</body>\n" + + "</html>"; + + getMockWebConnection().setDefaultResponse(html); + final URL firstUrl = new URL(getDefaultUrl(), "/foo/test.html"); + getMockWebConnection().setResponse(firstUrl, "", 302, "Moved", "text/html", responseHeader1); + + loadPageWithAlerts2(firstUrl, 25000); + } + /** * HttpOnly cookies should not be available from JS. * @throws Exception if the test fails |