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

Side by Side Diff: chrome/browser/chromeos/drive/file_system_unittest.cc

Issue 881403003: Rename gdata_errorcode.h to drive_api_error_codes.h (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix typos in BUILD.gn Created 5 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/drive/file_system.h" 5 #include "chrome/browser/chromeos/drive/file_system.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 dest_file_path, 384 dest_file_path,
385 false, // preserve_last_modified, 385 false, // preserve_last_modified,
386 google_apis::test_util::CreateCopyResultCallback(&error)); 386 google_apis::test_util::CreateCopyResultCallback(&error));
387 content::RunAllBlockingPoolTasksUntilIdle(); 387 content::RunAllBlockingPoolTasksUntilIdle();
388 EXPECT_EQ(FILE_ERROR_OK, error); 388 EXPECT_EQ(FILE_ERROR_OK, error);
389 389
390 // Entry is added on the server. 390 // Entry is added on the server.
391 scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(dest_file_path); 391 scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(dest_file_path);
392 ASSERT_TRUE(entry); 392 ASSERT_TRUE(entry);
393 393
394 google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR; 394 google_apis::DriveApiErrorCode status = google_apis::DRIVE_OTHER_ERROR;
395 scoped_ptr<google_apis::FileResource> server_entry; 395 scoped_ptr<google_apis::FileResource> server_entry;
396 fake_drive_service_->GetFileResource( 396 fake_drive_service_->GetFileResource(
397 entry->resource_id(), 397 entry->resource_id(),
398 google_apis::test_util::CreateCopyResultCallback(&status, &server_entry)); 398 google_apis::test_util::CreateCopyResultCallback(&status, &server_entry));
399 content::RunAllBlockingPoolTasksUntilIdle(); 399 content::RunAllBlockingPoolTasksUntilIdle();
400 EXPECT_EQ(google_apis::HTTP_SUCCESS, status); 400 EXPECT_EQ(google_apis::HTTP_SUCCESS, status);
401 ASSERT_TRUE(server_entry); 401 ASSERT_TRUE(server_entry);
402 EXPECT_EQ(entry->title(), server_entry->title()); 402 EXPECT_EQ(entry->title(), server_entry->title());
403 EXPECT_FALSE(server_entry->IsDirectory()); 403 EXPECT_FALSE(server_entry->IsDirectory());
404 } 404 }
(...skipping 12 matching lines...) Expand all
417 file_system_->Move(src_file_path, 417 file_system_->Move(src_file_path,
418 dest_file_path, 418 dest_file_path,
419 google_apis::test_util::CreateCopyResultCallback(&error)); 419 google_apis::test_util::CreateCopyResultCallback(&error));
420 content::RunAllBlockingPoolTasksUntilIdle(); 420 content::RunAllBlockingPoolTasksUntilIdle();
421 EXPECT_EQ(FILE_ERROR_OK, error); 421 EXPECT_EQ(FILE_ERROR_OK, error);
422 422
423 // Entry is moved on the server. 423 // Entry is moved on the server.
424 scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(dest_file_path); 424 scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(dest_file_path);
425 ASSERT_TRUE(entry); 425 ASSERT_TRUE(entry);
426 426
427 google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR; 427 google_apis::DriveApiErrorCode status = google_apis::DRIVE_OTHER_ERROR;
428 scoped_ptr<google_apis::FileResource> server_entry; 428 scoped_ptr<google_apis::FileResource> server_entry;
429 fake_drive_service_->GetFileResource( 429 fake_drive_service_->GetFileResource(
430 entry->resource_id(), 430 entry->resource_id(),
431 google_apis::test_util::CreateCopyResultCallback(&status, &server_entry)); 431 google_apis::test_util::CreateCopyResultCallback(&status, &server_entry));
432 content::RunAllBlockingPoolTasksUntilIdle(); 432 content::RunAllBlockingPoolTasksUntilIdle();
433 EXPECT_EQ(google_apis::HTTP_SUCCESS, status); 433 EXPECT_EQ(google_apis::HTTP_SUCCESS, status);
434 ASSERT_TRUE(server_entry); 434 ASSERT_TRUE(server_entry);
435 EXPECT_EQ(entry->title(), server_entry->title()); 435 EXPECT_EQ(entry->title(), server_entry->title());
436 436
437 ASSERT_FALSE(server_entry->parents().empty()); 437 ASSERT_FALSE(server_entry->parents().empty());
438 EXPECT_EQ(parent->resource_id(), server_entry->parents()[0].file_id()); 438 EXPECT_EQ(parent->resource_id(), server_entry->parents()[0].file_id());
439 } 439 }
440 440
441 TEST_F(FileSystemTest, Remove) { 441 TEST_F(FileSystemTest, Remove) {
442 base::FilePath file_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); 442 base::FilePath file_path(FILE_PATH_LITERAL("drive/root/File 1.txt"));
443 scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(file_path); 443 scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(file_path);
444 ASSERT_TRUE(entry); 444 ASSERT_TRUE(entry);
445 445
446 FileError error = FILE_ERROR_FAILED; 446 FileError error = FILE_ERROR_FAILED;
447 file_system_->Remove( 447 file_system_->Remove(
448 file_path, 448 file_path,
449 false, // is_resursive 449 false, // is_resursive
450 google_apis::test_util::CreateCopyResultCallback(&error)); 450 google_apis::test_util::CreateCopyResultCallback(&error));
451 content::RunAllBlockingPoolTasksUntilIdle(); 451 content::RunAllBlockingPoolTasksUntilIdle();
452 EXPECT_EQ(FILE_ERROR_OK, error); 452 EXPECT_EQ(FILE_ERROR_OK, error);
453 453
454 // Entry is removed on the server. 454 // Entry is removed on the server.
455 google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR; 455 google_apis::DriveApiErrorCode status = google_apis::DRIVE_OTHER_ERROR;
456 scoped_ptr<google_apis::FileResource> server_entry; 456 scoped_ptr<google_apis::FileResource> server_entry;
457 fake_drive_service_->GetFileResource( 457 fake_drive_service_->GetFileResource(
458 entry->resource_id(), 458 entry->resource_id(),
459 google_apis::test_util::CreateCopyResultCallback(&status, &server_entry)); 459 google_apis::test_util::CreateCopyResultCallback(&status, &server_entry));
460 content::RunAllBlockingPoolTasksUntilIdle(); 460 content::RunAllBlockingPoolTasksUntilIdle();
461 EXPECT_EQ(google_apis::HTTP_SUCCESS, status); 461 EXPECT_EQ(google_apis::HTTP_SUCCESS, status);
462 ASSERT_TRUE(server_entry); 462 ASSERT_TRUE(server_entry);
463 EXPECT_TRUE(server_entry->labels().is_trashed()); 463 EXPECT_TRUE(server_entry->labels().is_trashed());
464 } 464 }
465 465
466 TEST_F(FileSystemTest, CreateDirectory) { 466 TEST_F(FileSystemTest, CreateDirectory) {
467 base::FilePath directory_path(FILE_PATH_LITERAL("drive/root/New Directory")); 467 base::FilePath directory_path(FILE_PATH_LITERAL("drive/root/New Directory"));
468 EXPECT_FALSE(GetResourceEntrySync(directory_path)); 468 EXPECT_FALSE(GetResourceEntrySync(directory_path));
469 469
470 FileError error = FILE_ERROR_FAILED; 470 FileError error = FILE_ERROR_FAILED;
471 file_system_->CreateDirectory( 471 file_system_->CreateDirectory(
472 directory_path, 472 directory_path,
473 true, // is_exclusive 473 true, // is_exclusive
474 false, // is_recursive 474 false, // is_recursive
475 google_apis::test_util::CreateCopyResultCallback(&error)); 475 google_apis::test_util::CreateCopyResultCallback(&error));
476 content::RunAllBlockingPoolTasksUntilIdle(); 476 content::RunAllBlockingPoolTasksUntilIdle();
477 EXPECT_EQ(FILE_ERROR_OK, error); 477 EXPECT_EQ(FILE_ERROR_OK, error);
478 478
479 // Directory is created on the server. 479 // Directory is created on the server.
480 scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(directory_path); 480 scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(directory_path);
481 ASSERT_TRUE(entry); 481 ASSERT_TRUE(entry);
482 482
483 google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR; 483 google_apis::DriveApiErrorCode status = google_apis::DRIVE_OTHER_ERROR;
484 scoped_ptr<google_apis::FileResource> server_entry; 484 scoped_ptr<google_apis::FileResource> server_entry;
485 fake_drive_service_->GetFileResource( 485 fake_drive_service_->GetFileResource(
486 entry->resource_id(), 486 entry->resource_id(),
487 google_apis::test_util::CreateCopyResultCallback(&status, &server_entry)); 487 google_apis::test_util::CreateCopyResultCallback(&status, &server_entry));
488 content::RunAllBlockingPoolTasksUntilIdle(); 488 content::RunAllBlockingPoolTasksUntilIdle();
489 EXPECT_EQ(google_apis::HTTP_SUCCESS, status); 489 EXPECT_EQ(google_apis::HTTP_SUCCESS, status);
490 ASSERT_TRUE(server_entry); 490 ASSERT_TRUE(server_entry);
491 EXPECT_EQ(entry->title(), server_entry->title()); 491 EXPECT_EQ(entry->title(), server_entry->title());
492 EXPECT_TRUE(server_entry->IsDirectory()); 492 EXPECT_TRUE(server_entry->IsDirectory());
493 } 493 }
494 494
495 TEST_F(FileSystemTest, CreateFile) { 495 TEST_F(FileSystemTest, CreateFile) {
496 base::FilePath file_path(FILE_PATH_LITERAL("drive/root/New File.txt")); 496 base::FilePath file_path(FILE_PATH_LITERAL("drive/root/New File.txt"));
497 EXPECT_FALSE(GetResourceEntrySync(file_path)); 497 EXPECT_FALSE(GetResourceEntrySync(file_path));
498 498
499 FileError error = FILE_ERROR_FAILED; 499 FileError error = FILE_ERROR_FAILED;
500 file_system_->CreateFile( 500 file_system_->CreateFile(
501 file_path, 501 file_path,
502 true, // is_exclusive 502 true, // is_exclusive
503 "text/plain", 503 "text/plain",
504 google_apis::test_util::CreateCopyResultCallback(&error)); 504 google_apis::test_util::CreateCopyResultCallback(&error));
505 content::RunAllBlockingPoolTasksUntilIdle(); 505 content::RunAllBlockingPoolTasksUntilIdle();
506 EXPECT_EQ(FILE_ERROR_OK, error); 506 EXPECT_EQ(FILE_ERROR_OK, error);
507 507
508 // File is created on the server. 508 // File is created on the server.
509 scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(file_path); 509 scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(file_path);
510 ASSERT_TRUE(entry); 510 ASSERT_TRUE(entry);
511 511
512 google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR; 512 google_apis::DriveApiErrorCode status = google_apis::DRIVE_OTHER_ERROR;
513 scoped_ptr<google_apis::FileResource> server_entry; 513 scoped_ptr<google_apis::FileResource> server_entry;
514 fake_drive_service_->GetFileResource( 514 fake_drive_service_->GetFileResource(
515 entry->resource_id(), 515 entry->resource_id(),
516 google_apis::test_util::CreateCopyResultCallback(&status, &server_entry)); 516 google_apis::test_util::CreateCopyResultCallback(&status, &server_entry));
517 content::RunAllBlockingPoolTasksUntilIdle(); 517 content::RunAllBlockingPoolTasksUntilIdle();
518 EXPECT_EQ(google_apis::HTTP_SUCCESS, status); 518 EXPECT_EQ(google_apis::HTTP_SUCCESS, status);
519 ASSERT_TRUE(server_entry); 519 ASSERT_TRUE(server_entry);
520 EXPECT_EQ(entry->title(), server_entry->title()); 520 EXPECT_EQ(entry->title(), server_entry->title());
521 EXPECT_FALSE(server_entry->IsDirectory()); 521 EXPECT_FALSE(server_entry->IsDirectory());
522 } 522 }
(...skipping 13 matching lines...) Expand all
536 FileError error = FILE_ERROR_FAILED; 536 FileError error = FILE_ERROR_FAILED;
537 file_system_->TouchFile( 537 file_system_->TouchFile(
538 file_path, 538 file_path,
539 last_accessed, 539 last_accessed,
540 last_modified, 540 last_modified,
541 google_apis::test_util::CreateCopyResultCallback(&error)); 541 google_apis::test_util::CreateCopyResultCallback(&error));
542 content::RunAllBlockingPoolTasksUntilIdle(); 542 content::RunAllBlockingPoolTasksUntilIdle();
543 EXPECT_EQ(FILE_ERROR_OK, error); 543 EXPECT_EQ(FILE_ERROR_OK, error);
544 544
545 // File is touched on the server. 545 // File is touched on the server.
546 google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR; 546 google_apis::DriveApiErrorCode status = google_apis::DRIVE_OTHER_ERROR;
547 scoped_ptr<google_apis::FileResource> server_entry; 547 scoped_ptr<google_apis::FileResource> server_entry;
548 fake_drive_service_->GetFileResource( 548 fake_drive_service_->GetFileResource(
549 entry->resource_id(), 549 entry->resource_id(),
550 google_apis::test_util::CreateCopyResultCallback(&status, &server_entry)); 550 google_apis::test_util::CreateCopyResultCallback(&status, &server_entry));
551 content::RunAllBlockingPoolTasksUntilIdle(); 551 content::RunAllBlockingPoolTasksUntilIdle();
552 EXPECT_EQ(google_apis::HTTP_SUCCESS, status); 552 EXPECT_EQ(google_apis::HTTP_SUCCESS, status);
553 ASSERT_TRUE(server_entry); 553 ASSERT_TRUE(server_entry);
554 EXPECT_EQ(last_accessed, server_entry->last_viewed_by_me_date()); 554 EXPECT_EQ(last_accessed, server_entry->last_viewed_by_me_date());
555 EXPECT_EQ(last_modified, server_entry->modified_date()); 555 EXPECT_EQ(last_modified, server_entry->modified_date());
556 } 556 }
557 557
558 TEST_F(FileSystemTest, TruncateFile) { 558 TEST_F(FileSystemTest, TruncateFile) {
559 base::FilePath file_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); 559 base::FilePath file_path(FILE_PATH_LITERAL("drive/root/File 1.txt"));
560 scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(file_path); 560 scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(file_path);
561 ASSERT_TRUE(entry); 561 ASSERT_TRUE(entry);
562 562
563 const int64 kLength = entry->file_info().size() + 100; 563 const int64 kLength = entry->file_info().size() + 100;
564 564
565 FileError error = FILE_ERROR_FAILED; 565 FileError error = FILE_ERROR_FAILED;
566 file_system_->TruncateFile( 566 file_system_->TruncateFile(
567 file_path, 567 file_path,
568 kLength, 568 kLength,
569 google_apis::test_util::CreateCopyResultCallback(&error)); 569 google_apis::test_util::CreateCopyResultCallback(&error));
570 content::RunAllBlockingPoolTasksUntilIdle(); 570 content::RunAllBlockingPoolTasksUntilIdle();
571 EXPECT_EQ(FILE_ERROR_OK, error); 571 EXPECT_EQ(FILE_ERROR_OK, error);
572 572
573 // File is touched on the server. 573 // File is touched on the server.
574 google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR; 574 google_apis::DriveApiErrorCode status = google_apis::DRIVE_OTHER_ERROR;
575 scoped_ptr<google_apis::FileResource> server_entry; 575 scoped_ptr<google_apis::FileResource> server_entry;
576 fake_drive_service_->GetFileResource( 576 fake_drive_service_->GetFileResource(
577 entry->resource_id(), 577 entry->resource_id(),
578 google_apis::test_util::CreateCopyResultCallback(&status, &server_entry)); 578 google_apis::test_util::CreateCopyResultCallback(&status, &server_entry));
579 content::RunAllBlockingPoolTasksUntilIdle(); 579 content::RunAllBlockingPoolTasksUntilIdle();
580 EXPECT_EQ(google_apis::HTTP_SUCCESS, status); 580 EXPECT_EQ(google_apis::HTTP_SUCCESS, status);
581 ASSERT_TRUE(server_entry); 581 ASSERT_TRUE(server_entry);
582 EXPECT_EQ(kLength, server_entry->file_size()); 582 EXPECT_EQ(kLength, server_entry->file_size());
583 } 583 }
584 584
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 } 836 }
837 837
838 TEST_F(FileSystemTest, ReadDirectoryAfterUpdateWhileLoading) { 838 TEST_F(FileSystemTest, ReadDirectoryAfterUpdateWhileLoading) {
839 // Simulate the situation that full feed fetching takes very long time, 839 // Simulate the situation that full feed fetching takes very long time,
840 // to test the recursive "fast fetch" feature is properly working. 840 // to test the recursive "fast fetch" feature is properly working.
841 fake_drive_service_->set_never_return_all_file_list(true); 841 fake_drive_service_->set_never_return_all_file_list(true);
842 842
843 // On the fake server, create the test directory. 843 // On the fake server, create the test directory.
844 scoped_ptr<google_apis::FileResource> parent; 844 scoped_ptr<google_apis::FileResource> parent;
845 { 845 {
846 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; 846 google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR;
847 fake_drive_service_->AddNewDirectory( 847 fake_drive_service_->AddNewDirectory(
848 fake_drive_service_->GetRootResourceId(), 848 fake_drive_service_->GetRootResourceId(),
849 "UpdateWhileLoadingTestDir", 849 "UpdateWhileLoadingTestDir",
850 DriveServiceInterface::AddNewDirectoryOptions(), 850 DriveServiceInterface::AddNewDirectoryOptions(),
851 google_apis::test_util::CreateCopyResultCallback(&error, &parent)); 851 google_apis::test_util::CreateCopyResultCallback(&error, &parent));
852 base::RunLoop().RunUntilIdle(); 852 base::RunLoop().RunUntilIdle();
853 ASSERT_EQ(google_apis::HTTP_CREATED, error); 853 ASSERT_EQ(google_apis::HTTP_CREATED, error);
854 } 854 }
855 855
856 // Fetch the directory. Currently it is empty. 856 // Fetch the directory. Currently it is empty.
857 scoped_ptr<ResourceEntryVector> before = ReadDirectorySync(base::FilePath( 857 scoped_ptr<ResourceEntryVector> before = ReadDirectorySync(base::FilePath(
858 FILE_PATH_LITERAL("drive/root/UpdateWhileLoadingTestDir"))); 858 FILE_PATH_LITERAL("drive/root/UpdateWhileLoadingTestDir")));
859 ASSERT_TRUE(before); 859 ASSERT_TRUE(before);
860 EXPECT_EQ(0u, before->size()); 860 EXPECT_EQ(0u, before->size());
861 861
862 // Create a file in the test directory. 862 // Create a file in the test directory.
863 scoped_ptr<google_apis::FileResource> entry; 863 scoped_ptr<google_apis::FileResource> entry;
864 { 864 {
865 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; 865 google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR;
866 fake_drive_service_->AddNewFile( 866 fake_drive_service_->AddNewFile(
867 "text/plain", 867 "text/plain",
868 "(dummy data)", 868 "(dummy data)",
869 parent->file_id(), 869 parent->file_id(),
870 "TestFile", 870 "TestFile",
871 false, // shared_with_me 871 false, // shared_with_me
872 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); 872 google_apis::test_util::CreateCopyResultCallback(&error, &entry));
873 base::RunLoop().RunUntilIdle(); 873 base::RunLoop().RunUntilIdle();
874 ASSERT_EQ(google_apis::HTTP_CREATED, error); 874 ASSERT_EQ(google_apis::HTTP_CREATED, error);
875 } 875 }
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 kEmbedOrigin, 1022 kEmbedOrigin,
1023 google_apis::test_util::CreateCopyResultCallback(&error, &share_url)); 1023 google_apis::test_util::CreateCopyResultCallback(&error, &share_url));
1024 content::RunAllBlockingPoolTasksUntilIdle(); 1024 content::RunAllBlockingPoolTasksUntilIdle();
1025 1025
1026 // Verify the share url to the sharing dialog. 1026 // Verify the share url to the sharing dialog.
1027 EXPECT_EQ(FILE_ERROR_OK, error); 1027 EXPECT_EQ(FILE_ERROR_OK, error);
1028 EXPECT_TRUE(share_url.is_valid()); 1028 EXPECT_TRUE(share_url.is_valid());
1029 } 1029 }
1030 1030
1031 } // namespace drive 1031 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698