Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: webkit/appcache/appcache_storage_unittest.cc

Issue 10915202: Cleanup: merge MockQuotaManager in multiple places (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. 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 "base/message_loop.h"
6 #include "testing/gtest/include/gtest/gtest.h" 6 #include "testing/gtest/include/gtest/gtest.h"
7 #include "webkit/appcache/appcache.h" 7 #include "webkit/appcache/appcache.h"
8 #include "webkit/appcache/appcache_group.h" 8 #include "webkit/appcache/appcache_group.h"
9 #include "webkit/appcache/appcache_response.h" 9 #include "webkit/appcache/appcache_response.h"
10 #include "webkit/appcache/appcache_storage.h" 10 #include "webkit/appcache/appcache_storage.h"
11 #include "webkit/appcache/mock_appcache_service.h" 11 #include "webkit/appcache/mock_appcache_service.h"
12 #include "webkit/quota/mock_quota_manager.h"
12 13
13 namespace appcache { 14 namespace appcache {
14 15
16 namespace {
17 const quota::StorageType kTemp = quota::kStorageTypeTemporary;
18 }
19
15 class AppCacheStorageTest : public testing::Test { 20 class AppCacheStorageTest : public testing::Test {
16 public: 21 public:
17 class MockStorageDelegate : public AppCacheStorage::Delegate { 22 class MockStorageDelegate : public AppCacheStorage::Delegate {
18 public: 23 public:
19 }; 24 };
20
21 class MockQuotaManagerProxy : public quota::QuotaManagerProxy {
22 public:
23 MockQuotaManagerProxy()
24 : QuotaManagerProxy(NULL, NULL),
25 notify_storage_accessed_count_(0),
26 notify_storage_modified_count_(0),
27 last_delta_(0) {
28 }
29
30 virtual void NotifyStorageAccessed(quota::QuotaClient::ID client_id,
31 const GURL& origin,
32 quota::StorageType type) OVERRIDE {
33 EXPECT_EQ(quota::QuotaClient::kAppcache, client_id);
34 EXPECT_EQ(quota::kStorageTypeTemporary, type);
35 ++notify_storage_accessed_count_;
36 last_origin_ = origin;
37 }
38
39 virtual void NotifyStorageModified(quota::QuotaClient::ID client_id,
40 const GURL& origin,
41 quota::StorageType type,
42 int64 delta) OVERRIDE {
43 EXPECT_EQ(quota::QuotaClient::kAppcache, client_id);
44 EXPECT_EQ(quota::kStorageTypeTemporary, type);
45 ++notify_storage_modified_count_;
46 last_origin_ = origin;
47 last_delta_ = delta;
48 }
49
50 // Not needed for our tests.
51 virtual void RegisterClient(quota::QuotaClient* client) OVERRIDE {}
52 virtual void NotifyOriginInUse(const GURL& origin) OVERRIDE {}
53 virtual void NotifyOriginNoLongerInUse(const GURL& origin) OVERRIDE {}
54
55 int notify_storage_accessed_count_;
56 int notify_storage_modified_count_;
57 GURL last_origin_;
58 int last_delta_;
59
60 protected:
61 virtual ~MockQuotaManagerProxy() {}
62 };
63 }; 25 };
64 26
65 TEST_F(AppCacheStorageTest, AddRemoveCache) { 27 TEST_F(AppCacheStorageTest, AddRemoveCache) {
66 MockAppCacheService service; 28 MockAppCacheService service;
67 scoped_refptr<AppCache> cache(new AppCache(&service, 111)); 29 scoped_refptr<AppCache> cache(new AppCache(&service, 111));
68 30
69 EXPECT_EQ(cache.get(), 31 EXPECT_EQ(cache.get(),
70 service.storage()->working_set()->GetCache(111)); 32 service.storage()->working_set()->GetCache(111));
71 33
72 service.storage()->working_set()->RemoveCache(cache); 34 service.storage()->working_set()->RemoveCache(cache);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 EXPECT_TRUE(delegate_reference2->HasOneRef()); 110 EXPECT_TRUE(delegate_reference2->HasOneRef());
149 EXPECT_EQ(&delegate, delegate_reference2->delegate); 111 EXPECT_EQ(&delegate, delegate_reference2->delegate);
150 EXPECT_NE(delegate_reference1.get(), delegate_reference2.get()); 112 EXPECT_NE(delegate_reference1.get(), delegate_reference2.get());
151 } 113 }
152 114
153 TEST_F(AppCacheStorageTest, UsageMap) { 115 TEST_F(AppCacheStorageTest, UsageMap) {
154 const GURL kOrigin("http://origin/"); 116 const GURL kOrigin("http://origin/");
155 const GURL kOrigin2("http://origin2/"); 117 const GURL kOrigin2("http://origin2/");
156 118
157 MockAppCacheService service; 119 MockAppCacheService service;
158 scoped_refptr<MockQuotaManagerProxy> mock_proxy(new MockQuotaManagerProxy); 120 scoped_refptr<quota::MockQuotaManagerProxy> mock_proxy(
121 new quota::MockQuotaManagerProxy(NULL, NULL));
159 service.set_quota_manager_proxy(mock_proxy); 122 service.set_quota_manager_proxy(mock_proxy);
160 123
161 service.storage()->UpdateUsageMapAndNotify(kOrigin, 0); 124 service.storage()->UpdateUsageMapAndNotify(kOrigin, 0);
162 EXPECT_EQ(0, mock_proxy->notify_storage_modified_count_); 125 EXPECT_EQ(0, mock_proxy->notify_storage_modified_count());
163 126
164 service.storage()->UpdateUsageMapAndNotify(kOrigin, 10); 127 service.storage()->UpdateUsageMapAndNotify(kOrigin, 10);
165 EXPECT_EQ(1, mock_proxy->notify_storage_modified_count_); 128 EXPECT_EQ(1, mock_proxy->notify_storage_modified_count());
166 EXPECT_EQ(10, mock_proxy->last_delta_); 129 EXPECT_EQ(10, mock_proxy->last_notified_delta());
167 EXPECT_EQ(kOrigin, mock_proxy->last_origin_); 130 EXPECT_EQ(kOrigin, mock_proxy->last_notified_origin());
131 EXPECT_EQ(kTemp, mock_proxy->last_notified_type());
168 132
169 service.storage()->UpdateUsageMapAndNotify(kOrigin, 100); 133 service.storage()->UpdateUsageMapAndNotify(kOrigin, 100);
170 EXPECT_EQ(2, mock_proxy->notify_storage_modified_count_); 134 EXPECT_EQ(2, mock_proxy->notify_storage_modified_count());
171 EXPECT_EQ(90, mock_proxy->last_delta_); 135 EXPECT_EQ(90, mock_proxy->last_notified_delta());
172 EXPECT_EQ(kOrigin, mock_proxy->last_origin_); 136 EXPECT_EQ(kOrigin, mock_proxy->last_notified_origin());
137 EXPECT_EQ(kTemp, mock_proxy->last_notified_type());
173 138
174 service.storage()->UpdateUsageMapAndNotify(kOrigin, 0); 139 service.storage()->UpdateUsageMapAndNotify(kOrigin, 0);
175 EXPECT_EQ(3, mock_proxy->notify_storage_modified_count_); 140 EXPECT_EQ(3, mock_proxy->notify_storage_modified_count());
176 EXPECT_EQ(-100, mock_proxy->last_delta_); 141 EXPECT_EQ(-100, mock_proxy->last_notified_delta());
177 EXPECT_EQ(kOrigin, mock_proxy->last_origin_); 142 EXPECT_EQ(kOrigin, mock_proxy->last_notified_origin());
143 EXPECT_EQ(kTemp, mock_proxy->last_notified_type());
178 144
179 service.storage()->NotifyStorageAccessed(kOrigin2); 145 service.storage()->NotifyStorageAccessed(kOrigin2);
180 EXPECT_EQ(0, mock_proxy->notify_storage_accessed_count_); 146 EXPECT_EQ(0, mock_proxy->notify_storage_accessed_count());
181 147
182 service.storage()->usage_map_[kOrigin2] = 1; 148 service.storage()->usage_map_[kOrigin2] = 1;
183 service.storage()->NotifyStorageAccessed(kOrigin2); 149 service.storage()->NotifyStorageAccessed(kOrigin2);
184 EXPECT_EQ(1, mock_proxy->notify_storage_accessed_count_); 150 EXPECT_EQ(1, mock_proxy->notify_storage_accessed_count());
185 EXPECT_EQ(kOrigin2, mock_proxy->last_origin_); 151 EXPECT_EQ(kOrigin2, mock_proxy->last_notified_origin());
152 EXPECT_EQ(kTemp, mock_proxy->last_notified_type());
186 153
187 service.storage()->usage_map_.clear(); 154 service.storage()->usage_map_.clear();
188 service.storage()->usage_map_[kOrigin] = 5000; 155 service.storage()->usage_map_[kOrigin] = 5000;
189 service.storage()->ClearUsageMapAndNotify(); 156 service.storage()->ClearUsageMapAndNotify();
190 EXPECT_EQ(4, mock_proxy->notify_storage_modified_count_); 157 EXPECT_EQ(4, mock_proxy->notify_storage_modified_count());
191 EXPECT_EQ(-5000, mock_proxy->last_delta_); 158 EXPECT_EQ(-5000, mock_proxy->last_notified_delta());
192 EXPECT_EQ(kOrigin, mock_proxy->last_origin_); 159 EXPECT_EQ(kOrigin, mock_proxy->last_notified_origin());
160 EXPECT_EQ(kTemp, mock_proxy->last_notified_type());
193 EXPECT_TRUE(service.storage()->usage_map_.empty()); 161 EXPECT_TRUE(service.storage()->usage_map_.empty());
194 } 162 }
195 163
196 } // namespace appcache 164 } // namespace appcache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698