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

Side by Side Diff: webkit/fileapi/file_system_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
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 "base/bind.h"
5 #include "base/basictypes.h" 6 #include "base/basictypes.h"
6 #include "base/file_util.h" 7 #include "base/file_util.h"
7 #include "base/memory/scoped_callback_factory.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/message_loop_proxy.h" 9 #include "base/message_loop_proxy.h"
10 #include "base/platform_file.h" 10 #include "base/platform_file.h"
11 #include "base/scoped_temp_dir.h" 11 #include "base/scoped_temp_dir.h"
12 #include "googleurl/src/gurl.h" 12 #include "googleurl/src/gurl.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "webkit/fileapi/file_system_context.h" 14 #include "webkit/fileapi/file_system_context.h"
15 #include "webkit/fileapi/file_system_operation_context.h" 15 #include "webkit/fileapi/file_system_operation_context.h"
16 #include "webkit/fileapi/file_system_quota_client.h" 16 #include "webkit/fileapi/file_system_quota_client.h"
17 #include "webkit/fileapi/file_system_types.h" 17 #include "webkit/fileapi/file_system_types.h"
(...skipping 20 matching lines...) Expand all
38 explicit MockFileSystemPathManager(const FilePath& filesystem_path) 38 explicit MockFileSystemPathManager(const FilePath& filesystem_path)
39 : FileSystemPathManager(base::MessageLoopProxy::current(), 39 : FileSystemPathManager(base::MessageLoopProxy::current(),
40 filesystem_path, NULL, false, true) {} 40 filesystem_path, NULL, false, true) {}
41 }; 41 };
42 42
43 } // namespace 43 } // namespace
44 44
45 class FileSystemQuotaClientTest : public testing::Test { 45 class FileSystemQuotaClientTest : public testing::Test {
46 public: 46 public:
47 FileSystemQuotaClientTest() 47 FileSystemQuotaClientTest()
48 : callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 48 : weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
49 additional_callback_count_(0), 49 additional_callback_count_(0),
50 deletion_status_(quota::kQuotaStatusUnknown) { 50 deletion_status_(quota::kQuotaStatusUnknown) {
51 } 51 }
52 52
53 void SetUp() { 53 void SetUp() {
54 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); 54 ASSERT_TRUE(data_dir_.CreateUniqueTempDir());
55 file_system_context_ = 55 file_system_context_ =
56 new FileSystemContext( 56 new FileSystemContext(
57 base::MessageLoopProxy::current(), 57 base::MessageLoopProxy::current(),
58 base::MessageLoopProxy::current(), 58 base::MessageLoopProxy::current(),
(...skipping 13 matching lines...) Expand all
72 protected: 72 protected:
73 FileSystemQuotaClient* NewQuotaClient(bool is_incognito) { 73 FileSystemQuotaClient* NewQuotaClient(bool is_incognito) {
74 return new FileSystemQuotaClient( 74 return new FileSystemQuotaClient(
75 base::MessageLoopProxy::current(), 75 base::MessageLoopProxy::current(),
76 file_system_context_, is_incognito); 76 file_system_context_, is_incognito);
77 } 77 }
78 78
79 void GetOriginUsageAsync(FileSystemQuotaClient* quota_client, 79 void GetOriginUsageAsync(FileSystemQuotaClient* quota_client,
80 const std::string& origin_url, 80 const std::string& origin_url,
81 quota::StorageType type) { 81 quota::StorageType type) {
82 quota_client->GetOriginUsage(GURL(origin_url), type, 82 quota_client->GetOriginUsage(
83 callback_factory_.NewCallback( 83 GURL(origin_url), type,
84 &FileSystemQuotaClientTest::OnGetUsage)); 84 base::Bind(&FileSystemQuotaClientTest::OnGetUsage,
85 weak_factory_.GetWeakPtr()));
85 } 86 }
86 87
87 int64 GetOriginUsage(FileSystemQuotaClient* quota_client, 88 int64 GetOriginUsage(FileSystemQuotaClient* quota_client,
88 const std::string& origin_url, 89 const std::string& origin_url,
89 quota::StorageType type) { 90 quota::StorageType type) {
90 GetOriginUsageAsync(quota_client, origin_url, type); 91 GetOriginUsageAsync(quota_client, origin_url, type);
91 MessageLoop::current()->RunAllPending(); 92 MessageLoop::current()->RunAllPending();
92 return usage_; 93 return usage_;
93 } 94 }
94 95
95 const std::set<GURL>& GetOriginsForType(FileSystemQuotaClient* quota_client, 96 const std::set<GURL>& GetOriginsForType(FileSystemQuotaClient* quota_client,
96 quota::StorageType type) { 97 quota::StorageType type) {
97 origins_.clear(); 98 origins_.clear();
98 quota_client->GetOriginsForType(type, 99 quota_client->GetOriginsForType(
99 callback_factory_.NewCallback( 100 type,
100 &FileSystemQuotaClientTest::OnGetOrigins)); 101 base::Bind(&FileSystemQuotaClientTest::OnGetOrigins,
102 weak_factory_.GetWeakPtr()));
101 MessageLoop::current()->RunAllPending(); 103 MessageLoop::current()->RunAllPending();
102 return origins_; 104 return origins_;
103 } 105 }
104 106
105 const std::set<GURL>& GetOriginsForHost(FileSystemQuotaClient* quota_client, 107 const std::set<GURL>& GetOriginsForHost(FileSystemQuotaClient* quota_client,
106 quota::StorageType type, 108 quota::StorageType type,
107 const std::string& host) { 109 const std::string& host) {
108 origins_.clear(); 110 origins_.clear();
109 quota_client->GetOriginsForHost(type, host, 111 quota_client->GetOriginsForHost(
110 callback_factory_.NewCallback( 112 type, host,
111 &FileSystemQuotaClientTest::OnGetOrigins)); 113 base::Bind(&FileSystemQuotaClientTest::OnGetOrigins,
114 weak_factory_.GetWeakPtr()));
112 MessageLoop::current()->RunAllPending(); 115 MessageLoop::current()->RunAllPending();
113 return origins_; 116 return origins_;
114 } 117 }
115 118
116 void RunAdditionalOriginUsageTask(FileSystemQuotaClient* quota_client, 119 void RunAdditionalOriginUsageTask(FileSystemQuotaClient* quota_client,
117 const std::string& origin_url, 120 const std::string& origin_url,
118 quota::StorageType type) { 121 quota::StorageType type) {
119 quota_client->GetOriginUsage(GURL(origin_url), type, 122 quota_client->GetOriginUsage(
120 callback_factory_.NewCallback( 123 GURL(origin_url), type,
121 &FileSystemQuotaClientTest::OnGetAdditionalUsage)); 124 base::Bind(&FileSystemQuotaClientTest::OnGetAdditionalUsage,
125 weak_factory_.GetWeakPtr()));
122 } 126 }
123 127
124 FilePath GetOriginBasePath(const std::string& origin_url, 128 FilePath GetOriginBasePath(const std::string& origin_url,
125 quota::StorageType type) { 129 quota::StorageType type) {
126 // Note: this test assumes sandbox_provider impl is used for 130 // Note: this test assumes sandbox_provider impl is used for
127 // temporary and persistent filesystem. 131 // temporary and persistent filesystem.
128 return file_system_context_->path_manager()->sandbox_provider()-> 132 return file_system_context_->path_manager()->sandbox_provider()->
129 GetBaseDirectoryForOriginAndType( 133 GetBaseDirectoryForOriginAndType(
130 GURL(origin_url), QuotaStorageTypeToFileSystemType(type), true); 134 GURL(origin_url), QuotaStorageTypeToFileSystemType(type), true);
131 } 135 }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 } 231 }
228 return file_paths_cost; 232 return file_paths_cost;
229 } 233 }
230 234
231 void DeleteOriginData(FileSystemQuotaClient* quota_client, 235 void DeleteOriginData(FileSystemQuotaClient* quota_client,
232 const std::string& origin, 236 const std::string& origin,
233 quota::StorageType type) { 237 quota::StorageType type) {
234 deletion_status_ = quota::kQuotaStatusUnknown; 238 deletion_status_ = quota::kQuotaStatusUnknown;
235 quota_client->DeleteOriginData( 239 quota_client->DeleteOriginData(
236 GURL(origin), type, 240 GURL(origin), type,
237 callback_factory_.NewCallback( 241 base::Bind(&FileSystemQuotaClientTest::OnDeleteOrigin,
238 &FileSystemQuotaClientTest::OnDeleteOrigin)); 242 weak_factory_.GetWeakPtr()));
239 } 243 }
240 244
241 int64 usage() const { return usage_; } 245 int64 usage() const { return usage_; }
242 quota::QuotaStatusCode status() { return deletion_status_; } 246 quota::QuotaStatusCode status() { return deletion_status_; }
243 int additional_callback_count() const { return additional_callback_count_; } 247 int additional_callback_count() const { return additional_callback_count_; }
244 void set_additional_callback_count(int count) { 248 void set_additional_callback_count(int count) {
245 additional_callback_count_ = count; 249 additional_callback_count_ = count;
246 } 250 }
247 251
248 private: 252 private:
(...skipping 10 matching lines...) Expand all
259 void OnGetAdditionalUsage(int64 usage_unused) { 263 void OnGetAdditionalUsage(int64 usage_unused) {
260 ++additional_callback_count_; 264 ++additional_callback_count_;
261 } 265 }
262 266
263 void OnDeleteOrigin(quota::QuotaStatusCode status) { 267 void OnDeleteOrigin(quota::QuotaStatusCode status) {
264 deletion_status_ = status; 268 deletion_status_ = status;
265 } 269 }
266 270
267 ScopedTempDir data_dir_; 271 ScopedTempDir data_dir_;
268 scoped_refptr<FileSystemContext> file_system_context_; 272 scoped_refptr<FileSystemContext> file_system_context_;
269 base::ScopedCallbackFactory<FileSystemQuotaClientTest> callback_factory_; 273 base::WeakPtrFactory<FileSystemQuotaClientTest> weak_factory_;
270 int64 usage_; 274 int64 usage_;
271 int additional_callback_count_; 275 int additional_callback_count_;
272 std::set<GURL> origins_; 276 std::set<GURL> origins_;
273 quota::StorageType type_; 277 quota::StorageType type_;
274 quota::QuotaStatusCode deletion_status_; 278 quota::QuotaStatusCode deletion_status_;
275 279
276 DISALLOW_COPY_AND_ASSIGN(FileSystemQuotaClientTest); 280 DISALLOW_COPY_AND_ASSIGN(FileSystemQuotaClientTest);
277 }; 281 };
278 282
279 TEST_F(FileSystemQuotaClientTest, NoFileSystemTest) { 283 TEST_F(FileSystemQuotaClientTest, NoFileSystemTest) {
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 GetOriginUsage(quota_client.get(), 598 GetOriginUsage(quota_client.get(),
595 "https://bar.com/", 599 "https://bar.com/",
596 kPersistent)); 600 kPersistent));
597 EXPECT_EQ(64 + file_paths_cost_temporary_bar_https, 601 EXPECT_EQ(64 + file_paths_cost_temporary_bar_https,
598 GetOriginUsage(quota_client.get(), 602 GetOriginUsage(quota_client.get(),
599 "https://bar.com/", 603 "https://bar.com/",
600 kTemporary)); 604 kTemporary));
601 } 605 }
602 606
603 } // namespace fileapi 607 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/file_system_quota_client.cc ('k') | webkit/fileapi/file_system_quota_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698