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

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

Issue 14838003: Try fast-fetch rather than full fetch if drive::FileSystem::GetEntryInfo failed. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added (and fixed) tests. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #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 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 USE_SERVER_TIMESTAMP, 301 USE_SERVER_TIMESTAMP,
302 }; 302 };
303 303
304 // Saves a file representing a filesystem with directories: 304 // Saves a file representing a filesystem with directories:
305 // drive/root, drive/root/Dir1, drive/root/Dir1/SubDir2 305 // drive/root, drive/root/Dir1, drive/root/Dir1/SubDir2
306 // and files 306 // and files
307 // drive/root/File1, drive/root/Dir1/File2, drive/root/Dir1/SubDir2/File3. 307 // drive/root/File1, drive/root/Dir1/File2, drive/root/Dir1/SubDir2/File3.
308 // If |use_up_to_date_timestamp| is true, sets the changestamp to 654321, 308 // If |use_up_to_date_timestamp| is true, sets the changestamp to 654321,
309 // equal to that of "account_metadata.json" test data, indicating the cache is 309 // equal to that of "account_metadata.json" test data, indicating the cache is
310 // holding the latest file system info. 310 // holding the latest file system info.
311 bool SaveTestFileSystem(SaveTestFileSystemParam param) { 311 bool SaveTestFileSystem(SaveTestFileSystemParam param) {
satorux1 2013/05/07 06:29:45 This looks like a misnomer. I think this function
hashimoto 2013/05/07 06:49:01 Done.
312 // Destroy the existing resource metadata to close DB. 312 // Destroy the existing resource metadata to close DB.
313 resource_metadata_.reset(); 313 resource_metadata_.reset();
314 314
315 const std::string root_resource_id = 315 const std::string root_resource_id =
316 fake_drive_service_->GetRootResourceId(); 316 fake_drive_service_->GetRootResourceId();
317 scoped_ptr<internal::ResourceMetadata, test_util::DestroyHelperForTests> 317 scoped_ptr<internal::ResourceMetadata, test_util::DestroyHelperForTests>
318 resource_metadata(new internal::ResourceMetadata( 318 resource_metadata(new internal::ResourceMetadata(
319 cache_->GetCacheDirectoryPath(FileCache::CACHE_TYPE_META), 319 cache_->GetCacheDirectoryPath(FileCache::CACHE_TYPE_META),
320 blocking_task_runner_)); 320 blocking_task_runner_));
321 321
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 scoped_ptr<internal::ResourceMetadata, test_util::DestroyHelperForTests> 454 scoped_ptr<internal::ResourceMetadata, test_util::DestroyHelperForTests>
455 resource_metadata_; 455 resource_metadata_;
456 scoped_ptr<FakeFreeDiskSpaceGetter> fake_free_disk_space_getter_; 456 scoped_ptr<FakeFreeDiskSpaceGetter> fake_free_disk_space_getter_;
457 scoped_ptr<StrictMock<MockCacheObserver> > mock_cache_observer_; 457 scoped_ptr<StrictMock<MockCacheObserver> > mock_cache_observer_;
458 scoped_ptr<StrictMock<MockDirectoryChangeObserver> > mock_directory_observer_; 458 scoped_ptr<StrictMock<MockDirectoryChangeObserver> > mock_directory_observer_;
459 459
460 int root_feed_changestamp_; 460 int root_feed_changestamp_;
461 }; 461 };
462 462
463 TEST_F(DriveFileSystemTest, DuplicatedAsyncInitialization) { 463 TEST_F(DriveFileSystemTest, DuplicatedAsyncInitialization) {
464 // "Fast fetch" will fire an OnirectoryChanged event.
465 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
466 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1);
467
464 int counter = 0; 468 int counter = 0;
465 const GetEntryInfoCallback& callback = base::Bind( 469 const GetEntryInfoCallback& callback = base::Bind(
466 &AsyncInitializationCallback, &counter, 2, &message_loop_); 470 &AsyncInitializationCallback, &counter, 2, &message_loop_);
467 471
468 file_system_->GetEntryInfoByPath( 472 file_system_->GetEntryInfoByPath(
469 base::FilePath(FILE_PATH_LITERAL("drive/root")), callback); 473 base::FilePath(FILE_PATH_LITERAL("drive/root")), callback);
470 file_system_->GetEntryInfoByPath( 474 file_system_->GetEntryInfoByPath(
471 base::FilePath(FILE_PATH_LITERAL("drive/root")), callback); 475 base::FilePath(FILE_PATH_LITERAL("drive/root")), callback);
472 message_loop_.Run(); // Wait to get our result 476 message_loop_.Run(); // Wait to get our result
473 EXPECT_EQ(2, counter); 477 EXPECT_EQ(2, counter);
474 478
475 // Although GetEntryInfoByPath() was called twice, the account metadata 479 // Although GetEntryInfoByPath() was called twice, the account metadata
476 // should only be loaded once. In the past, there was a bug that caused 480 // should only be loaded once. In the past, there was a bug that caused
477 // it to be loaded twice. 481 // it to be loaded twice.
478 EXPECT_EQ(1, fake_drive_service_->about_resource_load_count());
479 EXPECT_EQ(1, fake_drive_service_->resource_list_load_count()); 482 EXPECT_EQ(1, fake_drive_service_->resource_list_load_count());
483 // See the comment in GetMyDriveRoot test case why this is 2.
484 EXPECT_EQ(2, fake_drive_service_->about_resource_load_count());
480 } 485 }
481 486
482 TEST_F(DriveFileSystemTest, GetGrandRootEntry) { 487 TEST_F(DriveFileSystemTest, GetGrandRootEntry) {
483 const base::FilePath kFilePath(FILE_PATH_LITERAL("drive")); 488 const base::FilePath kFilePath(FILE_PATH_LITERAL("drive"));
484 scoped_ptr<ResourceEntry> entry = GetEntryInfoByPathSync(kFilePath); 489 scoped_ptr<ResourceEntry> entry = GetEntryInfoByPathSync(kFilePath);
485 ASSERT_TRUE(entry); 490 ASSERT_TRUE(entry);
486 EXPECT_EQ(util::kDriveGrandRootSpecialResourceId, entry->resource_id()); 491 EXPECT_EQ(util::kDriveGrandRootSpecialResourceId, entry->resource_id());
487 492
488 // Getting the grand root entry should not cause the resource load to happen. 493 // Getting the grand root entry should not cause the resource load to happen.
489 EXPECT_EQ(0, fake_drive_service_->about_resource_load_count()); 494 EXPECT_EQ(0, fake_drive_service_->about_resource_load_count());
490 EXPECT_EQ(0, fake_drive_service_->resource_list_load_count()); 495 EXPECT_EQ(0, fake_drive_service_->resource_list_load_count());
491 } 496 }
492 497
493 TEST_F(DriveFileSystemTest, GetOtherDirEntry) { 498 TEST_F(DriveFileSystemTest, GetOtherDirEntry) {
494 const base::FilePath kFilePath(FILE_PATH_LITERAL("drive/other")); 499 const base::FilePath kFilePath(FILE_PATH_LITERAL("drive/other"));
495 scoped_ptr<ResourceEntry> entry = GetEntryInfoByPathSync(kFilePath); 500 scoped_ptr<ResourceEntry> entry = GetEntryInfoByPathSync(kFilePath);
496 ASSERT_TRUE(entry); 501 ASSERT_TRUE(entry);
497 EXPECT_EQ(util::kDriveOtherDirSpecialResourceId, entry->resource_id()); 502 EXPECT_EQ(util::kDriveOtherDirSpecialResourceId, entry->resource_id());
498 503
499 // Getting the "other" directory entry should not cause the resource load to 504 // Getting the "other" directory entry should not cause the resource load to
500 // happen. 505 // happen.
501 EXPECT_EQ(0, fake_drive_service_->about_resource_load_count()); 506 EXPECT_EQ(0, fake_drive_service_->about_resource_load_count());
502 EXPECT_EQ(0, fake_drive_service_->resource_list_load_count()); 507 EXPECT_EQ(0, fake_drive_service_->resource_list_load_count());
503 } 508 }
504 509
505 TEST_F(DriveFileSystemTest, GetMyDriveRoot) { 510 TEST_F(DriveFileSystemTest, GetMyDriveRoot) {
511 // "Fast fetch" will fire an OnirectoryChanged event.
512 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
513 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1);
514
506 const base::FilePath kFilePath(FILE_PATH_LITERAL("drive/root")); 515 const base::FilePath kFilePath(FILE_PATH_LITERAL("drive/root"));
507 scoped_ptr<ResourceEntry> entry = GetEntryInfoByPathSync(kFilePath); 516 scoped_ptr<ResourceEntry> entry = GetEntryInfoByPathSync(kFilePath);
508 ASSERT_TRUE(entry); 517 ASSERT_TRUE(entry);
509 EXPECT_EQ(fake_drive_service_->GetRootResourceId(), entry->resource_id()); 518 EXPECT_EQ(fake_drive_service_->GetRootResourceId(), entry->resource_id());
510 519
511 // The changestamp should be propagated to the root directory. 520 // Absence of "drive/root" in the local metadata triggers the "fast fetch"
512 EXPECT_EQ(fake_drive_service_->largest_changestamp(), 521 // of "drive" directory. Fetch of "drive" grand root directory has a special
513 entry->directory_specific_info().changestamp()); 522 // implementation. Instead of normal GetResourceListInDirectory(), it is
523 // emulated by calling GetAboutResource() so that the resource_id of
524 // "drive/root" is listed.
525 // Together with the normal GetAboutResource() call to retrieve the largest
526 // changestamp, the method is called twice.
527 EXPECT_EQ(2, fake_drive_service_->about_resource_load_count());
514 528
515 // The resource load should happen because "My Drive"'s root is not the grand 529 // After "fast fetch" is done, full resource list is fetched.
516 // root entry and hence does not present until the initial loading.
517 EXPECT_EQ(1, fake_drive_service_->about_resource_load_count());
518 EXPECT_EQ(1, fake_drive_service_->resource_list_load_count()); 530 EXPECT_EQ(1, fake_drive_service_->resource_list_load_count());
519 } 531 }
520 532
521 TEST_F(DriveFileSystemTest, GetExistingFile) { 533 TEST_F(DriveFileSystemTest, GetExistingFile) {
522 const base::FilePath kFilePath(FILE_PATH_LITERAL("drive/root/File 1.txt")); 534 const base::FilePath kFilePath(FILE_PATH_LITERAL("drive/root/File 1.txt"));
523 scoped_ptr<ResourceEntry> entry = GetEntryInfoByPathSync(kFilePath); 535 scoped_ptr<ResourceEntry> entry = GetEntryInfoByPathSync(kFilePath);
524 ASSERT_TRUE(entry); 536 ASSERT_TRUE(entry);
525 EXPECT_EQ("file:2_file_resource_id", entry->resource_id()); 537 EXPECT_EQ("file:2_file_resource_id", entry->resource_id());
526 538
527 EXPECT_EQ(1, fake_drive_service_->about_resource_load_count()); 539 EXPECT_EQ(1, fake_drive_service_->about_resource_load_count());
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
884 896
885 file_system_->CheckForUpdates(); 897 file_system_->CheckForUpdates();
886 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(_)) 898 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(_))
887 .Times(AtLeast(1)); 899 .Times(AtLeast(1));
888 900
889 google_apis::test_util::RunBlockingPoolTask(); 901 google_apis::test_util::RunBlockingPoolTask();
890 EXPECT_EQ(1, fake_drive_service_->about_resource_load_count()); 902 EXPECT_EQ(1, fake_drive_service_->about_resource_load_count());
891 EXPECT_EQ(1, fake_drive_service_->change_list_load_count()); 903 EXPECT_EQ(1, fake_drive_service_->change_list_load_count());
892 } 904 }
893 905
906 TEST_F(DriveFileSystemTest, ReadDirectoryWhileRefreshing) {
907 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(_))
908 .Times(AtLeast(1));
909
910 // Enter the "refreshing" state.
satorux1 2013/05/07 06:29:45 Enter the "refreshing" state so the fast fetch wil
hashimoto 2013/05/07 06:49:01 Done for ReadDirectoryWhileRefreshing and GetEntry
911 ASSERT_TRUE(SaveTestFileSystem(USE_OLD_TIMESTAMP));
912 file_system_->CheckForUpdates();
913
914 // The list of resources in "drive/root/Dir1" should be fetched.
915 EXPECT_TRUE(ReadDirectoryByPathSync(base::FilePath(
916 FILE_PATH_LITERAL("drive/root/Dir1"))));
917 EXPECT_EQ(1, fake_drive_service_->directory_load_count());
918 }
919
920 TEST_F(DriveFileSystemTest, GetEntryInfoExistingWhileRefreshing) {
921 // Enter the "refreshing" state.
922 ASSERT_TRUE(SaveTestFileSystem(USE_OLD_TIMESTAMP));
923 file_system_->CheckForUpdates();
924
925 // If an entry is already found in local metadata, no directory fetch happens.
926 EXPECT_TRUE(GetEntryInfoByPathSync(base::FilePath(
927 FILE_PATH_LITERAL("drive/root/Dir1/File2"))));
928 EXPECT_EQ(0, fake_drive_service_->directory_load_count());
929 }
930
931 TEST_F(DriveFileSystemTest, GetEntryInfoNonExistentWhileRefreshing) {
932 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(_))
933 .Times(AtLeast(1));
934
935 // Enter the "refreshing" state.
936 ASSERT_TRUE(SaveTestFileSystem(USE_OLD_TIMESTAMP));
937 file_system_->CheckForUpdates();
938
939 // If an entry is not found, parent directory's resource list is fetched.
940 EXPECT_FALSE(GetEntryInfoByPathSync(base::FilePath(
941 FILE_PATH_LITERAL("drive/root/Dir1/NonExistentFile"))));
942 EXPECT_EQ(1, fake_drive_service_->directory_load_count());
943 }
944
894 TEST_F(DriveFileSystemTest, TransferFileFromLocalToRemote_RegularFile) { 945 TEST_F(DriveFileSystemTest, TransferFileFromLocalToRemote_RegularFile) {
895 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace); 946 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace);
896 947
897 ASSERT_TRUE(LoadRootFeedDocument()); 948 ASSERT_TRUE(LoadRootFeedDocument());
898 949
899 // We'll add a file to the Drive root directory. 950 // We'll add a file to the Drive root directory.
900 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 951 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
901 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); 952 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1);
902 953
903 // Prepare a local file. 954 // Prepare a local file.
(...skipping 1393 matching lines...) Expand 10 before | Expand all | Expand 10 after
2297 2348
2298 // Create fails if the parent directory does not exist. 2349 // Create fails if the parent directory does not exist.
2299 file_system_->CreateFile( 2350 file_system_->CreateFile(
2300 kFileInNonExistingDirectory, false, 2351 kFileInNonExistingDirectory, false,
2301 google_apis::test_util::CreateCopyResultCallback(&error)); 2352 google_apis::test_util::CreateCopyResultCallback(&error));
2302 google_apis::test_util::RunBlockingPoolTask(); 2353 google_apis::test_util::RunBlockingPoolTask();
2303 EXPECT_EQ(FILE_ERROR_NOT_A_DIRECTORY, error); 2354 EXPECT_EQ(FILE_ERROR_NOT_A_DIRECTORY, error);
2304 } 2355 }
2305 2356
2306 } // namespace drive 2357 } // namespace drive
OLDNEW
« chrome/browser/chromeos/drive/file_system.cc ('K') | « chrome/browser/chromeos/drive/file_system.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698