use of java.net.CookieManager in project j2objc by google.
the class CookiesTest method testNetscapeResponse.
public void testNetscapeResponse() throws Exception {
CookieManager cookieManager = new CookieManager(null, ACCEPT_ORIGINAL_SERVER);
CookieHandler.setDefault(cookieManager);
MockWebServer server = new MockWebServer();
server.play();
server.enqueue(new MockResponse().addHeader("Set-Cookie: a=android; " + "expires=Fri, 31-Dec-9999 23:59:59 GMT; " + "path=/path; " + "domain=" + server.getCookieDomain() + "; " + "secure"));
get(server, "/path/foo");
List<HttpCookie> cookies = cookieManager.getCookieStore().getCookies();
assertEquals(1, cookies.size());
HttpCookie cookie = cookies.get(0);
assertEquals("a", cookie.getName());
assertEquals("android", cookie.getValue());
assertEquals(null, cookie.getComment());
assertEquals(null, cookie.getCommentURL());
assertEquals(false, cookie.getDiscard());
assertEquals(server.getCookieDomain(), cookie.getDomain());
assertTrue(cookie.getMaxAge() > 100000000000L);
assertEquals("/path", cookie.getPath());
assertEquals(true, cookie.getSecure());
assertEquals(0, cookie.getVersion());
}
use of java.net.CookieManager in project j2objc by google.
the class CookiesTest method testCookieStoreNullUris.
public void testCookieStoreNullUris() {
CookieStore cookieStore = new CookieManager().getCookieStore();
HttpCookie cookieA = createCookie("a", "android", ".android.com", "/source");
HttpCookie cookieB = createCookie("b", "banana", "code.google.com", "/p/android");
try {
cookieStore.add(null, cookieA);
} catch (NullPointerException expected) {
// the RI crashes even though the cookie does get added to the store; sigh
expected.printStackTrace();
}
assertEquals(Arrays.asList(cookieA), cookieStore.getCookies());
try {
cookieStore.add(null, cookieB);
} catch (NullPointerException expected) {
}
assertEquals(Arrays.asList(cookieA, cookieB), cookieStore.getCookies());
try {
cookieStore.get(null);
fail();
} catch (NullPointerException expected) {
}
assertEquals(Collections.<URI>emptyList(), cookieStore.getURIs());
assertTrue(cookieStore.remove(null, cookieA));
assertEquals(Arrays.asList(cookieB), cookieStore.getCookies());
assertTrue(cookieStore.removeAll());
assertEquals(Collections.<URI>emptyList(), cookieStore.getURIs());
assertEquals(Collections.<HttpCookie>emptyList(), cookieStore.getCookies());
}
use of java.net.CookieManager in project j2objc by google.
the class CookiesTest method testPathDefaulting.
public void testPathDefaulting() 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"));
assertEquals("/foo/", cookieStore.getCookie("a").getPath());
cookieManager.put(new URI("http://android.com/"), cookieHeaders("b=banana"));
assertEquals("/", cookieStore.getCookie("b").getPath());
cookieManager.put(new URI("http://android.com/foo/"), cookieHeaders("c=carrot"));
assertEquals("/foo/", cookieStore.getCookie("c").getPath());
}
use of java.net.CookieManager in project j2objc by google.
the class CookiesTest method testCookieManagerGet_schemeChecks.
public void testCookieManagerGet_schemeChecks() throws Exception {
CookieManager cookieManager = new CookieManager();
cookieManager.put(new URI("http://a.com/"), cookieHeaders("a1=android"));
cookieManager.put(new URI("https://a.com/"), cookieHeaders("a2=android"));
cookieManager.put(new URI("https://a.com/"), cookieHeaders("a3=android; Secure"));
assertManagerCookiesMatch(cookieManager, "http://a.com/", "a1=android; a2=android");
assertManagerCookiesMatch(cookieManager, "https://a.com/", "a1=android; a2=android; a3=android");
}
use of java.net.CookieManager in project j2objc by google.
the class CookiesTest method testMatchingDomainsAccepted.
public void testMatchingDomainsAccepted() throws Exception {
TestCookieStore cookieStore = new TestCookieStore();
CookieManager cookieManager = new CookieManager(cookieStore, ACCEPT_ORIGINAL_SERVER);
cookieManager.put(new URI("http://www.android.com/"), cookieHeaders("a=android;domain=.android.com"));
assertEquals(".android.com", cookieStore.getCookie("a").getDomain());
}
Aggregations