OLD | NEW |
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" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 FileSystemFileUtil* file_util() { | 65 FileSystemFileUtil* file_util() { |
66 return test_helper_.file_util(); | 66 return test_helper_.file_util(); |
67 } | 67 } |
68 | 68 |
69 FileSystemOperationContext* NewContext() { | 69 FileSystemOperationContext* NewContext() { |
70 FileSystemOperationContext* context = test_helper_.NewOperationContext(); | 70 FileSystemOperationContext* context = test_helper_.NewOperationContext(); |
71 context->set_allowed_bytes_growth(10000000); | 71 context->set_allowed_bytes_growth(10000000); |
72 return context; | 72 return context; |
73 } | 73 } |
74 | 74 |
75 void PrepareFileSet(const FilePath& virtual_path); | 75 void PrepareFileSet(const base::FilePath& virtual_path); |
76 | 76 |
77 FileSystemURL URLForPath(const FilePath& path) const { | 77 FileSystemURL URLForPath(const base::FilePath& path) const { |
78 return test_helper_.CreateURL(path); | 78 return test_helper_.CreateURL(path); |
79 } | 79 } |
80 | 80 |
81 FilePath PlatformPath(const FilePath& virtual_path) { | 81 base::FilePath PlatformPath(const base::FilePath& virtual_path) { |
82 return test_helper_.GetLocalPath(virtual_path); | 82 return test_helper_.GetLocalPath(virtual_path); |
83 } | 83 } |
84 | 84 |
85 int64 ActualFileSize() { | 85 int64 ActualFileSize() { |
86 return test_helper_.ComputeCurrentOriginUsage() - | 86 return test_helper_.ComputeCurrentOriginUsage() - |
87 test_helper_.ComputeCurrentDirectoryDatabaseUsage(); | 87 test_helper_.ComputeCurrentDirectoryDatabaseUsage(); |
88 } | 88 } |
89 | 89 |
90 int64 SizeByQuotaUtil() { | 90 int64 SizeByQuotaUtil() { |
91 MessageLoop::current()->RunUntilIdle(); | 91 MessageLoop::current()->RunUntilIdle(); |
92 return test_helper_.GetCachedOriginUsage(); | 92 return test_helper_.GetCachedOriginUsage(); |
93 } | 93 } |
94 | 94 |
95 void GetUsageAndQuotaFromQuotaManager() { | 95 void GetUsageAndQuotaFromQuotaManager() { |
96 quota_manager_->GetUsageAndQuota( | 96 quota_manager_->GetUsageAndQuota( |
97 test_helper_.origin(), test_helper_.storage_type(), | 97 test_helper_.origin(), test_helper_.storage_type(), |
98 base::Bind(&LocalFileSystemQuotaTest::OnGetUsageAndQuota, | 98 base::Bind(&LocalFileSystemQuotaTest::OnGetUsageAndQuota, |
99 weak_factory_.GetWeakPtr())); | 99 weak_factory_.GetWeakPtr())); |
100 MessageLoop::current()->RunUntilIdle(); | 100 MessageLoop::current()->RunUntilIdle(); |
101 } | 101 } |
102 | 102 |
103 bool FileExists(const FilePath& virtual_path) { | 103 bool FileExists(const base::FilePath& virtual_path) { |
104 FileSystemURL url = test_helper_.CreateURL(virtual_path); | 104 FileSystemURL url = test_helper_.CreateURL(virtual_path); |
105 base::PlatformFileInfo file_info; | 105 base::PlatformFileInfo file_info; |
106 FilePath platform_path; | 106 base::FilePath platform_path; |
107 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 107 scoped_ptr<FileSystemOperationContext> context(NewContext()); |
108 base::PlatformFileError error = file_util()->GetFileInfo( | 108 base::PlatformFileError error = file_util()->GetFileInfo( |
109 context.get(), url, &file_info, &platform_path); | 109 context.get(), url, &file_info, &platform_path); |
110 return error == base::PLATFORM_FILE_OK; | 110 return error == base::PLATFORM_FILE_OK; |
111 } | 111 } |
112 | 112 |
113 bool DirectoryExists(const FilePath& virtual_path) { | 113 bool DirectoryExists(const base::FilePath& virtual_path) { |
114 FileSystemURL path = test_helper_.CreateURL(virtual_path); | 114 FileSystemURL path = test_helper_.CreateURL(virtual_path); |
115 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 115 scoped_ptr<FileSystemOperationContext> context(NewContext()); |
116 return FileUtilHelper::DirectoryExists(context.get(), file_util(), path); | 116 return FileUtilHelper::DirectoryExists(context.get(), file_util(), path); |
117 } | 117 } |
118 | 118 |
119 FilePath CreateUniqueFileInDir(const FilePath& virtual_dir_path) { | 119 base::FilePath CreateUniqueFileInDir(const base::FilePath& virtual_dir_path) { |
120 FilePath file_name = FilePath::FromUTF8Unsafe( | 120 base::FilePath file_name = base::FilePath::FromUTF8Unsafe( |
121 "tmpfile-" + base::IntToString(next_unique_path_suffix_++)); | 121 "tmpfile-" + base::IntToString(next_unique_path_suffix_++)); |
122 FileSystemURL url = test_helper_.CreateURL( | 122 FileSystemURL url = test_helper_.CreateURL( |
123 virtual_dir_path.Append(file_name)); | 123 virtual_dir_path.Append(file_name)); |
124 | 124 |
125 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 125 scoped_ptr<FileSystemOperationContext> context(NewContext()); |
126 bool created; | 126 bool created; |
127 EXPECT_EQ(base::PLATFORM_FILE_OK, | 127 EXPECT_EQ(base::PLATFORM_FILE_OK, |
128 file_util()->EnsureFileExists(context.get(), url, &created)); | 128 file_util()->EnsureFileExists(context.get(), url, &created)); |
129 EXPECT_TRUE(created); | 129 EXPECT_TRUE(created); |
130 return url.path(); | 130 return url.path(); |
131 } | 131 } |
132 | 132 |
133 FilePath CreateUniqueDirInDir(const FilePath& virtual_dir_path) { | 133 base::FilePath CreateUniqueDirInDir(const base::FilePath& virtual_dir_path) { |
134 FilePath dir_name = FilePath::FromUTF8Unsafe( | 134 base::FilePath dir_name = base::FilePath::FromUTF8Unsafe( |
135 "tmpdir-" + base::IntToString(next_unique_path_suffix_++)); | 135 "tmpdir-" + base::IntToString(next_unique_path_suffix_++)); |
136 FileSystemURL url = test_helper_.CreateURL( | 136 FileSystemURL url = test_helper_.CreateURL( |
137 virtual_dir_path.Append(dir_name)); | 137 virtual_dir_path.Append(dir_name)); |
138 | 138 |
139 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 139 scoped_ptr<FileSystemOperationContext> context(NewContext()); |
140 EXPECT_EQ(base::PLATFORM_FILE_OK, | 140 EXPECT_EQ(base::PLATFORM_FILE_OK, |
141 file_util()->CreateDirectory(context.get(), url, false, true)); | 141 file_util()->CreateDirectory(context.get(), url, false, true)); |
142 return url.path(); | 142 return url.path(); |
143 } | 143 } |
144 | 144 |
145 FilePath CreateUniqueDir() { | 145 base::FilePath CreateUniqueDir() { |
146 return CreateUniqueDirInDir(FilePath()); | 146 return CreateUniqueDirInDir(base::FilePath()); |
147 } | 147 } |
148 | 148 |
149 FilePath child_dir_path_; | 149 base::FilePath child_dir_path_; |
150 FilePath child_file1_path_; | 150 base::FilePath child_file1_path_; |
151 FilePath child_file2_path_; | 151 base::FilePath child_file2_path_; |
152 FilePath grandchild_file1_path_; | 152 base::FilePath grandchild_file1_path_; |
153 FilePath grandchild_file2_path_; | 153 base::FilePath grandchild_file2_path_; |
154 | 154 |
155 int64 child_path_cost_; | 155 int64 child_path_cost_; |
156 int64 grandchild_path_cost_; | 156 int64 grandchild_path_cost_; |
157 | 157 |
158 protected: | 158 protected: |
159 // Callback for recording test results. | 159 // Callback for recording test results. |
160 FileSystemOperation::StatusCallback RecordStatusCallback() { | 160 FileSystemOperation::StatusCallback RecordStatusCallback() { |
161 return base::Bind(&LocalFileSystemQuotaTest::DidFinish, AsWeakPtr()); | 161 return base::Bind(&LocalFileSystemQuotaTest::DidFinish, AsWeakPtr()); |
162 } | 162 } |
163 | 163 |
(...skipping 15 matching lines...) Expand all Loading... |
179 int status_; | 179 int status_; |
180 quota::QuotaStatusCode quota_status_; | 180 quota::QuotaStatusCode quota_status_; |
181 int64 usage_; | 181 int64 usage_; |
182 int64 quota_; | 182 int64 quota_; |
183 | 183 |
184 DISALLOW_COPY_AND_ASSIGN(LocalFileSystemQuotaTest); | 184 DISALLOW_COPY_AND_ASSIGN(LocalFileSystemQuotaTest); |
185 }; | 185 }; |
186 | 186 |
187 void LocalFileSystemQuotaTest::SetUp() { | 187 void LocalFileSystemQuotaTest::SetUp() { |
188 ASSERT_TRUE(work_dir_.CreateUniqueTempDir()); | 188 ASSERT_TRUE(work_dir_.CreateUniqueTempDir()); |
189 FilePath filesystem_dir_path = work_dir_.path().AppendASCII("filesystem"); | 189 base::FilePath filesystem_dir_path = work_dir_.path().AppendASCII("filesystem"
); |
190 ASSERT_TRUE(file_util::CreateDirectory(filesystem_dir_path)); | 190 ASSERT_TRUE(file_util::CreateDirectory(filesystem_dir_path)); |
191 | 191 |
192 quota_manager_ = new quota::QuotaManager( | 192 quota_manager_ = new quota::QuotaManager( |
193 false /* is_incognito */, | 193 false /* is_incognito */, |
194 filesystem_dir_path, | 194 filesystem_dir_path, |
195 base::MessageLoopProxy::current(), | 195 base::MessageLoopProxy::current(), |
196 base::MessageLoopProxy::current(), | 196 base::MessageLoopProxy::current(), |
197 NULL); | 197 NULL); |
198 | 198 |
199 test_helper_.SetUp(filesystem_dir_path, | 199 test_helper_.SetUp(filesystem_dir_path, |
(...skipping 10 matching lines...) Expand all Loading... |
210 return test_helper_.NewOperation(); | 210 return test_helper_.NewOperation(); |
211 } | 211 } |
212 | 212 |
213 void LocalFileSystemQuotaTest::OnGetUsageAndQuota( | 213 void LocalFileSystemQuotaTest::OnGetUsageAndQuota( |
214 quota::QuotaStatusCode status, int64 usage, int64 quota) { | 214 quota::QuotaStatusCode status, int64 usage, int64 quota) { |
215 quota_status_ = status; | 215 quota_status_ = status; |
216 usage_ = usage; | 216 usage_ = usage; |
217 quota_ = quota; | 217 quota_ = quota; |
218 } | 218 } |
219 | 219 |
220 void LocalFileSystemQuotaTest::PrepareFileSet(const FilePath& virtual_path) { | 220 void LocalFileSystemQuotaTest::PrepareFileSet(const base::FilePath& virtual_path
) { |
221 int64 usage = SizeByQuotaUtil(); | 221 int64 usage = SizeByQuotaUtil(); |
222 child_dir_path_ = CreateUniqueDirInDir(virtual_path); | 222 child_dir_path_ = CreateUniqueDirInDir(virtual_path); |
223 child_file1_path_ = CreateUniqueFileInDir(virtual_path); | 223 child_file1_path_ = CreateUniqueFileInDir(virtual_path); |
224 child_file2_path_ = CreateUniqueFileInDir(virtual_path); | 224 child_file2_path_ = CreateUniqueFileInDir(virtual_path); |
225 child_path_cost_ = SizeByQuotaUtil() - usage; | 225 child_path_cost_ = SizeByQuotaUtil() - usage; |
226 usage += child_path_cost_; | 226 usage += child_path_cost_; |
227 | 227 |
228 grandchild_file1_path_ = CreateUniqueFileInDir(child_dir_path_); | 228 grandchild_file1_path_ = CreateUniqueFileInDir(child_dir_path_); |
229 grandchild_file2_path_ = CreateUniqueFileInDir(child_dir_path_); | 229 grandchild_file2_path_ = CreateUniqueFileInDir(child_dir_path_); |
230 grandchild_path_cost_ = SizeByQuotaUtil() - usage; | 230 grandchild_path_cost_ = SizeByQuotaUtil() - usage; |
231 } | 231 } |
232 | 232 |
233 TEST_F(LocalFileSystemQuotaTest, TestMoveSuccessSrcDirRecursive) { | 233 TEST_F(LocalFileSystemQuotaTest, TestMoveSuccessSrcDirRecursive) { |
234 FilePath src_dir_path(CreateUniqueDir()); | 234 base::FilePath src_dir_path(CreateUniqueDir()); |
235 int src_path_cost = SizeByQuotaUtil(); | 235 int src_path_cost = SizeByQuotaUtil(); |
236 PrepareFileSet(src_dir_path); | 236 PrepareFileSet(src_dir_path); |
237 FilePath dest_dir_path(CreateUniqueDir()); | 237 base::FilePath dest_dir_path(CreateUniqueDir()); |
238 | 238 |
239 EXPECT_EQ(0, ActualFileSize()); | 239 EXPECT_EQ(0, ActualFileSize()); |
240 int total_path_cost = SizeByQuotaUtil(); | 240 int total_path_cost = SizeByQuotaUtil(); |
241 | 241 |
242 operation()->Truncate(URLForPath(child_file1_path_), 5000, | 242 operation()->Truncate(URLForPath(child_file1_path_), 5000, |
243 base::Bind(&AssertFileErrorEq, base::PLATFORM_FILE_OK)); | 243 base::Bind(&AssertFileErrorEq, base::PLATFORM_FILE_OK)); |
244 operation()->Truncate(URLForPath(child_file2_path_), 400, | 244 operation()->Truncate(URLForPath(child_file2_path_), 400, |
245 base::Bind(&AssertFileErrorEq, base::PLATFORM_FILE_OK)); | 245 base::Bind(&AssertFileErrorEq, base::PLATFORM_FILE_OK)); |
246 operation()->Truncate(URLForPath(grandchild_file1_path_), 30, | 246 operation()->Truncate(URLForPath(grandchild_file1_path_), 30, |
247 base::Bind(&AssertFileErrorEq, base::PLATFORM_FILE_OK)); | 247 base::Bind(&AssertFileErrorEq, base::PLATFORM_FILE_OK)); |
(...skipping 24 matching lines...) Expand all Loading... |
272 EXPECT_EQ(all_file_size, ActualFileSize()); | 272 EXPECT_EQ(all_file_size, ActualFileSize()); |
273 EXPECT_EQ(all_file_size + total_path_cost - src_path_cost, | 273 EXPECT_EQ(all_file_size + total_path_cost - src_path_cost, |
274 SizeByQuotaUtil()); | 274 SizeByQuotaUtil()); |
275 GetUsageAndQuotaFromQuotaManager(); | 275 GetUsageAndQuotaFromQuotaManager(); |
276 EXPECT_EQ(quota::kQuotaStatusOk, quota_status()); | 276 EXPECT_EQ(quota::kQuotaStatusOk, quota_status()); |
277 EXPECT_EQ(all_file_size + total_path_cost - src_path_cost, usage()); | 277 EXPECT_EQ(all_file_size + total_path_cost - src_path_cost, usage()); |
278 ASSERT_LT(all_file_size + total_path_cost - src_path_cost, quota()); | 278 ASSERT_LT(all_file_size + total_path_cost - src_path_cost, quota()); |
279 } | 279 } |
280 | 280 |
281 TEST_F(LocalFileSystemQuotaTest, TestCopySuccessSrcDirRecursive) { | 281 TEST_F(LocalFileSystemQuotaTest, TestCopySuccessSrcDirRecursive) { |
282 FilePath src_dir_path(CreateUniqueDir()); | 282 base::FilePath src_dir_path(CreateUniqueDir()); |
283 PrepareFileSet(src_dir_path); | 283 PrepareFileSet(src_dir_path); |
284 FilePath dest_dir1_path(CreateUniqueDir()); | 284 base::FilePath dest_dir1_path(CreateUniqueDir()); |
285 FilePath dest_dir2_path(CreateUniqueDir()); | 285 base::FilePath dest_dir2_path(CreateUniqueDir()); |
286 | 286 |
287 EXPECT_EQ(0, ActualFileSize()); | 287 EXPECT_EQ(0, ActualFileSize()); |
288 int total_path_cost = SizeByQuotaUtil(); | 288 int total_path_cost = SizeByQuotaUtil(); |
289 | 289 |
290 operation()->Truncate(URLForPath(child_file1_path_), 8000, | 290 operation()->Truncate(URLForPath(child_file1_path_), 8000, |
291 base::Bind(&AssertFileErrorEq, base::PLATFORM_FILE_OK)); | 291 base::Bind(&AssertFileErrorEq, base::PLATFORM_FILE_OK)); |
292 operation()->Truncate(URLForPath(child_file2_path_), 700, | 292 operation()->Truncate(URLForPath(child_file2_path_), 700, |
293 base::Bind(&AssertFileErrorEq, base::PLATFORM_FILE_OK)); | 293 base::Bind(&AssertFileErrorEq, base::PLATFORM_FILE_OK)); |
294 operation()->Truncate(URLForPath(grandchild_file1_path_), 60, | 294 operation()->Truncate(URLForPath(grandchild_file1_path_), 60, |
295 base::Bind(&AssertFileErrorEq, base::PLATFORM_FILE_OK)); | 295 base::Bind(&AssertFileErrorEq, base::PLATFORM_FILE_OK)); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 | 344 |
345 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size, ActualFileSize()); | 345 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size, ActualFileSize()); |
346 EXPECT_EQ(expected_usage, SizeByQuotaUtil()); | 346 EXPECT_EQ(expected_usage, SizeByQuotaUtil()); |
347 GetUsageAndQuotaFromQuotaManager(); | 347 GetUsageAndQuotaFromQuotaManager(); |
348 EXPECT_EQ(quota::kQuotaStatusOk, quota_status()); | 348 EXPECT_EQ(quota::kQuotaStatusOk, quota_status()); |
349 EXPECT_EQ(expected_usage, usage()); | 349 EXPECT_EQ(expected_usage, usage()); |
350 ASSERT_LT(expected_usage, quota()); | 350 ASSERT_LT(expected_usage, quota()); |
351 } | 351 } |
352 | 352 |
353 } // namespace fileapi | 353 } // namespace fileapi |
OLD | NEW |