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

Side by Side Diff: content/browser/fileapi/obfuscated_file_util_unittest.cc

Issue 1498003003: Remove kint64max. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: INT64_MAX Created 5 years 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <stdint.h>
6
7 #include <limits>
5 #include <set> 8 #include <set>
6 #include <string> 9 #include <string>
7 #include <vector> 10 #include <vector>
8 11
9 #include "base/bind.h" 12 #include "base/bind.h"
10 #include "base/files/file.h" 13 #include "base/files/file.h"
11 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
12 #include "base/files/file_util.h" 15 #include "base/files/file_util.h"
13 #include "base/files/scoped_temp_dir.h" 16 #include "base/files/scoped_temp_dir.h"
14 #include "base/memory/scoped_ptr.h" 17 #include "base/memory/scoped_ptr.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 using storage::kFileSystemTypePersistent; 50 using storage::kFileSystemTypePersistent;
48 51
49 namespace content { 52 namespace content {
50 53
51 namespace { 54 namespace {
52 55
53 bool FileExists(const base::FilePath& path) { 56 bool FileExists(const base::FilePath& path) {
54 return base::PathExists(path) && !base::DirectoryExists(path); 57 return base::PathExists(path) && !base::DirectoryExists(path);
55 } 58 }
56 59
57 int64 GetSize(const base::FilePath& path) { 60 int64_t GetSize(const base::FilePath& path) {
58 int64 size; 61 int64_t size;
59 EXPECT_TRUE(base::GetFileSize(path, &size)); 62 EXPECT_TRUE(base::GetFileSize(path, &size));
60 return size; 63 return size;
61 } 64 }
62 65
63 // After a move, the dest exists and the source doesn't. 66 // After a move, the dest exists and the source doesn't.
64 // After a copy, both source and dest exist. 67 // After a copy, both source and dest exist.
65 struct CopyMoveTestCaseRecord { 68 struct CopyMoveTestCaseRecord {
66 bool is_copy_not_move; 69 bool is_copy_not_move;
67 const char source_path[64]; 70 const char source_path[64];
68 const char dest_path[64]; 71 const char dest_path[64];
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 change_observers_ = 178 change_observers_ =
176 storage::MockFileChangeObserver::CreateList(&change_observer_); 179 storage::MockFileChangeObserver::CreateList(&change_observer_);
177 } 180 }
178 181
179 void TearDown() override { 182 void TearDown() override {
180 quota_manager_ = NULL; 183 quota_manager_ = NULL;
181 sandbox_file_system_.TearDown(); 184 sandbox_file_system_.TearDown();
182 } 185 }
183 186
184 scoped_ptr<FileSystemOperationContext> LimitedContext( 187 scoped_ptr<FileSystemOperationContext> LimitedContext(
185 int64 allowed_bytes_growth) { 188 int64_t allowed_bytes_growth) {
186 scoped_ptr<FileSystemOperationContext> context( 189 scoped_ptr<FileSystemOperationContext> context(
187 sandbox_file_system_.NewOperationContext()); 190 sandbox_file_system_.NewOperationContext());
188 context->set_allowed_bytes_growth(allowed_bytes_growth); 191 context->set_allowed_bytes_growth(allowed_bytes_growth);
189 return context.Pass(); 192 return context.Pass();
190 } 193 }
191 194
192 scoped_ptr<FileSystemOperationContext> UnlimitedContext() { 195 scoped_ptr<FileSystemOperationContext> UnlimitedContext() {
193 return LimitedContext(kint64max); 196 return LimitedContext(std::numeric_limits<int64_t>::max());
194 } 197 }
195 198
196 FileSystemOperationContext* NewContext( 199 FileSystemOperationContext* NewContext(
197 SandboxFileSystemTestHelper* file_system) { 200 SandboxFileSystemTestHelper* file_system) {
198 change_observer()->ResetCount(); 201 change_observer()->ResetCount();
199 FileSystemOperationContext* context; 202 FileSystemOperationContext* context;
200 if (file_system) 203 if (file_system)
201 context = file_system->NewOperationContext(); 204 context = file_system->NewOperationContext();
202 else 205 else
203 context = sandbox_file_system_.NewOperationContext(); 206 context = sandbox_file_system_.NewOperationContext();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 const GURL& origin() const { 249 const GURL& origin() const {
247 return origin_; 250 return origin_;
248 } 251 }
249 252
250 storage::FileSystemType type() const { return type_; } 253 storage::FileSystemType type() const { return type_; }
251 254
252 std::string type_string() const { 255 std::string type_string() const {
253 return GetTypeString(type_); 256 return GetTypeString(type_);
254 } 257 }
255 258
256 int64 ComputeTotalFileSize() { 259 int64_t ComputeTotalFileSize() {
257 return sandbox_file_system_.ComputeCurrentOriginUsage() - 260 return sandbox_file_system_.ComputeCurrentOriginUsage() -
258 sandbox_file_system_.ComputeCurrentDirectoryDatabaseUsage(); 261 sandbox_file_system_.ComputeCurrentDirectoryDatabaseUsage();
259 } 262 }
260 263
261 void GetUsageFromQuotaManager() { 264 void GetUsageFromQuotaManager() {
262 int64 quota = -1; 265 int64_t quota = -1;
263 quota_status_ = 266 quota_status_ =
264 AsyncFileTestHelper::GetUsageAndQuota(quota_manager_.get(), 267 AsyncFileTestHelper::GetUsageAndQuota(quota_manager_.get(),
265 origin(), 268 origin(),
266 sandbox_file_system_.type(), 269 sandbox_file_system_.type(),
267 &usage_, 270 &usage_,
268 &quota); 271 &quota);
269 EXPECT_EQ(storage::kQuotaStatusOk, quota_status_); 272 EXPECT_EQ(storage::kQuotaStatusOk, quota_status_);
270 } 273 }
271 274
272 void RevokeUsageCache() { 275 void RevokeUsageCache() {
273 quota_manager_->ResetUsageTracker(sandbox_file_system_.storage_type()); 276 quota_manager_->ResetUsageTracker(sandbox_file_system_.storage_type());
274 usage_cache()->Delete(sandbox_file_system_.GetUsageCachePath()); 277 usage_cache()->Delete(sandbox_file_system_.GetUsageCachePath());
275 } 278 }
276 279
277 int64 SizeByQuotaUtil() { 280 int64_t SizeByQuotaUtil() {
278 return sandbox_file_system_.GetCachedOriginUsage(); 281 return sandbox_file_system_.GetCachedOriginUsage();
279 } 282 }
280 283
281 int64 SizeInUsageFile() { 284 int64_t SizeInUsageFile() {
282 base::RunLoop().RunUntilIdle(); 285 base::RunLoop().RunUntilIdle();
283 int64 usage = 0; 286 int64_t usage = 0;
284 return usage_cache()->GetUsage( 287 return usage_cache()->GetUsage(
285 sandbox_file_system_.GetUsageCachePath(), &usage) ? usage : -1; 288 sandbox_file_system_.GetUsageCachePath(), &usage) ? usage : -1;
286 } 289 }
287 290
288 bool PathExists(const FileSystemURL& url) { 291 bool PathExists(const FileSystemURL& url) {
289 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); 292 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
290 base::File::Info file_info; 293 base::File::Info file_info;
291 base::FilePath platform_path; 294 base::FilePath platform_path;
292 base::File::Error error = ofu()->GetFileInfo( 295 base::File::Error error = ofu()->GetFileInfo(
293 context.get(), url, &file_info, &platform_path); 296 context.get(), url, &file_info, &platform_path);
294 return error == base::File::FILE_OK; 297 return error == base::File::FILE_OK;
295 } 298 }
296 299
297 bool DirectoryExists(const FileSystemURL& url) { 300 bool DirectoryExists(const FileSystemURL& url) {
298 return AsyncFileTestHelper::DirectoryExists(file_system_context(), url); 301 return AsyncFileTestHelper::DirectoryExists(file_system_context(), url);
299 } 302 }
300 303
301 int64 usage() const { return usage_; } 304 int64_t usage() const { return usage_; }
302 storage::FileSystemUsageCache* usage_cache() { 305 storage::FileSystemUsageCache* usage_cache() {
303 return sandbox_file_system_.usage_cache(); 306 return sandbox_file_system_.usage_cache();
304 } 307 }
305 308
306 FileSystemURL CreateURLFromUTF8(const std::string& path) { 309 FileSystemURL CreateURLFromUTF8(const std::string& path) {
307 return sandbox_file_system_.CreateURLFromUTF8(path); 310 return sandbox_file_system_.CreateURLFromUTF8(path);
308 } 311 }
309 312
310 int64 PathCost(const FileSystemURL& url) { 313 int64_t PathCost(const FileSystemURL& url) {
311 return ObfuscatedFileUtil::ComputeFilePathCost(url.path()); 314 return ObfuscatedFileUtil::ComputeFilePathCost(url.path());
312 } 315 }
313 316
314 FileSystemURL CreateURL(const base::FilePath& path) { 317 FileSystemURL CreateURL(const base::FilePath& path) {
315 return sandbox_file_system_.CreateURL(path); 318 return sandbox_file_system_.CreateURL(path);
316 } 319 }
317 320
318 void CheckFileAndCloseHandle(const FileSystemURL& url, base::File file) { 321 void CheckFileAndCloseHandle(const FileSystemURL& url, base::File file) {
319 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); 322 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
320 base::FilePath local_path; 323 base::FilePath local_path;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 context.reset(NewContext(NULL)); 389 context.reset(NewContext(NULL));
387 EXPECT_TRUE(DirectoryExists( 390 EXPECT_TRUE(DirectoryExists(
388 FileSystemURLAppend(root_url, *iter))); 391 FileSystemURLAppend(root_url, *iter)));
389 } 392 }
390 } 393 }
391 394
392 class UsageVerifyHelper { 395 class UsageVerifyHelper {
393 public: 396 public:
394 UsageVerifyHelper(scoped_ptr<FileSystemOperationContext> context, 397 UsageVerifyHelper(scoped_ptr<FileSystemOperationContext> context,
395 SandboxFileSystemTestHelper* file_system, 398 SandboxFileSystemTestHelper* file_system,
396 int64 expected_usage) 399 int64_t expected_usage)
397 : context_(context.Pass()), 400 : context_(context.Pass()),
398 sandbox_file_system_(file_system), 401 sandbox_file_system_(file_system),
399 expected_usage_(expected_usage) {} 402 expected_usage_(expected_usage) {}
400 403
401 ~UsageVerifyHelper() { 404 ~UsageVerifyHelper() {
402 base::RunLoop().RunUntilIdle(); 405 base::RunLoop().RunUntilIdle();
403 Check(); 406 Check();
404 } 407 }
405 408
406 FileSystemOperationContext* context() { 409 FileSystemOperationContext* context() {
407 return context_.get(); 410 return context_.get();
408 } 411 }
409 412
410 private: 413 private:
411 void Check() { 414 void Check() {
412 ASSERT_EQ(expected_usage_, 415 ASSERT_EQ(expected_usage_,
413 sandbox_file_system_->GetCachedOriginUsage()); 416 sandbox_file_system_->GetCachedOriginUsage());
414 } 417 }
415 418
416 scoped_ptr<FileSystemOperationContext> context_; 419 scoped_ptr<FileSystemOperationContext> context_;
417 SandboxFileSystemTestHelper* sandbox_file_system_; 420 SandboxFileSystemTestHelper* sandbox_file_system_;
418 int64 expected_usage_; 421 int64_t expected_usage_;
419 }; 422 };
420 423
421 scoped_ptr<UsageVerifyHelper> AllowUsageIncrease(int64 requested_growth) { 424 scoped_ptr<UsageVerifyHelper> AllowUsageIncrease(int64_t requested_growth) {
422 int64 usage = sandbox_file_system_.GetCachedOriginUsage(); 425 int64_t usage = sandbox_file_system_.GetCachedOriginUsage();
423 return scoped_ptr<UsageVerifyHelper>(new UsageVerifyHelper( 426 return scoped_ptr<UsageVerifyHelper>(new UsageVerifyHelper(
424 LimitedContext(requested_growth), 427 LimitedContext(requested_growth),
425 &sandbox_file_system_, usage + requested_growth)); 428 &sandbox_file_system_, usage + requested_growth));
426 } 429 }
427 430
428 scoped_ptr<UsageVerifyHelper> DisallowUsageIncrease(int64 requested_growth) { 431 scoped_ptr<UsageVerifyHelper> DisallowUsageIncrease(
429 int64 usage = sandbox_file_system_.GetCachedOriginUsage(); 432 int64_t requested_growth) {
433 int64_t usage = sandbox_file_system_.GetCachedOriginUsage();
430 return scoped_ptr<UsageVerifyHelper>(new UsageVerifyHelper( 434 return scoped_ptr<UsageVerifyHelper>(new UsageVerifyHelper(
431 LimitedContext(requested_growth - 1), &sandbox_file_system_, usage)); 435 LimitedContext(requested_growth - 1), &sandbox_file_system_, usage));
432 } 436 }
433 437
434 void FillTestDirectory( 438 void FillTestDirectory(
435 const FileSystemURL& root_url, 439 const FileSystemURL& root_url,
436 std::set<base::FilePath::StringType>* files, 440 std::set<base::FilePath::StringType>* files,
437 std::set<base::FilePath::StringType>* directories) { 441 std::set<base::FilePath::StringType>* directories) {
438 scoped_ptr<FileSystemOperationContext> context; 442 scoped_ptr<FileSystemOperationContext> context;
439 std::vector<storage::DirectoryEntry> entries; 443 std::vector<storage::DirectoryEntry> entries;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 if (is_file) // Directories in OFU don't support atime. 541 if (is_file) // Directories in OFU don't support atime.
538 EXPECT_EQ(file_info.last_accessed.ToTimeT(), last_access_time.ToTimeT()); 542 EXPECT_EQ(file_info.last_accessed.ToTimeT(), last_access_time.ToTimeT());
539 } 543 }
540 544
541 void TestCopyInForeignFileHelper(bool overwrite) { 545 void TestCopyInForeignFileHelper(bool overwrite) {
542 base::ScopedTempDir source_dir; 546 base::ScopedTempDir source_dir;
543 ASSERT_TRUE(source_dir.CreateUniqueTempDir()); 547 ASSERT_TRUE(source_dir.CreateUniqueTempDir());
544 base::FilePath root_file_path = source_dir.path(); 548 base::FilePath root_file_path = source_dir.path();
545 base::FilePath src_file_path = root_file_path.AppendASCII("file_name"); 549 base::FilePath src_file_path = root_file_path.AppendASCII("file_name");
546 FileSystemURL dest_url = CreateURLFromUTF8("new file"); 550 FileSystemURL dest_url = CreateURLFromUTF8("new file");
547 int64 src_file_length = 87; 551 int64_t src_file_length = 87;
548 552
549 base::File file(src_file_path, 553 base::File file(src_file_path,
550 base::File::FLAG_CREATE | base::File::FLAG_WRITE); 554 base::File::FLAG_CREATE | base::File::FLAG_WRITE);
551 ASSERT_TRUE(file.IsValid()); 555 ASSERT_TRUE(file.IsValid());
552 EXPECT_TRUE(file.created()); 556 EXPECT_TRUE(file.created());
553 ASSERT_TRUE(file.SetLength(src_file_length)); 557 ASSERT_TRUE(file.SetLength(src_file_length));
554 file.Close(); 558 file.Close();
555 559
556 scoped_ptr<FileSystemOperationContext> context; 560 scoped_ptr<FileSystemOperationContext> context;
557 561
558 if (overwrite) { 562 if (overwrite) {
559 context.reset(NewContext(NULL)); 563 context.reset(NewContext(NULL));
560 bool created = false; 564 bool created = false;
561 EXPECT_EQ(base::File::FILE_OK, 565 EXPECT_EQ(base::File::FILE_OK,
562 ofu()->EnsureFileExists(context.get(), dest_url, &created)); 566 ofu()->EnsureFileExists(context.get(), dest_url, &created));
563 EXPECT_TRUE(created); 567 EXPECT_TRUE(created);
564 568
565 // We must have observed one (and only one) create_file_count. 569 // We must have observed one (and only one) create_file_count.
566 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); 570 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count());
567 EXPECT_TRUE(change_observer()->HasNoChange()); 571 EXPECT_TRUE(change_observer()->HasNoChange());
568 } 572 }
569 573
570 const int64 path_cost = 574 const int64_t path_cost =
571 ObfuscatedFileUtil::ComputeFilePathCost(dest_url.path()); 575 ObfuscatedFileUtil::ComputeFilePathCost(dest_url.path());
572 if (!overwrite) { 576 if (!overwrite) {
573 // Verify that file creation requires sufficient quota for the path. 577 // Verify that file creation requires sufficient quota for the path.
574 context.reset(NewContext(NULL)); 578 context.reset(NewContext(NULL));
575 context->set_allowed_bytes_growth(path_cost + src_file_length - 1); 579 context->set_allowed_bytes_growth(path_cost + src_file_length - 1);
576 EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE, 580 EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE,
577 ofu()->CopyInForeignFile(context.get(), 581 ofu()->CopyInForeignFile(context.get(),
578 src_file_path, dest_url)); 582 src_file_path, dest_url));
579 } 583 }
580 584
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 EXPECT_FALSE(base::DirectoryExists(old_directory_db_path)); 776 EXPECT_FALSE(base::DirectoryExists(old_directory_db_path));
773 777
774 // Check we see the same contents in the new origin directory. 778 // Check we see the same contents in the new origin directory.
775 std::string origin_db_data; 779 std::string origin_db_data;
776 EXPECT_TRUE(base::PathExists(origin_directory.AppendASCII("dummy"))); 780 EXPECT_TRUE(base::PathExists(origin_directory.AppendASCII("dummy")));
777 EXPECT_TRUE(base::ReadFileToString( 781 EXPECT_TRUE(base::ReadFileToString(
778 origin_directory.AppendASCII("dummy"), &origin_db_data)); 782 origin_directory.AppendASCII("dummy"), &origin_db_data));
779 EXPECT_EQ(kFakeDirectoryData, origin_db_data); 783 EXPECT_EQ(kFakeDirectoryData, origin_db_data);
780 } 784 }
781 785
782 int64 ComputeCurrentUsage() { 786 int64_t ComputeCurrentUsage() {
783 return sandbox_file_system_.ComputeCurrentOriginUsage() - 787 return sandbox_file_system_.ComputeCurrentOriginUsage() -
784 sandbox_file_system_.ComputeCurrentDirectoryDatabaseUsage(); 788 sandbox_file_system_.ComputeCurrentDirectoryDatabaseUsage();
785 } 789 }
786 790
787 FileSystemContext* file_system_context() { 791 FileSystemContext* file_system_context() {
788 return sandbox_file_system_.file_system_context(); 792 return sandbox_file_system_.file_system_context();
789 } 793 }
790 794
791 const base::FilePath& data_dir_path() const { 795 const base::FilePath& data_dir_path() const {
792 return data_dir_.path(); 796 return data_dir_.path();
793 } 797 }
794 798
795 protected: 799 protected:
796 base::ScopedTempDir data_dir_; 800 base::ScopedTempDir data_dir_;
797 base::MessageLoopForIO message_loop_; 801 base::MessageLoopForIO message_loop_;
798 scoped_refptr<MockSpecialStoragePolicy> storage_policy_; 802 scoped_refptr<MockSpecialStoragePolicy> storage_policy_;
799 scoped_refptr<storage::QuotaManager> quota_manager_; 803 scoped_refptr<storage::QuotaManager> quota_manager_;
800 scoped_refptr<FileSystemContext> file_system_context_; 804 scoped_refptr<FileSystemContext> file_system_context_;
801 GURL origin_; 805 GURL origin_;
802 storage::FileSystemType type_; 806 storage::FileSystemType type_;
803 SandboxFileSystemTestHelper sandbox_file_system_; 807 SandboxFileSystemTestHelper sandbox_file_system_;
804 storage::QuotaStatusCode quota_status_; 808 storage::QuotaStatusCode quota_status_;
805 int64 usage_; 809 int64_t usage_;
806 storage::MockFileChangeObserver change_observer_; 810 storage::MockFileChangeObserver change_observer_;
807 storage::ChangeObserverList change_observers_; 811 storage::ChangeObserverList change_observers_;
808 base::WeakPtrFactory<ObfuscatedFileUtilTest> weak_factory_; 812 base::WeakPtrFactory<ObfuscatedFileUtilTest> weak_factory_;
809 813
810 private: 814 private:
811 DISALLOW_COPY_AND_ASSIGN(ObfuscatedFileUtilTest); 815 DISALLOW_COPY_AND_ASSIGN(ObfuscatedFileUtilTest);
812 }; 816 };
813 817
814 TEST_F(ObfuscatedFileUtilTest, TestCreateAndDeleteFile) { 818 TEST_F(ObfuscatedFileUtilTest, TestCreateAndDeleteFile) {
815 FileSystemURL url = CreateURLFromUTF8("fake/file"); 819 FileSystemURL url = CreateURLFromUTF8("fake/file");
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
1257 url = CreateURLFromUTF8("file name"); 1261 url = CreateURLFromUTF8("file name");
1258 context->set_allowed_bytes_growth(5); 1262 context->set_allowed_bytes_growth(5);
1259 bool created = false; 1263 bool created = false;
1260 EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE, 1264 EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE,
1261 ofu()->EnsureFileExists(context.get(), url, &created)); 1265 ofu()->EnsureFileExists(context.get(), url, &created));
1262 EXPECT_FALSE(created); 1266 EXPECT_FALSE(created);
1263 context->set_allowed_bytes_growth(1024); 1267 context->set_allowed_bytes_growth(1024);
1264 EXPECT_EQ(base::File::FILE_OK, 1268 EXPECT_EQ(base::File::FILE_OK,
1265 ofu()->EnsureFileExists(context.get(), url, &created)); 1269 ofu()->EnsureFileExists(context.get(), url, &created));
1266 EXPECT_TRUE(created); 1270 EXPECT_TRUE(created);
1267 int64 path_cost = ObfuscatedFileUtil::ComputeFilePathCost(url.path()); 1271 int64_t path_cost = ObfuscatedFileUtil::ComputeFilePathCost(url.path());
1268 EXPECT_EQ(1024 - path_cost, context->allowed_bytes_growth()); 1272 EXPECT_EQ(1024 - path_cost, context->allowed_bytes_growth());
1269 1273
1270 context->set_allowed_bytes_growth(1024); 1274 context->set_allowed_bytes_growth(1024);
1271 bool exclusive = true; 1275 bool exclusive = true;
1272 bool recursive = true; 1276 bool recursive = true;
1273 url = CreateURLFromUTF8("directory/to/use"); 1277 url = CreateURLFromUTF8("directory/to/use");
1274 std::vector<base::FilePath::StringType> components; 1278 std::vector<base::FilePath::StringType> components;
1275 url.path().GetComponents(&components); 1279 url.path().GetComponents(&components);
1276 path_cost = 0; 1280 path_cost = 0;
1277 typedef std::vector<base::FilePath::StringType>::iterator iterator; 1281 typedef std::vector<base::FilePath::StringType>::iterator iterator;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1323 context.reset(NewContext(NULL)); 1327 context.reset(NewContext(NULL));
1324 is_copy_not_move = true; 1328 is_copy_not_move = true;
1325 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, 1329 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
1326 ofu()->CopyOrMoveFile(context.get(), source_url, dest_url, 1330 ofu()->CopyOrMoveFile(context.get(), source_url, dest_url,
1327 FileSystemOperation::OPTION_NONE, 1331 FileSystemOperation::OPTION_NONE,
1328 is_copy_not_move)); 1332 is_copy_not_move));
1329 EXPECT_TRUE(change_observer()->HasNoChange()); 1333 EXPECT_TRUE(change_observer()->HasNoChange());
1330 } 1334 }
1331 1335
1332 TEST_F(ObfuscatedFileUtilTest, TestCopyOrMoveFileSuccess) { 1336 TEST_F(ObfuscatedFileUtilTest, TestCopyOrMoveFileSuccess) {
1333 const int64 kSourceLength = 5; 1337 const int64_t kSourceLength = 5;
1334 const int64 kDestLength = 50; 1338 const int64_t kDestLength = 50;
1335 1339
1336 for (size_t i = 0; i < arraysize(kCopyMoveTestCases); ++i) { 1340 for (size_t i = 0; i < arraysize(kCopyMoveTestCases); ++i) {
1337 SCOPED_TRACE(testing::Message() << "kCopyMoveTestCase " << i); 1341 SCOPED_TRACE(testing::Message() << "kCopyMoveTestCase " << i);
1338 const CopyMoveTestCaseRecord& test_case = kCopyMoveTestCases[i]; 1342 const CopyMoveTestCaseRecord& test_case = kCopyMoveTestCases[i];
1339 SCOPED_TRACE(testing::Message() << "\t is_copy_not_move " << 1343 SCOPED_TRACE(testing::Message() << "\t is_copy_not_move " <<
1340 test_case.is_copy_not_move); 1344 test_case.is_copy_not_move);
1341 SCOPED_TRACE(testing::Message() << "\t source_path " << 1345 SCOPED_TRACE(testing::Message() << "\t source_path " <<
1342 test_case.source_path); 1346 test_case.source_path);
1343 SCOPED_TRACE(testing::Message() << "\t dest_path " << 1347 SCOPED_TRACE(testing::Message() << "\t dest_path " <<
1344 test_case.dest_path); 1348 test_case.dest_path);
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
1497 FileSystemURL dir_url = CreateURLFromUTF8("directory path"); 1501 FileSystemURL dir_url = CreateURLFromUTF8("directory path");
1498 context.reset(NewContext(NULL)); 1502 context.reset(NewContext(NULL));
1499 ASSERT_EQ(base::File::FILE_OK, 1503 ASSERT_EQ(base::File::FILE_OK,
1500 ofu()->CreateDirectory(context.get(), dir_url, exclusive, 1504 ofu()->CreateDirectory(context.get(), dir_url, exclusive,
1501 recursive)); 1505 recursive));
1502 1506
1503 FileSystemURL dest_url = FileSystemURLAppend( 1507 FileSystemURL dest_url = FileSystemURLAppend(
1504 dir_url, src_url.path().value()); 1508 dir_url, src_url.path().value());
1505 1509
1506 bool is_copy = false; 1510 bool is_copy = false;
1507 int64 allowed_bytes_growth = -1000; // Over quota, this should still work. 1511 int64_t allowed_bytes_growth = -1000; // Over quota, this should still work.
1508 // Move, no rename, no overwrite. 1512 // Move, no rename, no overwrite.
1509 context.reset(NewContext(NULL)); 1513 context.reset(NewContext(NULL));
1510 context->set_allowed_bytes_growth(allowed_bytes_growth); 1514 context->set_allowed_bytes_growth(allowed_bytes_growth);
1511 EXPECT_EQ(base::File::FILE_OK, 1515 EXPECT_EQ(base::File::FILE_OK,
1512 ofu()->CopyOrMoveFile(context.get(), src_url, dest_url, 1516 ofu()->CopyOrMoveFile(context.get(), src_url, dest_url,
1513 FileSystemOperation::OPTION_NONE, is_copy)); 1517 FileSystemOperation::OPTION_NONE, is_copy));
1514 EXPECT_EQ(allowed_bytes_growth, context->allowed_bytes_growth()); 1518 EXPECT_EQ(allowed_bytes_growth, context->allowed_bytes_growth());
1515 1519
1516 // Move, no rename, with overwrite. 1520 // Move, no rename, with overwrite.
1517 context.reset(NewContext(NULL)); 1521 context.reset(NewContext(NULL));
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1648 std::set<GURL> diff; 1652 std::set<GURL> diff;
1649 std::set_symmetric_difference(origins_expected.begin(), 1653 std::set_symmetric_difference(origins_expected.begin(),
1650 origins_expected.end(), origins_found.begin(), origins_found.end(), 1654 origins_expected.end(), origins_found.begin(), origins_found.end(),
1651 inserter(diff, diff.begin())); 1655 inserter(diff, diff.begin()));
1652 EXPECT_TRUE(diff.empty()); 1656 EXPECT_TRUE(diff.empty());
1653 } 1657 }
1654 1658
1655 TEST_F(ObfuscatedFileUtilTest, TestRevokeUsageCache) { 1659 TEST_F(ObfuscatedFileUtilTest, TestRevokeUsageCache) {
1656 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); 1660 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
1657 1661
1658 int64 expected_quota = 0; 1662 int64_t expected_quota = 0;
1659 1663
1660 for (size_t i = 0; i < kRegularFileSystemTestCaseSize; ++i) { 1664 for (size_t i = 0; i < kRegularFileSystemTestCaseSize; ++i) {
1661 SCOPED_TRACE(testing::Message() << "Creating kRegularTestCase " << i); 1665 SCOPED_TRACE(testing::Message() << "Creating kRegularTestCase " << i);
1662 const FileSystemTestCaseRecord& test_case = 1666 const FileSystemTestCaseRecord& test_case =
1663 kRegularFileSystemTestCases[i]; 1667 kRegularFileSystemTestCases[i];
1664 base::FilePath file_path(test_case.path); 1668 base::FilePath file_path(test_case.path);
1665 expected_quota += ObfuscatedFileUtil::ComputeFilePathCost(file_path); 1669 expected_quota += ObfuscatedFileUtil::ComputeFilePathCost(file_path);
1666 if (test_case.is_directory) { 1670 if (test_case.is_directory) {
1667 bool exclusive = true; 1671 bool exclusive = true;
1668 bool recursive = false; 1672 bool recursive = false;
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
2065 #else 2069 #else
2066 #define MAYBE_TestQuotaOnCopyFile TestQuotaOnCopyFile 2070 #define MAYBE_TestQuotaOnCopyFile TestQuotaOnCopyFile
2067 #endif 2071 #endif
2068 TEST_F(ObfuscatedFileUtilTest, MAYBE_TestQuotaOnCopyFile) { 2072 TEST_F(ObfuscatedFileUtilTest, MAYBE_TestQuotaOnCopyFile) {
2069 FileSystemURL from_file(CreateURLFromUTF8("fromfile")); 2073 FileSystemURL from_file(CreateURLFromUTF8("fromfile"));
2070 FileSystemURL obstacle_file(CreateURLFromUTF8("obstaclefile")); 2074 FileSystemURL obstacle_file(CreateURLFromUTF8("obstaclefile"));
2071 FileSystemURL to_file1(CreateURLFromUTF8("tofile1")); 2075 FileSystemURL to_file1(CreateURLFromUTF8("tofile1"));
2072 FileSystemURL to_file2(CreateURLFromUTF8("tofile2")); 2076 FileSystemURL to_file2(CreateURLFromUTF8("tofile2"));
2073 bool created; 2077 bool created;
2074 2078
2075 int64 expected_total_file_size = 0; 2079 int64_t expected_total_file_size = 0;
2076 ASSERT_EQ(base::File::FILE_OK, 2080 ASSERT_EQ(base::File::FILE_OK,
2077 ofu()->EnsureFileExists( 2081 ofu()->EnsureFileExists(
2078 AllowUsageIncrease(PathCost(from_file))->context(), 2082 AllowUsageIncrease(PathCost(from_file))->context(),
2079 from_file, &created)); 2083 from_file, &created));
2080 ASSERT_TRUE(created); 2084 ASSERT_TRUE(created);
2081 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize()); 2085 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
2082 2086
2083 ASSERT_EQ(base::File::FILE_OK, 2087 ASSERT_EQ(base::File::FILE_OK,
2084 ofu()->EnsureFileExists( 2088 ofu()->EnsureFileExists(
2085 AllowUsageIncrease(PathCost(obstacle_file))->context(), 2089 AllowUsageIncrease(PathCost(obstacle_file))->context(),
2086 obstacle_file, &created)); 2090 obstacle_file, &created));
2087 ASSERT_TRUE(created); 2091 ASSERT_TRUE(created);
2088 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize()); 2092 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
2089 2093
2090 int64 from_file_size = 1020; 2094 int64_t from_file_size = 1020;
2091 expected_total_file_size += from_file_size; 2095 expected_total_file_size += from_file_size;
2092 ASSERT_EQ(base::File::FILE_OK, 2096 ASSERT_EQ(base::File::FILE_OK,
2093 ofu()->Truncate( 2097 ofu()->Truncate(
2094 AllowUsageIncrease(from_file_size)->context(), 2098 AllowUsageIncrease(from_file_size)->context(),
2095 from_file, from_file_size)); 2099 from_file, from_file_size));
2096 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize()); 2100 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
2097 2101
2098 int64 obstacle_file_size = 1; 2102 int64_t obstacle_file_size = 1;
2099 expected_total_file_size += obstacle_file_size; 2103 expected_total_file_size += obstacle_file_size;
2100 ASSERT_EQ(base::File::FILE_OK, 2104 ASSERT_EQ(base::File::FILE_OK,
2101 ofu()->Truncate( 2105 ofu()->Truncate(
2102 AllowUsageIncrease(obstacle_file_size)->context(), 2106 AllowUsageIncrease(obstacle_file_size)->context(),
2103 obstacle_file, obstacle_file_size)); 2107 obstacle_file, obstacle_file_size));
2104 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize()); 2108 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
2105 2109
2106 int64 to_file1_size = from_file_size; 2110 int64_t to_file1_size = from_file_size;
2107 expected_total_file_size += to_file1_size; 2111 expected_total_file_size += to_file1_size;
2108 ASSERT_EQ(base::File::FILE_OK, 2112 ASSERT_EQ(base::File::FILE_OK,
2109 ofu()->CopyOrMoveFile( 2113 ofu()->CopyOrMoveFile(
2110 AllowUsageIncrease( 2114 AllowUsageIncrease(
2111 PathCost(to_file1) + to_file1_size)->context(), 2115 PathCost(to_file1) + to_file1_size)->context(),
2112 from_file, to_file1, 2116 from_file, to_file1,
2113 FileSystemOperation::OPTION_NONE, 2117 FileSystemOperation::OPTION_NONE,
2114 true /* copy */)); 2118 true /* copy */));
2115 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize()); 2119 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
2116 2120
2117 ASSERT_EQ(base::File::FILE_ERROR_NO_SPACE, 2121 ASSERT_EQ(base::File::FILE_ERROR_NO_SPACE,
2118 ofu()->CopyOrMoveFile( 2122 ofu()->CopyOrMoveFile(
2119 DisallowUsageIncrease( 2123 DisallowUsageIncrease(
2120 PathCost(to_file2) + from_file_size)->context(), 2124 PathCost(to_file2) + from_file_size)->context(),
2121 from_file, to_file2, FileSystemOperation::OPTION_NONE, 2125 from_file, to_file2, FileSystemOperation::OPTION_NONE,
2122 true /* copy */)); 2126 true /* copy */));
2123 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize()); 2127 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
2124 2128
2125 int64 old_obstacle_file_size = obstacle_file_size; 2129 int64_t old_obstacle_file_size = obstacle_file_size;
2126 obstacle_file_size = from_file_size; 2130 obstacle_file_size = from_file_size;
2127 expected_total_file_size += obstacle_file_size - old_obstacle_file_size; 2131 expected_total_file_size += obstacle_file_size - old_obstacle_file_size;
2128 ASSERT_EQ(base::File::FILE_OK, 2132 ASSERT_EQ(base::File::FILE_OK,
2129 ofu()->CopyOrMoveFile( 2133 ofu()->CopyOrMoveFile(
2130 AllowUsageIncrease( 2134 AllowUsageIncrease(
2131 obstacle_file_size - old_obstacle_file_size)->context(), 2135 obstacle_file_size - old_obstacle_file_size)->context(),
2132 from_file, obstacle_file, 2136 from_file, obstacle_file,
2133 FileSystemOperation::OPTION_NONE, 2137 FileSystemOperation::OPTION_NONE,
2134 true /* copy */)); 2138 true /* copy */));
2135 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize()); 2139 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
2136 2140
2137 int64 old_from_file_size = from_file_size; 2141 int64_t old_from_file_size = from_file_size;
2138 from_file_size = old_from_file_size - 1; 2142 from_file_size = old_from_file_size - 1;
2139 expected_total_file_size += from_file_size - old_from_file_size; 2143 expected_total_file_size += from_file_size - old_from_file_size;
2140 ASSERT_EQ(base::File::FILE_OK, 2144 ASSERT_EQ(base::File::FILE_OK,
2141 ofu()->Truncate( 2145 ofu()->Truncate(
2142 AllowUsageIncrease( 2146 AllowUsageIncrease(
2143 from_file_size - old_from_file_size)->context(), 2147 from_file_size - old_from_file_size)->context(),
2144 from_file, from_file_size)); 2148 from_file, from_file_size));
2145 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize()); 2149 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
2146 2150
2147 // quota exceeded 2151 // quota exceeded
(...skipping 14 matching lines...) Expand all
2162 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize()); 2166 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
2163 } 2167 }
2164 } 2168 }
2165 2169
2166 TEST_F(ObfuscatedFileUtilTest, TestQuotaOnMoveFile) { 2170 TEST_F(ObfuscatedFileUtilTest, TestQuotaOnMoveFile) {
2167 FileSystemURL from_file(CreateURLFromUTF8("fromfile")); 2171 FileSystemURL from_file(CreateURLFromUTF8("fromfile"));
2168 FileSystemURL obstacle_file(CreateURLFromUTF8("obstaclefile")); 2172 FileSystemURL obstacle_file(CreateURLFromUTF8("obstaclefile"));
2169 FileSystemURL to_file(CreateURLFromUTF8("tofile")); 2173 FileSystemURL to_file(CreateURLFromUTF8("tofile"));
2170 bool created; 2174 bool created;
2171 2175
2172 int64 expected_total_file_size = 0; 2176 int64_t expected_total_file_size = 0;
2173 ASSERT_EQ(base::File::FILE_OK, 2177 ASSERT_EQ(base::File::FILE_OK,
2174 ofu()->EnsureFileExists( 2178 ofu()->EnsureFileExists(
2175 AllowUsageIncrease(PathCost(from_file))->context(), 2179 AllowUsageIncrease(PathCost(from_file))->context(),
2176 from_file, &created)); 2180 from_file, &created));
2177 ASSERT_TRUE(created); 2181 ASSERT_TRUE(created);
2178 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize()); 2182 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
2179 2183
2180 int64 from_file_size = 1020; 2184 int64_t from_file_size = 1020;
2181 expected_total_file_size += from_file_size; 2185 expected_total_file_size += from_file_size;
2182 ASSERT_EQ(base::File::FILE_OK, 2186 ASSERT_EQ(base::File::FILE_OK,
2183 ofu()->Truncate( 2187 ofu()->Truncate(
2184 AllowUsageIncrease(from_file_size)->context(), 2188 AllowUsageIncrease(from_file_size)->context(),
2185 from_file, from_file_size)); 2189 from_file, from_file_size));
2186 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize()); 2190 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
2187 2191
2188 from_file_size = 0; 2192 from_file_size = 0;
2189 ASSERT_EQ(base::File::FILE_OK, 2193 ASSERT_EQ(base::File::FILE_OK,
2190 ofu()->CopyOrMoveFile( 2194 ofu()->CopyOrMoveFile(
(...skipping 19 matching lines...) Expand all
2210 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize()); 2214 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
2211 2215
2212 from_file_size = 1020; 2216 from_file_size = 1020;
2213 expected_total_file_size += from_file_size; 2217 expected_total_file_size += from_file_size;
2214 ASSERT_EQ(base::File::FILE_OK, 2218 ASSERT_EQ(base::File::FILE_OK,
2215 ofu()->Truncate( 2219 ofu()->Truncate(
2216 AllowUsageIncrease(from_file_size)->context(), 2220 AllowUsageIncrease(from_file_size)->context(),
2217 from_file, from_file_size)); 2221 from_file, from_file_size));
2218 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize()); 2222 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
2219 2223
2220 int64 obstacle_file_size = 1; 2224 int64_t obstacle_file_size = 1;
2221 expected_total_file_size += obstacle_file_size; 2225 expected_total_file_size += obstacle_file_size;
2222 ASSERT_EQ(base::File::FILE_OK, 2226 ASSERT_EQ(base::File::FILE_OK,
2223 ofu()->Truncate( 2227 ofu()->Truncate(
2224 AllowUsageIncrease(1)->context(), 2228 AllowUsageIncrease(1)->context(),
2225 obstacle_file, obstacle_file_size)); 2229 obstacle_file, obstacle_file_size));
2226 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize()); 2230 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
2227 2231
2228 int64 old_obstacle_file_size = obstacle_file_size; 2232 int64_t old_obstacle_file_size = obstacle_file_size;
2229 obstacle_file_size = from_file_size; 2233 obstacle_file_size = from_file_size;
2230 from_file_size = 0; 2234 from_file_size = 0;
2231 expected_total_file_size -= old_obstacle_file_size; 2235 expected_total_file_size -= old_obstacle_file_size;
2232 ASSERT_EQ(base::File::FILE_OK, 2236 ASSERT_EQ(base::File::FILE_OK,
2233 ofu()->CopyOrMoveFile( 2237 ofu()->CopyOrMoveFile(
2234 AllowUsageIncrease( 2238 AllowUsageIncrease(
2235 -old_obstacle_file_size - PathCost(from_file))->context(), 2239 -old_obstacle_file_size - PathCost(from_file))->context(),
2236 from_file, obstacle_file, 2240 from_file, obstacle_file,
2237 FileSystemOperation::OPTION_NONE, 2241 FileSystemOperation::OPTION_NONE,
2238 false /* move */)); 2242 false /* move */));
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
2560 ofu()->GetDirectoryForOriginAndType( 2564 ofu()->GetDirectoryForOriginAndType(
2561 origin2, GetTypeString(kFileSystemTypeTemporary), false, &error); 2565 origin2, GetTypeString(kFileSystemTypeTemporary), false, &error);
2562 ASSERT_EQ(base::File::FILE_OK, error); 2566 ASSERT_EQ(base::File::FILE_OK, error);
2563 error = base::File::FILE_ERROR_FAILED; 2567 error = base::File::FILE_ERROR_FAILED;
2564 ofu()->GetDirectoryForOriginAndType( 2568 ofu()->GetDirectoryForOriginAndType(
2565 origin2, GetTypeString(kFileSystemTypePersistent), false, &error); 2569 origin2, GetTypeString(kFileSystemTypePersistent), false, &error);
2566 ASSERT_EQ(base::File::FILE_OK, error); 2570 ASSERT_EQ(base::File::FILE_OK, error);
2567 } 2571 }
2568 2572
2569 } // namespace content 2573 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/fileapi/file_writer_delegate_unittest.cc ('k') | content/browser/quota/mock_quota_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698