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

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

Issue 145303002: Convert Media Galleries to use base::File (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 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 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 <set> 5 #include <set>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/files/file.h"
11 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
12 #include "base/files/scoped_temp_dir.h" 13 #include "base/files/scoped_temp_dir.h"
13 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
14 #include "base/platform_file.h" 15 #include "base/platform_file.h"
15 #include "base/run_loop.h" 16 #include "base/run_loop.h"
16 #include "content/public/test/sandbox_file_system_test_helper.h" 17 #include "content/public/test/sandbox_file_system_test_helper.h"
17 #include "content/public/test/test_file_system_context.h" 18 #include "content/public/test/test_file_system_context.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
19 #include "webkit/browser/fileapi/async_file_test_helper.h" 20 #include "webkit/browser/fileapi/async_file_test_helper.h"
20 #include "webkit/browser/fileapi/external_mount_points.h" 21 #include "webkit/browser/fileapi/external_mount_points.h"
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 287
287 int64 SizeInUsageFile() { 288 int64 SizeInUsageFile() {
288 base::RunLoop().RunUntilIdle(); 289 base::RunLoop().RunUntilIdle();
289 int64 usage = 0; 290 int64 usage = 0;
290 return usage_cache()->GetUsage( 291 return usage_cache()->GetUsage(
291 sandbox_file_system_.GetUsageCachePath(), &usage) ? usage : -1; 292 sandbox_file_system_.GetUsageCachePath(), &usage) ? usage : -1;
292 } 293 }
293 294
294 bool PathExists(const FileSystemURL& url) { 295 bool PathExists(const FileSystemURL& url) {
295 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); 296 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
296 base::PlatformFileInfo file_info; 297 base::File::Info file_info;
297 base::FilePath platform_path; 298 base::FilePath platform_path;
298 base::PlatformFileError error = ofu()->GetFileInfo( 299 base::File::Error error = ofu()->GetFileInfo(
299 context.get(), url, &file_info, &platform_path); 300 context.get(), url, &file_info, &platform_path);
300 return error == base::PLATFORM_FILE_OK; 301 return error == base::File::FILE_OK;
301 } 302 }
302 303
303 bool DirectoryExists(const FileSystemURL& url) { 304 bool DirectoryExists(const FileSystemURL& url) {
304 return AsyncFileTestHelper::DirectoryExists(file_system_context(), url); 305 return AsyncFileTestHelper::DirectoryExists(file_system_context(), url);
305 } 306 }
306 307
307 int64 usage() const { return usage_; } 308 int64 usage() const { return usage_; }
308 fileapi::FileSystemUsageCache* usage_cache() { 309 fileapi::FileSystemUsageCache* usage_cache() {
309 return sandbox_file_system_.usage_cache(); 310 return sandbox_file_system_.usage_cache();
310 } 311 }
311 312
312 FileSystemURL CreateURLFromUTF8(const std::string& path) { 313 FileSystemURL CreateURLFromUTF8(const std::string& path) {
313 return sandbox_file_system_.CreateURLFromUTF8(path); 314 return sandbox_file_system_.CreateURLFromUTF8(path);
314 } 315 }
315 316
316 int64 PathCost(const FileSystemURL& url) { 317 int64 PathCost(const FileSystemURL& url) {
317 return ObfuscatedFileUtil::ComputeFilePathCost(url.path()); 318 return ObfuscatedFileUtil::ComputeFilePathCost(url.path());
318 } 319 }
319 320
320 FileSystemURL CreateURL(const base::FilePath& path) { 321 FileSystemURL CreateURL(const base::FilePath& path) {
321 return sandbox_file_system_.CreateURL(path); 322 return sandbox_file_system_.CreateURL(path);
322 } 323 }
323 324
324 void CheckFileAndCloseHandle( 325 void CheckFileAndCloseHandle(
325 const FileSystemURL& url, base::PlatformFile file_handle) { 326 const FileSystemURL& url, base::PlatformFile file_handle) {
326 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); 327 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
327 base::FilePath local_path; 328 base::FilePath local_path;
328 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetLocalFilePath( 329 EXPECT_EQ(base::File::FILE_OK,
329 context.get(), url, &local_path)); 330 ofu()->GetLocalFilePath(context.get(), url, &local_path));
330 331
331 base::PlatformFileInfo file_info0; 332 base::File::Info file_info0;
332 base::FilePath data_path; 333 base::FilePath data_path;
333 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo( 334 EXPECT_EQ(base::File::FILE_OK,
334 context.get(), url, &file_info0, &data_path)); 335 ofu()->GetFileInfo(context.get(), url, &file_info0, &data_path));
335 EXPECT_EQ(data_path, local_path); 336 EXPECT_EQ(data_path, local_path);
336 EXPECT_TRUE(FileExists(data_path)); 337 EXPECT_TRUE(FileExists(data_path));
337 EXPECT_EQ(0, GetSize(data_path)); 338 EXPECT_EQ(0, GetSize(data_path));
338 339
339 const char data[] = "test data"; 340 const char data[] = "test data";
340 const int length = arraysize(data) - 1; 341 const int length = arraysize(data) - 1;
341 342
342 if (base::kInvalidPlatformFileValue == file_handle) { 343 if (base::kInvalidPlatformFileValue == file_handle) {
343 bool created = true; 344 base::File file(data_path,
344 base::PlatformFileError error; 345 base::File::FLAG_OPEN | base::File::FLAG_WRITE);
345 file_handle = base::CreatePlatformFile( 346 ASSERT_TRUE(file.IsValid());
346 data_path, 347 EXPECT_FALSE(file.created());
347 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE, 348 file_handle = file.TakePlatformFile();
348 &created,
349 &error);
350 ASSERT_NE(base::kInvalidPlatformFileValue, file_handle);
351 ASSERT_EQ(base::PLATFORM_FILE_OK, error);
352 EXPECT_FALSE(created);
353 } 349 }
354 ASSERT_EQ(length, base::WritePlatformFile(file_handle, 0, data, length)); 350 ASSERT_EQ(length, base::WritePlatformFile(file_handle, 0, data, length));
355 EXPECT_TRUE(base::ClosePlatformFile(file_handle)); 351 EXPECT_TRUE(base::ClosePlatformFile(file_handle));
356 352
357 base::PlatformFileInfo file_info1; 353 base::File::Info file_info1;
358 EXPECT_EQ(length, GetSize(data_path)); 354 EXPECT_EQ(length, GetSize(data_path));
359 context.reset(NewContext(NULL)); 355 context.reset(NewContext(NULL));
360 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo( 356 EXPECT_EQ(base::File::FILE_OK,
361 context.get(), url, &file_info1, &data_path)); 357 ofu()->GetFileInfo(context.get(), url, &file_info1, &data_path));
362 EXPECT_EQ(data_path, local_path); 358 EXPECT_EQ(data_path, local_path);
363 359
364 EXPECT_FALSE(file_info0.is_directory); 360 EXPECT_FALSE(file_info0.is_directory);
365 EXPECT_FALSE(file_info1.is_directory); 361 EXPECT_FALSE(file_info1.is_directory);
366 EXPECT_FALSE(file_info0.is_symbolic_link); 362 EXPECT_FALSE(file_info0.is_symbolic_link);
367 EXPECT_FALSE(file_info1.is_symbolic_link); 363 EXPECT_FALSE(file_info1.is_symbolic_link);
368 EXPECT_EQ(0, file_info0.size); 364 EXPECT_EQ(0, file_info0.size);
369 EXPECT_EQ(length, file_info1.size); 365 EXPECT_EQ(length, file_info1.size);
370 EXPECT_LE(file_info0.last_modified, file_info1.last_modified); 366 EXPECT_LE(file_info0.last_modified, file_info1.last_modified);
371 367
372 context.reset(NewContext(NULL)); 368 context.reset(NewContext(NULL));
373 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->Truncate( 369 EXPECT_EQ(base::File::FILE_OK,
374 context.get(), url, length * 2)); 370 ofu()->Truncate(context.get(), url, length * 2));
375 EXPECT_EQ(length * 2, GetSize(data_path)); 371 EXPECT_EQ(length * 2, GetSize(data_path));
376 372
377 context.reset(NewContext(NULL)); 373 context.reset(NewContext(NULL));
378 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->Truncate( 374 EXPECT_EQ(base::File::FILE_OK,
379 context.get(), url, 0)); 375 ofu()->Truncate(context.get(), url, 0));
380 EXPECT_EQ(0, GetSize(data_path)); 376 EXPECT_EQ(0, GetSize(data_path));
381 } 377 }
382 378
383 void ValidateTestDirectory( 379 void ValidateTestDirectory(
384 const FileSystemURL& root_url, 380 const FileSystemURL& root_url,
385 const std::set<base::FilePath::StringType>& files, 381 const std::set<base::FilePath::StringType>& files,
386 const std::set<base::FilePath::StringType>& directories) { 382 const std::set<base::FilePath::StringType>& directories) {
387 scoped_ptr<FileSystemOperationContext> context; 383 scoped_ptr<FileSystemOperationContext> context;
388 std::set<base::FilePath::StringType>::const_iterator iter; 384 std::set<base::FilePath::StringType>::const_iterator iter;
389 for (iter = files.begin(); iter != files.end(); ++iter) { 385 for (iter = files.begin(); iter != files.end(); ++iter) {
390 bool created = true; 386 bool created = true;
391 context.reset(NewContext(NULL)); 387 context.reset(NewContext(NULL));
392 ASSERT_EQ(base::PLATFORM_FILE_OK, 388 ASSERT_EQ(base::File::FILE_OK,
393 ofu()->EnsureFileExists( 389 ofu()->EnsureFileExists(context.get(),
394 context.get(), FileSystemURLAppend(root_url, *iter), 390 FileSystemURLAppend(root_url, *iter),
395 &created)); 391 &created));
396 ASSERT_FALSE(created); 392 ASSERT_FALSE(created);
397 } 393 }
398 for (iter = directories.begin(); iter != directories.end(); ++iter) { 394 for (iter = directories.begin(); iter != directories.end(); ++iter) {
399 context.reset(NewContext(NULL)); 395 context.reset(NewContext(NULL));
400 EXPECT_TRUE(DirectoryExists( 396 EXPECT_TRUE(DirectoryExists(
401 FileSystemURLAppend(root_url, *iter))); 397 FileSystemURLAppend(root_url, *iter)));
402 } 398 }
403 } 399 }
404 400
405 class UsageVerifyHelper { 401 class UsageVerifyHelper {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 return scoped_ptr<UsageVerifyHelper>(new UsageVerifyHelper( 439 return scoped_ptr<UsageVerifyHelper>(new UsageVerifyHelper(
444 LimitedContext(requested_growth - 1), &sandbox_file_system_, usage)); 440 LimitedContext(requested_growth - 1), &sandbox_file_system_, usage));
445 } 441 }
446 442
447 void FillTestDirectory( 443 void FillTestDirectory(
448 const FileSystemURL& root_url, 444 const FileSystemURL& root_url,
449 std::set<base::FilePath::StringType>* files, 445 std::set<base::FilePath::StringType>* files,
450 std::set<base::FilePath::StringType>* directories) { 446 std::set<base::FilePath::StringType>* directories) {
451 scoped_ptr<FileSystemOperationContext> context; 447 scoped_ptr<FileSystemOperationContext> context;
452 std::vector<fileapi::DirectoryEntry> entries; 448 std::vector<fileapi::DirectoryEntry> entries;
453 EXPECT_EQ(base::PLATFORM_FILE_OK, 449 EXPECT_EQ(base::File::FILE_OK,
454 AsyncFileTestHelper::ReadDirectory( 450 AsyncFileTestHelper::ReadDirectory(file_system_context(),
455 file_system_context(), root_url, &entries)); 451 root_url, &entries));
456 EXPECT_EQ(0UL, entries.size()); 452 EXPECT_EQ(0UL, entries.size());
457 453
458 files->clear(); 454 files->clear();
459 files->insert(FILE_PATH_LITERAL("first")); 455 files->insert(FILE_PATH_LITERAL("first"));
460 files->insert(FILE_PATH_LITERAL("second")); 456 files->insert(FILE_PATH_LITERAL("second"));
461 files->insert(FILE_PATH_LITERAL("third")); 457 files->insert(FILE_PATH_LITERAL("third"));
462 directories->clear(); 458 directories->clear();
463 directories->insert(FILE_PATH_LITERAL("fourth")); 459 directories->insert(FILE_PATH_LITERAL("fourth"));
464 directories->insert(FILE_PATH_LITERAL("fifth")); 460 directories->insert(FILE_PATH_LITERAL("fifth"));
465 directories->insert(FILE_PATH_LITERAL("sixth")); 461 directories->insert(FILE_PATH_LITERAL("sixth"));
466 std::set<base::FilePath::StringType>::iterator iter; 462 std::set<base::FilePath::StringType>::iterator iter;
467 for (iter = files->begin(); iter != files->end(); ++iter) { 463 for (iter = files->begin(); iter != files->end(); ++iter) {
468 bool created = false; 464 bool created = false;
469 context.reset(NewContext(NULL)); 465 context.reset(NewContext(NULL));
470 ASSERT_EQ(base::PLATFORM_FILE_OK, 466 ASSERT_EQ(base::File::FILE_OK,
471 ofu()->EnsureFileExists( 467 ofu()->EnsureFileExists(context.get(),
472 context.get(), 468 FileSystemURLAppend(root_url, *iter),
473 FileSystemURLAppend(root_url, *iter), 469 &created));
474 &created));
475 ASSERT_TRUE(created); 470 ASSERT_TRUE(created);
476 } 471 }
477 for (iter = directories->begin(); iter != directories->end(); ++iter) { 472 for (iter = directories->begin(); iter != directories->end(); ++iter) {
478 bool exclusive = true; 473 bool exclusive = true;
479 bool recursive = false; 474 bool recursive = false;
480 context.reset(NewContext(NULL)); 475 context.reset(NewContext(NULL));
481 EXPECT_EQ(base::PLATFORM_FILE_OK, 476 EXPECT_EQ(base::File::FILE_OK,
482 ofu()->CreateDirectory( 477 ofu()->CreateDirectory(context.get(),
483 context.get(), 478 FileSystemURLAppend(root_url, *iter),
484 FileSystemURLAppend(root_url, *iter), 479 exclusive, recursive));
485 exclusive, recursive));
486 } 480 }
487 ValidateTestDirectory(root_url, *files, *directories); 481 ValidateTestDirectory(root_url, *files, *directories);
488 } 482 }
489 483
490 void TestReadDirectoryHelper(const FileSystemURL& root_url) { 484 void TestReadDirectoryHelper(const FileSystemURL& root_url) {
491 std::set<base::FilePath::StringType> files; 485 std::set<base::FilePath::StringType> files;
492 std::set<base::FilePath::StringType> directories; 486 std::set<base::FilePath::StringType> directories;
493 FillTestDirectory(root_url, &files, &directories); 487 FillTestDirectory(root_url, &files, &directories);
494 488
495 scoped_ptr<FileSystemOperationContext> context; 489 scoped_ptr<FileSystemOperationContext> context;
496 std::vector<fileapi::DirectoryEntry> entries; 490 std::vector<fileapi::DirectoryEntry> entries;
497 context.reset(NewContext(NULL)); 491 context.reset(NewContext(NULL));
498 EXPECT_EQ(base::PLATFORM_FILE_OK, 492 EXPECT_EQ(base::File::FILE_OK,
499 AsyncFileTestHelper::ReadDirectory( 493 AsyncFileTestHelper::ReadDirectory(
500 file_system_context(), root_url, &entries)); 494 file_system_context(), root_url, &entries));
501 std::vector<fileapi::DirectoryEntry>::iterator entry_iter; 495 std::vector<fileapi::DirectoryEntry>::iterator entry_iter;
502 EXPECT_EQ(files.size() + directories.size(), entries.size()); 496 EXPECT_EQ(files.size() + directories.size(), entries.size());
503 EXPECT_TRUE(change_observer()->HasNoChange()); 497 EXPECT_TRUE(change_observer()->HasNoChange());
504 for (entry_iter = entries.begin(); entry_iter != entries.end(); 498 for (entry_iter = entries.begin(); entry_iter != entries.end();
505 ++entry_iter) { 499 ++entry_iter) {
506 const fileapi::DirectoryEntry& entry = *entry_iter; 500 const fileapi::DirectoryEntry& entry = *entry_iter;
507 std::set<base::FilePath::StringType>::iterator iter = 501 std::set<base::FilePath::StringType>::iterator iter =
508 files.find(entry.name); 502 files.find(entry.name);
509 if (iter != files.end()) { 503 if (iter != files.end()) {
510 EXPECT_FALSE(entry.is_directory); 504 EXPECT_FALSE(entry.is_directory);
511 files.erase(iter); 505 files.erase(iter);
512 continue; 506 continue;
513 } 507 }
514 iter = directories.find(entry.name); 508 iter = directories.find(entry.name);
515 EXPECT_FALSE(directories.end() == iter); 509 EXPECT_FALSE(directories.end() == iter);
516 EXPECT_TRUE(entry.is_directory); 510 EXPECT_TRUE(entry.is_directory);
517 directories.erase(iter); 511 directories.erase(iter);
518 } 512 }
519 } 513 }
520 514
521 void TestTouchHelper(const FileSystemURL& url, bool is_file) { 515 void TestTouchHelper(const FileSystemURL& url, bool is_file) {
522 base::Time last_access_time = base::Time::Now(); 516 base::Time last_access_time = base::Time::Now();
523 base::Time last_modified_time = base::Time::Now(); 517 base::Time last_modified_time = base::Time::Now();
524 518
525 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); 519 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
526 EXPECT_EQ(base::PLATFORM_FILE_OK, 520 EXPECT_EQ(base::File::FILE_OK,
527 ofu()->Touch( 521 ofu()->Touch(context.get(), url, last_access_time,
528 context.get(), url, last_access_time, last_modified_time)); 522 last_modified_time));
529 // Currently we fire no change notifications for Touch. 523 // Currently we fire no change notifications for Touch.
530 EXPECT_TRUE(change_observer()->HasNoChange()); 524 EXPECT_TRUE(change_observer()->HasNoChange());
531 base::FilePath local_path; 525 base::FilePath local_path;
532 base::PlatformFileInfo file_info; 526 base::File::Info file_info;
533 context.reset(NewContext(NULL)); 527 context.reset(NewContext(NULL));
534 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo( 528 EXPECT_EQ(base::File::FILE_OK, ofu()->GetFileInfo(
535 context.get(), url, &file_info, &local_path)); 529 context.get(), url, &file_info, &local_path));
536 // We compare as time_t here to lower our resolution, to avoid false 530 // We compare as time_t here to lower our resolution, to avoid false
537 // negatives caused by conversion to the local filesystem's native 531 // negatives caused by conversion to the local filesystem's native
538 // representation and back. 532 // representation and back.
539 EXPECT_EQ(file_info.last_modified.ToTimeT(), last_modified_time.ToTimeT()); 533 EXPECT_EQ(file_info.last_modified.ToTimeT(), last_modified_time.ToTimeT());
540 534
541 context.reset(NewContext(NULL)); 535 context.reset(NewContext(NULL));
542 last_modified_time += base::TimeDelta::FromHours(1); 536 last_modified_time += base::TimeDelta::FromHours(1);
543 last_access_time += base::TimeDelta::FromHours(14); 537 last_access_time += base::TimeDelta::FromHours(14);
544 EXPECT_EQ(base::PLATFORM_FILE_OK, 538 EXPECT_EQ(base::File::FILE_OK,
545 ofu()->Touch( 539 ofu()->Touch(context.get(), url, last_access_time,
546 context.get(), url, last_access_time, last_modified_time)); 540 last_modified_time));
547 EXPECT_TRUE(change_observer()->HasNoChange()); 541 EXPECT_TRUE(change_observer()->HasNoChange());
548 context.reset(NewContext(NULL)); 542 context.reset(NewContext(NULL));
549 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo( 543 EXPECT_EQ(base::File::FILE_OK,
550 context.get(), url, &file_info, &local_path)); 544 ofu()->GetFileInfo(context.get(), url, &file_info, &local_path));
551 EXPECT_EQ(file_info.last_modified.ToTimeT(), last_modified_time.ToTimeT()); 545 EXPECT_EQ(file_info.last_modified.ToTimeT(), last_modified_time.ToTimeT());
552 if (is_file) // Directories in OFU don't support atime. 546 if (is_file) // Directories in OFU don't support atime.
553 EXPECT_EQ(file_info.last_accessed.ToTimeT(), last_access_time.ToTimeT()); 547 EXPECT_EQ(file_info.last_accessed.ToTimeT(), last_access_time.ToTimeT());
554 } 548 }
555 549
556 void TestCopyInForeignFileHelper(bool overwrite) { 550 void TestCopyInForeignFileHelper(bool overwrite) {
557 base::ScopedTempDir source_dir; 551 base::ScopedTempDir source_dir;
558 ASSERT_TRUE(source_dir.CreateUniqueTempDir()); 552 ASSERT_TRUE(source_dir.CreateUniqueTempDir());
559 base::FilePath root_file_path = source_dir.path(); 553 base::FilePath root_file_path = source_dir.path();
560 base::FilePath src_file_path = root_file_path.AppendASCII("file_name"); 554 base::FilePath src_file_path = root_file_path.AppendASCII("file_name");
561 FileSystemURL dest_url = CreateURLFromUTF8("new file"); 555 FileSystemURL dest_url = CreateURLFromUTF8("new file");
562 int64 src_file_length = 87; 556 int64 src_file_length = 87;
563 557
564 base::PlatformFileError error_code; 558 base::File file(src_file_path,
565 bool created = false; 559 base::File::FLAG_CREATE | base::File::FLAG_WRITE);
566 int file_flags = base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE; 560 ASSERT_TRUE(file.IsValid());
567 base::PlatformFile file_handle = 561 EXPECT_TRUE(file.created());
568 base::CreatePlatformFile( 562 ASSERT_TRUE(file.SetLength(src_file_length));
569 src_file_path, file_flags, &created, &error_code); 563 file.Close();
570 EXPECT_TRUE(created);
571 ASSERT_EQ(base::PLATFORM_FILE_OK, error_code);
572 ASSERT_NE(base::kInvalidPlatformFileValue, file_handle);
573 ASSERT_TRUE(base::TruncatePlatformFile(file_handle, src_file_length));
574 EXPECT_TRUE(base::ClosePlatformFile(file_handle));
575 564
576 scoped_ptr<FileSystemOperationContext> context; 565 scoped_ptr<FileSystemOperationContext> context;
577 566
578 if (overwrite) { 567 if (overwrite) {
579 context.reset(NewContext(NULL)); 568 context.reset(NewContext(NULL));
580 EXPECT_EQ(base::PLATFORM_FILE_OK, 569 bool created = false;
581 ofu()->EnsureFileExists(context.get(), dest_url, &created)); 570 EXPECT_EQ(base::File::FILE_OK,
571 ofu()->EnsureFileExists(context.get(), dest_url, &created));
582 EXPECT_TRUE(created); 572 EXPECT_TRUE(created);
583 573
584 // We must have observed one (and only one) create_file_count. 574 // We must have observed one (and only one) create_file_count.
585 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); 575 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count());
586 EXPECT_TRUE(change_observer()->HasNoChange()); 576 EXPECT_TRUE(change_observer()->HasNoChange());
587 } 577 }
588 578
589 const int64 path_cost = 579 const int64 path_cost =
590 ObfuscatedFileUtil::ComputeFilePathCost(dest_url.path()); 580 ObfuscatedFileUtil::ComputeFilePathCost(dest_url.path());
591 if (!overwrite) { 581 if (!overwrite) {
592 // Verify that file creation requires sufficient quota for the path. 582 // Verify that file creation requires sufficient quota for the path.
593 context.reset(NewContext(NULL)); 583 context.reset(NewContext(NULL));
594 context->set_allowed_bytes_growth(path_cost + src_file_length - 1); 584 context->set_allowed_bytes_growth(path_cost + src_file_length - 1);
595 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, 585 EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE,
596 ofu()->CopyInForeignFile(context.get(), 586 ofu()->CopyInForeignFile(context.get(),
597 src_file_path, dest_url)); 587 src_file_path, dest_url));
598 } 588 }
599 589
600 context.reset(NewContext(NULL)); 590 context.reset(NewContext(NULL));
601 context->set_allowed_bytes_growth(path_cost + src_file_length); 591 context->set_allowed_bytes_growth(path_cost + src_file_length);
602 EXPECT_EQ(base::PLATFORM_FILE_OK, 592 EXPECT_EQ(base::File::FILE_OK,
603 ofu()->CopyInForeignFile(context.get(), 593 ofu()->CopyInForeignFile(context.get(),
604 src_file_path, dest_url)); 594 src_file_path, dest_url));
605 595
606 EXPECT_TRUE(PathExists(dest_url)); 596 EXPECT_TRUE(PathExists(dest_url));
607 EXPECT_FALSE(DirectoryExists(dest_url)); 597 EXPECT_FALSE(DirectoryExists(dest_url));
608 598
609 context.reset(NewContext(NULL)); 599 context.reset(NewContext(NULL));
610 base::PlatformFileInfo file_info; 600 base::File::Info file_info;
611 base::FilePath data_path; 601 base::FilePath data_path;
612 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo( 602 EXPECT_EQ(base::File::FILE_OK,
613 context.get(), dest_url, &file_info, &data_path)); 603 ofu()->GetFileInfo(context.get(), dest_url, &file_info,
604 &data_path));
614 EXPECT_NE(data_path, src_file_path); 605 EXPECT_NE(data_path, src_file_path);
615 EXPECT_TRUE(FileExists(data_path)); 606 EXPECT_TRUE(FileExists(data_path));
616 EXPECT_EQ(src_file_length, GetSize(data_path)); 607 EXPECT_EQ(src_file_length, GetSize(data_path));
617 608
618 EXPECT_EQ(base::PLATFORM_FILE_OK, 609 EXPECT_EQ(base::File::FILE_OK,
619 ofu()->DeleteFile(context.get(), dest_url)); 610 ofu()->DeleteFile(context.get(), dest_url));
620 } 611 }
621 612
622 void ClearTimestamp(const FileSystemURL& url) { 613 void ClearTimestamp(const FileSystemURL& url) {
623 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); 614 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
624 EXPECT_EQ(base::PLATFORM_FILE_OK, 615 EXPECT_EQ(base::File::FILE_OK,
625 ofu()->Touch(context.get(), url, base::Time(), base::Time())); 616 ofu()->Touch(context.get(), url, base::Time(), base::Time()));
626 EXPECT_EQ(base::Time(), GetModifiedTime(url)); 617 EXPECT_EQ(base::Time(), GetModifiedTime(url));
627 } 618 }
628 619
629 base::Time GetModifiedTime(const FileSystemURL& url) { 620 base::Time GetModifiedTime(const FileSystemURL& url) {
630 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); 621 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
631 base::FilePath data_path; 622 base::FilePath data_path;
632 base::PlatformFileInfo file_info; 623 base::File::Info file_info;
633 context.reset(NewContext(NULL)); 624 context.reset(NewContext(NULL));
634 EXPECT_EQ(base::PLATFORM_FILE_OK, 625 EXPECT_EQ(base::File::FILE_OK,
635 ofu()->GetFileInfo(context.get(), url, &file_info, &data_path)); 626 ofu()->GetFileInfo(context.get(), url, &file_info, &data_path));
636 EXPECT_TRUE(change_observer()->HasNoChange()); 627 EXPECT_TRUE(change_observer()->HasNoChange());
637 return file_info.last_modified; 628 return file_info.last_modified;
638 } 629 }
639 630
640 void TestDirectoryTimestampHelper(const FileSystemURL& base_dir, 631 void TestDirectoryTimestampHelper(const FileSystemURL& base_dir,
641 bool copy, 632 bool copy,
642 bool overwrite) { 633 bool overwrite) {
643 scoped_ptr<FileSystemOperationContext> context; 634 scoped_ptr<FileSystemOperationContext> context;
644 const FileSystemURL src_dir_url( 635 const FileSystemURL src_dir_url(
645 FileSystemURLAppendUTF8(base_dir, "foo_dir")); 636 FileSystemURLAppendUTF8(base_dir, "foo_dir"));
646 const FileSystemURL dest_dir_url( 637 const FileSystemURL dest_dir_url(
647 FileSystemURLAppendUTF8(base_dir, "bar_dir")); 638 FileSystemURLAppendUTF8(base_dir, "bar_dir"));
648 639
649 const FileSystemURL src_file_url( 640 const FileSystemURL src_file_url(
650 FileSystemURLAppendUTF8(src_dir_url, "hoge")); 641 FileSystemURLAppendUTF8(src_dir_url, "hoge"));
651 const FileSystemURL dest_file_url( 642 const FileSystemURL dest_file_url(
652 FileSystemURLAppendUTF8(dest_dir_url, "fuga")); 643 FileSystemURLAppendUTF8(dest_dir_url, "fuga"));
653 644
654 context.reset(NewContext(NULL)); 645 context.reset(NewContext(NULL));
655 EXPECT_EQ(base::PLATFORM_FILE_OK, 646 EXPECT_EQ(base::File::FILE_OK,
656 ofu()->CreateDirectory(context.get(), src_dir_url, true, true)); 647 ofu()->CreateDirectory(context.get(), src_dir_url, true, true));
657 context.reset(NewContext(NULL)); 648 context.reset(NewContext(NULL));
658 EXPECT_EQ(base::PLATFORM_FILE_OK, 649 EXPECT_EQ(base::File::FILE_OK,
659 ofu()->CreateDirectory(context.get(), dest_dir_url, true, true)); 650 ofu()->CreateDirectory(context.get(), dest_dir_url, true, true));
660 651
661 bool created = false; 652 bool created = false;
662 context.reset(NewContext(NULL)); 653 context.reset(NewContext(NULL));
663 EXPECT_EQ(base::PLATFORM_FILE_OK, 654 EXPECT_EQ(base::File::FILE_OK,
664 ofu()->EnsureFileExists(context.get(), src_file_url, &created)); 655 ofu()->EnsureFileExists(context.get(), src_file_url, &created));
665 if (overwrite) { 656 if (overwrite) {
666 context.reset(NewContext(NULL)); 657 context.reset(NewContext(NULL));
667 EXPECT_EQ(base::PLATFORM_FILE_OK, 658 EXPECT_EQ(base::File::FILE_OK,
668 ofu()->EnsureFileExists(context.get(), 659 ofu()->EnsureFileExists(context.get(),
669 dest_file_url, &created)); 660 dest_file_url, &created));
670 } 661 }
671 662
672 ClearTimestamp(src_dir_url); 663 ClearTimestamp(src_dir_url);
673 ClearTimestamp(dest_dir_url); 664 ClearTimestamp(dest_dir_url);
674 context.reset(NewContext(NULL)); 665 context.reset(NewContext(NULL));
675 EXPECT_EQ(base::PLATFORM_FILE_OK, 666 EXPECT_EQ(base::File::FILE_OK,
676 ofu()->CopyOrMoveFile(context.get(), 667 ofu()->CopyOrMoveFile(context.get(),
677 src_file_url, dest_file_url, 668 src_file_url, dest_file_url,
678 FileSystemOperation::OPTION_NONE, 669 FileSystemOperation::OPTION_NONE,
679 copy)); 670 copy));
680 if (copy) 671 if (copy)
681 EXPECT_EQ(base::Time(), GetModifiedTime(src_dir_url)); 672 EXPECT_EQ(base::Time(), GetModifiedTime(src_dir_url));
682 else 673 else
683 EXPECT_NE(base::Time(), GetModifiedTime(src_dir_url)); 674 EXPECT_NE(base::Time(), GetModifiedTime(src_dir_url));
684 EXPECT_NE(base::Time(), GetModifiedTime(dest_dir_url)); 675 EXPECT_NE(base::Time(), GetModifiedTime(dest_dir_url));
685 } 676 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 ASSERT_TRUE(base::CreateDirectory(old_directory_db_path)); 765 ASSERT_TRUE(base::CreateDirectory(old_directory_db_path));
775 EXPECT_EQ(static_cast<int>(kFakeDirectoryData.size()), 766 EXPECT_EQ(static_cast<int>(kFakeDirectoryData.size()),
776 file_util::WriteFile(old_directory_db_path.AppendASCII("dummy"), 767 file_util::WriteFile(old_directory_db_path.AppendASCII("dummy"),
777 kFakeDirectoryData.data(), 768 kFakeDirectoryData.data(),
778 kFakeDirectoryData.size())); 769 kFakeDirectoryData.size()));
779 } 770 }
780 771
781 storage_policy_->AddIsolated(origin_); 772 storage_policy_->AddIsolated(origin_);
782 scoped_ptr<ObfuscatedFileUtil> file_util = CreateObfuscatedFileUtil( 773 scoped_ptr<ObfuscatedFileUtil> file_util = CreateObfuscatedFileUtil(
783 storage_policy_.get()); 774 storage_policy_.get());
784 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; 775 base::File::Error error = base::File::FILE_ERROR_FAILED;
785 base::FilePath origin_directory = file_util->GetDirectoryForOrigin( 776 base::FilePath origin_directory = file_util->GetDirectoryForOrigin(
786 origin_, true /* create */, &error); 777 origin_, true /* create */, &error);
787 EXPECT_EQ(base::PLATFORM_FILE_OK, error); 778 EXPECT_EQ(base::File::FILE_OK, error);
788 779
789 // The database is migrated from the old one. 780 // The database is migrated from the old one.
790 EXPECT_TRUE(base::DirectoryExists(origin_directory)); 781 EXPECT_TRUE(base::DirectoryExists(origin_directory));
791 EXPECT_FALSE(base::DirectoryExists(old_directory_db_path)); 782 EXPECT_FALSE(base::DirectoryExists(old_directory_db_path));
792 783
793 // Check we see the same contents in the new origin directory. 784 // Check we see the same contents in the new origin directory.
794 std::string origin_db_data; 785 std::string origin_db_data;
795 EXPECT_TRUE(base::PathExists(origin_directory.AppendASCII("dummy"))); 786 EXPECT_TRUE(base::PathExists(origin_directory.AppendASCII("dummy")));
796 EXPECT_TRUE(base::ReadFileToString( 787 EXPECT_TRUE(base::ReadFileToString(
797 origin_directory.AppendASCII("dummy"), &origin_db_data)); 788 origin_directory.AppendASCII("dummy"), &origin_db_data));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 DISALLOW_COPY_AND_ASSIGN(ObfuscatedFileUtilTest); 821 DISALLOW_COPY_AND_ASSIGN(ObfuscatedFileUtilTest);
831 }; 822 };
832 823
833 TEST_F(ObfuscatedFileUtilTest, TestCreateAndDeleteFile) { 824 TEST_F(ObfuscatedFileUtilTest, TestCreateAndDeleteFile) {
834 base::PlatformFile file_handle = base::kInvalidPlatformFileValue; 825 base::PlatformFile file_handle = base::kInvalidPlatformFileValue;
835 bool created; 826 bool created;
836 FileSystemURL url = CreateURLFromUTF8("fake/file"); 827 FileSystemURL url = CreateURLFromUTF8("fake/file");
837 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); 828 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
838 int file_flags = base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE; 829 int file_flags = base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE;
839 830
840 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 831 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
841 ofu()->CreateOrOpen( 832 ofu()->CreateOrOpen(context.get(), url, file_flags, &file_handle,
842 context.get(), url, file_flags, &file_handle, 833 &created));
843 &created));
844 834
845 context.reset(NewContext(NULL)); 835 context.reset(NewContext(NULL));
846 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 836 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
847 ofu()->DeleteFile(context.get(), url)); 837 ofu()->DeleteFile(context.get(), url));
848 838
849 url = CreateURLFromUTF8("test file"); 839 url = CreateURLFromUTF8("test file");
850 840
851 EXPECT_TRUE(change_observer()->HasNoChange()); 841 EXPECT_TRUE(change_observer()->HasNoChange());
852 842
853 // Verify that file creation requires sufficient quota for the path. 843 // Verify that file creation requires sufficient quota for the path.
854 context.reset(NewContext(NULL)); 844 context.reset(NewContext(NULL));
855 context->set_allowed_bytes_growth( 845 context->set_allowed_bytes_growth(
856 ObfuscatedFileUtil::ComputeFilePathCost(url.path()) - 1); 846 ObfuscatedFileUtil::ComputeFilePathCost(url.path()) - 1);
857 ASSERT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, 847 ASSERT_EQ(base::File::FILE_ERROR_NO_SPACE,
858 ofu()->CreateOrOpen( 848 ofu()->CreateOrOpen(context.get(), url, file_flags,
859 context.get(), url, file_flags, &file_handle, &created)); 849 &file_handle, &created));
860 850
861 context.reset(NewContext(NULL)); 851 context.reset(NewContext(NULL));
862 context->set_allowed_bytes_growth( 852 context->set_allowed_bytes_growth(
863 ObfuscatedFileUtil::ComputeFilePathCost(url.path())); 853 ObfuscatedFileUtil::ComputeFilePathCost(url.path()));
864 ASSERT_EQ(base::PLATFORM_FILE_OK, 854 ASSERT_EQ(base::File::FILE_OK,
865 ofu()->CreateOrOpen( 855 ofu()->CreateOrOpen(context.get(), url, file_flags, &file_handle,
866 context.get(), url, file_flags, &file_handle, &created)); 856 &created));
867 ASSERT_TRUE(created); 857 ASSERT_TRUE(created);
868 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); 858 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count());
869 EXPECT_NE(base::kInvalidPlatformFileValue, file_handle); 859 EXPECT_NE(base::kInvalidPlatformFileValue, file_handle);
870 860
871 CheckFileAndCloseHandle(url, file_handle); 861 CheckFileAndCloseHandle(url, file_handle);
872 862
873 context.reset(NewContext(NULL)); 863 context.reset(NewContext(NULL));
874 base::FilePath local_path; 864 base::FilePath local_path;
875 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetLocalFilePath( 865 EXPECT_EQ(base::File::FILE_OK,
876 context.get(), url, &local_path)); 866 ofu()->GetLocalFilePath(context.get(), url, &local_path));
877 EXPECT_TRUE(base::PathExists(local_path)); 867 EXPECT_TRUE(base::PathExists(local_path));
878 868
879 // Verify that deleting a file isn't stopped by zero quota, and that it frees 869 // Verify that deleting a file isn't stopped by zero quota, and that it frees
880 // up quote from its path. 870 // up quote from its path.
881 context.reset(NewContext(NULL)); 871 context.reset(NewContext(NULL));
882 context->set_allowed_bytes_growth(0); 872 context->set_allowed_bytes_growth(0);
883 EXPECT_EQ(base::PLATFORM_FILE_OK, 873 EXPECT_EQ(base::File::FILE_OK, ofu()->DeleteFile(context.get(), url));
884 ofu()->DeleteFile(context.get(), url));
885 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); 874 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count());
886 EXPECT_FALSE(base::PathExists(local_path)); 875 EXPECT_FALSE(base::PathExists(local_path));
887 EXPECT_EQ(ObfuscatedFileUtil::ComputeFilePathCost(url.path()), 876 EXPECT_EQ(ObfuscatedFileUtil::ComputeFilePathCost(url.path()),
888 context->allowed_bytes_growth()); 877 context->allowed_bytes_growth());
889 878
890 context.reset(NewContext(NULL)); 879 context.reset(NewContext(NULL));
891 bool exclusive = true; 880 bool exclusive = true;
892 bool recursive = true; 881 bool recursive = true;
893 FileSystemURL directory_url = CreateURLFromUTF8( 882 FileSystemURL directory_url = CreateURLFromUTF8(
894 "series/of/directories"); 883 "series/of/directories");
895 url = FileSystemURLAppendUTF8(directory_url, "file name"); 884 url = FileSystemURLAppendUTF8(directory_url, "file name");
896 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory( 885 EXPECT_EQ(base::File::FILE_OK,
897 context.get(), directory_url, exclusive, recursive)); 886 ofu()->CreateDirectory(context.get(), directory_url, exclusive,
887 recursive));
898 // The oepration created 3 directories recursively. 888 // The oepration created 3 directories recursively.
899 EXPECT_EQ(3, change_observer()->get_and_reset_create_directory_count()); 889 EXPECT_EQ(3, change_observer()->get_and_reset_create_directory_count());
900 890
901 context.reset(NewContext(NULL)); 891 context.reset(NewContext(NULL));
902 file_handle = base::kInvalidPlatformFileValue; 892 file_handle = base::kInvalidPlatformFileValue;
903 ASSERT_EQ(base::PLATFORM_FILE_OK, 893 ASSERT_EQ(base::File::FILE_OK,
904 ofu()->CreateOrOpen( 894 ofu()->CreateOrOpen(context.get(), url, file_flags, &file_handle,
905 context.get(), url, file_flags, &file_handle, &created)); 895 &created));
906 ASSERT_TRUE(created); 896 ASSERT_TRUE(created);
907 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); 897 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count());
908 EXPECT_NE(base::kInvalidPlatformFileValue, file_handle); 898 EXPECT_NE(base::kInvalidPlatformFileValue, file_handle);
909 899
910 CheckFileAndCloseHandle(url, file_handle); 900 CheckFileAndCloseHandle(url, file_handle);
911 901
912 context.reset(NewContext(NULL)); 902 context.reset(NewContext(NULL));
913 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetLocalFilePath( 903 EXPECT_EQ(base::File::FILE_OK,
914 context.get(), url, &local_path)); 904 ofu()->GetLocalFilePath(context.get(), url, &local_path));
915 EXPECT_TRUE(base::PathExists(local_path)); 905 EXPECT_TRUE(base::PathExists(local_path));
916 906
917 context.reset(NewContext(NULL)); 907 context.reset(NewContext(NULL));
918 EXPECT_EQ(base::PLATFORM_FILE_OK, 908 EXPECT_EQ(base::File::FILE_OK, ofu()->DeleteFile(context.get(), url));
919 ofu()->DeleteFile(context.get(), url));
920 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); 909 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count());
921 EXPECT_FALSE(base::PathExists(local_path)); 910 EXPECT_FALSE(base::PathExists(local_path));
922 911
923 // Make sure we have no unexpected changes. 912 // Make sure we have no unexpected changes.
924 EXPECT_TRUE(change_observer()->HasNoChange()); 913 EXPECT_TRUE(change_observer()->HasNoChange());
925 } 914 }
926 915
927 TEST_F(ObfuscatedFileUtilTest, TestTruncate) { 916 TEST_F(ObfuscatedFileUtilTest, TestTruncate) {
928 bool created = false; 917 bool created = false;
929 FileSystemURL url = CreateURLFromUTF8("file"); 918 FileSystemURL url = CreateURLFromUTF8("file");
930 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); 919 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
931 920
932 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 921 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
933 ofu()->Truncate(context.get(), url, 4)); 922 ofu()->Truncate(context.get(), url, 4));
934 923
935 context.reset(NewContext(NULL)); 924 context.reset(NewContext(NULL));
936 ASSERT_EQ(base::PLATFORM_FILE_OK, 925 ASSERT_EQ(base::File::FILE_OK,
937 ofu()->EnsureFileExists(context.get(), url, &created)); 926 ofu()->EnsureFileExists(context.get(), url, &created));
938 ASSERT_TRUE(created); 927 ASSERT_TRUE(created);
939 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); 928 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count());
940 929
941 context.reset(NewContext(NULL)); 930 context.reset(NewContext(NULL));
942 base::FilePath local_path; 931 base::FilePath local_path;
943 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetLocalFilePath( 932 EXPECT_EQ(base::File::FILE_OK,
944 context.get(), url, &local_path)); 933 ofu()->GetLocalFilePath(context.get(), url, &local_path));
945 EXPECT_EQ(0, GetSize(local_path)); 934 EXPECT_EQ(0, GetSize(local_path));
946 935
947 context.reset(NewContext(NULL)); 936 context.reset(NewContext(NULL));
948 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->Truncate( 937 EXPECT_EQ(base::File::FILE_OK, ofu()->Truncate(context.get(), url, 10));
949 context.get(), url, 10));
950 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); 938 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count());
951 EXPECT_EQ(10, GetSize(local_path)); 939 EXPECT_EQ(10, GetSize(local_path));
952 940
953 context.reset(NewContext(NULL)); 941 context.reset(NewContext(NULL));
954 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->Truncate( 942 EXPECT_EQ(base::File::FILE_OK, ofu()->Truncate(context.get(), url, 1));
955 context.get(), url, 1));
956 EXPECT_EQ(1, GetSize(local_path)); 943 EXPECT_EQ(1, GetSize(local_path));
957 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); 944 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count());
958 945
959 EXPECT_FALSE(DirectoryExists(url)); 946 EXPECT_FALSE(DirectoryExists(url));
960 EXPECT_TRUE(PathExists(url)); 947 EXPECT_TRUE(PathExists(url));
961 948
962 // Make sure we have no unexpected changes. 949 // Make sure we have no unexpected changes.
963 EXPECT_TRUE(change_observer()->HasNoChange()); 950 EXPECT_TRUE(change_observer()->HasNoChange());
964 } 951 }
965 952
966 TEST_F(ObfuscatedFileUtilTest, TestQuotaOnTruncation) { 953 TEST_F(ObfuscatedFileUtilTest, TestQuotaOnTruncation) {
967 bool created = false; 954 bool created = false;
968 FileSystemURL url = CreateURLFromUTF8("file"); 955 FileSystemURL url = CreateURLFromUTF8("file");
969 956
970 ASSERT_EQ(base::PLATFORM_FILE_OK, 957 ASSERT_EQ(base::File::FILE_OK,
971 ofu()->EnsureFileExists( 958 ofu()->EnsureFileExists(
972 AllowUsageIncrease(PathCost(url))->context(), 959 AllowUsageIncrease(PathCost(url))->context(),
973 url, &created)); 960 url, &created));
974 ASSERT_TRUE(created); 961 ASSERT_TRUE(created);
975 ASSERT_EQ(0, ComputeTotalFileSize()); 962 ASSERT_EQ(0, ComputeTotalFileSize());
976 963
977 ASSERT_EQ(base::PLATFORM_FILE_OK, 964 ASSERT_EQ(base::File::FILE_OK,
978 ofu()->Truncate( 965 ofu()->Truncate(AllowUsageIncrease(1020)->context(), url, 1020));
979 AllowUsageIncrease(1020)->context(),
980 url, 1020));
981 ASSERT_EQ(1020, ComputeTotalFileSize()); 966 ASSERT_EQ(1020, ComputeTotalFileSize());
982 967
983 ASSERT_EQ(base::PLATFORM_FILE_OK, 968 ASSERT_EQ(base::File::FILE_OK,
984 ofu()->Truncate( 969 ofu()->Truncate(AllowUsageIncrease(-1020)->context(), url, 0));
985 AllowUsageIncrease(-1020)->context(),
986 url, 0));
987 ASSERT_EQ(0, ComputeTotalFileSize()); 970 ASSERT_EQ(0, ComputeTotalFileSize());
988 971
989 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, 972 EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE,
990 ofu()->Truncate( 973 ofu()->Truncate(DisallowUsageIncrease(1021)->context(),
991 DisallowUsageIncrease(1021)->context(), 974 url, 1021));
992 url, 1021));
993 ASSERT_EQ(0, ComputeTotalFileSize()); 975 ASSERT_EQ(0, ComputeTotalFileSize());
994 976
995 EXPECT_EQ(base::PLATFORM_FILE_OK, 977 EXPECT_EQ(base::File::FILE_OK,
996 ofu()->Truncate( 978 ofu()->Truncate(AllowUsageIncrease(1020)->context(), url, 1020));
997 AllowUsageIncrease(1020)->context(),
998 url, 1020));
999 ASSERT_EQ(1020, ComputeTotalFileSize()); 979 ASSERT_EQ(1020, ComputeTotalFileSize());
1000 980
1001 EXPECT_EQ(base::PLATFORM_FILE_OK, 981 EXPECT_EQ(base::File::FILE_OK,
1002 ofu()->Truncate( 982 ofu()->Truncate(AllowUsageIncrease(0)->context(), url, 1020));
1003 AllowUsageIncrease(0)->context(),
1004 url, 1020));
1005 ASSERT_EQ(1020, ComputeTotalFileSize()); 983 ASSERT_EQ(1020, ComputeTotalFileSize());
1006 984
1007 // quota exceeded 985 // quota exceeded
1008 { 986 {
1009 scoped_ptr<UsageVerifyHelper> helper = AllowUsageIncrease(-1); 987 scoped_ptr<UsageVerifyHelper> helper = AllowUsageIncrease(-1);
1010 helper->context()->set_allowed_bytes_growth( 988 helper->context()->set_allowed_bytes_growth(
1011 helper->context()->allowed_bytes_growth() - 1); 989 helper->context()->allowed_bytes_growth() - 1);
1012 EXPECT_EQ(base::PLATFORM_FILE_OK, 990 EXPECT_EQ(base::File::FILE_OK,
1013 ofu()->Truncate(helper->context(), url, 1019)); 991 ofu()->Truncate(helper->context(), url, 1019));
1014 ASSERT_EQ(1019, ComputeTotalFileSize()); 992 ASSERT_EQ(1019, ComputeTotalFileSize());
1015 } 993 }
1016 994
1017 // Delete backing file to make following truncation fail. 995 // Delete backing file to make following truncation fail.
1018 base::FilePath local_path; 996 base::FilePath local_path;
1019 ASSERT_EQ(base::PLATFORM_FILE_OK, 997 ASSERT_EQ(base::File::FILE_OK,
1020 ofu()->GetLocalFilePath( 998 ofu()->GetLocalFilePath(UnlimitedContext().get(), url,
1021 UnlimitedContext().get(), 999 &local_path));
1022 url, &local_path));
1023 ASSERT_FALSE(local_path.empty()); 1000 ASSERT_FALSE(local_path.empty());
1024 ASSERT_TRUE(base::DeleteFile(local_path, false)); 1001 ASSERT_TRUE(base::DeleteFile(local_path, false));
1025 1002
1026 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 1003 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
1027 ofu()->Truncate( 1004 ofu()->Truncate(LimitedContext(1234).get(), url, 1234));
1028 LimitedContext(1234).get(),
1029 url, 1234));
1030 ASSERT_EQ(0, ComputeTotalFileSize()); 1005 ASSERT_EQ(0, ComputeTotalFileSize());
1031 } 1006 }
1032 1007
1033 TEST_F(ObfuscatedFileUtilTest, TestEnsureFileExists) { 1008 TEST_F(ObfuscatedFileUtilTest, TestEnsureFileExists) {
1034 FileSystemURL url = CreateURLFromUTF8("fake/file"); 1009 FileSystemURL url = CreateURLFromUTF8("fake/file");
1035 bool created = false; 1010 bool created = false;
1036 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); 1011 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
1037 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 1012 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
1038 ofu()->EnsureFileExists( 1013 ofu()->EnsureFileExists(context.get(), url, &created));
1039 context.get(), url, &created));
1040 EXPECT_TRUE(change_observer()->HasNoChange()); 1014 EXPECT_TRUE(change_observer()->HasNoChange());
1041 1015
1042 // Verify that file creation requires sufficient quota for the path. 1016 // Verify that file creation requires sufficient quota for the path.
1043 context.reset(NewContext(NULL)); 1017 context.reset(NewContext(NULL));
1044 url = CreateURLFromUTF8("test file"); 1018 url = CreateURLFromUTF8("test file");
1045 created = false; 1019 created = false;
1046 context->set_allowed_bytes_growth( 1020 context->set_allowed_bytes_growth(
1047 ObfuscatedFileUtil::ComputeFilePathCost(url.path()) - 1); 1021 ObfuscatedFileUtil::ComputeFilePathCost(url.path()) - 1);
1048 ASSERT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, 1022 ASSERT_EQ(base::File::FILE_ERROR_NO_SPACE,
1049 ofu()->EnsureFileExists(context.get(), url, &created)); 1023 ofu()->EnsureFileExists(context.get(), url, &created));
1050 ASSERT_FALSE(created); 1024 ASSERT_FALSE(created);
1051 EXPECT_TRUE(change_observer()->HasNoChange()); 1025 EXPECT_TRUE(change_observer()->HasNoChange());
1052 1026
1053 context.reset(NewContext(NULL)); 1027 context.reset(NewContext(NULL));
1054 context->set_allowed_bytes_growth( 1028 context->set_allowed_bytes_growth(
1055 ObfuscatedFileUtil::ComputeFilePathCost(url.path())); 1029 ObfuscatedFileUtil::ComputeFilePathCost(url.path()));
1056 ASSERT_EQ(base::PLATFORM_FILE_OK, 1030 ASSERT_EQ(base::File::FILE_OK,
1057 ofu()->EnsureFileExists(context.get(), url, &created)); 1031 ofu()->EnsureFileExists(context.get(), url, &created));
1058 ASSERT_TRUE(created); 1032 ASSERT_TRUE(created);
1059 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); 1033 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count());
1060 1034
1061 CheckFileAndCloseHandle(url, base::kInvalidPlatformFileValue); 1035 CheckFileAndCloseHandle(url, base::kInvalidPlatformFileValue);
1062 1036
1063 context.reset(NewContext(NULL)); 1037 context.reset(NewContext(NULL));
1064 ASSERT_EQ(base::PLATFORM_FILE_OK, 1038 ASSERT_EQ(base::File::FILE_OK,
1065 ofu()->EnsureFileExists(context.get(), url, &created)); 1039 ofu()->EnsureFileExists(context.get(), url, &created));
1066 ASSERT_FALSE(created); 1040 ASSERT_FALSE(created);
1067 EXPECT_TRUE(change_observer()->HasNoChange()); 1041 EXPECT_TRUE(change_observer()->HasNoChange());
1068 1042
1069 // Also test in a subdirectory. 1043 // Also test in a subdirectory.
1070 url = CreateURLFromUTF8("path/to/file.txt"); 1044 url = CreateURLFromUTF8("path/to/file.txt");
1071 context.reset(NewContext(NULL)); 1045 context.reset(NewContext(NULL));
1072 bool exclusive = true; 1046 bool exclusive = true;
1073 bool recursive = true; 1047 bool recursive = true;
1074 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory( 1048 EXPECT_EQ(base::File::FILE_OK,
1075 context.get(), 1049 ofu()->CreateDirectory(context.get(), FileSystemURLDirName(url),
1076 FileSystemURLDirName(url), 1050 exclusive, recursive));
1077 exclusive, recursive));
1078 // 2 directories: path/ and path/to. 1051 // 2 directories: path/ and path/to.
1079 EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count()); 1052 EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count());
1080 1053
1081 context.reset(NewContext(NULL)); 1054 context.reset(NewContext(NULL));
1082 ASSERT_EQ(base::PLATFORM_FILE_OK, 1055 ASSERT_EQ(base::File::FILE_OK,
1083 ofu()->EnsureFileExists(context.get(), url, &created)); 1056 ofu()->EnsureFileExists(context.get(), url, &created));
1084 ASSERT_TRUE(created); 1057 ASSERT_TRUE(created);
1085 EXPECT_FALSE(DirectoryExists(url)); 1058 EXPECT_FALSE(DirectoryExists(url));
1086 EXPECT_TRUE(PathExists(url)); 1059 EXPECT_TRUE(PathExists(url));
1087 EXPECT_TRUE(change_observer()->HasNoChange()); 1060 EXPECT_TRUE(change_observer()->HasNoChange());
1088 } 1061 }
1089 1062
1090 TEST_F(ObfuscatedFileUtilTest, TestDirectoryOps) { 1063 TEST_F(ObfuscatedFileUtilTest, TestDirectoryOps) {
1091 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); 1064 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
1092 1065
1093 bool exclusive = false; 1066 bool exclusive = false;
1094 bool recursive = false; 1067 bool recursive = false;
1095 FileSystemURL url = CreateURLFromUTF8("foo/bar"); 1068 FileSystemURL url = CreateURLFromUTF8("foo/bar");
1096 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, ofu()->CreateDirectory( 1069 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
1097 context.get(), url, exclusive, recursive)); 1070 ofu()->CreateDirectory(context.get(), url, exclusive, recursive));
1098 1071
1099 context.reset(NewContext(NULL)); 1072 context.reset(NewContext(NULL));
1100 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 1073 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
1101 ofu()->DeleteDirectory(context.get(), url)); 1074 ofu()->DeleteDirectory(context.get(), url));
1102 1075
1103 FileSystemURL root = CreateURLFromUTF8(std::string()); 1076 FileSystemURL root = CreateURLFromUTF8(std::string());
1104 EXPECT_FALSE(DirectoryExists(url)); 1077 EXPECT_FALSE(DirectoryExists(url));
1105 EXPECT_FALSE(PathExists(url)); 1078 EXPECT_FALSE(PathExists(url));
1106 context.reset(NewContext(NULL)); 1079 context.reset(NewContext(NULL));
1107 EXPECT_TRUE(ofu()->IsDirectoryEmpty(context.get(), root)); 1080 EXPECT_TRUE(ofu()->IsDirectoryEmpty(context.get(), root));
1108 1081
1109 context.reset(NewContext(NULL)); 1082 context.reset(NewContext(NULL));
1110 exclusive = false; 1083 exclusive = false;
1111 recursive = true; 1084 recursive = true;
1112 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory( 1085 EXPECT_EQ(base::File::FILE_OK,
1113 context.get(), url, exclusive, recursive)); 1086 ofu()->CreateDirectory(context.get(), url, exclusive, recursive));
1114 EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count()); 1087 EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count());
1115 1088
1116 EXPECT_TRUE(DirectoryExists(url)); 1089 EXPECT_TRUE(DirectoryExists(url));
1117 EXPECT_TRUE(PathExists(url)); 1090 EXPECT_TRUE(PathExists(url));
1118 1091
1119 context.reset(NewContext(NULL)); 1092 context.reset(NewContext(NULL));
1120 EXPECT_FALSE(ofu()->IsDirectoryEmpty(context.get(), root)); 1093 EXPECT_FALSE(ofu()->IsDirectoryEmpty(context.get(), root));
1121 EXPECT_TRUE(DirectoryExists(FileSystemURLDirName(url))); 1094 EXPECT_TRUE(DirectoryExists(FileSystemURLDirName(url)));
1122 1095
1123 context.reset(NewContext(NULL)); 1096 context.reset(NewContext(NULL));
1124 EXPECT_FALSE(ofu()->IsDirectoryEmpty(context.get(), 1097 EXPECT_FALSE(ofu()->IsDirectoryEmpty(context.get(),
1125 FileSystemURLDirName(url))); 1098 FileSystemURLDirName(url)));
1126 1099
1127 // Can't remove a non-empty directory. 1100 // Can't remove a non-empty directory.
1128 context.reset(NewContext(NULL)); 1101 context.reset(NewContext(NULL));
1129 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, 1102 EXPECT_EQ(base::File::FILE_ERROR_NOT_EMPTY,
1130 ofu()->DeleteDirectory(context.get(), 1103 ofu()->DeleteDirectory(context.get(),
1131 FileSystemURLDirName(url))); 1104 FileSystemURLDirName(url)));
1132 EXPECT_TRUE(change_observer()->HasNoChange()); 1105 EXPECT_TRUE(change_observer()->HasNoChange());
1133 1106
1134 base::PlatformFileInfo file_info; 1107 base::File::Info file_info;
1135 base::FilePath local_path; 1108 base::FilePath local_path;
1136 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo( 1109 EXPECT_EQ(base::File::FILE_OK,
1137 context.get(), url, &file_info, &local_path)); 1110 ofu()->GetFileInfo(context.get(), url, &file_info, &local_path));
1138 EXPECT_TRUE(local_path.empty()); 1111 EXPECT_TRUE(local_path.empty());
1139 EXPECT_TRUE(file_info.is_directory); 1112 EXPECT_TRUE(file_info.is_directory);
1140 EXPECT_FALSE(file_info.is_symbolic_link); 1113 EXPECT_FALSE(file_info.is_symbolic_link);
1141 1114
1142 // Same create again should succeed, since exclusive is false. 1115 // Same create again should succeed, since exclusive is false.
1143 context.reset(NewContext(NULL)); 1116 context.reset(NewContext(NULL));
1144 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory( 1117 EXPECT_EQ(base::File::FILE_OK,
1145 context.get(), url, exclusive, recursive)); 1118 ofu()->CreateDirectory(context.get(), url, exclusive, recursive));
1146 EXPECT_TRUE(change_observer()->HasNoChange()); 1119 EXPECT_TRUE(change_observer()->HasNoChange());
1147 1120
1148 exclusive = true; 1121 exclusive = true;
1149 recursive = true; 1122 recursive = true;
1150 context.reset(NewContext(NULL)); 1123 context.reset(NewContext(NULL));
1151 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, ofu()->CreateDirectory( 1124 EXPECT_EQ(base::File::FILE_ERROR_EXISTS,
1152 context.get(), url, exclusive, recursive)); 1125 ofu()->CreateDirectory(context.get(), url, exclusive, recursive));
1153 EXPECT_TRUE(change_observer()->HasNoChange()); 1126 EXPECT_TRUE(change_observer()->HasNoChange());
1154 1127
1155 // Verify that deleting a directory isn't stopped by zero quota, and that it 1128 // Verify that deleting a directory isn't stopped by zero quota, and that it
1156 // frees up quota from its path. 1129 // frees up quota from its path.
1157 context.reset(NewContext(NULL)); 1130 context.reset(NewContext(NULL));
1158 context->set_allowed_bytes_growth(0); 1131 context->set_allowed_bytes_growth(0);
1159 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->DeleteDirectory(context.get(), url)); 1132 EXPECT_EQ(base::File::FILE_OK, ofu()->DeleteDirectory(context.get(), url));
1160 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); 1133 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count());
1161 EXPECT_EQ(ObfuscatedFileUtil::ComputeFilePathCost(url.path()), 1134 EXPECT_EQ(ObfuscatedFileUtil::ComputeFilePathCost(url.path()),
1162 context->allowed_bytes_growth()); 1135 context->allowed_bytes_growth());
1163 1136
1164 url = CreateURLFromUTF8("foo/bop"); 1137 url = CreateURLFromUTF8("foo/bop");
1165 1138
1166 EXPECT_FALSE(DirectoryExists(url)); 1139 EXPECT_FALSE(DirectoryExists(url));
1167 EXPECT_FALSE(PathExists(url)); 1140 EXPECT_FALSE(PathExists(url));
1168 1141
1169 context.reset(NewContext(NULL)); 1142 context.reset(NewContext(NULL));
1170 EXPECT_TRUE(ofu()->IsDirectoryEmpty(context.get(), url)); 1143 EXPECT_TRUE(ofu()->IsDirectoryEmpty(context.get(), url));
1171 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, ofu()->GetFileInfo( 1144 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
1172 context.get(), url, &file_info, &local_path)); 1145 ofu()->GetFileInfo(context.get(), url, &file_info, &local_path));
1173 1146
1174 // Verify that file creation requires sufficient quota for the path. 1147 // Verify that file creation requires sufficient quota for the path.
1175 exclusive = true; 1148 exclusive = true;
1176 recursive = false; 1149 recursive = false;
1177 context.reset(NewContext(NULL)); 1150 context.reset(NewContext(NULL));
1178 context->set_allowed_bytes_growth( 1151 context->set_allowed_bytes_growth(
1179 ObfuscatedFileUtil::ComputeFilePathCost(url.path()) - 1); 1152 ObfuscatedFileUtil::ComputeFilePathCost(url.path()) - 1);
1180 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, ofu()->CreateDirectory( 1153 EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE,
1181 context.get(), url, exclusive, recursive)); 1154 ofu()->CreateDirectory(context.get(), url, exclusive, recursive));
1182 EXPECT_TRUE(change_observer()->HasNoChange()); 1155 EXPECT_TRUE(change_observer()->HasNoChange());
1183 1156
1184 context.reset(NewContext(NULL)); 1157 context.reset(NewContext(NULL));
1185 context->set_allowed_bytes_growth( 1158 context->set_allowed_bytes_growth(
1186 ObfuscatedFileUtil::ComputeFilePathCost(url.path())); 1159 ObfuscatedFileUtil::ComputeFilePathCost(url.path()));
1187 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory( 1160 EXPECT_EQ(base::File::FILE_OK,
1188 context.get(), url, exclusive, recursive)); 1161 ofu()->CreateDirectory(context.get(), url, exclusive, recursive));
1189 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); 1162 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count());
1190 1163
1191 EXPECT_TRUE(DirectoryExists(url)); 1164 EXPECT_TRUE(DirectoryExists(url));
1192 EXPECT_TRUE(PathExists(url)); 1165 EXPECT_TRUE(PathExists(url));
1193 1166
1194 exclusive = true; 1167 exclusive = true;
1195 recursive = false; 1168 recursive = false;
1196 context.reset(NewContext(NULL)); 1169 context.reset(NewContext(NULL));
1197 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, ofu()->CreateDirectory( 1170 EXPECT_EQ(base::File::FILE_ERROR_EXISTS,
1198 context.get(), url, exclusive, recursive)); 1171 ofu()->CreateDirectory(context.get(), url, exclusive, recursive));
1199 EXPECT_TRUE(change_observer()->HasNoChange()); 1172 EXPECT_TRUE(change_observer()->HasNoChange());
1200 1173
1201 exclusive = true; 1174 exclusive = true;
1202 recursive = false; 1175 recursive = false;
1203 url = CreateURLFromUTF8("foo"); 1176 url = CreateURLFromUTF8("foo");
1204 context.reset(NewContext(NULL)); 1177 context.reset(NewContext(NULL));
1205 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, ofu()->CreateDirectory( 1178 EXPECT_EQ(base::File::FILE_ERROR_EXISTS,
1206 context.get(), url, exclusive, recursive)); 1179 ofu()->CreateDirectory(context.get(), url, exclusive, recursive));
1207 EXPECT_TRUE(change_observer()->HasNoChange()); 1180 EXPECT_TRUE(change_observer()->HasNoChange());
1208 1181
1209 url = CreateURLFromUTF8("blah"); 1182 url = CreateURLFromUTF8("blah");
1210 1183
1211 EXPECT_FALSE(DirectoryExists(url)); 1184 EXPECT_FALSE(DirectoryExists(url));
1212 EXPECT_FALSE(PathExists(url)); 1185 EXPECT_FALSE(PathExists(url));
1213 1186
1214 exclusive = true; 1187 exclusive = true;
1215 recursive = false; 1188 recursive = false;
1216 context.reset(NewContext(NULL)); 1189 context.reset(NewContext(NULL));
1217 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory( 1190 EXPECT_EQ(base::File::FILE_OK,
1218 context.get(), url, exclusive, recursive)); 1191 ofu()->CreateDirectory(context.get(), url, exclusive, recursive));
1219 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); 1192 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count());
1220 1193
1221 EXPECT_TRUE(DirectoryExists(url)); 1194 EXPECT_TRUE(DirectoryExists(url));
1222 EXPECT_TRUE(PathExists(url)); 1195 EXPECT_TRUE(PathExists(url));
1223 1196
1224 exclusive = true; 1197 exclusive = true;
1225 recursive = false; 1198 recursive = false;
1226 context.reset(NewContext(NULL)); 1199 context.reset(NewContext(NULL));
1227 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, ofu()->CreateDirectory( 1200 EXPECT_EQ(base::File::FILE_ERROR_EXISTS,
1228 context.get(), url, exclusive, recursive)); 1201 ofu()->CreateDirectory(context.get(), url, exclusive, recursive));
1229 EXPECT_TRUE(change_observer()->HasNoChange()); 1202 EXPECT_TRUE(change_observer()->HasNoChange());
1230 } 1203 }
1231 1204
1232 TEST_F(ObfuscatedFileUtilTest, TestReadDirectory) { 1205 TEST_F(ObfuscatedFileUtilTest, TestReadDirectory) {
1233 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); 1206 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
1234 bool exclusive = true; 1207 bool exclusive = true;
1235 bool recursive = true; 1208 bool recursive = true;
1236 FileSystemURL url = CreateURLFromUTF8("directory/to/use"); 1209 FileSystemURL url = CreateURLFromUTF8("directory/to/use");
1237 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory( 1210 EXPECT_EQ(base::File::FILE_OK,
1238 context.get(), url, exclusive, recursive)); 1211 ofu()->CreateDirectory(context.get(), url, exclusive, recursive));
1239 TestReadDirectoryHelper(url); 1212 TestReadDirectoryHelper(url);
1240 } 1213 }
1241 1214
1242 TEST_F(ObfuscatedFileUtilTest, TestReadRootWithSlash) { 1215 TEST_F(ObfuscatedFileUtilTest, TestReadRootWithSlash) {
1243 TestReadDirectoryHelper(CreateURLFromUTF8(std::string())); 1216 TestReadDirectoryHelper(CreateURLFromUTF8(std::string()));
1244 } 1217 }
1245 1218
1246 TEST_F(ObfuscatedFileUtilTest, TestReadRootWithEmptyString) { 1219 TEST_F(ObfuscatedFileUtilTest, TestReadRootWithEmptyString) {
1247 TestReadDirectoryHelper(CreateURLFromUTF8("/")); 1220 TestReadDirectoryHelper(CreateURLFromUTF8("/"));
1248 } 1221 }
1249 1222
1250 TEST_F(ObfuscatedFileUtilTest, TestReadDirectoryOnFile) { 1223 TEST_F(ObfuscatedFileUtilTest, TestReadDirectoryOnFile) {
1251 FileSystemURL url = CreateURLFromUTF8("file"); 1224 FileSystemURL url = CreateURLFromUTF8("file");
1252 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); 1225 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
1253 1226
1254 bool created = false; 1227 bool created = false;
1255 ASSERT_EQ(base::PLATFORM_FILE_OK, 1228 ASSERT_EQ(base::File::FILE_OK,
1256 ofu()->EnsureFileExists(context.get(), url, &created)); 1229 ofu()->EnsureFileExists(context.get(), url, &created));
1257 ASSERT_TRUE(created); 1230 ASSERT_TRUE(created);
1258 1231
1259 std::vector<fileapi::DirectoryEntry> entries; 1232 std::vector<fileapi::DirectoryEntry> entries;
1260 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY, 1233 EXPECT_EQ(base::File::FILE_ERROR_NOT_A_DIRECTORY,
1261 AsyncFileTestHelper::ReadDirectory( 1234 AsyncFileTestHelper::ReadDirectory(file_system_context(), url,
1262 file_system_context(), url, &entries)); 1235 &entries));
1263 1236
1264 EXPECT_TRUE(ofu()->IsDirectoryEmpty(context.get(), url)); 1237 EXPECT_TRUE(ofu()->IsDirectoryEmpty(context.get(), url));
1265 } 1238 }
1266 1239
1267 TEST_F(ObfuscatedFileUtilTest, TestTouch) { 1240 TEST_F(ObfuscatedFileUtilTest, TestTouch) {
1268 FileSystemURL url = CreateURLFromUTF8("file"); 1241 FileSystemURL url = CreateURLFromUTF8("file");
1269 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); 1242 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
1270 1243
1271 base::Time last_access_time = base::Time::Now(); 1244 base::Time last_access_time = base::Time::Now();
1272 base::Time last_modified_time = base::Time::Now(); 1245 base::Time last_modified_time = base::Time::Now();
1273 1246
1274 // It's not there yet. 1247 // It's not there yet.
1275 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 1248 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
1276 ofu()->Touch( 1249 ofu()->Touch(context.get(), url, last_access_time,
1277 context.get(), url, last_access_time, last_modified_time)); 1250 last_modified_time));
1278 1251
1279 // OK, now create it. 1252 // OK, now create it.
1280 context.reset(NewContext(NULL)); 1253 context.reset(NewContext(NULL));
1281 bool created = false; 1254 bool created = false;
1282 ASSERT_EQ(base::PLATFORM_FILE_OK, 1255 ASSERT_EQ(base::File::FILE_OK,
1283 ofu()->EnsureFileExists(context.get(), url, &created)); 1256 ofu()->EnsureFileExists(context.get(), url, &created));
1284 ASSERT_TRUE(created); 1257 ASSERT_TRUE(created);
1285 TestTouchHelper(url, true); 1258 TestTouchHelper(url, true);
1286 1259
1287 // Now test a directory: 1260 // Now test a directory:
1288 context.reset(NewContext(NULL)); 1261 context.reset(NewContext(NULL));
1289 bool exclusive = true; 1262 bool exclusive = true;
1290 bool recursive = false; 1263 bool recursive = false;
1291 url = CreateURLFromUTF8("dir"); 1264 url = CreateURLFromUTF8("dir");
1292 ASSERT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory(context.get(), 1265 ASSERT_EQ(base::File::FILE_OK,
1293 url, exclusive, recursive)); 1266 ofu()->CreateDirectory(context.get(), url, exclusive, recursive));
1294 TestTouchHelper(url, false); 1267 TestTouchHelper(url, false);
1295 } 1268 }
1296 1269
1297 TEST_F(ObfuscatedFileUtilTest, TestPathQuotas) { 1270 TEST_F(ObfuscatedFileUtilTest, TestPathQuotas) {
1298 FileSystemURL url = CreateURLFromUTF8("fake/file"); 1271 FileSystemURL url = CreateURLFromUTF8("fake/file");
1299 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); 1272 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
1300 1273
1301 url = CreateURLFromUTF8("file name"); 1274 url = CreateURLFromUTF8("file name");
1302 context->set_allowed_bytes_growth(5); 1275 context->set_allowed_bytes_growth(5);
1303 bool created = false; 1276 bool created = false;
1304 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, 1277 EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE,
1305 ofu()->EnsureFileExists(context.get(), url, &created)); 1278 ofu()->EnsureFileExists(context.get(), url, &created));
1306 EXPECT_FALSE(created); 1279 EXPECT_FALSE(created);
1307 context->set_allowed_bytes_growth(1024); 1280 context->set_allowed_bytes_growth(1024);
1308 EXPECT_EQ(base::PLATFORM_FILE_OK, 1281 EXPECT_EQ(base::File::FILE_OK,
1309 ofu()->EnsureFileExists(context.get(), url, &created)); 1282 ofu()->EnsureFileExists(context.get(), url, &created));
1310 EXPECT_TRUE(created); 1283 EXPECT_TRUE(created);
1311 int64 path_cost = ObfuscatedFileUtil::ComputeFilePathCost(url.path()); 1284 int64 path_cost = ObfuscatedFileUtil::ComputeFilePathCost(url.path());
1312 EXPECT_EQ(1024 - path_cost, context->allowed_bytes_growth()); 1285 EXPECT_EQ(1024 - path_cost, context->allowed_bytes_growth());
1313 1286
1314 context->set_allowed_bytes_growth(1024); 1287 context->set_allowed_bytes_growth(1024);
1315 bool exclusive = true; 1288 bool exclusive = true;
1316 bool recursive = true; 1289 bool recursive = true;
1317 url = CreateURLFromUTF8("directory/to/use"); 1290 url = CreateURLFromUTF8("directory/to/use");
1318 std::vector<base::FilePath::StringType> components; 1291 std::vector<base::FilePath::StringType> components;
1319 url.path().GetComponents(&components); 1292 url.path().GetComponents(&components);
1320 path_cost = 0; 1293 path_cost = 0;
1321 typedef std::vector<base::FilePath::StringType>::iterator iterator; 1294 typedef std::vector<base::FilePath::StringType>::iterator iterator;
1322 for (iterator iter = components.begin(); 1295 for (iterator iter = components.begin();
1323 iter != components.end(); ++iter) { 1296 iter != components.end(); ++iter) {
1324 path_cost += ObfuscatedFileUtil::ComputeFilePathCost( 1297 path_cost += ObfuscatedFileUtil::ComputeFilePathCost(
1325 base::FilePath(*iter)); 1298 base::FilePath(*iter));
1326 } 1299 }
1327 context.reset(NewContext(NULL)); 1300 context.reset(NewContext(NULL));
1328 context->set_allowed_bytes_growth(1024); 1301 context->set_allowed_bytes_growth(1024);
1329 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory( 1302 EXPECT_EQ(base::File::FILE_OK,
1330 context.get(), url, exclusive, recursive)); 1303 ofu()->CreateDirectory(context.get(), url, exclusive, recursive));
1331 EXPECT_EQ(1024 - path_cost, context->allowed_bytes_growth()); 1304 EXPECT_EQ(1024 - path_cost, context->allowed_bytes_growth());
1332 } 1305 }
1333 1306
1334 TEST_F(ObfuscatedFileUtilTest, TestCopyOrMoveFileNotFound) { 1307 TEST_F(ObfuscatedFileUtilTest, TestCopyOrMoveFileNotFound) {
1335 FileSystemURL source_url = CreateURLFromUTF8("path0.txt"); 1308 FileSystemURL source_url = CreateURLFromUTF8("path0.txt");
1336 FileSystemURL dest_url = CreateURLFromUTF8("path1.txt"); 1309 FileSystemURL dest_url = CreateURLFromUTF8("path1.txt");
1337 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); 1310 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
1338 1311
1339 bool is_copy_not_move = false; 1312 bool is_copy_not_move = false;
1340 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 1313 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
1341 ofu()->CopyOrMoveFile(context.get(), source_url, dest_url, 1314 ofu()->CopyOrMoveFile(context.get(), source_url, dest_url,
1342 FileSystemOperation::OPTION_NONE, 1315 FileSystemOperation::OPTION_NONE,
1343 is_copy_not_move)); 1316 is_copy_not_move));
1344 EXPECT_TRUE(change_observer()->HasNoChange()); 1317 EXPECT_TRUE(change_observer()->HasNoChange());
1345 context.reset(NewContext(NULL)); 1318 context.reset(NewContext(NULL));
1346 is_copy_not_move = true; 1319 is_copy_not_move = true;
1347 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 1320 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
1348 ofu()->CopyOrMoveFile(context.get(), source_url, dest_url, 1321 ofu()->CopyOrMoveFile(context.get(), source_url, dest_url,
1349 FileSystemOperation::OPTION_NONE, 1322 FileSystemOperation::OPTION_NONE,
1350 is_copy_not_move)); 1323 is_copy_not_move));
1351 EXPECT_TRUE(change_observer()->HasNoChange()); 1324 EXPECT_TRUE(change_observer()->HasNoChange());
1352 source_url = CreateURLFromUTF8("dir/dir/file"); 1325 source_url = CreateURLFromUTF8("dir/dir/file");
1353 bool exclusive = true; 1326 bool exclusive = true;
1354 bool recursive = true; 1327 bool recursive = true;
1355 context.reset(NewContext(NULL)); 1328 context.reset(NewContext(NULL));
1356 ASSERT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory( 1329 ASSERT_EQ(base::File::FILE_OK,
1357 context.get(), 1330 ofu()->CreateDirectory(context.get(),
1358 FileSystemURLDirName(source_url), 1331 FileSystemURLDirName(source_url),
1359 exclusive, recursive)); 1332 exclusive, recursive));
1360 EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count()); 1333 EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count());
1361 is_copy_not_move = false; 1334 is_copy_not_move = false;
1362 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 1335 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
1363 ofu()->CopyOrMoveFile(context.get(), source_url, dest_url, 1336 ofu()->CopyOrMoveFile(context.get(), source_url, dest_url,
1364 FileSystemOperation::OPTION_NONE, 1337 FileSystemOperation::OPTION_NONE,
1365 is_copy_not_move)); 1338 is_copy_not_move));
1366 EXPECT_TRUE(change_observer()->HasNoChange()); 1339 EXPECT_TRUE(change_observer()->HasNoChange());
1367 context.reset(NewContext(NULL)); 1340 context.reset(NewContext(NULL));
1368 is_copy_not_move = true; 1341 is_copy_not_move = true;
1369 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 1342 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
1370 ofu()->CopyOrMoveFile(context.get(), source_url, dest_url, 1343 ofu()->CopyOrMoveFile(context.get(), source_url, dest_url,
1371 FileSystemOperation::OPTION_NONE, 1344 FileSystemOperation::OPTION_NONE,
1372 is_copy_not_move)); 1345 is_copy_not_move));
1373 EXPECT_TRUE(change_observer()->HasNoChange()); 1346 EXPECT_TRUE(change_observer()->HasNoChange());
1374 } 1347 }
1375 1348
1376 TEST_F(ObfuscatedFileUtilTest, TestCopyOrMoveFileSuccess) { 1349 TEST_F(ObfuscatedFileUtilTest, TestCopyOrMoveFileSuccess) {
1377 const int64 kSourceLength = 5; 1350 const int64 kSourceLength = 5;
1378 const int64 kDestLength = 50; 1351 const int64 kDestLength = 50;
1379 1352
1380 for (size_t i = 0; i < arraysize(kCopyMoveTestCases); ++i) { 1353 for (size_t i = 0; i < arraysize(kCopyMoveTestCases); ++i) {
1381 SCOPED_TRACE(testing::Message() << "kCopyMoveTestCase " << i); 1354 SCOPED_TRACE(testing::Message() << "kCopyMoveTestCase " << i);
1382 const CopyMoveTestCaseRecord& test_case = kCopyMoveTestCases[i]; 1355 const CopyMoveTestCaseRecord& test_case = kCopyMoveTestCases[i];
1383 SCOPED_TRACE(testing::Message() << "\t is_copy_not_move " << 1356 SCOPED_TRACE(testing::Message() << "\t is_copy_not_move " <<
1384 test_case.is_copy_not_move); 1357 test_case.is_copy_not_move);
1385 SCOPED_TRACE(testing::Message() << "\t source_path " << 1358 SCOPED_TRACE(testing::Message() << "\t source_path " <<
1386 test_case.source_path); 1359 test_case.source_path);
1387 SCOPED_TRACE(testing::Message() << "\t dest_path " << 1360 SCOPED_TRACE(testing::Message() << "\t dest_path " <<
1388 test_case.dest_path); 1361 test_case.dest_path);
1389 SCOPED_TRACE(testing::Message() << "\t cause_overwrite " << 1362 SCOPED_TRACE(testing::Message() << "\t cause_overwrite " <<
1390 test_case.cause_overwrite); 1363 test_case.cause_overwrite);
1391 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); 1364 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
1392 1365
1393 bool exclusive = false; 1366 bool exclusive = false;
1394 bool recursive = true; 1367 bool recursive = true;
1395 FileSystemURL source_url = CreateURLFromUTF8(test_case.source_path); 1368 FileSystemURL source_url = CreateURLFromUTF8(test_case.source_path);
1396 FileSystemURL dest_url = CreateURLFromUTF8(test_case.dest_path); 1369 FileSystemURL dest_url = CreateURLFromUTF8(test_case.dest_path);
1397 1370
1398 context.reset(NewContext(NULL)); 1371 context.reset(NewContext(NULL));
1399 ASSERT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory( 1372 ASSERT_EQ(base::File::FILE_OK,
1400 context.get(), 1373 ofu()->CreateDirectory(context.get(),
1401 FileSystemURLDirName(source_url), 1374 FileSystemURLDirName(source_url),
1402 exclusive, recursive)); 1375 exclusive, recursive));
1403 context.reset(NewContext(NULL)); 1376 context.reset(NewContext(NULL));
1404 ASSERT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory( 1377 ASSERT_EQ(base::File::FILE_OK,
1405 context.get(), 1378 ofu()->CreateDirectory(context.get(),
1406 FileSystemURLDirName(dest_url), 1379 FileSystemURLDirName(dest_url),
1407 exclusive, recursive)); 1380 exclusive, recursive));
1408 1381
1409 bool created = false; 1382 bool created = false;
1410 context.reset(NewContext(NULL)); 1383 context.reset(NewContext(NULL));
1411 ASSERT_EQ(base::PLATFORM_FILE_OK, 1384 ASSERT_EQ(base::File::FILE_OK,
1412 ofu()->EnsureFileExists(context.get(), source_url, &created)); 1385 ofu()->EnsureFileExists(context.get(), source_url, &created));
1413 ASSERT_TRUE(created); 1386 ASSERT_TRUE(created);
1414 context.reset(NewContext(NULL)); 1387 context.reset(NewContext(NULL));
1415 ASSERT_EQ(base::PLATFORM_FILE_OK, 1388 ASSERT_EQ(base::File::FILE_OK,
1416 ofu()->Truncate(context.get(), source_url, kSourceLength)); 1389 ofu()->Truncate(context.get(), source_url, kSourceLength));
1417 1390
1418 if (test_case.cause_overwrite) { 1391 if (test_case.cause_overwrite) {
1419 context.reset(NewContext(NULL)); 1392 context.reset(NewContext(NULL));
1420 created = false; 1393 created = false;
1421 ASSERT_EQ(base::PLATFORM_FILE_OK, 1394 ASSERT_EQ(base::File::FILE_OK,
1422 ofu()->EnsureFileExists(context.get(), dest_url, &created)); 1395 ofu()->EnsureFileExists(context.get(), dest_url, &created));
1423 ASSERT_TRUE(created); 1396 ASSERT_TRUE(created);
1424 context.reset(NewContext(NULL)); 1397 context.reset(NewContext(NULL));
1425 ASSERT_EQ(base::PLATFORM_FILE_OK, 1398 ASSERT_EQ(base::File::FILE_OK,
1426 ofu()->Truncate(context.get(), dest_url, kDestLength)); 1399 ofu()->Truncate(context.get(), dest_url, kDestLength));
1427 } 1400 }
1428 1401
1429 context.reset(NewContext(NULL)); 1402 context.reset(NewContext(NULL));
1430 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->CopyOrMoveFile( 1403 EXPECT_EQ(base::File::FILE_OK,
1431 context.get(), source_url, dest_url, FileSystemOperation::OPTION_NONE, 1404 ofu()->CopyOrMoveFile(context.get(), source_url, dest_url,
1432 test_case.is_copy_not_move)); 1405 FileSystemOperation::OPTION_NONE,
1406 test_case.is_copy_not_move));
1433 1407
1434 if (test_case.is_copy_not_move) { 1408 if (test_case.is_copy_not_move) {
1435 base::PlatformFileInfo file_info; 1409 base::File::Info file_info;
1436 base::FilePath local_path; 1410 base::FilePath local_path;
1437 context.reset(NewContext(NULL)); 1411 context.reset(NewContext(NULL));
1438 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo( 1412 EXPECT_EQ(base::File::FILE_OK,
1439 context.get(), source_url, &file_info, &local_path)); 1413 ofu()->GetFileInfo(context.get(), source_url, &file_info,
1414 &local_path));
1440 EXPECT_EQ(kSourceLength, file_info.size); 1415 EXPECT_EQ(kSourceLength, file_info.size);
1441 EXPECT_EQ(base::PLATFORM_FILE_OK, 1416 EXPECT_EQ(base::File::FILE_OK,
1442 ofu()->DeleteFile(context.get(), source_url)); 1417 ofu()->DeleteFile(context.get(), source_url));
1443 } else { 1418 } else {
1444 base::PlatformFileInfo file_info; 1419 base::File::Info file_info;
1445 base::FilePath local_path; 1420 base::FilePath local_path;
1446 context.reset(NewContext(NULL)); 1421 context.reset(NewContext(NULL));
1447 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, ofu()->GetFileInfo( 1422 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
1448 context.get(), source_url, &file_info, &local_path)); 1423 ofu()->GetFileInfo(context.get(), source_url, &file_info,
1424 &local_path));
1449 } 1425 }
1450 base::PlatformFileInfo file_info; 1426 base::File::Info file_info;
1451 base::FilePath local_path; 1427 base::FilePath local_path;
1452 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo( 1428 EXPECT_EQ(base::File::FILE_OK,
1453 context.get(), dest_url, &file_info, &local_path)); 1429 ofu()->GetFileInfo(context.get(), dest_url, &file_info,
1430 &local_path));
1454 EXPECT_EQ(kSourceLength, file_info.size); 1431 EXPECT_EQ(kSourceLength, file_info.size);
1455 1432
1456 EXPECT_EQ(base::PLATFORM_FILE_OK, 1433 EXPECT_EQ(base::File::FILE_OK,
1457 ofu()->DeleteFile(context.get(), dest_url)); 1434 ofu()->DeleteFile(context.get(), dest_url));
1458 } 1435 }
1459 } 1436 }
1460 1437
1461 TEST_F(ObfuscatedFileUtilTest, TestCopyPathQuotas) { 1438 TEST_F(ObfuscatedFileUtilTest, TestCopyPathQuotas) {
1462 FileSystemURL src_url = CreateURLFromUTF8("src path"); 1439 FileSystemURL src_url = CreateURLFromUTF8("src path");
1463 FileSystemURL dest_url = CreateURLFromUTF8("destination path"); 1440 FileSystemURL dest_url = CreateURLFromUTF8("destination path");
1464 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); 1441 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
1465 bool created = false; 1442 bool created = false;
1466 ASSERT_EQ(base::PLATFORM_FILE_OK, ofu()->EnsureFileExists( 1443 ASSERT_EQ(base::File::FILE_OK,
1467 context.get(), src_url, &created)); 1444 ofu()->EnsureFileExists(context.get(), src_url, &created));
1468 1445
1469 bool is_copy = true; 1446 bool is_copy = true;
1470 // Copy, no overwrite. 1447 // Copy, no overwrite.
1471 context->set_allowed_bytes_growth( 1448 context->set_allowed_bytes_growth(
1472 ObfuscatedFileUtil::ComputeFilePathCost(dest_url.path()) - 1); 1449 ObfuscatedFileUtil::ComputeFilePathCost(dest_url.path()) - 1);
1473 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, 1450 EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE,
1474 ofu()->CopyOrMoveFile( 1451 ofu()->CopyOrMoveFile(context.get(), src_url, dest_url,
1475 context.get(), 1452 FileSystemOperation::OPTION_NONE, is_copy));
1476 src_url, dest_url, FileSystemOperation::OPTION_NONE, is_copy));
1477 context.reset(NewContext(NULL)); 1453 context.reset(NewContext(NULL));
1478 context->set_allowed_bytes_growth( 1454 context->set_allowed_bytes_growth(
1479 ObfuscatedFileUtil::ComputeFilePathCost(dest_url.path())); 1455 ObfuscatedFileUtil::ComputeFilePathCost(dest_url.path()));
1480 EXPECT_EQ(base::PLATFORM_FILE_OK, 1456 EXPECT_EQ(base::File::FILE_OK,
1481 ofu()->CopyOrMoveFile( 1457 ofu()->CopyOrMoveFile(context.get(), src_url, dest_url,
1482 context.get(), 1458 FileSystemOperation::OPTION_NONE, is_copy));
1483 src_url, dest_url, FileSystemOperation::OPTION_NONE, is_copy));
1484 1459
1485 // Copy, with overwrite. 1460 // Copy, with overwrite.
1486 context.reset(NewContext(NULL)); 1461 context.reset(NewContext(NULL));
1487 context->set_allowed_bytes_growth(0); 1462 context->set_allowed_bytes_growth(0);
1488 EXPECT_EQ(base::PLATFORM_FILE_OK, 1463 EXPECT_EQ(base::File::FILE_OK,
1489 ofu()->CopyOrMoveFile( 1464 ofu()->CopyOrMoveFile(context.get(), src_url, dest_url,
1490 context.get(), 1465 FileSystemOperation::OPTION_NONE, is_copy));
1491 src_url, dest_url, FileSystemOperation::OPTION_NONE, is_copy));
1492 } 1466 }
1493 1467
1494 TEST_F(ObfuscatedFileUtilTest, TestMovePathQuotasWithRename) { 1468 TEST_F(ObfuscatedFileUtilTest, TestMovePathQuotasWithRename) {
1495 FileSystemURL src_url = CreateURLFromUTF8("src path"); 1469 FileSystemURL src_url = CreateURLFromUTF8("src path");
1496 FileSystemURL dest_url = CreateURLFromUTF8("destination path"); 1470 FileSystemURL dest_url = CreateURLFromUTF8("destination path");
1497 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); 1471 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
1498 bool created = false; 1472 bool created = false;
1499 ASSERT_EQ(base::PLATFORM_FILE_OK, ofu()->EnsureFileExists( 1473 ASSERT_EQ(base::File::FILE_OK,
1500 context.get(), src_url, &created)); 1474 ofu()->EnsureFileExists(context.get(), src_url, &created));
1501 1475
1502 bool is_copy = false; 1476 bool is_copy = false;
1503 // Move, rename, no overwrite. 1477 // Move, rename, no overwrite.
1504 context.reset(NewContext(NULL)); 1478 context.reset(NewContext(NULL));
1505 context->set_allowed_bytes_growth( 1479 context->set_allowed_bytes_growth(
1506 ObfuscatedFileUtil::ComputeFilePathCost(dest_url.path()) - 1480 ObfuscatedFileUtil::ComputeFilePathCost(dest_url.path()) -
1507 ObfuscatedFileUtil::ComputeFilePathCost(src_url.path()) - 1); 1481 ObfuscatedFileUtil::ComputeFilePathCost(src_url.path()) - 1);
1508 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, 1482 EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE,
1509 ofu()->CopyOrMoveFile( 1483 ofu()->CopyOrMoveFile(context.get(), src_url, dest_url,
1510 context.get(), 1484 FileSystemOperation::OPTION_NONE, is_copy));
1511 src_url, dest_url, FileSystemOperation::OPTION_NONE, is_copy));
1512 context.reset(NewContext(NULL)); 1485 context.reset(NewContext(NULL));
1513 context->set_allowed_bytes_growth( 1486 context->set_allowed_bytes_growth(
1514 ObfuscatedFileUtil::ComputeFilePathCost(dest_url.path()) - 1487 ObfuscatedFileUtil::ComputeFilePathCost(dest_url.path()) -
1515 ObfuscatedFileUtil::ComputeFilePathCost(src_url.path())); 1488 ObfuscatedFileUtil::ComputeFilePathCost(src_url.path()));
1516 EXPECT_EQ(base::PLATFORM_FILE_OK, 1489 EXPECT_EQ(base::File::FILE_OK,
1517 ofu()->CopyOrMoveFile( 1490 ofu()->CopyOrMoveFile(context.get(), src_url, dest_url,
1518 context.get(), 1491 FileSystemOperation::OPTION_NONE, is_copy));
1519 src_url, dest_url, FileSystemOperation::OPTION_NONE, is_copy));
1520 1492
1521 context.reset(NewContext(NULL)); 1493 context.reset(NewContext(NULL));
1522 ASSERT_EQ(base::PLATFORM_FILE_OK, ofu()->EnsureFileExists( 1494 ASSERT_EQ(base::File::FILE_OK,
1523 context.get(), src_url, &created)); 1495 ofu()->EnsureFileExists(context.get(), src_url, &created));
1524 1496
1525 // Move, rename, with overwrite. 1497 // Move, rename, with overwrite.
1526 context.reset(NewContext(NULL)); 1498 context.reset(NewContext(NULL));
1527 context->set_allowed_bytes_growth(0); 1499 context->set_allowed_bytes_growth(0);
1528 EXPECT_EQ(base::PLATFORM_FILE_OK, 1500 EXPECT_EQ(base::File::FILE_OK,
1529 ofu()->CopyOrMoveFile( 1501 ofu()->CopyOrMoveFile(context.get(), src_url, dest_url,
1530 context.get(), 1502 FileSystemOperation::OPTION_NONE, is_copy));
1531 src_url, dest_url, FileSystemOperation::OPTION_NONE, is_copy));
1532 } 1503 }
1533 1504
1534 TEST_F(ObfuscatedFileUtilTest, TestMovePathQuotasWithoutRename) { 1505 TEST_F(ObfuscatedFileUtilTest, TestMovePathQuotasWithoutRename) {
1535 FileSystemURL src_url = CreateURLFromUTF8("src path"); 1506 FileSystemURL src_url = CreateURLFromUTF8("src path");
1536 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); 1507 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
1537 bool created = false; 1508 bool created = false;
1538 ASSERT_EQ(base::PLATFORM_FILE_OK, ofu()->EnsureFileExists( 1509 ASSERT_EQ(base::File::FILE_OK,
1539 context.get(), src_url, &created)); 1510 ofu()->EnsureFileExists(context.get(), src_url, &created));
1540 1511
1541 bool exclusive = true; 1512 bool exclusive = true;
1542 bool recursive = false; 1513 bool recursive = false;
1543 FileSystemURL dir_url = CreateURLFromUTF8("directory path"); 1514 FileSystemURL dir_url = CreateURLFromUTF8("directory path");
1544 context.reset(NewContext(NULL)); 1515 context.reset(NewContext(NULL));
1545 ASSERT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory( 1516 ASSERT_EQ(base::File::FILE_OK,
1546 context.get(), dir_url, exclusive, recursive)); 1517 ofu()->CreateDirectory(context.get(), dir_url, exclusive,
1518 recursive));
1547 1519
1548 FileSystemURL dest_url = FileSystemURLAppend( 1520 FileSystemURL dest_url = FileSystemURLAppend(
1549 dir_url, src_url.path().value()); 1521 dir_url, src_url.path().value());
1550 1522
1551 bool is_copy = false; 1523 bool is_copy = false;
1552 int64 allowed_bytes_growth = -1000; // Over quota, this should still work. 1524 int64 allowed_bytes_growth = -1000; // Over quota, this should still work.
1553 // Move, no rename, no overwrite. 1525 // Move, no rename, no overwrite.
1554 context.reset(NewContext(NULL)); 1526 context.reset(NewContext(NULL));
1555 context->set_allowed_bytes_growth(allowed_bytes_growth); 1527 context->set_allowed_bytes_growth(allowed_bytes_growth);
1556 EXPECT_EQ(base::PLATFORM_FILE_OK, 1528 EXPECT_EQ(base::File::FILE_OK,
1557 ofu()->CopyOrMoveFile( 1529 ofu()->CopyOrMoveFile(context.get(), src_url, dest_url,
1558 context.get(), 1530 FileSystemOperation::OPTION_NONE, is_copy));
1559 src_url, dest_url, FileSystemOperation::OPTION_NONE, is_copy));
1560 EXPECT_EQ(allowed_bytes_growth, context->allowed_bytes_growth()); 1531 EXPECT_EQ(allowed_bytes_growth, context->allowed_bytes_growth());
1561 1532
1562 // Move, no rename, with overwrite. 1533 // Move, no rename, with overwrite.
1563 context.reset(NewContext(NULL)); 1534 context.reset(NewContext(NULL));
1564 ASSERT_EQ(base::PLATFORM_FILE_OK, ofu()->EnsureFileExists( 1535 ASSERT_EQ(base::File::FILE_OK,
1565 context.get(), src_url, &created)); 1536 ofu()->EnsureFileExists(context.get(), src_url, &created));
1566 context.reset(NewContext(NULL)); 1537 context.reset(NewContext(NULL));
1567 context->set_allowed_bytes_growth(allowed_bytes_growth); 1538 context->set_allowed_bytes_growth(allowed_bytes_growth);
1568 EXPECT_EQ(base::PLATFORM_FILE_OK, 1539 EXPECT_EQ(base::File::FILE_OK,
1569 ofu()->CopyOrMoveFile( 1540 ofu()->CopyOrMoveFile(context.get(), src_url, dest_url,
1570 context.get(), 1541 FileSystemOperation::OPTION_NONE, is_copy));
1571 src_url, dest_url, FileSystemOperation::OPTION_NONE, is_copy));
1572 EXPECT_EQ( 1542 EXPECT_EQ(
1573 allowed_bytes_growth + 1543 allowed_bytes_growth +
1574 ObfuscatedFileUtil::ComputeFilePathCost(src_url.path()), 1544 ObfuscatedFileUtil::ComputeFilePathCost(src_url.path()),
1575 context->allowed_bytes_growth()); 1545 context->allowed_bytes_growth());
1576 } 1546 }
1577 1547
1578 TEST_F(ObfuscatedFileUtilTest, TestCopyInForeignFile) { 1548 TEST_F(ObfuscatedFileUtilTest, TestCopyInForeignFile) {
1579 TestCopyInForeignFileHelper(false /* overwrite */); 1549 TestCopyInForeignFileHelper(false /* overwrite */);
1580 TestCopyInForeignFileHelper(true /* overwrite */); 1550 TestCopyInForeignFileHelper(true /* overwrite */);
1581 } 1551 }
1582 1552
1583 TEST_F(ObfuscatedFileUtilTest, TestEnumerator) { 1553 TEST_F(ObfuscatedFileUtilTest, TestEnumerator) {
1584 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); 1554 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
1585 FileSystemURL src_url = CreateURLFromUTF8("source dir"); 1555 FileSystemURL src_url = CreateURLFromUTF8("source dir");
1586 bool exclusive = true; 1556 bool exclusive = true;
1587 bool recursive = false; 1557 bool recursive = false;
1588 ASSERT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory( 1558 ASSERT_EQ(base::File::FILE_OK,
1589 context.get(), src_url, exclusive, recursive)); 1559 ofu()->CreateDirectory(context.get(), src_url, exclusive,
1560 recursive));
1590 1561
1591 std::set<base::FilePath::StringType> files; 1562 std::set<base::FilePath::StringType> files;
1592 std::set<base::FilePath::StringType> directories; 1563 std::set<base::FilePath::StringType> directories;
1593 FillTestDirectory(src_url, &files, &directories); 1564 FillTestDirectory(src_url, &files, &directories);
1594 1565
1595 FileSystemURL dest_url = CreateURLFromUTF8("destination dir"); 1566 FileSystemURL dest_url = CreateURLFromUTF8("destination dir");
1596 1567
1597 EXPECT_FALSE(DirectoryExists(dest_url)); 1568 EXPECT_FALSE(DirectoryExists(dest_url));
1598 ASSERT_EQ(base::PLATFORM_FILE_OK, 1569 ASSERT_EQ(base::File::FILE_OK,
1599 AsyncFileTestHelper::Copy( 1570 AsyncFileTestHelper::Copy(
1600 file_system_context(), src_url, dest_url)); 1571 file_system_context(), src_url, dest_url));
1601 1572
1602 ValidateTestDirectory(dest_url, files, directories); 1573 ValidateTestDirectory(dest_url, files, directories);
1603 EXPECT_TRUE(DirectoryExists(src_url)); 1574 EXPECT_TRUE(DirectoryExists(src_url));
1604 EXPECT_TRUE(DirectoryExists(dest_url)); 1575 EXPECT_TRUE(DirectoryExists(dest_url));
1605 recursive = true; 1576 recursive = true;
1606 ASSERT_EQ(base::PLATFORM_FILE_OK, 1577 ASSERT_EQ(base::File::FILE_OK,
1607 AsyncFileTestHelper::Remove( 1578 AsyncFileTestHelper::Remove(
1608 file_system_context(), dest_url, recursive)); 1579 file_system_context(), dest_url, recursive));
1609 EXPECT_FALSE(DirectoryExists(dest_url)); 1580 EXPECT_FALSE(DirectoryExists(dest_url));
1610 } 1581 }
1611 1582
1612 TEST_F(ObfuscatedFileUtilTest, TestOriginEnumerator) { 1583 TEST_F(ObfuscatedFileUtilTest, TestOriginEnumerator) {
1613 scoped_ptr<ObfuscatedFileUtil::AbstractOriginEnumerator> 1584 scoped_ptr<ObfuscatedFileUtil::AbstractOriginEnumerator>
1614 enumerator(ofu()->CreateOriginEnumerator()); 1585 enumerator(ofu()->CreateOriginEnumerator());
1615 // The test helper starts out with a single filesystem. 1586 // The test helper starts out with a single filesystem.
1616 EXPECT_TRUE(enumerator.get()); 1587 EXPECT_TRUE(enumerator.get());
(...skipping 14 matching lines...) Expand all
1631 const OriginEnumerationTestRecord& record = 1602 const OriginEnumerationTestRecord& record =
1632 kOriginEnumerationTestRecords[i]; 1603 kOriginEnumerationTestRecords[i];
1633 GURL origin_url(record.origin_url); 1604 GURL origin_url(record.origin_url);
1634 origins_expected.insert(origin_url); 1605 origins_expected.insert(origin_url);
1635 if (record.has_temporary) { 1606 if (record.has_temporary) {
1636 scoped_ptr<SandboxFileSystemTestHelper> file_system( 1607 scoped_ptr<SandboxFileSystemTestHelper> file_system(
1637 NewFileSystem(origin_url, kFileSystemTypeTemporary)); 1608 NewFileSystem(origin_url, kFileSystemTypeTemporary));
1638 scoped_ptr<FileSystemOperationContext> context( 1609 scoped_ptr<FileSystemOperationContext> context(
1639 NewContext(file_system.get())); 1610 NewContext(file_system.get()));
1640 bool created = false; 1611 bool created = false;
1641 ASSERT_EQ(base::PLATFORM_FILE_OK, 1612 ASSERT_EQ(base::File::FILE_OK,
1642 ofu()->EnsureFileExists( 1613 ofu()->EnsureFileExists(
1643 context.get(), 1614 context.get(),
1644 file_system->CreateURLFromUTF8("file"), 1615 file_system->CreateURLFromUTF8("file"),
1645 &created)); 1616 &created));
1646 EXPECT_TRUE(created); 1617 EXPECT_TRUE(created);
1647 } 1618 }
1648 if (record.has_persistent) { 1619 if (record.has_persistent) {
1649 scoped_ptr<SandboxFileSystemTestHelper> file_system( 1620 scoped_ptr<SandboxFileSystemTestHelper> file_system(
1650 NewFileSystem(origin_url, kFileSystemTypePersistent)); 1621 NewFileSystem(origin_url, kFileSystemTypePersistent));
1651 scoped_ptr<FileSystemOperationContext> context( 1622 scoped_ptr<FileSystemOperationContext> context(
1652 NewContext(file_system.get())); 1623 NewContext(file_system.get()));
1653 bool created = false; 1624 bool created = false;
1654 ASSERT_EQ(base::PLATFORM_FILE_OK, 1625 ASSERT_EQ(base::File::FILE_OK,
1655 ofu()->EnsureFileExists( 1626 ofu()->EnsureFileExists(
1656 context.get(), 1627 context.get(),
1657 file_system->CreateURLFromUTF8("file"), 1628 file_system->CreateURLFromUTF8("file"),
1658 &created)); 1629 &created));
1659 EXPECT_TRUE(created); 1630 EXPECT_TRUE(created);
1660 } 1631 }
1661 } 1632 }
1662 enumerator.reset(ofu()->CreateOriginEnumerator()); 1633 enumerator.reset(ofu()->CreateOriginEnumerator());
1663 EXPECT_TRUE(enumerator.get()); 1634 EXPECT_TRUE(enumerator.get());
1664 std::set<GURL> origins_found; 1635 std::set<GURL> origins_found;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1705 1676
1706 for (size_t i = 0; i < fileapi::test::kRegularTestCaseSize; ++i) { 1677 for (size_t i = 0; i < fileapi::test::kRegularTestCaseSize; ++i) {
1707 SCOPED_TRACE(testing::Message() << "Creating kRegularTestCase " << i); 1678 SCOPED_TRACE(testing::Message() << "Creating kRegularTestCase " << i);
1708 const fileapi::test::TestCaseRecord& test_case = 1679 const fileapi::test::TestCaseRecord& test_case =
1709 fileapi::test::kRegularTestCases[i]; 1680 fileapi::test::kRegularTestCases[i];
1710 base::FilePath file_path(test_case.path); 1681 base::FilePath file_path(test_case.path);
1711 expected_quota += ObfuscatedFileUtil::ComputeFilePathCost(file_path); 1682 expected_quota += ObfuscatedFileUtil::ComputeFilePathCost(file_path);
1712 if (test_case.is_directory) { 1683 if (test_case.is_directory) {
1713 bool exclusive = true; 1684 bool exclusive = true;
1714 bool recursive = false; 1685 bool recursive = false;
1715 ASSERT_EQ(base::PLATFORM_FILE_OK, 1686 ASSERT_EQ(base::File::FILE_OK,
1716 ofu()->CreateDirectory(context.get(), CreateURL(file_path), 1687 ofu()->CreateDirectory(context.get(), CreateURL(file_path),
1717 exclusive, recursive)); 1688 exclusive, recursive));
1718 } else { 1689 } else {
1719 bool created = false; 1690 bool created = false;
1720 ASSERT_EQ(base::PLATFORM_FILE_OK, 1691 ASSERT_EQ(base::File::FILE_OK,
1721 ofu()->EnsureFileExists(context.get(), CreateURL(file_path), 1692 ofu()->EnsureFileExists(context.get(), CreateURL(file_path),
1722 &created)); 1693 &created));
1723 ASSERT_TRUE(created); 1694 ASSERT_TRUE(created);
1724 ASSERT_EQ(base::PLATFORM_FILE_OK, 1695 ASSERT_EQ(base::File::FILE_OK,
1725 ofu()->Truncate(context.get(), 1696 ofu()->Truncate(context.get(), CreateURL(file_path),
1726 CreateURL(file_path), 1697 test_case.data_file_size));
1727 test_case.data_file_size));
1728 expected_quota += test_case.data_file_size; 1698 expected_quota += test_case.data_file_size;
1729 } 1699 }
1730 } 1700 }
1731 1701
1732 // Usually raw size in usage cache and the usage returned by QuotaUtil 1702 // Usually raw size in usage cache and the usage returned by QuotaUtil
1733 // should be same. 1703 // should be same.
1734 EXPECT_EQ(expected_quota, SizeInUsageFile()); 1704 EXPECT_EQ(expected_quota, SizeInUsageFile());
1735 EXPECT_EQ(expected_quota, SizeByQuotaUtil()); 1705 EXPECT_EQ(expected_quota, SizeByQuotaUtil());
1736 1706
1737 RevokeUsageCache(); 1707 RevokeUsageCache();
1738 EXPECT_EQ(-1, SizeInUsageFile()); 1708 EXPECT_EQ(-1, SizeInUsageFile());
1739 EXPECT_EQ(expected_quota, SizeByQuotaUtil()); 1709 EXPECT_EQ(expected_quota, SizeByQuotaUtil());
1740 1710
1741 // This should reconstruct the cache. 1711 // This should reconstruct the cache.
1742 GetUsageFromQuotaManager(); 1712 GetUsageFromQuotaManager();
1743 EXPECT_EQ(expected_quota, SizeInUsageFile()); 1713 EXPECT_EQ(expected_quota, SizeInUsageFile());
1744 EXPECT_EQ(expected_quota, SizeByQuotaUtil()); 1714 EXPECT_EQ(expected_quota, SizeByQuotaUtil());
1745 EXPECT_EQ(expected_quota, usage()); 1715 EXPECT_EQ(expected_quota, usage());
1746 } 1716 }
1747 1717
1748 TEST_F(ObfuscatedFileUtilTest, TestInconsistency) { 1718 TEST_F(ObfuscatedFileUtilTest, TestInconsistency) {
1749 const FileSystemURL kPath1 = CreateURLFromUTF8("hoge"); 1719 const FileSystemURL kPath1 = CreateURLFromUTF8("hoge");
1750 const FileSystemURL kPath2 = CreateURLFromUTF8("fuga"); 1720 const FileSystemURL kPath2 = CreateURLFromUTF8("fuga");
1751 1721
1752 scoped_ptr<FileSystemOperationContext> context; 1722 scoped_ptr<FileSystemOperationContext> context;
1753 base::PlatformFile file; 1723 base::PlatformFile file;
1754 base::PlatformFileInfo file_info; 1724 base::File::Info file_info;
1755 base::FilePath data_path; 1725 base::FilePath data_path;
1756 bool created = false; 1726 bool created = false;
1757 1727
1758 // Create a non-empty file. 1728 // Create a non-empty file.
1759 context.reset(NewContext(NULL)); 1729 context.reset(NewContext(NULL));
1760 EXPECT_EQ(base::PLATFORM_FILE_OK, 1730 EXPECT_EQ(base::File::FILE_OK,
1761 ofu()->EnsureFileExists(context.get(), kPath1, &created)); 1731 ofu()->EnsureFileExists(context.get(), kPath1, &created));
1762 EXPECT_TRUE(created); 1732 EXPECT_TRUE(created);
1763 context.reset(NewContext(NULL)); 1733 context.reset(NewContext(NULL));
1764 EXPECT_EQ(base::PLATFORM_FILE_OK, 1734 EXPECT_EQ(base::File::FILE_OK,
1765 ofu()->Truncate(context.get(), kPath1, 10)); 1735 ofu()->Truncate(context.get(), kPath1, 10));
1766 context.reset(NewContext(NULL)); 1736 context.reset(NewContext(NULL));
1767 EXPECT_EQ(base::PLATFORM_FILE_OK, 1737 EXPECT_EQ(base::File::FILE_OK,
1768 ofu()->GetFileInfo( 1738 ofu()->GetFileInfo(
1769 context.get(), kPath1, &file_info, &data_path)); 1739 context.get(), kPath1, &file_info, &data_path));
1770 EXPECT_EQ(10, file_info.size); 1740 EXPECT_EQ(10, file_info.size);
1771 1741
1772 // Destroy database to make inconsistency between database and filesystem. 1742 // Destroy database to make inconsistency between database and filesystem.
1773 ofu()->DestroyDirectoryDatabase(origin(), type_string()); 1743 ofu()->DestroyDirectoryDatabase(origin(), type_string());
1774 1744
1775 // Try to get file info of broken file. 1745 // Try to get file info of broken file.
1776 EXPECT_FALSE(PathExists(kPath1)); 1746 EXPECT_FALSE(PathExists(kPath1));
1777 context.reset(NewContext(NULL)); 1747 context.reset(NewContext(NULL));
1778 EXPECT_EQ(base::PLATFORM_FILE_OK, 1748 EXPECT_EQ(base::File::FILE_OK,
1779 ofu()->EnsureFileExists(context.get(), kPath1, &created)); 1749 ofu()->EnsureFileExists(context.get(), kPath1, &created));
1780 EXPECT_TRUE(created); 1750 EXPECT_TRUE(created);
1781 context.reset(NewContext(NULL)); 1751 context.reset(NewContext(NULL));
1782 EXPECT_EQ(base::PLATFORM_FILE_OK, 1752 EXPECT_EQ(base::File::FILE_OK,
1783 ofu()->GetFileInfo( 1753 ofu()->GetFileInfo(
1784 context.get(), kPath1, &file_info, &data_path)); 1754 context.get(), kPath1, &file_info, &data_path));
1785 EXPECT_EQ(0, file_info.size); 1755 EXPECT_EQ(0, file_info.size);
1786 1756
1787 // Make another broken file to |kPath2|. 1757 // Make another broken file to |kPath2|.
1788 context.reset(NewContext(NULL)); 1758 context.reset(NewContext(NULL));
1789 EXPECT_EQ(base::PLATFORM_FILE_OK, 1759 EXPECT_EQ(base::File::FILE_OK,
1790 ofu()->EnsureFileExists(context.get(), kPath2, &created)); 1760 ofu()->EnsureFileExists(context.get(), kPath2, &created));
1791 EXPECT_TRUE(created); 1761 EXPECT_TRUE(created);
1792 1762
1793 // Destroy again. 1763 // Destroy again.
1794 ofu()->DestroyDirectoryDatabase(origin(), type_string()); 1764 ofu()->DestroyDirectoryDatabase(origin(), type_string());
1795 1765
1796 // Repair broken |kPath1|. 1766 // Repair broken |kPath1|.
1797 context.reset(NewContext(NULL)); 1767 context.reset(NewContext(NULL));
1798 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 1768 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
1799 ofu()->Touch(context.get(), kPath1, base::Time::Now(), 1769 ofu()->Touch(context.get(), kPath1, base::Time::Now(),
1800 base::Time::Now())); 1770 base::Time::Now()));
1801 EXPECT_EQ(base::PLATFORM_FILE_OK, 1771 EXPECT_EQ(base::File::FILE_OK,
1802 ofu()->EnsureFileExists(context.get(), kPath1, &created)); 1772 ofu()->EnsureFileExists(context.get(), kPath1, &created));
1803 EXPECT_TRUE(created); 1773 EXPECT_TRUE(created);
1804 1774
1805 // Copy from sound |kPath1| to broken |kPath2|. 1775 // Copy from sound |kPath1| to broken |kPath2|.
1806 context.reset(NewContext(NULL)); 1776 context.reset(NewContext(NULL));
1807 EXPECT_EQ(base::PLATFORM_FILE_OK, 1777 EXPECT_EQ(base::File::FILE_OK,
1808 ofu()->CopyOrMoveFile(context.get(), kPath1, kPath2, 1778 ofu()->CopyOrMoveFile(context.get(), kPath1, kPath2,
1809 FileSystemOperation::OPTION_NONE, 1779 FileSystemOperation::OPTION_NONE,
1810 true /* copy */)); 1780 true /* copy */));
1811 1781
1812 ofu()->DestroyDirectoryDatabase(origin(), type_string()); 1782 ofu()->DestroyDirectoryDatabase(origin(), type_string());
1813 context.reset(NewContext(NULL)); 1783 context.reset(NewContext(NULL));
1814 EXPECT_EQ(base::PLATFORM_FILE_OK, 1784 EXPECT_EQ(base::File::FILE_OK,
1815 ofu()->CreateOrOpen( 1785 ofu()->CreateOrOpen(
1816 context.get(), kPath1, 1786 context.get(), kPath1,
1817 base::PLATFORM_FILE_READ | base::PLATFORM_FILE_CREATE, 1787 base::PLATFORM_FILE_READ | base::PLATFORM_FILE_CREATE,
1818 &file, &created)); 1788 &file, &created));
1819 EXPECT_TRUE(created); 1789 EXPECT_TRUE(created);
1820 EXPECT_TRUE(base::GetPlatformFileInfo(file, &file_info)); 1790
1791 base::File base_file(file);
1792 EXPECT_TRUE(base_file.GetInfo(&file_info));
1821 EXPECT_EQ(0, file_info.size); 1793 EXPECT_EQ(0, file_info.size);
1822 EXPECT_TRUE(base::ClosePlatformFile(file));
1823 } 1794 }
1824 1795
1825 TEST_F(ObfuscatedFileUtilTest, TestIncompleteDirectoryReading) { 1796 TEST_F(ObfuscatedFileUtilTest, TestIncompleteDirectoryReading) {
1826 const FileSystemURL kPath[] = { 1797 const FileSystemURL kPath[] = {
1827 CreateURLFromUTF8("foo"), 1798 CreateURLFromUTF8("foo"),
1828 CreateURLFromUTF8("bar"), 1799 CreateURLFromUTF8("bar"),
1829 CreateURLFromUTF8("baz") 1800 CreateURLFromUTF8("baz")
1830 }; 1801 };
1831 const FileSystemURL empty_path = CreateURL(base::FilePath()); 1802 const FileSystemURL empty_path = CreateURL(base::FilePath());
1832 scoped_ptr<FileSystemOperationContext> context; 1803 scoped_ptr<FileSystemOperationContext> context;
1833 1804
1834 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kPath); ++i) { 1805 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kPath); ++i) {
1835 bool created = false; 1806 bool created = false;
1836 context.reset(NewContext(NULL)); 1807 context.reset(NewContext(NULL));
1837 EXPECT_EQ(base::PLATFORM_FILE_OK, 1808 EXPECT_EQ(base::File::FILE_OK,
1838 ofu()->EnsureFileExists(context.get(), kPath[i], &created)); 1809 ofu()->EnsureFileExists(context.get(), kPath[i], &created));
1839 EXPECT_TRUE(created); 1810 EXPECT_TRUE(created);
1840 } 1811 }
1841 1812
1842 std::vector<fileapi::DirectoryEntry> entries; 1813 std::vector<fileapi::DirectoryEntry> entries;
1843 EXPECT_EQ(base::PLATFORM_FILE_OK, 1814 EXPECT_EQ(base::File::FILE_OK,
1844 AsyncFileTestHelper::ReadDirectory( 1815 AsyncFileTestHelper::ReadDirectory(
1845 file_system_context(), empty_path, &entries)); 1816 file_system_context(), empty_path, &entries));
1846 EXPECT_EQ(3u, entries.size()); 1817 EXPECT_EQ(3u, entries.size());
1847 1818
1848 base::FilePath local_path; 1819 base::FilePath local_path;
1849 EXPECT_EQ(base::PLATFORM_FILE_OK, 1820 EXPECT_EQ(base::File::FILE_OK,
1850 ofu()->GetLocalFilePath(context.get(), kPath[0], &local_path)); 1821 ofu()->GetLocalFilePath(context.get(), kPath[0], &local_path));
1851 EXPECT_TRUE(base::DeleteFile(local_path, false)); 1822 EXPECT_TRUE(base::DeleteFile(local_path, false));
1852 1823
1853 entries.clear(); 1824 entries.clear();
1854 EXPECT_EQ(base::PLATFORM_FILE_OK, 1825 EXPECT_EQ(base::File::FILE_OK,
1855 AsyncFileTestHelper::ReadDirectory( 1826 AsyncFileTestHelper::ReadDirectory(
1856 file_system_context(), empty_path, &entries)); 1827 file_system_context(), empty_path, &entries));
1857 EXPECT_EQ(ARRAYSIZE_UNSAFE(kPath) - 1, entries.size()); 1828 EXPECT_EQ(ARRAYSIZE_UNSAFE(kPath) - 1, entries.size());
1858 } 1829 }
1859 1830
1860 TEST_F(ObfuscatedFileUtilTest, TestDirectoryTimestampForCreation) { 1831 TEST_F(ObfuscatedFileUtilTest, TestDirectoryTimestampForCreation) {
1861 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); 1832 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
1862 const FileSystemURL dir_url = CreateURLFromUTF8("foo_dir"); 1833 const FileSystemURL dir_url = CreateURLFromUTF8("foo_dir");
1863 1834
1864 // Create working directory. 1835 // Create working directory.
1865 EXPECT_EQ(base::PLATFORM_FILE_OK, 1836 EXPECT_EQ(base::File::FILE_OK,
1866 ofu()->CreateDirectory(context.get(), dir_url, false, false)); 1837 ofu()->CreateDirectory(context.get(), dir_url, false, false));
1867 1838
1868 // EnsureFileExists, create case. 1839 // EnsureFileExists, create case.
1869 FileSystemURL url(FileSystemURLAppendUTF8( 1840 FileSystemURL url(FileSystemURLAppendUTF8(
1870 dir_url, "EnsureFileExists_file")); 1841 dir_url, "EnsureFileExists_file"));
1871 bool created = false; 1842 bool created = false;
1872 ClearTimestamp(dir_url); 1843 ClearTimestamp(dir_url);
1873 context.reset(NewContext(NULL)); 1844 context.reset(NewContext(NULL));
1874 EXPECT_EQ(base::PLATFORM_FILE_OK, 1845 EXPECT_EQ(base::File::FILE_OK,
1875 ofu()->EnsureFileExists(context.get(), url, &created)); 1846 ofu()->EnsureFileExists(context.get(), url, &created));
1876 EXPECT_TRUE(created); 1847 EXPECT_TRUE(created);
1877 EXPECT_NE(base::Time(), GetModifiedTime(dir_url)); 1848 EXPECT_NE(base::Time(), GetModifiedTime(dir_url));
1878 1849
1879 // non create case. 1850 // non create case.
1880 created = true; 1851 created = true;
1881 ClearTimestamp(dir_url); 1852 ClearTimestamp(dir_url);
1882 context.reset(NewContext(NULL)); 1853 context.reset(NewContext(NULL));
1883 EXPECT_EQ(base::PLATFORM_FILE_OK, 1854 EXPECT_EQ(base::File::FILE_OK,
1884 ofu()->EnsureFileExists(context.get(), url, &created)); 1855 ofu()->EnsureFileExists(context.get(), url, &created));
1885 EXPECT_FALSE(created); 1856 EXPECT_FALSE(created);
1886 EXPECT_EQ(base::Time(), GetModifiedTime(dir_url)); 1857 EXPECT_EQ(base::Time(), GetModifiedTime(dir_url));
1887 1858
1888 // fail case. 1859 // fail case.
1889 url = FileSystemURLAppendUTF8(dir_url, "EnsureFileExists_dir"); 1860 url = FileSystemURLAppendUTF8(dir_url, "EnsureFileExists_dir");
1890 context.reset(NewContext(NULL)); 1861 context.reset(NewContext(NULL));
1891 EXPECT_EQ(base::PLATFORM_FILE_OK, 1862 EXPECT_EQ(base::File::FILE_OK,
1892 ofu()->CreateDirectory(context.get(), url, false, false)); 1863 ofu()->CreateDirectory(context.get(), url, false, false));
1893 1864
1894 ClearTimestamp(dir_url); 1865 ClearTimestamp(dir_url);
1895 context.reset(NewContext(NULL)); 1866 context.reset(NewContext(NULL));
1896 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_FILE, 1867 EXPECT_EQ(base::File::FILE_ERROR_NOT_A_FILE,
1897 ofu()->EnsureFileExists(context.get(), url, &created)); 1868 ofu()->EnsureFileExists(context.get(), url, &created));
1898 EXPECT_EQ(base::Time(), GetModifiedTime(dir_url)); 1869 EXPECT_EQ(base::Time(), GetModifiedTime(dir_url));
1899 1870
1900 // CreateOrOpen, create case. 1871 // CreateOrOpen, create case.
1901 url = FileSystemURLAppendUTF8(dir_url, "CreateOrOpen_file"); 1872 url = FileSystemURLAppendUTF8(dir_url, "CreateOrOpen_file");
1902 base::PlatformFile file_handle = base::kInvalidPlatformFileValue; 1873 base::PlatformFile file_handle = base::kInvalidPlatformFileValue;
1903 created = false; 1874 created = false;
1904 ClearTimestamp(dir_url); 1875 ClearTimestamp(dir_url);
1905 context.reset(NewContext(NULL)); 1876 context.reset(NewContext(NULL));
1906 EXPECT_EQ(base::PLATFORM_FILE_OK, 1877 EXPECT_EQ(base::File::FILE_OK,
1907 ofu()->CreateOrOpen( 1878 ofu()->CreateOrOpen(
1908 context.get(), url, 1879 context.get(), url,
1909 base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE, 1880 base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE,
1910 &file_handle, &created)); 1881 &file_handle, &created));
1911 EXPECT_NE(base::kInvalidPlatformFileValue, file_handle); 1882 EXPECT_NE(base::kInvalidPlatformFileValue, file_handle);
1912 EXPECT_TRUE(created); 1883 EXPECT_TRUE(created);
1913 EXPECT_TRUE(base::ClosePlatformFile(file_handle)); 1884 EXPECT_TRUE(base::ClosePlatformFile(file_handle));
1914 EXPECT_NE(base::Time(), GetModifiedTime(dir_url)); 1885 EXPECT_NE(base::Time(), GetModifiedTime(dir_url));
1915 1886
1916 // open case. 1887 // open case.
1917 file_handle = base::kInvalidPlatformFileValue; 1888 file_handle = base::kInvalidPlatformFileValue;
1918 created = true; 1889 created = true;
1919 ClearTimestamp(dir_url); 1890 ClearTimestamp(dir_url);
1920 context.reset(NewContext(NULL)); 1891 context.reset(NewContext(NULL));
1921 EXPECT_EQ(base::PLATFORM_FILE_OK, 1892 EXPECT_EQ(base::File::FILE_OK,
1922 ofu()->CreateOrOpen( 1893 ofu()->CreateOrOpen(
1923 context.get(), url, 1894 context.get(), url,
1924 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE, 1895 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE,
1925 &file_handle, &created)); 1896 &file_handle, &created));
1926 EXPECT_NE(base::kInvalidPlatformFileValue, file_handle); 1897 EXPECT_NE(base::kInvalidPlatformFileValue, file_handle);
1927 EXPECT_FALSE(created); 1898 EXPECT_FALSE(created);
1928 EXPECT_TRUE(base::ClosePlatformFile(file_handle)); 1899 EXPECT_TRUE(base::ClosePlatformFile(file_handle));
1929 EXPECT_EQ(base::Time(), GetModifiedTime(dir_url)); 1900 EXPECT_EQ(base::Time(), GetModifiedTime(dir_url));
1930 1901
1931 // fail case 1902 // fail case
1932 file_handle = base::kInvalidPlatformFileValue; 1903 file_handle = base::kInvalidPlatformFileValue;
1933 ClearTimestamp(dir_url); 1904 ClearTimestamp(dir_url);
1934 context.reset(NewContext(NULL)); 1905 context.reset(NewContext(NULL));
1935 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, 1906 EXPECT_EQ(base::File::FILE_ERROR_EXISTS,
1936 ofu()->CreateOrOpen( 1907 ofu()->CreateOrOpen(
1937 context.get(), url, 1908 context.get(), url,
1938 base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE, 1909 base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE,
1939 &file_handle, &created)); 1910 &file_handle, &created));
1940 EXPECT_EQ(base::kInvalidPlatformFileValue, file_handle); 1911 EXPECT_EQ(base::kInvalidPlatformFileValue, file_handle);
1941 EXPECT_EQ(base::Time(), GetModifiedTime(dir_url)); 1912 EXPECT_EQ(base::Time(), GetModifiedTime(dir_url));
1942 1913
1943 // CreateDirectory, create case. 1914 // CreateDirectory, create case.
1944 // Creating CreateDirectory_dir and CreateDirectory_dir/subdir. 1915 // Creating CreateDirectory_dir and CreateDirectory_dir/subdir.
1945 url = FileSystemURLAppendUTF8(dir_url, "CreateDirectory_dir"); 1916 url = FileSystemURLAppendUTF8(dir_url, "CreateDirectory_dir");
1946 FileSystemURL subdir_url(FileSystemURLAppendUTF8(url, "subdir")); 1917 FileSystemURL subdir_url(FileSystemURLAppendUTF8(url, "subdir"));
1947 ClearTimestamp(dir_url); 1918 ClearTimestamp(dir_url);
1948 context.reset(NewContext(NULL)); 1919 context.reset(NewContext(NULL));
1949 EXPECT_EQ(base::PLATFORM_FILE_OK, 1920 EXPECT_EQ(base::File::FILE_OK,
1950 ofu()->CreateDirectory(context.get(), subdir_url, 1921 ofu()->CreateDirectory(context.get(), subdir_url,
1951 true /* exclusive */, true /* recursive */)); 1922 true /* exclusive */, true /* recursive */));
1952 EXPECT_NE(base::Time(), GetModifiedTime(dir_url)); 1923 EXPECT_NE(base::Time(), GetModifiedTime(dir_url));
1953 1924
1954 // create subdir case. 1925 // create subdir case.
1955 // Creating CreateDirectory_dir/subdir2. 1926 // Creating CreateDirectory_dir/subdir2.
1956 subdir_url = FileSystemURLAppendUTF8(url, "subdir2"); 1927 subdir_url = FileSystemURLAppendUTF8(url, "subdir2");
1957 ClearTimestamp(dir_url); 1928 ClearTimestamp(dir_url);
1958 ClearTimestamp(url); 1929 ClearTimestamp(url);
1959 context.reset(NewContext(NULL)); 1930 context.reset(NewContext(NULL));
1960 EXPECT_EQ(base::PLATFORM_FILE_OK, 1931 EXPECT_EQ(base::File::FILE_OK,
1961 ofu()->CreateDirectory(context.get(), subdir_url, 1932 ofu()->CreateDirectory(context.get(), subdir_url,
1962 true /* exclusive */, true /* recursive */)); 1933 true /* exclusive */, true /* recursive */));
1963 EXPECT_EQ(base::Time(), GetModifiedTime(dir_url)); 1934 EXPECT_EQ(base::Time(), GetModifiedTime(dir_url));
1964 EXPECT_NE(base::Time(), GetModifiedTime(url)); 1935 EXPECT_NE(base::Time(), GetModifiedTime(url));
1965 1936
1966 // fail case. 1937 // fail case.
1967 url = FileSystemURLAppendUTF8(dir_url, "CreateDirectory_dir"); 1938 url = FileSystemURLAppendUTF8(dir_url, "CreateDirectory_dir");
1968 ClearTimestamp(dir_url); 1939 ClearTimestamp(dir_url);
1969 context.reset(NewContext(NULL)); 1940 context.reset(NewContext(NULL));
1970 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, 1941 EXPECT_EQ(base::File::FILE_ERROR_EXISTS,
1971 ofu()->CreateDirectory(context.get(), url, 1942 ofu()->CreateDirectory(context.get(), url,
1972 true /* exclusive */, true /* recursive */)); 1943 true /* exclusive */, true /* recursive */));
1973 EXPECT_EQ(base::Time(), GetModifiedTime(dir_url)); 1944 EXPECT_EQ(base::Time(), GetModifiedTime(dir_url));
1974 1945
1975 // CopyInForeignFile, create case. 1946 // CopyInForeignFile, create case.
1976 url = FileSystemURLAppendUTF8(dir_url, "CopyInForeignFile_file"); 1947 url = FileSystemURLAppendUTF8(dir_url, "CopyInForeignFile_file");
1977 FileSystemURL src_path = FileSystemURLAppendUTF8( 1948 FileSystemURL src_path = FileSystemURLAppendUTF8(
1978 dir_url, "CopyInForeignFile_src_file"); 1949 dir_url, "CopyInForeignFile_src_file");
1979 context.reset(NewContext(NULL)); 1950 context.reset(NewContext(NULL));
1980 EXPECT_EQ(base::PLATFORM_FILE_OK, 1951 EXPECT_EQ(base::File::FILE_OK,
1981 ofu()->EnsureFileExists(context.get(), src_path, &created)); 1952 ofu()->EnsureFileExists(context.get(), src_path, &created));
1982 EXPECT_TRUE(created); 1953 EXPECT_TRUE(created);
1983 base::FilePath src_local_path; 1954 base::FilePath src_local_path;
1984 context.reset(NewContext(NULL)); 1955 context.reset(NewContext(NULL));
1985 EXPECT_EQ(base::PLATFORM_FILE_OK, 1956 EXPECT_EQ(base::File::FILE_OK,
1986 ofu()->GetLocalFilePath(context.get(), src_path, &src_local_path)); 1957 ofu()->GetLocalFilePath(context.get(), src_path, &src_local_path));
1987 1958
1988 ClearTimestamp(dir_url); 1959 ClearTimestamp(dir_url);
1989 context.reset(NewContext(NULL)); 1960 context.reset(NewContext(NULL));
1990 EXPECT_EQ(base::PLATFORM_FILE_OK, 1961 EXPECT_EQ(base::File::FILE_OK,
1991 ofu()->CopyInForeignFile(context.get(), 1962 ofu()->CopyInForeignFile(context.get(),
1992 src_local_path, 1963 src_local_path,
1993 url)); 1964 url));
1994 EXPECT_NE(base::Time(), GetModifiedTime(dir_url)); 1965 EXPECT_NE(base::Time(), GetModifiedTime(dir_url));
1995 } 1966 }
1996 1967
1997 TEST_F(ObfuscatedFileUtilTest, TestDirectoryTimestampForDeletion) { 1968 TEST_F(ObfuscatedFileUtilTest, TestDirectoryTimestampForDeletion) {
1998 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); 1969 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
1999 const FileSystemURL dir_url = CreateURLFromUTF8("foo_dir"); 1970 const FileSystemURL dir_url = CreateURLFromUTF8("foo_dir");
2000 1971
2001 // Create working directory. 1972 // Create working directory.
2002 EXPECT_EQ(base::PLATFORM_FILE_OK, 1973 EXPECT_EQ(base::File::FILE_OK,
2003 ofu()->CreateDirectory(context.get(), dir_url, false, false)); 1974 ofu()->CreateDirectory(context.get(), dir_url, false, false));
2004 1975
2005 // DeleteFile, delete case. 1976 // DeleteFile, delete case.
2006 FileSystemURL url = FileSystemURLAppendUTF8( 1977 FileSystemURL url = FileSystemURLAppendUTF8(
2007 dir_url, "DeleteFile_file"); 1978 dir_url, "DeleteFile_file");
2008 bool created = false; 1979 bool created = false;
2009 context.reset(NewContext(NULL)); 1980 context.reset(NewContext(NULL));
2010 EXPECT_EQ(base::PLATFORM_FILE_OK, 1981 EXPECT_EQ(base::File::FILE_OK,
2011 ofu()->EnsureFileExists(context.get(), url, &created)); 1982 ofu()->EnsureFileExists(context.get(), url, &created));
2012 EXPECT_TRUE(created); 1983 EXPECT_TRUE(created);
2013 1984
2014 ClearTimestamp(dir_url); 1985 ClearTimestamp(dir_url);
2015 context.reset(NewContext(NULL)); 1986 context.reset(NewContext(NULL));
2016 EXPECT_EQ(base::PLATFORM_FILE_OK, 1987 EXPECT_EQ(base::File::FILE_OK,
2017 ofu()->DeleteFile(context.get(), url)); 1988 ofu()->DeleteFile(context.get(), url));
2018 EXPECT_NE(base::Time(), GetModifiedTime(dir_url)); 1989 EXPECT_NE(base::Time(), GetModifiedTime(dir_url));
2019 1990
2020 // fail case. 1991 // fail case.
2021 ClearTimestamp(dir_url); 1992 ClearTimestamp(dir_url);
2022 context.reset(NewContext(NULL)); 1993 context.reset(NewContext(NULL));
2023 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 1994 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
2024 ofu()->DeleteFile(context.get(), url)); 1995 ofu()->DeleteFile(context.get(), url));
2025 EXPECT_EQ(base::Time(), GetModifiedTime(dir_url)); 1996 EXPECT_EQ(base::Time(), GetModifiedTime(dir_url));
2026 1997
2027 // DeleteDirectory, fail case. 1998 // DeleteDirectory, fail case.
2028 url = FileSystemURLAppendUTF8(dir_url, "DeleteDirectory_dir"); 1999 url = FileSystemURLAppendUTF8(dir_url, "DeleteDirectory_dir");
2029 FileSystemURL file_path(FileSystemURLAppendUTF8(url, "pakeratta")); 2000 FileSystemURL file_path(FileSystemURLAppendUTF8(url, "pakeratta"));
2030 context.reset(NewContext(NULL)); 2001 context.reset(NewContext(NULL));
2031 EXPECT_EQ(base::PLATFORM_FILE_OK, 2002 EXPECT_EQ(base::File::FILE_OK,
2032 ofu()->CreateDirectory(context.get(), url, true, true)); 2003 ofu()->CreateDirectory(context.get(), url, true, true));
2033 created = false; 2004 created = false;
2034 context.reset(NewContext(NULL)); 2005 context.reset(NewContext(NULL));
2035 EXPECT_EQ(base::PLATFORM_FILE_OK, 2006 EXPECT_EQ(base::File::FILE_OK,
2036 ofu()->EnsureFileExists(context.get(), file_path, &created)); 2007 ofu()->EnsureFileExists(context.get(), file_path, &created));
2037 EXPECT_TRUE(created); 2008 EXPECT_TRUE(created);
2038 2009
2039 ClearTimestamp(dir_url); 2010 ClearTimestamp(dir_url);
2040 context.reset(NewContext(NULL)); 2011 context.reset(NewContext(NULL));
2041 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, 2012 EXPECT_EQ(base::File::FILE_ERROR_NOT_EMPTY,
2042 ofu()->DeleteDirectory(context.get(), url)); 2013 ofu()->DeleteDirectory(context.get(), url));
2043 EXPECT_EQ(base::Time(), GetModifiedTime(dir_url)); 2014 EXPECT_EQ(base::Time(), GetModifiedTime(dir_url));
2044 2015
2045 // delete case. 2016 // delete case.
2046 context.reset(NewContext(NULL)); 2017 context.reset(NewContext(NULL));
2047 EXPECT_EQ(base::PLATFORM_FILE_OK, 2018 EXPECT_EQ(base::File::FILE_OK,
2048 ofu()->DeleteFile(context.get(), file_path)); 2019 ofu()->DeleteFile(context.get(), file_path));
2049 2020
2050 ClearTimestamp(dir_url); 2021 ClearTimestamp(dir_url);
2051 context.reset(NewContext(NULL)); 2022 context.reset(NewContext(NULL));
2052 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->DeleteDirectory(context.get(), url)); 2023 EXPECT_EQ(base::File::FILE_OK, ofu()->DeleteDirectory(context.get(), url));
2053 EXPECT_NE(base::Time(), GetModifiedTime(dir_url)); 2024 EXPECT_NE(base::Time(), GetModifiedTime(dir_url));
2054 } 2025 }
2055 2026
2056 TEST_F(ObfuscatedFileUtilTest, TestDirectoryTimestampForCopyAndMove) { 2027 TEST_F(ObfuscatedFileUtilTest, TestDirectoryTimestampForCopyAndMove) {
2057 TestDirectoryTimestampHelper( 2028 TestDirectoryTimestampHelper(
2058 CreateURLFromUTF8("copy overwrite"), true, true); 2029 CreateURLFromUTF8("copy overwrite"), true, true);
2059 TestDirectoryTimestampHelper( 2030 TestDirectoryTimestampHelper(
2060 CreateURLFromUTF8("copy non-overwrite"), true, false); 2031 CreateURLFromUTF8("copy non-overwrite"), true, false);
2061 TestDirectoryTimestampHelper( 2032 TestDirectoryTimestampHelper(
2062 CreateURLFromUTF8("move overwrite"), false, true); 2033 CreateURLFromUTF8("move overwrite"), false, true);
2063 TestDirectoryTimestampHelper( 2034 TestDirectoryTimestampHelper(
2064 CreateURLFromUTF8("move non-overwrite"), false, false); 2035 CreateURLFromUTF8("move non-overwrite"), false, false);
2065 } 2036 }
2066 2037
2067 TEST_F(ObfuscatedFileUtilTest, TestFileEnumeratorTimestamp) { 2038 TEST_F(ObfuscatedFileUtilTest, TestFileEnumeratorTimestamp) {
2068 FileSystemURL dir = CreateURLFromUTF8("foo"); 2039 FileSystemURL dir = CreateURLFromUTF8("foo");
2069 FileSystemURL url1 = FileSystemURLAppendUTF8(dir, "bar"); 2040 FileSystemURL url1 = FileSystemURLAppendUTF8(dir, "bar");
2070 FileSystemURL url2 = FileSystemURLAppendUTF8(dir, "baz"); 2041 FileSystemURL url2 = FileSystemURLAppendUTF8(dir, "baz");
2071 2042
2072 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); 2043 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
2073 EXPECT_EQ(base::PLATFORM_FILE_OK, 2044 EXPECT_EQ(base::File::FILE_OK,
2074 ofu()->CreateDirectory(context.get(), dir, false, false)); 2045 ofu()->CreateDirectory(context.get(), dir, false, false));
2075 2046
2076 bool created = false; 2047 bool created = false;
2077 context.reset(NewContext(NULL)); 2048 context.reset(NewContext(NULL));
2078 EXPECT_EQ(base::PLATFORM_FILE_OK, 2049 EXPECT_EQ(base::File::FILE_OK,
2079 ofu()->EnsureFileExists(context.get(), url1, &created)); 2050 ofu()->EnsureFileExists(context.get(), url1, &created));
2080 EXPECT_TRUE(created); 2051 EXPECT_TRUE(created);
2081 2052
2082 context.reset(NewContext(NULL)); 2053 context.reset(NewContext(NULL));
2083 EXPECT_EQ(base::PLATFORM_FILE_OK, 2054 EXPECT_EQ(base::File::FILE_OK,
2084 ofu()->CreateDirectory(context.get(), url2, false, false)); 2055 ofu()->CreateDirectory(context.get(), url2, false, false));
2085 2056
2086 base::FilePath file_path; 2057 base::FilePath file_path;
2087 context.reset(NewContext(NULL)); 2058 context.reset(NewContext(NULL));
2088 EXPECT_EQ(base::PLATFORM_FILE_OK, 2059 EXPECT_EQ(base::File::FILE_OK,
2089 ofu()->GetLocalFilePath(context.get(), url1, &file_path)); 2060 ofu()->GetLocalFilePath(context.get(), url1, &file_path));
2090 EXPECT_FALSE(file_path.empty()); 2061 EXPECT_FALSE(file_path.empty());
2091 2062
2092 context.reset(NewContext(NULL)); 2063 context.reset(NewContext(NULL));
2093 EXPECT_EQ(base::PLATFORM_FILE_OK, 2064 EXPECT_EQ(base::File::FILE_OK,
2094 ofu()->Touch(context.get(), url1, 2065 ofu()->Touch(context.get(), url1,
2095 base::Time::Now() + base::TimeDelta::FromHours(1), 2066 base::Time::Now() + base::TimeDelta::FromHours(1),
2096 base::Time())); 2067 base::Time()));
2097 2068
2098 context.reset(NewContext(NULL)); 2069 context.reset(NewContext(NULL));
2099 scoped_ptr<fileapi::FileSystemFileUtil::AbstractFileEnumerator> file_enum( 2070 scoped_ptr<fileapi::FileSystemFileUtil::AbstractFileEnumerator> file_enum(
2100 ofu()->CreateFileEnumerator(context.get(), dir, false)); 2071 ofu()->CreateFileEnumerator(context.get(), dir, false));
2101 2072
2102 int count = 0; 2073 int count = 0;
2103 base::FilePath file_path_each; 2074 base::FilePath file_path_each;
2104 while (!(file_path_each = file_enum->Next()).empty()) { 2075 while (!(file_path_each = file_enum->Next()).empty()) {
2105 context.reset(NewContext(NULL)); 2076 context.reset(NewContext(NULL));
2106 base::PlatformFileInfo file_info; 2077 base::File::Info file_info;
2107 base::FilePath file_path; 2078 base::FilePath file_path;
2108 EXPECT_EQ(base::PLATFORM_FILE_OK, 2079 EXPECT_EQ(base::File::FILE_OK,
2109 ofu()->GetFileInfo(context.get(), 2080 ofu()->GetFileInfo(context.get(),
2110 FileSystemURL::CreateForTest( 2081 FileSystemURL::CreateForTest(
2111 dir.origin(), 2082 dir.origin(),
2112 dir.mount_type(), 2083 dir.mount_type(),
2113 file_path_each), 2084 file_path_each),
2114 &file_info, &file_path)); 2085 &file_info, &file_path));
2115 EXPECT_EQ(file_info.is_directory, file_enum->IsDirectory()); 2086 EXPECT_EQ(file_info.is_directory, file_enum->IsDirectory());
2116 EXPECT_EQ(file_info.last_modified, file_enum->LastModifiedTime()); 2087 EXPECT_EQ(file_info.last_modified, file_enum->LastModifiedTime());
2117 EXPECT_EQ(file_info.size, file_enum->Size()); 2088 EXPECT_EQ(file_info.size, file_enum->Size());
2118 ++count; 2089 ++count;
2119 } 2090 }
2120 EXPECT_EQ(2, count); 2091 EXPECT_EQ(2, count);
2121 } 2092 }
2122 2093
2123 // crbug.com/176470 2094 // crbug.com/176470
2124 #if defined(OS_WIN) || defined(OS_ANDROID) 2095 #if defined(OS_WIN) || defined(OS_ANDROID)
2125 #define MAYBE_TestQuotaOnCopyFile DISABLED_TestQuotaOnCopyFile 2096 #define MAYBE_TestQuotaOnCopyFile DISABLED_TestQuotaOnCopyFile
2126 #else 2097 #else
2127 #define MAYBE_TestQuotaOnCopyFile TestQuotaOnCopyFile 2098 #define MAYBE_TestQuotaOnCopyFile TestQuotaOnCopyFile
2128 #endif 2099 #endif
2129 TEST_F(ObfuscatedFileUtilTest, MAYBE_TestQuotaOnCopyFile) { 2100 TEST_F(ObfuscatedFileUtilTest, MAYBE_TestQuotaOnCopyFile) {
2130 FileSystemURL from_file(CreateURLFromUTF8("fromfile")); 2101 FileSystemURL from_file(CreateURLFromUTF8("fromfile"));
2131 FileSystemURL obstacle_file(CreateURLFromUTF8("obstaclefile")); 2102 FileSystemURL obstacle_file(CreateURLFromUTF8("obstaclefile"));
2132 FileSystemURL to_file1(CreateURLFromUTF8("tofile1")); 2103 FileSystemURL to_file1(CreateURLFromUTF8("tofile1"));
2133 FileSystemURL to_file2(CreateURLFromUTF8("tofile2")); 2104 FileSystemURL to_file2(CreateURLFromUTF8("tofile2"));
2134 bool created; 2105 bool created;
2135 2106
2136 int64 expected_total_file_size = 0; 2107 int64 expected_total_file_size = 0;
2137 ASSERT_EQ(base::PLATFORM_FILE_OK, 2108 ASSERT_EQ(base::File::FILE_OK,
2138 ofu()->EnsureFileExists( 2109 ofu()->EnsureFileExists(
2139 AllowUsageIncrease(PathCost(from_file))->context(), 2110 AllowUsageIncrease(PathCost(from_file))->context(),
2140 from_file, &created)); 2111 from_file, &created));
2141 ASSERT_TRUE(created); 2112 ASSERT_TRUE(created);
2142 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize()); 2113 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
2143 2114
2144 ASSERT_EQ(base::PLATFORM_FILE_OK, 2115 ASSERT_EQ(base::File::FILE_OK,
2145 ofu()->EnsureFileExists( 2116 ofu()->EnsureFileExists(
2146 AllowUsageIncrease(PathCost(obstacle_file))->context(), 2117 AllowUsageIncrease(PathCost(obstacle_file))->context(),
2147 obstacle_file, &created)); 2118 obstacle_file, &created));
2148 ASSERT_TRUE(created); 2119 ASSERT_TRUE(created);
2149 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize()); 2120 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
2150 2121
2151 int64 from_file_size = 1020; 2122 int64 from_file_size = 1020;
2152 expected_total_file_size += from_file_size; 2123 expected_total_file_size += from_file_size;
2153 ASSERT_EQ(base::PLATFORM_FILE_OK, 2124 ASSERT_EQ(base::File::FILE_OK,
2154 ofu()->Truncate( 2125 ofu()->Truncate(
2155 AllowUsageIncrease(from_file_size)->context(), 2126 AllowUsageIncrease(from_file_size)->context(),
2156 from_file, from_file_size)); 2127 from_file, from_file_size));
2157 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize()); 2128 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
2158 2129
2159 int64 obstacle_file_size = 1; 2130 int64 obstacle_file_size = 1;
2160 expected_total_file_size += obstacle_file_size; 2131 expected_total_file_size += obstacle_file_size;
2161 ASSERT_EQ(base::PLATFORM_FILE_OK, 2132 ASSERT_EQ(base::File::FILE_OK,
2162 ofu()->Truncate( 2133 ofu()->Truncate(
2163 AllowUsageIncrease(obstacle_file_size)->context(), 2134 AllowUsageIncrease(obstacle_file_size)->context(),
2164 obstacle_file, obstacle_file_size)); 2135 obstacle_file, obstacle_file_size));
2165 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize()); 2136 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
2166 2137
2167 int64 to_file1_size = from_file_size; 2138 int64 to_file1_size = from_file_size;
2168 expected_total_file_size += to_file1_size; 2139 expected_total_file_size += to_file1_size;
2169 ASSERT_EQ(base::PLATFORM_FILE_OK, 2140 ASSERT_EQ(base::File::FILE_OK,
2170 ofu()->CopyOrMoveFile( 2141 ofu()->CopyOrMoveFile(
2171 AllowUsageIncrease( 2142 AllowUsageIncrease(
2172 PathCost(to_file1) + to_file1_size)->context(), 2143 PathCost(to_file1) + to_file1_size)->context(),
2173 from_file, to_file1, 2144 from_file, to_file1,
2174 FileSystemOperation::OPTION_NONE, 2145 FileSystemOperation::OPTION_NONE,
2175 true /* copy */)); 2146 true /* copy */));
2176 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize()); 2147 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
2177 2148
2178 ASSERT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, 2149 ASSERT_EQ(base::File::FILE_ERROR_NO_SPACE,
2179 ofu()->CopyOrMoveFile( 2150 ofu()->CopyOrMoveFile(
2180 DisallowUsageIncrease( 2151 DisallowUsageIncrease(
2181 PathCost(to_file2) + from_file_size)->context(), 2152 PathCost(to_file2) + from_file_size)->context(),
2182 from_file, to_file2, FileSystemOperation::OPTION_NONE, 2153 from_file, to_file2, FileSystemOperation::OPTION_NONE,
2183 true /* copy */)); 2154 true /* copy */));
2184 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize()); 2155 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
2185 2156
2186 int64 old_obstacle_file_size = obstacle_file_size; 2157 int64 old_obstacle_file_size = obstacle_file_size;
2187 obstacle_file_size = from_file_size; 2158 obstacle_file_size = from_file_size;
2188 expected_total_file_size += obstacle_file_size - old_obstacle_file_size; 2159 expected_total_file_size += obstacle_file_size - old_obstacle_file_size;
2189 ASSERT_EQ(base::PLATFORM_FILE_OK, 2160 ASSERT_EQ(base::File::FILE_OK,
2190 ofu()->CopyOrMoveFile( 2161 ofu()->CopyOrMoveFile(
2191 AllowUsageIncrease( 2162 AllowUsageIncrease(
2192 obstacle_file_size - old_obstacle_file_size)->context(), 2163 obstacle_file_size - old_obstacle_file_size)->context(),
2193 from_file, obstacle_file, 2164 from_file, obstacle_file,
2194 FileSystemOperation::OPTION_NONE, 2165 FileSystemOperation::OPTION_NONE,
2195 true /* copy */)); 2166 true /* copy */));
2196 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize()); 2167 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
2197 2168
2198 int64 old_from_file_size = from_file_size; 2169 int64 old_from_file_size = from_file_size;
2199 from_file_size = old_from_file_size - 1; 2170 from_file_size = old_from_file_size - 1;
2200 expected_total_file_size += from_file_size - old_from_file_size; 2171 expected_total_file_size += from_file_size - old_from_file_size;
2201 ASSERT_EQ(base::PLATFORM_FILE_OK, 2172 ASSERT_EQ(base::File::FILE_OK,
2202 ofu()->Truncate( 2173 ofu()->Truncate(
2203 AllowUsageIncrease( 2174 AllowUsageIncrease(
2204 from_file_size - old_from_file_size)->context(), 2175 from_file_size - old_from_file_size)->context(),
2205 from_file, from_file_size)); 2176 from_file, from_file_size));
2206 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize()); 2177 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
2207 2178
2208 // quota exceeded 2179 // quota exceeded
2209 { 2180 {
2210 old_obstacle_file_size = obstacle_file_size; 2181 old_obstacle_file_size = obstacle_file_size;
2211 obstacle_file_size = from_file_size; 2182 obstacle_file_size = from_file_size;
2212 expected_total_file_size += obstacle_file_size - old_obstacle_file_size; 2183 expected_total_file_size += obstacle_file_size - old_obstacle_file_size;
2213 scoped_ptr<UsageVerifyHelper> helper = AllowUsageIncrease( 2184 scoped_ptr<UsageVerifyHelper> helper = AllowUsageIncrease(
2214 obstacle_file_size - old_obstacle_file_size); 2185 obstacle_file_size - old_obstacle_file_size);
2215 helper->context()->set_allowed_bytes_growth( 2186 helper->context()->set_allowed_bytes_growth(
2216 helper->context()->allowed_bytes_growth() - 1); 2187 helper->context()->allowed_bytes_growth() - 1);
2217 ASSERT_EQ(base::PLATFORM_FILE_OK, 2188 ASSERT_EQ(base::File::FILE_OK,
2218 ofu()->CopyOrMoveFile( 2189 ofu()->CopyOrMoveFile(
2219 helper->context(), 2190 helper->context(),
2220 from_file, obstacle_file, 2191 from_file, obstacle_file,
2221 FileSystemOperation::OPTION_NONE, 2192 FileSystemOperation::OPTION_NONE,
2222 true /* copy */)); 2193 true /* copy */));
2223 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize()); 2194 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
2224 } 2195 }
2225 } 2196 }
2226 2197
2227 TEST_F(ObfuscatedFileUtilTest, TestQuotaOnMoveFile) { 2198 TEST_F(ObfuscatedFileUtilTest, TestQuotaOnMoveFile) {
2228 FileSystemURL from_file(CreateURLFromUTF8("fromfile")); 2199 FileSystemURL from_file(CreateURLFromUTF8("fromfile"));
2229 FileSystemURL obstacle_file(CreateURLFromUTF8("obstaclefile")); 2200 FileSystemURL obstacle_file(CreateURLFromUTF8("obstaclefile"));
2230 FileSystemURL to_file(CreateURLFromUTF8("tofile")); 2201 FileSystemURL to_file(CreateURLFromUTF8("tofile"));
2231 bool created; 2202 bool created;
2232 2203
2233 int64 expected_total_file_size = 0; 2204 int64 expected_total_file_size = 0;
2234 ASSERT_EQ(base::PLATFORM_FILE_OK, 2205 ASSERT_EQ(base::File::FILE_OK,
2235 ofu()->EnsureFileExists( 2206 ofu()->EnsureFileExists(
2236 AllowUsageIncrease(PathCost(from_file))->context(), 2207 AllowUsageIncrease(PathCost(from_file))->context(),
2237 from_file, &created)); 2208 from_file, &created));
2238 ASSERT_TRUE(created); 2209 ASSERT_TRUE(created);
2239 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize()); 2210 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
2240 2211
2241 int64 from_file_size = 1020; 2212 int64 from_file_size = 1020;
2242 expected_total_file_size += from_file_size; 2213 expected_total_file_size += from_file_size;
2243 ASSERT_EQ(base::PLATFORM_FILE_OK, 2214 ASSERT_EQ(base::File::FILE_OK,
2244 ofu()->Truncate( 2215 ofu()->Truncate(
2245 AllowUsageIncrease(from_file_size)->context(), 2216 AllowUsageIncrease(from_file_size)->context(),
2246 from_file, from_file_size)); 2217 from_file, from_file_size));
2247 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize()); 2218 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
2248 2219
2249 int64 to_file_size ALLOW_UNUSED = from_file_size; 2220 int64 to_file_size ALLOW_UNUSED = from_file_size;
2250 from_file_size = 0; 2221 from_file_size = 0;
2251 ASSERT_EQ(base::PLATFORM_FILE_OK, 2222 ASSERT_EQ(base::File::FILE_OK,
2252 ofu()->CopyOrMoveFile( 2223 ofu()->CopyOrMoveFile(
2253 AllowUsageIncrease(-PathCost(from_file) + 2224 AllowUsageIncrease(-PathCost(from_file) +
2254 PathCost(to_file))->context(), 2225 PathCost(to_file))->context(),
2255 from_file, to_file, 2226 from_file, to_file,
2256 FileSystemOperation::OPTION_NONE, 2227 FileSystemOperation::OPTION_NONE,
2257 false /* move */)); 2228 false /* move */));
2258 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize()); 2229 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
2259 2230
2260 ASSERT_EQ(base::PLATFORM_FILE_OK, 2231 ASSERT_EQ(base::File::FILE_OK,
2261 ofu()->EnsureFileExists( 2232 ofu()->EnsureFileExists(
2262 AllowUsageIncrease(PathCost(from_file))->context(), 2233 AllowUsageIncrease(PathCost(from_file))->context(),
2263 from_file, &created)); 2234 from_file, &created));
2264 ASSERT_TRUE(created); 2235 ASSERT_TRUE(created);
2265 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize()); 2236 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
2266 2237
2267 ASSERT_EQ(base::PLATFORM_FILE_OK, 2238 ASSERT_EQ(base::File::FILE_OK,
2268 ofu()->EnsureFileExists( 2239 ofu()->EnsureFileExists(
2269 AllowUsageIncrease(PathCost(obstacle_file))->context(), 2240 AllowUsageIncrease(PathCost(obstacle_file))->context(),
2270 obstacle_file, &created)); 2241 obstacle_file, &created));
2271 ASSERT_TRUE(created); 2242 ASSERT_TRUE(created);
2272 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize()); 2243 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
2273 2244
2274 from_file_size = 1020; 2245 from_file_size = 1020;
2275 expected_total_file_size += from_file_size; 2246 expected_total_file_size += from_file_size;
2276 ASSERT_EQ(base::PLATFORM_FILE_OK, 2247 ASSERT_EQ(base::File::FILE_OK,
2277 ofu()->Truncate( 2248 ofu()->Truncate(
2278 AllowUsageIncrease(from_file_size)->context(), 2249 AllowUsageIncrease(from_file_size)->context(),
2279 from_file, from_file_size)); 2250 from_file, from_file_size));
2280 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize()); 2251 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
2281 2252
2282 int64 obstacle_file_size = 1; 2253 int64 obstacle_file_size = 1;
2283 expected_total_file_size += obstacle_file_size; 2254 expected_total_file_size += obstacle_file_size;
2284 ASSERT_EQ(base::PLATFORM_FILE_OK, 2255 ASSERT_EQ(base::File::FILE_OK,
2285 ofu()->Truncate( 2256 ofu()->Truncate(
2286 AllowUsageIncrease(1)->context(), 2257 AllowUsageIncrease(1)->context(),
2287 obstacle_file, obstacle_file_size)); 2258 obstacle_file, obstacle_file_size));
2288 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize()); 2259 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
2289 2260
2290 int64 old_obstacle_file_size = obstacle_file_size; 2261 int64 old_obstacle_file_size = obstacle_file_size;
2291 obstacle_file_size = from_file_size; 2262 obstacle_file_size = from_file_size;
2292 from_file_size = 0; 2263 from_file_size = 0;
2293 expected_total_file_size -= old_obstacle_file_size; 2264 expected_total_file_size -= old_obstacle_file_size;
2294 ASSERT_EQ(base::PLATFORM_FILE_OK, 2265 ASSERT_EQ(base::File::FILE_OK,
2295 ofu()->CopyOrMoveFile( 2266 ofu()->CopyOrMoveFile(
2296 AllowUsageIncrease( 2267 AllowUsageIncrease(
2297 -old_obstacle_file_size - PathCost(from_file))->context(), 2268 -old_obstacle_file_size - PathCost(from_file))->context(),
2298 from_file, obstacle_file, 2269 from_file, obstacle_file,
2299 FileSystemOperation::OPTION_NONE, 2270 FileSystemOperation::OPTION_NONE,
2300 false /* move */)); 2271 false /* move */));
2301 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize()); 2272 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
2302 2273
2303 ASSERT_EQ(base::PLATFORM_FILE_OK, 2274 ASSERT_EQ(base::File::FILE_OK,
2304 ofu()->EnsureFileExists( 2275 ofu()->EnsureFileExists(
2305 AllowUsageIncrease(PathCost(from_file))->context(), 2276 AllowUsageIncrease(PathCost(from_file))->context(),
2306 from_file, &created)); 2277 from_file, &created));
2307 ASSERT_TRUE(created); 2278 ASSERT_TRUE(created);
2308 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize()); 2279 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
2309 2280
2310 from_file_size = 10; 2281 from_file_size = 10;
2311 expected_total_file_size += from_file_size; 2282 expected_total_file_size += from_file_size;
2312 ASSERT_EQ(base::PLATFORM_FILE_OK, 2283 ASSERT_EQ(base::File::FILE_OK,
2313 ofu()->Truncate( 2284 ofu()->Truncate(
2314 AllowUsageIncrease(from_file_size)->context(), 2285 AllowUsageIncrease(from_file_size)->context(),
2315 from_file, from_file_size)); 2286 from_file, from_file_size));
2316 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize()); 2287 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
2317 2288
2318 // quota exceeded even after operation 2289 // quota exceeded even after operation
2319 old_obstacle_file_size = obstacle_file_size; 2290 old_obstacle_file_size = obstacle_file_size;
2320 obstacle_file_size = from_file_size; 2291 obstacle_file_size = from_file_size;
2321 from_file_size = 0; 2292 from_file_size = 0;
2322 expected_total_file_size -= old_obstacle_file_size; 2293 expected_total_file_size -= old_obstacle_file_size;
2323 scoped_ptr<FileSystemOperationContext> context = 2294 scoped_ptr<FileSystemOperationContext> context =
2324 LimitedContext(-old_obstacle_file_size - PathCost(from_file) - 1); 2295 LimitedContext(-old_obstacle_file_size - PathCost(from_file) - 1);
2325 ASSERT_EQ(base::PLATFORM_FILE_OK, 2296 ASSERT_EQ(base::File::FILE_OK,
2326 ofu()->CopyOrMoveFile( 2297 ofu()->CopyOrMoveFile(
2327 context.get(), from_file, obstacle_file, 2298 context.get(), from_file, obstacle_file,
2328 FileSystemOperation::OPTION_NONE, 2299 FileSystemOperation::OPTION_NONE,
2329 false /* move */)); 2300 false /* move */));
2330 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize()); 2301 ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
2331 context.reset(); 2302 context.reset();
2332 } 2303 }
2333 2304
2334 TEST_F(ObfuscatedFileUtilTest, TestQuotaOnRemove) { 2305 TEST_F(ObfuscatedFileUtilTest, TestQuotaOnRemove) {
2335 FileSystemURL dir(CreateURLFromUTF8("dir")); 2306 FileSystemURL dir(CreateURLFromUTF8("dir"));
2336 FileSystemURL file(CreateURLFromUTF8("file")); 2307 FileSystemURL file(CreateURLFromUTF8("file"));
2337 FileSystemURL dfile1(CreateURLFromUTF8("dir/dfile1")); 2308 FileSystemURL dfile1(CreateURLFromUTF8("dir/dfile1"));
2338 FileSystemURL dfile2(CreateURLFromUTF8("dir/dfile2")); 2309 FileSystemURL dfile2(CreateURLFromUTF8("dir/dfile2"));
2339 bool created; 2310 bool created;
2340 2311
2341 ASSERT_EQ(base::PLATFORM_FILE_OK, 2312 ASSERT_EQ(base::File::FILE_OK,
2342 ofu()->EnsureFileExists( 2313 ofu()->EnsureFileExists(
2343 AllowUsageIncrease(PathCost(file))->context(), 2314 AllowUsageIncrease(PathCost(file))->context(),
2344 file, &created)); 2315 file, &created));
2345 ASSERT_TRUE(created); 2316 ASSERT_TRUE(created);
2346 ASSERT_EQ(0, ComputeTotalFileSize()); 2317 ASSERT_EQ(0, ComputeTotalFileSize());
2347 2318
2348 ASSERT_EQ(base::PLATFORM_FILE_OK, 2319 ASSERT_EQ(base::File::FILE_OK,
2349 ofu()->CreateDirectory( 2320 ofu()->CreateDirectory(
2350 AllowUsageIncrease(PathCost(dir))->context(), 2321 AllowUsageIncrease(PathCost(dir))->context(),
2351 dir, false, false)); 2322 dir, false, false));
2352 ASSERT_EQ(0, ComputeTotalFileSize()); 2323 ASSERT_EQ(0, ComputeTotalFileSize());
2353 2324
2354 ASSERT_EQ(base::PLATFORM_FILE_OK, 2325 ASSERT_EQ(base::File::FILE_OK,
2355 ofu()->EnsureFileExists( 2326 ofu()->EnsureFileExists(
2356 AllowUsageIncrease(PathCost(dfile1))->context(), 2327 AllowUsageIncrease(PathCost(dfile1))->context(),
2357 dfile1, &created)); 2328 dfile1, &created));
2358 ASSERT_TRUE(created); 2329 ASSERT_TRUE(created);
2359 ASSERT_EQ(0, ComputeTotalFileSize()); 2330 ASSERT_EQ(0, ComputeTotalFileSize());
2360 2331
2361 ASSERT_EQ(base::PLATFORM_FILE_OK, 2332 ASSERT_EQ(base::File::FILE_OK,
2362 ofu()->EnsureFileExists( 2333 ofu()->EnsureFileExists(
2363 AllowUsageIncrease(PathCost(dfile2))->context(), 2334 AllowUsageIncrease(PathCost(dfile2))->context(),
2364 dfile2, &created)); 2335 dfile2, &created));
2365 ASSERT_TRUE(created); 2336 ASSERT_TRUE(created);
2366 ASSERT_EQ(0, ComputeTotalFileSize()); 2337 ASSERT_EQ(0, ComputeTotalFileSize());
2367 2338
2368 ASSERT_EQ(base::PLATFORM_FILE_OK, 2339 ASSERT_EQ(base::File::FILE_OK,
2369 ofu()->Truncate( 2340 ofu()->Truncate(
2370 AllowUsageIncrease(340)->context(), 2341 AllowUsageIncrease(340)->context(),
2371 file, 340)); 2342 file, 340));
2372 ASSERT_EQ(340, ComputeTotalFileSize()); 2343 ASSERT_EQ(340, ComputeTotalFileSize());
2373 2344
2374 ASSERT_EQ(base::PLATFORM_FILE_OK, 2345 ASSERT_EQ(base::File::FILE_OK,
2375 ofu()->Truncate( 2346 ofu()->Truncate(
2376 AllowUsageIncrease(1020)->context(), 2347 AllowUsageIncrease(1020)->context(),
2377 dfile1, 1020)); 2348 dfile1, 1020));
2378 ASSERT_EQ(1360, ComputeTotalFileSize()); 2349 ASSERT_EQ(1360, ComputeTotalFileSize());
2379 2350
2380 ASSERT_EQ(base::PLATFORM_FILE_OK, 2351 ASSERT_EQ(base::File::FILE_OK,
2381 ofu()->Truncate( 2352 ofu()->Truncate(
2382 AllowUsageIncrease(120)->context(), 2353 AllowUsageIncrease(120)->context(),
2383 dfile2, 120)); 2354 dfile2, 120));
2384 ASSERT_EQ(1480, ComputeTotalFileSize()); 2355 ASSERT_EQ(1480, ComputeTotalFileSize());
2385 2356
2386 ASSERT_EQ(base::PLATFORM_FILE_OK, 2357 ASSERT_EQ(base::File::FILE_OK,
2387 ofu()->DeleteFile( 2358 ofu()->DeleteFile(
2388 AllowUsageIncrease(-PathCost(file) - 340)->context(), 2359 AllowUsageIncrease(-PathCost(file) - 340)->context(),
2389 file)); 2360 file));
2390 ASSERT_EQ(1140, ComputeTotalFileSize()); 2361 ASSERT_EQ(1140, ComputeTotalFileSize());
2391 2362
2392 ASSERT_EQ(base::PLATFORM_FILE_OK, 2363 ASSERT_EQ(base::File::FILE_OK,
2393 AsyncFileTestHelper::Remove( 2364 AsyncFileTestHelper::Remove(
2394 file_system_context(), dir, true /* recursive */)); 2365 file_system_context(), dir, true /* recursive */));
2395 ASSERT_EQ(0, ComputeTotalFileSize()); 2366 ASSERT_EQ(0, ComputeTotalFileSize());
2396 } 2367 }
2397 2368
2398 TEST_F(ObfuscatedFileUtilTest, TestQuotaOnOpen) { 2369 TEST_F(ObfuscatedFileUtilTest, TestQuotaOnOpen) {
2399 FileSystemURL file(CreateURLFromUTF8("file")); 2370 FileSystemURL file(CreateURLFromUTF8("file"));
2400 base::PlatformFile file_handle; 2371 base::PlatformFile file_handle;
2401 bool created; 2372 bool created;
2402 2373
2403 // Creating a file. 2374 // Creating a file.
2404 ASSERT_EQ(base::PLATFORM_FILE_OK, 2375 ASSERT_EQ(base::File::FILE_OK,
2405 ofu()->EnsureFileExists( 2376 ofu()->EnsureFileExists(
2406 AllowUsageIncrease(PathCost(file))->context(), 2377 AllowUsageIncrease(PathCost(file))->context(),
2407 file, &created)); 2378 file, &created));
2408 ASSERT_TRUE(created); 2379 ASSERT_TRUE(created);
2409 ASSERT_EQ(0, ComputeTotalFileSize()); 2380 ASSERT_EQ(0, ComputeTotalFileSize());
2410 2381
2411 // Opening it, which shouldn't change the usage. 2382 // Opening it, which shouldn't change the usage.
2412 ASSERT_EQ(base::PLATFORM_FILE_OK, 2383 ASSERT_EQ(base::File::FILE_OK,
2413 ofu()->CreateOrOpen( 2384 ofu()->CreateOrOpen(
2414 AllowUsageIncrease(0)->context(), file, 2385 AllowUsageIncrease(0)->context(), file,
2415 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE, 2386 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE,
2416 &file_handle, &created)); 2387 &file_handle, &created));
2417 ASSERT_EQ(0, ComputeTotalFileSize()); 2388 ASSERT_EQ(0, ComputeTotalFileSize());
2418 EXPECT_TRUE(base::ClosePlatformFile(file_handle)); 2389 EXPECT_TRUE(base::ClosePlatformFile(file_handle));
2419 2390
2420 const int length = 33; 2391 const int length = 33;
2421 ASSERT_EQ(base::PLATFORM_FILE_OK, 2392 ASSERT_EQ(base::File::FILE_OK,
2422 ofu()->Truncate( 2393 ofu()->Truncate(
2423 AllowUsageIncrease(length)->context(), file, length)); 2394 AllowUsageIncrease(length)->context(), file, length));
2424 ASSERT_EQ(length, ComputeTotalFileSize()); 2395 ASSERT_EQ(length, ComputeTotalFileSize());
2425 2396
2426 // Opening it with CREATE_ALWAYS flag, which should truncate the file size. 2397 // Opening it with CREATE_ALWAYS flag, which should truncate the file size.
2427 ASSERT_EQ(base::PLATFORM_FILE_OK, 2398 ASSERT_EQ(base::File::FILE_OK,
2428 ofu()->CreateOrOpen( 2399 ofu()->CreateOrOpen(
2429 AllowUsageIncrease(-length)->context(), file, 2400 AllowUsageIncrease(-length)->context(), file,
2430 base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_WRITE, 2401 base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_WRITE,
2431 &file_handle, &created)); 2402 &file_handle, &created));
2432 ASSERT_EQ(0, ComputeTotalFileSize()); 2403 ASSERT_EQ(0, ComputeTotalFileSize());
2433 EXPECT_TRUE(base::ClosePlatformFile(file_handle)); 2404 EXPECT_TRUE(base::ClosePlatformFile(file_handle));
2434 2405
2435 // Extending the file again. 2406 // Extending the file again.
2436 ASSERT_EQ(base::PLATFORM_FILE_OK, 2407 ASSERT_EQ(base::File::FILE_OK,
2437 ofu()->Truncate( 2408 ofu()->Truncate(
2438 AllowUsageIncrease(length)->context(), file, length)); 2409 AllowUsageIncrease(length)->context(), file, length));
2439 ASSERT_EQ(length, ComputeTotalFileSize()); 2410 ASSERT_EQ(length, ComputeTotalFileSize());
2440 2411
2441 // Opening it with TRUNCATED flag, which should truncate the file size. 2412 // Opening it with TRUNCATED flag, which should truncate the file size.
2442 ASSERT_EQ(base::PLATFORM_FILE_OK, 2413 ASSERT_EQ(base::File::FILE_OK,
2443 ofu()->CreateOrOpen( 2414 ofu()->CreateOrOpen(
2444 AllowUsageIncrease(-length)->context(), file, 2415 AllowUsageIncrease(-length)->context(), file,
2445 base::PLATFORM_FILE_OPEN_TRUNCATED | base::PLATFORM_FILE_WRITE, 2416 base::PLATFORM_FILE_OPEN_TRUNCATED | base::PLATFORM_FILE_WRITE,
2446 &file_handle, &created)); 2417 &file_handle, &created));
2447 ASSERT_EQ(0, ComputeTotalFileSize()); 2418 ASSERT_EQ(0, ComputeTotalFileSize());
2448 EXPECT_TRUE(base::ClosePlatformFile(file_handle)); 2419 EXPECT_TRUE(base::ClosePlatformFile(file_handle));
2449 } 2420 }
2450 2421
2451 TEST_F(ObfuscatedFileUtilTest, MaybeDropDatabasesAliveCase) { 2422 TEST_F(ObfuscatedFileUtilTest, MaybeDropDatabasesAliveCase) {
2452 MaybeDropDatabasesAliveCaseTestBody(); 2423 MaybeDropDatabasesAliveCaseTestBody();
(...skipping 13 matching lines...) Expand all
2466 2437
2467 TEST_F(ObfuscatedFileUtilTest, MigrationBackFromIsolated) { 2438 TEST_F(ObfuscatedFileUtilTest, MigrationBackFromIsolated) {
2468 MigrationBackFromIsolatedTestBody(); 2439 MigrationBackFromIsolatedTestBody();
2469 } 2440 }
2470 2441
2471 TEST_F(ObfuscatedFileUtilTest, OpenPathInNonDirectory) { 2442 TEST_F(ObfuscatedFileUtilTest, OpenPathInNonDirectory) {
2472 FileSystemURL file(CreateURLFromUTF8("file")); 2443 FileSystemURL file(CreateURLFromUTF8("file"));
2473 FileSystemURL path_in_file(CreateURLFromUTF8("file/file")); 2444 FileSystemURL path_in_file(CreateURLFromUTF8("file/file"));
2474 bool created; 2445 bool created;
2475 2446
2476 ASSERT_EQ(base::PLATFORM_FILE_OK, 2447 ASSERT_EQ(base::File::FILE_OK,
2477 ofu()->EnsureFileExists(UnlimitedContext().get(), file, &created)); 2448 ofu()->EnsureFileExists(UnlimitedContext().get(), file, &created));
2478 ASSERT_TRUE(created); 2449 ASSERT_TRUE(created);
2479 2450
2480 created = false; 2451 created = false;
2481 base::PlatformFile file_handle = base::kInvalidPlatformFileValue; 2452 base::PlatformFile file_handle = base::kInvalidPlatformFileValue;
2482 int file_flags = base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE; 2453 int file_flags = base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE;
2483 ASSERT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY, 2454 ASSERT_EQ(base::File::FILE_ERROR_NOT_A_DIRECTORY,
2484 ofu()->CreateOrOpen(UnlimitedContext().get(), 2455 ofu()->CreateOrOpen(UnlimitedContext().get(),
2485 path_in_file, 2456 path_in_file,
2486 file_flags, 2457 file_flags,
2487 &file_handle, 2458 &file_handle,
2488 &created)); 2459 &created));
2489 ASSERT_FALSE(created); 2460 ASSERT_FALSE(created);
2490 ASSERT_EQ(base::kInvalidPlatformFileValue, file_handle); 2461 ASSERT_EQ(base::kInvalidPlatformFileValue, file_handle);
2491 2462
2492 ASSERT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY, 2463 ASSERT_EQ(base::File::FILE_ERROR_NOT_A_DIRECTORY,
2493 ofu()->CreateDirectory(UnlimitedContext().get(), 2464 ofu()->CreateDirectory(UnlimitedContext().get(),
2494 path_in_file, 2465 path_in_file,
2495 false /* exclusive */, 2466 false /* exclusive */,
2496 false /* recursive */)); 2467 false /* recursive */));
2497 } 2468 }
2498 2469
2499 TEST_F(ObfuscatedFileUtilTest, CreateDirectory_NotADirectoryInRecursive) { 2470 TEST_F(ObfuscatedFileUtilTest, CreateDirectory_NotADirectoryInRecursive) {
2500 FileSystemURL file(CreateURLFromUTF8("file")); 2471 FileSystemURL file(CreateURLFromUTF8("file"));
2501 FileSystemURL path_in_file(CreateURLFromUTF8("file/child")); 2472 FileSystemURL path_in_file(CreateURLFromUTF8("file/child"));
2502 FileSystemURL path_in_file_in_file( 2473 FileSystemURL path_in_file_in_file(
2503 CreateURLFromUTF8("file/child/grandchild")); 2474 CreateURLFromUTF8("file/child/grandchild"));
2504 bool created; 2475 bool created;
2505 2476
2506 ASSERT_EQ(base::PLATFORM_FILE_OK, 2477 ASSERT_EQ(base::File::FILE_OK,
2507 ofu()->EnsureFileExists(UnlimitedContext().get(), file, &created)); 2478 ofu()->EnsureFileExists(UnlimitedContext().get(), file, &created));
2508 ASSERT_TRUE(created); 2479 ASSERT_TRUE(created);
2509 2480
2510 ASSERT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY, 2481 ASSERT_EQ(base::File::FILE_ERROR_NOT_A_DIRECTORY,
2511 ofu()->CreateDirectory(UnlimitedContext().get(), 2482 ofu()->CreateDirectory(UnlimitedContext().get(),
2512 path_in_file, 2483 path_in_file,
2513 false /* exclusive */, 2484 false /* exclusive */,
2514 true /* recursive */)); 2485 true /* recursive */));
2515 ASSERT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY, 2486 ASSERT_EQ(base::File::FILE_ERROR_NOT_A_DIRECTORY,
2516 ofu()->CreateDirectory(UnlimitedContext().get(), 2487 ofu()->CreateDirectory(UnlimitedContext().get(),
2517 path_in_file_in_file, 2488 path_in_file_in_file,
2518 false /* exclusive */, 2489 false /* exclusive */,
2519 true /* recursive */)); 2490 true /* recursive */));
2520 } 2491 }
2521 2492
2522 } // namespace content 2493 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698