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

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

Issue 7031065: AppCache + Quota integration (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 12
13 namespace appcache { 13 namespace appcache {
14 14
15 class AppCacheStorageTest : public testing::Test { 15 class AppCacheStorageTest : public testing::Test {
16 public: 16 public:
17 class MockStorageDelegate : public AppCacheStorage::Delegate { 17 class MockStorageDelegate : public AppCacheStorage::Delegate {
18 public: 18 public:
19 }; 19 };
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 virtual void NotifyStorageAccessed(quota::QuotaClient::ID client_id,
30 const GURL& origin,
31 quota::StorageType type) {
32 EXPECT_EQ(quota::QuotaClient::kAppcache, client_id);
33 EXPECT_EQ(quota::kStorageTypeTemporary, type);
34 ++notify_storage_accessed_count_;
35 last_origin_ = origin;
36 }
37
38 virtual void NotifyStorageModified(quota::QuotaClient::ID client_id,
39 const GURL& origin,
40 quota::StorageType type,
41 int64 delta) {
42 EXPECT_EQ(quota::QuotaClient::kAppcache, client_id);
43 EXPECT_EQ(quota::kStorageTypeTemporary, type);
44 ++notify_storage_modified_count_;
45 last_origin_ = origin;
46 last_delta_ = delta;
47 }
48
49 // Not needed for our tests.
50 virtual void RegisterClient(quota::QuotaClient* client) {}
51 virtual void NotifyOriginInUse(const GURL& origin) {}
52 virtual void NotifyOriginNoLongerInUse(const GURL& origin) {}
53
54 int notify_storage_accessed_count_;
55 int notify_storage_modified_count_;
56 GURL last_origin_;
57 int last_delta_;
58 };
20 }; 59 };
21 60
22 TEST_F(AppCacheStorageTest, AddRemoveCache) { 61 TEST_F(AppCacheStorageTest, AddRemoveCache) {
23 MockAppCacheService service; 62 MockAppCacheService service;
24 scoped_refptr<AppCache> cache(new AppCache(&service, 111)); 63 scoped_refptr<AppCache> cache(new AppCache(&service, 111));
25 64
26 EXPECT_EQ(cache.get(), 65 EXPECT_EQ(cache.get(),
27 service.storage()->working_set()->GetCache(111)); 66 service.storage()->working_set()->GetCache(111));
28 67
29 service.storage()->working_set()->RemoveCache(cache); 68 service.storage()->working_set()->RemoveCache(cache);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 EXPECT_FALSE(service.storage()->GetDelegateReference(&delegate)); 139 EXPECT_FALSE(service.storage()->GetDelegateReference(&delegate));
101 140
102 delegate_reference2 = 141 delegate_reference2 =
103 service.storage()->GetOrCreateDelegateReference(&delegate); 142 service.storage()->GetOrCreateDelegateReference(&delegate);
104 EXPECT_TRUE(delegate_reference2.get()); 143 EXPECT_TRUE(delegate_reference2.get());
105 EXPECT_TRUE(delegate_reference2->HasOneRef()); 144 EXPECT_TRUE(delegate_reference2->HasOneRef());
106 EXPECT_EQ(&delegate, delegate_reference2->delegate); 145 EXPECT_EQ(&delegate, delegate_reference2->delegate);
107 EXPECT_NE(delegate_reference1.get(), delegate_reference2.get()); 146 EXPECT_NE(delegate_reference1.get(), delegate_reference2.get());
108 } 147 }
109 148
149 TEST_F(AppCacheStorageTest, UsageMap) {
150 const GURL kOrigin("http://origin/");
151 const GURL kOrigin2("http://origin2/");
152
153 MockAppCacheService service;
154 scoped_refptr<MockQuotaManagerProxy> mock_proxy(new MockQuotaManagerProxy);
155 service.set_quota_manager_proxy(mock_proxy);
156
157 service.storage()->UpdateUsageMapAndNotify(kOrigin, 0);
158 EXPECT_EQ(0, mock_proxy->notify_storage_modified_count_);
159
160 service.storage()->UpdateUsageMapAndNotify(kOrigin, 10);
161 EXPECT_EQ(1, mock_proxy->notify_storage_modified_count_);
162 EXPECT_EQ(10, mock_proxy->last_delta_);
163 EXPECT_EQ(kOrigin, mock_proxy->last_origin_);
164
165 service.storage()->UpdateUsageMapAndNotify(kOrigin, 100);
166 EXPECT_EQ(2, mock_proxy->notify_storage_modified_count_);
167 EXPECT_EQ(90, mock_proxy->last_delta_);
168 EXPECT_EQ(kOrigin, mock_proxy->last_origin_);
169
170 service.storage()->UpdateUsageMapAndNotify(kOrigin, 0);
171 EXPECT_EQ(3, mock_proxy->notify_storage_modified_count_);
172 EXPECT_EQ(-100, mock_proxy->last_delta_);
173 EXPECT_EQ(kOrigin, mock_proxy->last_origin_);
174
175 service.storage()->NotifyStorageAccessed(kOrigin2);
176 EXPECT_EQ(0, mock_proxy->notify_storage_accessed_count_);
177
178 service.storage()->usage_map_[kOrigin2] = 1;
179 service.storage()->NotifyStorageAccessed(kOrigin2);
180 EXPECT_EQ(1, mock_proxy->notify_storage_accessed_count_);
181 EXPECT_EQ(kOrigin2, mock_proxy->last_origin_);
182
183 service.storage()->usage_map_.clear();
184 service.storage()->usage_map_[kOrigin] = 5000;
185 service.storage()->ClearUsageMapAndNotify();
186 EXPECT_EQ(4, mock_proxy->notify_storage_modified_count_);
187 EXPECT_EQ(-5000, mock_proxy->last_delta_);
188 EXPECT_EQ(kOrigin, mock_proxy->last_origin_);
189 EXPECT_TRUE(service.storage()->usage_map_.empty());
190 }
191
110 } // namespace appcache 192 } // namespace appcache
OLDNEW
« no previous file with comments | « webkit/appcache/appcache_storage_impl_unittest.cc ('k') | webkit/appcache/mock_appcache_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698