OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authos. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authos. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
| 5 #include "base/message_loop.h" |
5 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
6 #include "webkit/appcache/appcache.h" | 7 #include "webkit/appcache/appcache.h" |
7 #include "webkit/appcache/appcache_group.h" | 8 #include "webkit/appcache/appcache_group.h" |
| 9 #include "webkit/appcache/appcache_response.h" |
8 #include "webkit/appcache/appcache_storage.h" | 10 #include "webkit/appcache/appcache_storage.h" |
9 #include "webkit/appcache/appcache_response.h" | |
10 #include "webkit/appcache/mock_appcache_service.h" | 11 #include "webkit/appcache/mock_appcache_service.h" |
11 | 12 |
12 namespace appcache { | 13 namespace appcache { |
13 | 14 |
14 class AppCacheStorageTest : public testing::Test { | 15 class AppCacheStorageTest : public testing::Test { |
| 16 public: |
| 17 class MockStorageDelegate : public AppCacheStorage::Delegate { |
| 18 public: |
| 19 }; |
15 }; | 20 }; |
16 | 21 |
17 TEST(AppCacheStorageTest, AddRemoveCache) { | 22 TEST_F(AppCacheStorageTest, AddRemoveCache) { |
18 MockAppCacheService service; | 23 MockAppCacheService service; |
19 scoped_refptr<AppCache> cache = new AppCache(&service, 111); | 24 scoped_refptr<AppCache> cache = new AppCache(&service, 111); |
20 | 25 |
21 EXPECT_EQ(cache.get(), | 26 EXPECT_EQ(cache.get(), |
22 service.storage()->working_set()->GetCache(111)); | 27 service.storage()->working_set()->GetCache(111)); |
23 | 28 |
24 service.storage()->working_set()->RemoveCache(cache); | 29 service.storage()->working_set()->RemoveCache(cache); |
25 | 30 |
26 EXPECT_TRUE(!service.storage()->working_set()->GetCache(111)); | 31 EXPECT_TRUE(!service.storage()->working_set()->GetCache(111)); |
27 | 32 |
28 // Removing non-existing cache from service should not fail. | 33 // Removing non-existing cache from service should not fail. |
29 MockAppCacheService dummy; | 34 MockAppCacheService dummy; |
30 dummy.storage()->working_set()->RemoveCache(cache); | 35 dummy.storage()->working_set()->RemoveCache(cache); |
31 } | 36 } |
32 | 37 |
33 TEST(AppCacheStorageTest, AddRemoveGroup) { | 38 TEST_F(AppCacheStorageTest, AddRemoveGroup) { |
34 MockAppCacheService service; | 39 MockAppCacheService service; |
35 scoped_refptr<AppCacheGroup> group = | 40 scoped_refptr<AppCacheGroup> group = |
36 new AppCacheGroup(&service, GURL::EmptyGURL()); | 41 new AppCacheGroup(&service, GURL::EmptyGURL()); |
37 | 42 |
38 EXPECT_EQ(group.get(), | 43 EXPECT_EQ(group.get(), |
39 service.storage()->working_set()->GetGroup(GURL::EmptyGURL())); | 44 service.storage()->working_set()->GetGroup(GURL::EmptyGURL())); |
40 | 45 |
41 service.storage()->working_set()->RemoveGroup(group); | 46 service.storage()->working_set()->RemoveGroup(group); |
42 | 47 |
43 EXPECT_TRUE(!service.storage()->working_set()->GetGroup(GURL::EmptyGURL())); | 48 EXPECT_TRUE(!service.storage()->working_set()->GetGroup(GURL::EmptyGURL())); |
44 | 49 |
45 // Removing non-existing group from service should not fail. | 50 // Removing non-existing group from service should not fail. |
46 MockAppCacheService dummy; | 51 MockAppCacheService dummy; |
47 dummy.storage()->working_set()->RemoveGroup(group); | 52 dummy.storage()->working_set()->RemoveGroup(group); |
48 } | 53 } |
49 | 54 |
50 TEST(AppCacheStorageTest, AddRemoveResponseInfo) { | 55 TEST_F(AppCacheStorageTest, AddRemoveResponseInfo) { |
51 MockAppCacheService service; | 56 MockAppCacheService service; |
52 scoped_refptr<AppCacheResponseInfo> info = | 57 scoped_refptr<AppCacheResponseInfo> info = |
53 new AppCacheResponseInfo(&service, 111, new net::HttpResponseInfo); | 58 new AppCacheResponseInfo(&service, 111, new net::HttpResponseInfo); |
54 | 59 |
55 EXPECT_EQ(info.get(), | 60 EXPECT_EQ(info.get(), |
56 service.storage()->working_set()->GetResponseInfo(111)); | 61 service.storage()->working_set()->GetResponseInfo(111)); |
57 | 62 |
58 service.storage()->working_set()->RemoveResponseInfo(info); | 63 service.storage()->working_set()->RemoveResponseInfo(info); |
59 | 64 |
60 EXPECT_TRUE(!service.storage()->working_set()->GetResponseInfo(111)); | 65 EXPECT_TRUE(!service.storage()->working_set()->GetResponseInfo(111)); |
61 | 66 |
62 // Removing non-existing info from service should not fail. | 67 // Removing non-existing info from service should not fail. |
63 MockAppCacheService dummy; | 68 MockAppCacheService dummy; |
64 dummy.storage()->working_set()->RemoveResponseInfo(info); | 69 dummy.storage()->working_set()->RemoveResponseInfo(info); |
65 } | 70 } |
66 | 71 |
| 72 TEST_F(AppCacheStorageTest, DelegateReferences) { |
| 73 typedef scoped_refptr<AppCacheStorage::DelegateReference> |
| 74 ScopedDelegateReference; |
| 75 MockAppCacheService service; |
| 76 MockStorageDelegate delegate; |
| 77 ScopedDelegateReference delegate_reference1; |
| 78 ScopedDelegateReference delegate_reference2; |
| 79 |
| 80 EXPECT_FALSE(service.storage()->GetDelegateReference(&delegate)); |
| 81 |
| 82 delegate_reference1 = |
| 83 service.storage()->GetOrCreateDelegateReference(&delegate); |
| 84 EXPECT_TRUE(delegate_reference1.get()); |
| 85 EXPECT_TRUE(delegate_reference1->HasOneRef()); |
| 86 EXPECT_TRUE(service.storage()->GetDelegateReference(&delegate)); |
| 87 EXPECT_EQ(&delegate, |
| 88 service.storage()->GetDelegateReference(&delegate)->delegate); |
| 89 EXPECT_EQ(service.storage()->GetDelegateReference(&delegate), |
| 90 service.storage()->GetOrCreateDelegateReference(&delegate)); |
| 91 delegate_reference1 = NULL; |
| 92 EXPECT_FALSE(service.storage()->GetDelegateReference(&delegate)); |
| 93 |
| 94 delegate_reference1 = |
| 95 service.storage()->GetOrCreateDelegateReference(&delegate); |
| 96 service.storage()->CancelDelegateCallbacks(&delegate); |
| 97 EXPECT_TRUE(delegate_reference1.get()); |
| 98 EXPECT_TRUE(delegate_reference1->HasOneRef()); |
| 99 EXPECT_FALSE(delegate_reference1->delegate); |
| 100 EXPECT_FALSE(service.storage()->GetDelegateReference(&delegate)); |
| 101 |
| 102 delegate_reference2 = |
| 103 service.storage()->GetOrCreateDelegateReference(&delegate); |
| 104 EXPECT_TRUE(delegate_reference2.get()); |
| 105 EXPECT_TRUE(delegate_reference2->HasOneRef()); |
| 106 EXPECT_EQ(&delegate, delegate_reference2->delegate); |
| 107 EXPECT_NE(delegate_reference1.get(), delegate_reference2.get()); |
| 108 } |
| 109 |
67 } // namespace appcache | 110 } // namespace appcache |
OLD | NEW |