use of java.net.CookieManager in project j2objc by google.
the class CookiesTest method testCookieStoreGetWithSecure.
// TODO(tball): enable when libcore is updated with latest fixes.
/**
* Regression test for http://b/25682357 /
* https://code.google.com/p/android/issues/detail?id=193475
* CookieStoreImpl.get(URI) not handling ports properly in the absence of an explicit cookie
* Domain.
*
public void testCookieStoreGetWithPort() throws Exception {
CookieStore cookieStore = new CookieManager().getCookieStore();
HttpCookie cookie = new HttpCookie("theme", "light");
// Deliberately not setting the cookie domain or path.
cookieStore.add(new URI("http://a.com:12345"), cookie);
// CookieStoreImpl must ignore the port during retrieval when domain is not set.
assertEquals(1, cookieStore.get(new URI("http://a.com:12345/path1")).size());
assertEquals(1, cookieStore.get(new URI("http://a.com/path1")).size());
}
*/
public void testCookieStoreGetWithSecure() throws Exception {
CookieStore cookieStore = new CookieManager().getCookieStore();
HttpCookie cookie = createCookie("theme", "light", "a.com", "/path");
cookie.setSecure(true);
cookieStore.add(new URI("https://a.com/path"), cookie);
// CookieStoreImpl on Android ignores the "Secure" attribute. The RI implements the secure
// check in CookieStoreImpl. For safety / app compatibility, if this is changed Android
// should probably implement it in both places.
assertEquals(1, cookieStore.get(new URI("http://a.com/path")).size());
assertEquals(1, cookieStore.get(new URI("https://a.com/path")).size());
}
use of java.net.CookieManager in project j2objc by google.
the class CookiesTest method testCookieStoreEviction.
public void testCookieStoreEviction() throws Exception {
CookieStore cookieStore = new CookieManager().getCookieStore();
HttpCookie themeCookie = createCookie("theme", "light", "a.com", "/");
cookieStore.add(new URI("http://a.com/"), themeCookie);
HttpCookie sidCookie = createCookie("sid", "mysid", "a.com", "/");
cookieStore.add(new URI("http://a.com/"), sidCookie);
HttpCookie replacementThemeCookie = createCookie("theme", "dark", "a.com", "/");
cookieStore.add(new URI("http://a.com/"), replacementThemeCookie);
// toString() is used below to avoid confusion with assertEquals():
// HttpCookie.equals() is implemented so that it only checks name, path and domain
// attributes but we also want to check the value.
assertEquals("[sid=\"mysid\";$Path=\"/\";$Domain=\"a.com\", " + "theme=\"dark\";$Path=\"/\";$Domain=\"a.com\"]", cookieStore.get(new URI("http://a.com/")).toString());
HttpCookie replacementSidCookie = createCookie("sid", "mynewsid", "A.cOm", "/");
cookieStore.add(new URI("http://a.com/"), replacementSidCookie);
assertEquals("[theme=\"dark\";$Path=\"/\";$Domain=\"a.com\", " + "sid=\"mynewsid\";$Path=\"/\";$Domain=\"a.com\"]", cookieStore.get(new URI("http://a.com/")).toString());
}
use of java.net.CookieManager in project j2objc by google.
the class CookiesTest method testCookieStoreRemoveRequiresUri.
public void testCookieStoreRemoveRequiresUri() throws URISyntaxException {
CookieStore cookieStore = new CookieManager().getCookieStore();
HttpCookie cookieA = new HttpCookie("a", "android");
cookieStore.add(new URI("http://android.com/source/"), cookieA);
assertFalse(// RI6 fails this
"Expected remove() to take the cookie URI into account.", cookieStore.remove(new URI("http://code.google.com/"), cookieA));
assertEquals(Arrays.asList(cookieA), cookieStore.getCookies());
}
use of java.net.CookieManager in project j2objc by google.
the class CookiesTest method testNonMatchingPathsRejected.
public void testNonMatchingPathsRejected() throws Exception {
TestCookieStore cookieStore = new TestCookieStore();
CookieManager cookieManager = new CookieManager(cookieStore, ACCEPT_ORIGINAL_SERVER);
cookieManager.put(new URI("http://android.com/foo/bar"), cookieHeaders("a=android;path=/baz/bar"));
assertEquals("Expected to reject cookies whose path is not a prefix of the request path", Collections.<HttpCookie>emptyList(), // RI6 fails this
cookieStore.cookies);
}
use of java.net.CookieManager in project j2objc by google.
the class CookiesTest method testCookieManagerGet_hostChecks.
public void testCookieManagerGet_hostChecks() throws Exception {
CookieManager cookieManager = new CookieManager();
cookieManager.put(new URI("http://a.com/"), cookieHeaders("a1=android"));
cookieManager.put(new URI("http://b.com/"), cookieHeaders("b1=android"));
assertManagerCookiesMatch(cookieManager, "http://a.com/", "a1=android");
assertManagerCookiesMatch(cookieManager, "http://b.com/", "b1=android");
}
Aggregations