use of java.net.CookieManager in project j2objc by google.
the class CookiesTest method testCookieStoreUriDropsFragment.
public void testCookieStoreUriDropsFragment() throws URISyntaxException {
CookieStore cookieStore = new CookieManager().getCookieStore();
cookieStore.add(new URI("http://a.com/a/foo#fragment"), new HttpCookie("a", "android"));
assertEquals(Arrays.asList(new URI("http://a.com")), cookieStore.getURIs());
}
use of java.net.CookieManager in project j2objc by google.
the class CookiesTest method testNoCookieHeaderSentIfNoCookiesMatch.
public void testNoCookieHeaderSentIfNoCookiesMatch() throws IOException, URISyntaxException {
CookieManager cookieManager = new CookieManager(null, ACCEPT_ORIGINAL_SERVER);
Map<String, List<String>> cookieHeaders = cookieManager.get(new URI("http://android.com/foo/bar/"), EMPTY_COOKIES_MAP);
assertTrue(cookieHeaders.toString(), cookieHeaders.isEmpty() || (cookieHeaders.size() == 1 && cookieHeaders.get("Cookie").isEmpty()));
}
use of java.net.CookieManager in project j2objc by google.
the class CookiesTest method testMatchingPathsAccepted.
public void testMatchingPathsAccepted() 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=/foo"));
assertEquals("/foo", cookieStore.getCookie("a").getPath());
}
use of java.net.CookieManager in project j2objc by google.
the class CookiesTest method testResponseWithMultipleCookieHeaderLines.
public void testResponseWithMultipleCookieHeaderLines() throws Exception {
TestCookieStore cookieStore = new TestCookieStore();
CookieManager cookieManager = new CookieManager(cookieStore, ACCEPT_ORIGINAL_SERVER);
cookieManager.put(new URI("http://android.com"), cookieHeaders("a=android", "b=banana"));
List<HttpCookie> cookies = sortedCopy(cookieStore.cookies);
assertEquals(2, cookies.size());
HttpCookie cookieA = cookies.get(0);
assertEquals("a", cookieA.getName());
assertEquals("android", cookieA.getValue());
HttpCookie cookieB = cookies.get(1);
assertEquals("b", cookieB.getName());
assertEquals("banana", cookieB.getValue());
}
use of java.net.CookieManager in project j2objc by google.
the class CookiesTest method testCookieStoreGet.
public void testCookieStoreGet() throws Exception {
CookieStore cookieStore = new CookieManager().getCookieStore();
HttpCookie cookiePort1 = createCookie("a1", "android", "a.com", "/path1");
HttpCookie cookiePort2 = createCookie("a2", "android", "a.com", "/path2");
HttpCookie secureCookie = createCookie("a3", "android", "a.com", "/path3");
secureCookie.setSecure(true);
HttpCookie notSecureCookie = createCookie("a4", "android", "a.com", "/path4");
HttpCookie bCookie = createCookie("b1", "android", "b.com", "/path5");
cookieStore.add(new URI("http://a.com:443/path1"), cookiePort1);
cookieStore.add(new URI("http://a.com:8080/path2"), cookiePort2);
cookieStore.add(new URI("https://a.com:443/path3"), secureCookie);
cookieStore.add(new URI("https://a.com:443/path4"), notSecureCookie);
cookieStore.add(new URI("https://b.com:8080/path5"), bCookie);
List<HttpCookie> expectedStoreCookies = new ArrayList<>();
expectedStoreCookies.add(cookiePort1);
expectedStoreCookies.add(cookiePort2);
expectedStoreCookies.add(secureCookie);
expectedStoreCookies.add(notSecureCookie);
// The default CookieStore implementation on Android is currently responsible for matching
// the host/domain but not handling other cookie rules: it ignores the scheme (e.g. "secure"
// checks), port and path.
// The tests below fail on the RI. It looks like in the RI it is CookieStoreImpl that is
// enforcing "secure" checks.
assertEquals(expectedStoreCookies, cookieStore.get(new URI("http://a.com:443/anypath")));
assertEquals(expectedStoreCookies, cookieStore.get(new URI("http://a.com:8080/anypath")));
assertEquals(expectedStoreCookies, cookieStore.get(new URI("https://a.com/anypath")));
assertEquals(expectedStoreCookies, cookieStore.get(new URI("http://a.com/anypath")));
}
Aggregations