summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNarayan Kamath <narayan@google.com>2013-11-27 13:02:42 +0000
committerNarayan Kamath <narayan@google.com>2013-12-11 12:43:00 +0000
commitf25dfbd1b88a63029bcf391600f9d1a30c98be99 (patch)
treec0704dfb5a779510aa6b163d70b08719005140e4
parent510ffdf8d55fa65d9e9441974981a3ce9c2de7cf (diff)
downloadlibcore-f25dfbd1b88a63029bcf391600f9d1a30c98be99.zip
libcore-f25dfbd1b88a63029bcf391600f9d1a30c98be99.tar.gz
libcore-f25dfbd1b88a63029bcf391600f9d1a30c98be99.tar.bz2
Fix several issues in CookieManagerTest
- Fix a mistaken assumption about how path matching works. - Change a TreeMap to a LinkedHashMap, because TreeMaps are not required to support null keys. - Change a bogus "equals" check for the version to a startsWith check. - Change various tests re: the size of the output list. The specification doesn't require us to create separate Cookie headers for each cookie found in the store. It is free to concatenate the contents of matching cookies. - Change tests that expected the addition of an empty list to the headers map when there are no matching cookies. The spec does not require this. bug: 11689102 Change-Id: I341c301f18e410b983d010b5d2f14b3462901bf5
-rw-r--r--harmony-tests/src/test/java/org/apache/harmony/tests/java/net/CookieManagerTest.java24
1 files changed, 15 insertions, 9 deletions
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/CookieManagerTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/CookieManagerTest.java
index c96a407..d0c4ee1 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/CookieManagerTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/CookieManagerTest.java
@@ -25,6 +25,7 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
@@ -77,7 +78,7 @@ public class CookieManagerTest extends TestCase {
}
private static Map<String, List<String>> addCookie(String[][] cookies) {
- Map<String, List<String>> responseHeaders = new TreeMap<String, List<String>>();
+ Map<String, List<String>> responseHeaders = new LinkedHashMap<String, List<String>>();
for (int i = 0; i < cookies.length; i++) {
List<String> fields = new ArrayList<String>();
for (int j = 1; j < cookies[i].length; j += 2) {
@@ -103,8 +104,10 @@ public class CookieManagerTest extends TestCase {
}
/**
- * {@link java.net.CookieManager#get(java.net.URI, java.util.Map)} &
- * {@link java.net.CookieManager#put(java.net.URI, java.util.Map)}
+ * Unlike the RI, we flatten all matching cookies into a single Cookie header
+ * instead of sending down multiple cookie headers. Also, when no cookies match
+ * a given URI, we leave the requestHeaders unmodified.
+ *
* @since 1.6
*/
public void test_Put_Get_LURI_LMap() throws IOException, URISyntaxException {
@@ -151,7 +154,10 @@ public class CookieManagerTest extends TestCase {
// requires path of cookie is the prefix of uri
map = manager.get(new URI("http://a.b.c/te"), dummyMap);
list = map.get("Cookie");
- assertEquals(2, list.size());
+ assertEquals(1, list.size());
+ assertTrue(list.get(0).contains("PREF=test"));
+ // Cookies from "/test" should *not* match the URI "/te".
+ assertFalse(list.get(0).contains("NAME=VALUE"));
// If all cookies are of version 1, then $version=1 will be added
// ,no matter the value cookie-key
@@ -159,8 +165,8 @@ public class CookieManagerTest extends TestCase {
manager = store(new String[][] { cookies[2] }, responseHeaders, null);
map = manager.get(new URI("http://a.beg.com/test"), dummyMap);
list = map.get("Cookie");
- assertEquals("$Version=\"1\"", list.get(0));
- assertEquals(3, list.size());
+ assertEquals(1, list.size());
+ assertTrue(list.get(0).startsWith("$Version=\"1\""));
// cookie-key will not have effect on determining cookie version
responseHeaders = addCookie(new String[][] { cookies[3] });
@@ -177,7 +183,7 @@ public class CookieManagerTest extends TestCase {
CookiePolicy.ACCEPT_ALL);
map = manager.get(new URI("http://a.test.org/"), responseHeaders);
list = map.get("Cookie");
- assertEquals(0, list.size());
+ assertNull(list);
// All cookies will be rejected if policy == ACCEPT_NONE
responseHeaders = addCookie(new String[][] { cookies[3] });
@@ -185,13 +191,13 @@ public class CookieManagerTest extends TestCase {
CookiePolicy.ACCEPT_NONE);
map = manager.get(new URI("http://a.test.org/"), responseHeaders);
list = map.get("Cookie");
- assertEquals(0, list.size());
+ assertNull(list);
responseHeaders = addCookie(new String[][] { cookies[5] });
manager = store(new String[][] { cookies[5] }, responseHeaders,
CookiePolicy.ACCEPT_ALL);
list = map.get("Cookie");
- assertEquals(0, list.size());
+ assertNull(list);
try {
map.put(null, null);