Index: webkit/appcache/appcache_storage_unittest.cc |
=================================================================== |
--- webkit/appcache/appcache_storage_unittest.cc (revision 29670) |
+++ webkit/appcache/appcache_storage_unittest.cc (working copy) |
@@ -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_response.h" |
#include "webkit/appcache/appcache_storage.h" |
-#include "webkit/appcache/appcache_response.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 @@ |
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 @@ |
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 @@ |
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 |