summaryrefslogtreecommitdiffstats
path: root/webkit/appcache/appcache_storage_unittest.cc
diff options
context:
space:
mode:
authormichaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-24 21:42:25 +0000
committermichaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-24 21:42:25 +0000
commit550890ec7f1cf968abc4544b170e97a67f919902 (patch)
tree632dec32bed5266837a2668a9225d303303e3160 /webkit/appcache/appcache_storage_unittest.cc
parented249ab7916d438b0bdb650a796aaf709f6ae1ae (diff)
downloadchromium_src-550890ec7f1cf968abc4544b170e97a67f919902.zip
chromium_src-550890ec7f1cf968abc4544b170e97a67f919902.tar.gz
chromium_src-550890ec7f1cf968abc4544b170e97a67f919902.tar.bz2
MockAppCacheStorage implemention
This is a quick and easy 'mock' implementation of the storage interface that doesn't put anything to disk. We simply add an extra reference to objects when they're put in storage, and remove the extra reference when they are removed from storage. Responses are never really removed from the in-memory disk cache. Delegate callbacks are made asyncly to appropiately mimic what will happen with a real disk-backed storage impl that involves IO on a background thread. This is for use in unit tests and to initially bring up the appcache related layout tests. TEST=mock_appcache_storage_unittest.cc BUG=none Review URL: http://codereview.chromium.org/300043 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30017 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/appcache/appcache_storage_unittest.cc')
-rw-r--r--webkit/appcache/appcache_storage_unittest.cc51
1 files changed, 47 insertions, 4 deletions
diff --git a/webkit/appcache/appcache_storage_unittest.cc b/webkit/appcache/appcache_storage_unittest.cc
index 6e06265..7025e75 100644
--- a/webkit/appcache/appcache_storage_unittest.cc
+++ b/webkit/appcache/appcache_storage_unittest.cc
@@ -2,19 +2,24 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/message_loop.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "webkit/appcache/appcache.h"
#include "webkit/appcache/appcache_group.h"
-#include "webkit/appcache/appcache_storage.h"
#include "webkit/appcache/appcache_response.h"
+#include "webkit/appcache/appcache_storage.h"
#include "webkit/appcache/mock_appcache_service.h"
namespace appcache {
class AppCacheStorageTest : public testing::Test {
+ public:
+ class MockStorageDelegate : public AppCacheStorage::Delegate {
+ public:
+ };
};
-TEST(AppCacheStorageTest, AddRemoveCache) {
+TEST_F(AppCacheStorageTest, AddRemoveCache) {
MockAppCacheService service;
scoped_refptr<AppCache> cache = new AppCache(&service, 111);
@@ -30,7 +35,7 @@ TEST(AppCacheStorageTest, AddRemoveCache) {
dummy.storage()->working_set()->RemoveCache(cache);
}
-TEST(AppCacheStorageTest, AddRemoveGroup) {
+TEST_F(AppCacheStorageTest, AddRemoveGroup) {
MockAppCacheService service;
scoped_refptr<AppCacheGroup> group =
new AppCacheGroup(&service, GURL::EmptyGURL());
@@ -47,7 +52,7 @@ TEST(AppCacheStorageTest, AddRemoveGroup) {
dummy.storage()->working_set()->RemoveGroup(group);
}
-TEST(AppCacheStorageTest, AddRemoveResponseInfo) {
+TEST_F(AppCacheStorageTest, AddRemoveResponseInfo) {
MockAppCacheService service;
scoped_refptr<AppCacheResponseInfo> info =
new AppCacheResponseInfo(&service, 111, new net::HttpResponseInfo);
@@ -64,4 +69,42 @@ TEST(AppCacheStorageTest, AddRemoveResponseInfo) {
dummy.storage()->working_set()->RemoveResponseInfo(info);
}
+TEST_F(AppCacheStorageTest, DelegateReferences) {
+ typedef scoped_refptr<AppCacheStorage::DelegateReference>
+ ScopedDelegateReference;
+ MockAppCacheService service;
+ MockStorageDelegate delegate;
+ ScopedDelegateReference delegate_reference1;
+ ScopedDelegateReference delegate_reference2;
+
+ EXPECT_FALSE(service.storage()->GetDelegateReference(&delegate));
+
+ delegate_reference1 =
+ service.storage()->GetOrCreateDelegateReference(&delegate);
+ EXPECT_TRUE(delegate_reference1.get());
+ EXPECT_TRUE(delegate_reference1->HasOneRef());
+ EXPECT_TRUE(service.storage()->GetDelegateReference(&delegate));
+ EXPECT_EQ(&delegate,
+ service.storage()->GetDelegateReference(&delegate)->delegate);
+ EXPECT_EQ(service.storage()->GetDelegateReference(&delegate),
+ service.storage()->GetOrCreateDelegateReference(&delegate));
+ delegate_reference1 = NULL;
+ EXPECT_FALSE(service.storage()->GetDelegateReference(&delegate));
+
+ delegate_reference1 =
+ service.storage()->GetOrCreateDelegateReference(&delegate);
+ service.storage()->CancelDelegateCallbacks(&delegate);
+ EXPECT_TRUE(delegate_reference1.get());
+ EXPECT_TRUE(delegate_reference1->HasOneRef());
+ EXPECT_FALSE(delegate_reference1->delegate);
+ EXPECT_FALSE(service.storage()->GetDelegateReference(&delegate));
+
+ delegate_reference2 =
+ service.storage()->GetOrCreateDelegateReference(&delegate);
+ EXPECT_TRUE(delegate_reference2.get());
+ EXPECT_TRUE(delegate_reference2->HasOneRef());
+ EXPECT_EQ(&delegate, delegate_reference2->delegate);
+ EXPECT_NE(delegate_reference1.get(), delegate_reference2.get());
+}
+
} // namespace appcache