Fixes for tests in libcore.java.net.CookiesTest
Fixed InMemoryCookieStore#remove to verify cookie URI before removal
Fixed InMemoryCookieStore#removeAll to return false is it's empty.
Added cookie/url path verification in CookieManager#put.
Change-Id: If7d593ea6209d8da8660224a44187ee1ca070573
diff --git a/ojluni/src/main/java/java/net/CookieManager.java b/ojluni/src/main/java/java/net/CookieManager.java
index 532999b..85df889 100755
--- a/ojluni/src/main/java/java/net/CookieManager.java
+++ b/ojluni/src/main/java/java/net/CookieManager.java
@@ -303,7 +303,15 @@
}
}
cookie.setPath(path);
+ /* ----- BEGIN android -----
+ Added path validation code */
+ } else {
+ // Validate existing path
+ if (!pathMatches(uri.getPath(), cookie.getPath())) {
+ continue;
+ }
}
+ /* ----- END android ----- */
// As per RFC 2965, section 3.3.1:
// Domain Defaults to the effective request-host. (Note that because
diff --git a/ojluni/src/main/java/java/net/InMemoryCookieStore.java b/ojluni/src/main/java/java/net/InMemoryCookieStore.java
index e885cdd..217dc5f 100755
--- a/ojluni/src/main/java/java/net/InMemoryCookieStore.java
+++ b/ojluni/src/main/java/java/net/InMemoryCookieStore.java
@@ -192,7 +192,14 @@
boolean modified = false;
lock.lock();
try {
- modified = cookieJar.remove(ck);
+ /* ----- BEGIN android -----
+ Added uri check */
+ if (uri != null && uriIndex.get(uri) == null) {
+ modified = false;
+ } else {
+ /* ----- END android ----- */
+ modified = cookieJar.remove(ck);
+ }
} finally {
lock.unlock();
}
@@ -206,7 +213,12 @@
*/
public boolean removeAll() {
lock.lock();
+ /* ----- BEGIN android -----
+ // Added result var */
+ boolean result = false;
+
try {
+ result = !cookieJar.isEmpty();
cookieJar.clear();
domainIndex.clear();
uriIndex.clear();
@@ -214,7 +226,7 @@
lock.unlock();
}
- return true;
+ return result;
}