diff options
author | Jesse Wilson <jessewilson@google.com> | 2012-02-15 16:52:01 -0500 |
---|---|---|
committer | Jesse Wilson <jessewilson@google.com> | 2012-02-15 16:53:57 -0500 |
commit | 18c227ba72406c0b69ce9925a80113060d870256 (patch) | |
tree | 2a4d680e4452361c7a74cc840629913a68321d84 /core/tests/coretests | |
parent | 71878402dd6fcf764875afaefdfa6dffc1f97e31 (diff) | |
download | frameworks_base-18c227ba72406c0b69ce9925a80113060d870256.zip frameworks_base-18c227ba72406c0b69ce9925a80113060d870256.tar.gz frameworks_base-18c227ba72406c0b69ce9925a80113060d870256.tar.bz2 |
Implement the (hidden) ExtendedResponseCache interface.
Bug: http://code.google.com/p/android/issues/detail?id=25418
Change-Id: I4b20d576bac7036f94e57db7124de44f5b8d75be
Diffstat (limited to 'core/tests/coretests')
-rw-r--r-- | core/tests/coretests/src/android/net/http/HttpResponseCacheTest.java | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/core/tests/coretests/src/android/net/http/HttpResponseCacheTest.java b/core/tests/coretests/src/android/net/http/HttpResponseCacheTest.java index 4d65588..9015a6f 100644 --- a/core/tests/coretests/src/android/net/http/HttpResponseCacheTest.java +++ b/core/tests/coretests/src/android/net/http/HttpResponseCacheTest.java @@ -16,6 +16,8 @@ package android.net.http; +import com.google.mockwebserver.MockResponse; +import com.google.mockwebserver.MockWebServer; import java.io.File; import java.net.CacheRequest; import java.net.CacheResponse; @@ -30,6 +32,7 @@ import junit.framework.TestCase; public final class HttpResponseCacheTest extends TestCase { private File cacheDir; + private MockWebServer server = new MockWebServer(); @Override public void setUp() throws Exception { super.setUp(); @@ -39,6 +42,7 @@ public final class HttpResponseCacheTest extends TestCase { @Override protected void tearDown() throws Exception { ResponseCache.setDefault(null); + server.shutdown(); super.tearDown(); } @@ -100,4 +104,32 @@ public final class HttpResponseCacheTest extends TestCase { cache.delete(); assertNull(ResponseCache.getDefault()); } + + /** + * Make sure that statistics tracking are wired all the way through the + * wrapper class. http://code.google.com/p/android/issues/detail?id=25418 + */ + public void testStatisticsTracking() throws Exception { + HttpResponseCache cache = HttpResponseCache.install(cacheDir, 10 * 1024 * 1024); + + server.enqueue(new MockResponse() + .addHeader("Cache-Control: max-age=60") + .setBody("A")); + server.play(); + + URLConnection c1 = server.getUrl("/").openConnection(); + assertEquals('A', c1.getInputStream().read()); + assertEquals(1, cache.getRequestCount()); + assertEquals(1, cache.getNetworkCount()); + assertEquals(0, cache.getHitCount()); + + URLConnection c2 = server.getUrl("/").openConnection(); + assertEquals('A', c2.getInputStream().read()); + + URLConnection c3 = server.getUrl("/").openConnection(); + assertEquals('A', c3.getInputStream().read()); + assertEquals(3, cache.getRequestCount()); + assertEquals(1, cache.getNetworkCount()); + assertEquals(2, cache.getHitCount()); + } } |