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

Side by Side Diff: webkit/fileapi/local_file_system_quota_unittest.cc

Issue 12223006: Cleanup: Introduce AsyncFileTestHelper for testing with async file/quota operations (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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 // This test checks the entire behavior of FileSystem usage and quota, such as: 5 // This test checks the entire behavior of FileSystem usage and quota, such as:
6 // 1) the actual size of files on disk, 6 // 1) the actual size of files on disk,
7 // 2) the described size in .usage, and 7 // 2) the described size in .usage, and
8 // 3) the result of QuotaManager::GetUsageAndQuota. 8 // 3) the result of QuotaManager::GetUsageAndQuota.
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "base/message_loop.h" 15 #include "base/message_loop.h"
16 #include "base/platform_file.h" 16 #include "base/platform_file.h"
17 #include "base/string_number_conversions.h" 17 #include "base/string_number_conversions.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "webkit/fileapi/async_file_test_helper.h"
19 #include "webkit/fileapi/file_system_usage_cache.h" 20 #include "webkit/fileapi/file_system_usage_cache.h"
20 #include "webkit/fileapi/file_system_util.h" 21 #include "webkit/fileapi/file_system_util.h"
21 #include "webkit/fileapi/file_util_helper.h"
22 #include "webkit/fileapi/local_file_system_operation.h" 22 #include "webkit/fileapi/local_file_system_operation.h"
23 #include "webkit/fileapi/local_file_system_test_helper.h" 23 #include "webkit/fileapi/local_file_system_test_helper.h"
24 #include "webkit/quota/quota_manager.h" 24 #include "webkit/quota/quota_manager.h"
25 25
26 namespace fileapi { 26 namespace fileapi {
27 27
28 const int kFileOperationStatusNotSet = 1; 28 const int kFileOperationStatusNotSet = 1;
29 29
30 namespace { 30 namespace {
31 31
(...skipping 19 matching lines...) Expand all
51 LocalFileSystemOperation* operation(); 51 LocalFileSystemOperation* operation();
52 52
53 int status() const { return status_; } 53 int status() const { return status_; }
54 quota::QuotaStatusCode quota_status() const { return quota_status_; } 54 quota::QuotaStatusCode quota_status() const { return quota_status_; }
55 int64 usage() { return usage_; } 55 int64 usage() { return usage_; }
56 int64 quota() { return quota_; } 56 int64 quota() { return quota_; }
57 57
58 virtual void SetUp() OVERRIDE; 58 virtual void SetUp() OVERRIDE;
59 virtual void TearDown() OVERRIDE; 59 virtual void TearDown() OVERRIDE;
60 60
61 void OnGetUsageAndQuota(
62 quota::QuotaStatusCode status, int64 usage, int64 quota);
63
64 protected: 61 protected:
65 FileSystemFileUtil* file_util() { 62 FileSystemFileUtil* file_util() {
66 return test_helper_.file_util(); 63 return test_helper_.file_util();
67 } 64 }
68 65
69 FileSystemOperationContext* NewContext() { 66 FileSystemOperationContext* NewContext() {
70 FileSystemOperationContext* context = test_helper_.NewOperationContext(); 67 FileSystemOperationContext* context = test_helper_.NewOperationContext();
71 context->set_allowed_bytes_growth(10000000); 68 context->set_allowed_bytes_growth(10000000);
72 return context; 69 return context;
73 } 70 }
(...skipping 12 matching lines...) Expand all
86 return test_helper_.ComputeCurrentOriginUsage() - 83 return test_helper_.ComputeCurrentOriginUsage() -
87 test_helper_.ComputeCurrentDirectoryDatabaseUsage(); 84 test_helper_.ComputeCurrentDirectoryDatabaseUsage();
88 } 85 }
89 86
90 int64 SizeByQuotaUtil() { 87 int64 SizeByQuotaUtil() {
91 MessageLoop::current()->RunUntilIdle(); 88 MessageLoop::current()->RunUntilIdle();
92 return test_helper_.GetCachedOriginUsage(); 89 return test_helper_.GetCachedOriginUsage();
93 } 90 }
94 91
95 void GetUsageAndQuotaFromQuotaManager() { 92 void GetUsageAndQuotaFromQuotaManager() {
96 quota_manager_->GetUsageAndQuota( 93 quota_status_ = AsyncFileTestHelper::GetUsageAndQuota(
97 test_helper_.origin(), test_helper_.storage_type(), 94 quota_manager_, test_helper_.origin(), test_helper_.type(),
98 base::Bind(&LocalFileSystemQuotaTest::OnGetUsageAndQuota, 95 &usage_, &quota_);
99 weak_factory_.GetWeakPtr()));
100 MessageLoop::current()->RunUntilIdle(); 96 MessageLoop::current()->RunUntilIdle();
101 } 97 }
102 98
103 bool FileExists(const base::FilePath& virtual_path) { 99 bool FileExists(const base::FilePath& virtual_path) {
104 FileSystemURL url = test_helper_.CreateURL(virtual_path); 100 FileSystemURL url = test_helper_.CreateURL(virtual_path);
105 base::PlatformFileInfo file_info; 101 return AsyncFileTestHelper::FileExists(
106 base::FilePath platform_path; 102 test_helper_.file_system_context(), url,
107 scoped_ptr<FileSystemOperationContext> context(NewContext()); 103 AsyncFileTestHelper::kDontCheckSize);
108 base::PlatformFileError error = file_util()->GetFileInfo(
109 context.get(), url, &file_info, &platform_path);
110 return error == base::PLATFORM_FILE_OK;
111 } 104 }
112 105
113 bool DirectoryExists(const base::FilePath& virtual_path) { 106 bool DirectoryExists(const base::FilePath& virtual_path) {
114 FileSystemURL path = test_helper_.CreateURL(virtual_path); 107 FileSystemURL url = test_helper_.CreateURL(virtual_path);
115 scoped_ptr<FileSystemOperationContext> context(NewContext()); 108 return AsyncFileTestHelper::DirectoryExists(
116 return FileUtilHelper::DirectoryExists(context.get(), file_util(), path); 109 test_helper_.file_system_context(), url);
117 } 110 }
118 111
119 base::FilePath CreateUniqueFileInDir(const base::FilePath& virtual_dir_path) { 112 base::FilePath CreateUniqueFileInDir(const base::FilePath& virtual_dir_path) {
120 base::FilePath file_name = base::FilePath::FromUTF8Unsafe( 113 base::FilePath file_name = base::FilePath::FromUTF8Unsafe(
121 "tmpfile-" + base::IntToString(next_unique_path_suffix_++)); 114 "tmpfile-" + base::IntToString(next_unique_path_suffix_++));
122 FileSystemURL url = test_helper_.CreateURL( 115 FileSystemURL url = test_helper_.CreateURL(
123 virtual_dir_path.Append(file_name)); 116 virtual_dir_path.Append(file_name));
124 117
125 scoped_ptr<FileSystemOperationContext> context(NewContext()); 118 scoped_ptr<FileSystemOperationContext> context(NewContext());
126 bool created; 119 bool created;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 196
204 void LocalFileSystemQuotaTest::TearDown() { 197 void LocalFileSystemQuotaTest::TearDown() {
205 quota_manager_ = NULL; 198 quota_manager_ = NULL;
206 test_helper_.TearDown(); 199 test_helper_.TearDown();
207 } 200 }
208 201
209 LocalFileSystemOperation* LocalFileSystemQuotaTest::operation() { 202 LocalFileSystemOperation* LocalFileSystemQuotaTest::operation() {
210 return test_helper_.NewOperation(); 203 return test_helper_.NewOperation();
211 } 204 }
212 205
213 void LocalFileSystemQuotaTest::OnGetUsageAndQuota(
214 quota::QuotaStatusCode status, int64 usage, int64 quota) {
215 quota_status_ = status;
216 usage_ = usage;
217 quota_ = quota;
218 }
219
220 void LocalFileSystemQuotaTest::PrepareFileSet(const base::FilePath& virtual_path ) { 206 void LocalFileSystemQuotaTest::PrepareFileSet(const base::FilePath& virtual_path ) {
221 int64 usage = SizeByQuotaUtil(); 207 int64 usage = SizeByQuotaUtil();
222 child_dir_path_ = CreateUniqueDirInDir(virtual_path); 208 child_dir_path_ = CreateUniqueDirInDir(virtual_path);
223 child_file1_path_ = CreateUniqueFileInDir(virtual_path); 209 child_file1_path_ = CreateUniqueFileInDir(virtual_path);
224 child_file2_path_ = CreateUniqueFileInDir(virtual_path); 210 child_file2_path_ = CreateUniqueFileInDir(virtual_path);
225 child_path_cost_ = SizeByQuotaUtil() - usage; 211 child_path_cost_ = SizeByQuotaUtil() - usage;
226 usage += child_path_cost_; 212 usage += child_path_cost_;
227 213
228 grandchild_file1_path_ = CreateUniqueFileInDir(child_dir_path_); 214 grandchild_file1_path_ = CreateUniqueFileInDir(child_dir_path_);
229 grandchild_file2_path_ = CreateUniqueFileInDir(child_dir_path_); 215 grandchild_file2_path_ = CreateUniqueFileInDir(child_dir_path_);
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 330
345 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size, ActualFileSize()); 331 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size, ActualFileSize());
346 EXPECT_EQ(expected_usage, SizeByQuotaUtil()); 332 EXPECT_EQ(expected_usage, SizeByQuotaUtil());
347 GetUsageAndQuotaFromQuotaManager(); 333 GetUsageAndQuotaFromQuotaManager();
348 EXPECT_EQ(quota::kQuotaStatusOk, quota_status()); 334 EXPECT_EQ(quota::kQuotaStatusOk, quota_status());
349 EXPECT_EQ(expected_usage, usage()); 335 EXPECT_EQ(expected_usage, usage());
350 ASSERT_LT(expected_usage, quota()); 336 ASSERT_LT(expected_usage, quota());
351 } 337 }
352 338
353 } // namespace fileapi 339 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698