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

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

Issue 8070001: Use base::Callback in Quota related code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 9 years, 2 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
« no previous file with comments | « webkit/appcache/appcache_quota_client.cc ('k') | webkit/appcache/appcache_storage_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <map> 5 #include <map>
6 #include <set>
6 7
8 #include "base/bind.h"
7 #include "base/memory/scoped_callback_factory.h" 9 #include "base/memory/scoped_callback_factory.h"
8 #include "base/message_loop.h" 10 #include "base/message_loop.h"
9 #include "base/message_loop_proxy.h" 11 #include "base/message_loop_proxy.h"
10 #include "net/base/net_errors.h" 12 #include "net/base/net_errors.h"
11 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
12 #include "webkit/appcache/appcache_quota_client.h" 14 #include "webkit/appcache/appcache_quota_client.h"
13 #include "webkit/appcache/mock_appcache_service.h" 15 #include "webkit/appcache/mock_appcache_service.h"
14 16
15 namespace appcache { 17 namespace appcache {
16 18
(...skipping 10 matching lines...) Expand all
27 29
28 AppCacheQuotaClientTest() 30 AppCacheQuotaClientTest()
29 : kOriginA("http://host"), 31 : kOriginA("http://host"),
30 kOriginB("http://host:8000"), 32 kOriginB("http://host:8000"),
31 kOriginOther("http://other"), 33 kOriginOther("http://other"),
32 usage_(0), 34 usage_(0),
33 delete_status_(quota::kQuotaStatusUnknown), 35 delete_status_(quota::kQuotaStatusUnknown),
34 num_get_origin_usage_completions_(0), 36 num_get_origin_usage_completions_(0),
35 num_get_origins_completions_(0), 37 num_get_origins_completions_(0),
36 num_delete_origins_completions_(0), 38 num_delete_origins_completions_(0),
37 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 39 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
38 } 40 }
39 41
40 int64 GetOriginUsage( 42 int64 GetOriginUsage(
41 quota::QuotaClient* client, 43 quota::QuotaClient* client,
42 const GURL& origin, 44 const GURL& origin,
43 quota::StorageType type) { 45 quota::StorageType type) {
44 usage_ = -1; 46 usage_ = -1;
45 AsyncGetOriginUsage(client, origin, type); 47 AsyncGetOriginUsage(client, origin, type);
46 MessageLoop::current()->RunAllPending(); 48 MessageLoop::current()->RunAllPending();
47 return usage_; 49 return usage_;
(...skipping 25 matching lines...) Expand all
73 delete_status_ = quota::kQuotaStatusUnknown; 75 delete_status_ = quota::kQuotaStatusUnknown;
74 AsyncDeleteOriginData(client, type, origin); 76 AsyncDeleteOriginData(client, type, origin);
75 MessageLoop::current()->RunAllPending(); 77 MessageLoop::current()->RunAllPending();
76 return delete_status_; 78 return delete_status_;
77 } 79 }
78 80
79 void AsyncGetOriginUsage( 81 void AsyncGetOriginUsage(
80 quota::QuotaClient* client, 82 quota::QuotaClient* client,
81 const GURL& origin, 83 const GURL& origin,
82 quota::StorageType type) { 84 quota::StorageType type) {
83 client->GetOriginUsage(origin, type, 85 client->GetOriginUsage(
84 callback_factory_.NewCallback( 86 origin, type,
85 &AppCacheQuotaClientTest::OnGetOriginUsageComplete)); 87 base::Bind(&AppCacheQuotaClientTest::OnGetOriginUsageComplete,
88 weak_factory_.GetWeakPtr()));
86 } 89 }
87 90
88 void AsyncGetOriginsForType( 91 void AsyncGetOriginsForType(
89 quota::QuotaClient* client, 92 quota::QuotaClient* client,
90 quota::StorageType type) { 93 quota::StorageType type) {
91 client->GetOriginsForType(type, 94 client->GetOriginsForType(
92 callback_factory_.NewCallback( 95 type,
93 &AppCacheQuotaClientTest::OnGetOriginsComplete)); 96 base::Bind(&AppCacheQuotaClientTest::OnGetOriginsComplete,
97 weak_factory_.GetWeakPtr()));
94 } 98 }
95 99
96 void AsyncGetOriginsForHost( 100 void AsyncGetOriginsForHost(
97 quota::QuotaClient* client, 101 quota::QuotaClient* client,
98 quota::StorageType type, 102 quota::StorageType type,
99 const std::string& host) { 103 const std::string& host) {
100 client->GetOriginsForHost(type, host, 104 client->GetOriginsForHost(
101 callback_factory_.NewCallback( 105 type, host,
102 &AppCacheQuotaClientTest::OnGetOriginsComplete)); 106 base::Bind(&AppCacheQuotaClientTest::OnGetOriginsComplete,
107 weak_factory_.GetWeakPtr()));
103 } 108 }
104 109
105 void AsyncDeleteOriginData( 110 void AsyncDeleteOriginData(
106 quota::QuotaClient* client, 111 quota::QuotaClient* client,
107 quota::StorageType type, 112 quota::StorageType type,
108 const GURL& origin) { 113 const GURL& origin) {
109 client->DeleteOriginData(origin, type, 114 client->DeleteOriginData(
110 callback_factory_.NewCallback( 115 origin, type,
111 &AppCacheQuotaClientTest::OnDeleteOriginDataComplete)); 116 base::Bind(&AppCacheQuotaClientTest::OnDeleteOriginDataComplete,
117 weak_factory_.GetWeakPtr()));
112 } 118 }
113 119
114 void SetUsageMapEntry(const GURL& origin, int64 usage) { 120 void SetUsageMapEntry(const GURL& origin, int64 usage) {
115 mock_service_.storage()->usage_map_[origin] = usage; 121 mock_service_.storage()->usage_map_[origin] = usage;
116 } 122 }
117 123
118 AppCacheQuotaClient* CreateClient() { 124 AppCacheQuotaClient* CreateClient() {
119 return new AppCacheQuotaClient(&mock_service_); 125 return new AppCacheQuotaClient(&mock_service_);
120 } 126 }
121 127
(...skipping 28 matching lines...) Expand all
150 } 156 }
151 157
152 int64 usage_; 158 int64 usage_;
153 std::set<GURL> origins_; 159 std::set<GURL> origins_;
154 quota::StorageType type_; 160 quota::StorageType type_;
155 quota::QuotaStatusCode delete_status_; 161 quota::QuotaStatusCode delete_status_;
156 int num_get_origin_usage_completions_; 162 int num_get_origin_usage_completions_;
157 int num_get_origins_completions_; 163 int num_get_origins_completions_;
158 int num_delete_origins_completions_; 164 int num_delete_origins_completions_;
159 MockAppCacheService mock_service_; 165 MockAppCacheService mock_service_;
160 base::ScopedCallbackFactory<AppCacheQuotaClientTest> callback_factory_; 166 base::WeakPtrFactory<AppCacheQuotaClientTest> weak_factory_;
161 }; 167 };
162 168
163 169
164 TEST_F(AppCacheQuotaClientTest, BasicCreateDestroy) { 170 TEST_F(AppCacheQuotaClientTest, BasicCreateDestroy) {
165 AppCacheQuotaClient* client = CreateClient(); 171 AppCacheQuotaClient* client = CreateClient();
166 Call_NotifyAppCacheReady(client); 172 Call_NotifyAppCacheReady(client);
167 Call_OnQuotaManagerDestroyed(client); 173 Call_OnQuotaManagerDestroyed(client);
168 Call_NotifyAppCacheDestroyed(client); 174 Call_NotifyAppCacheDestroyed(client);
169 } 175 }
170 176
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 // A real completion callback from the service should 429 // A real completion callback from the service should
424 // be dropped if it comes in after NotifyAppCacheDestroyed. 430 // be dropped if it comes in after NotifyAppCacheDestroyed.
425 MessageLoop::current()->RunAllPending(); 431 MessageLoop::current()->RunAllPending();
426 EXPECT_EQ(1, num_delete_origins_completions_); 432 EXPECT_EQ(1, num_delete_origins_completions_);
427 EXPECT_EQ(quota::kQuotaErrorAbort, delete_status_); 433 EXPECT_EQ(quota::kQuotaErrorAbort, delete_status_);
428 434
429 Call_OnQuotaManagerDestroyed(client); 435 Call_OnQuotaManagerDestroyed(client);
430 } 436 }
431 437
432 } // namespace appcache 438 } // namespace appcache
OLDNEW
« no previous file with comments | « webkit/appcache/appcache_quota_client.cc ('k') | webkit/appcache/appcache_storage_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698