Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/drive/drive_file_system.h" | 5 #include "chrome/browser/chromeos/drive/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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 mock_directory_observer_.reset(new StrictMock<MockDirectoryChangeObserver>); | 135 mock_directory_observer_.reset(new StrictMock<MockDirectoryChangeObserver>); |
| 136 | 136 |
| 137 cache_->RequestInitializeForTesting(); | 137 cache_->RequestInitializeForTesting(); |
| 138 google_apis::test_util::RunBlockingPoolTask(); | 138 google_apis::test_util::RunBlockingPoolTask(); |
| 139 | 139 |
| 140 SetUpResourceMetadataAndFileSystem(); | 140 SetUpResourceMetadataAndFileSystem(); |
| 141 } | 141 } |
| 142 | 142 |
| 143 void SetUpResourceMetadataAndFileSystem() { | 143 void SetUpResourceMetadataAndFileSystem() { |
| 144 resource_metadata_.reset(new DriveResourceMetadata( | 144 resource_metadata_.reset(new DriveResourceMetadata( |
| 145 fake_drive_service_->GetRootResourceId(), | |
| 146 cache_->GetCacheDirectoryPath(DriveCache::CACHE_TYPE_META), | 145 cache_->GetCacheDirectoryPath(DriveCache::CACHE_TYPE_META), |
| 147 blocking_task_runner_)); | 146 blocking_task_runner_)); |
| 148 | 147 |
| 149 file_system_.reset(new DriveFileSystem(profile_.get(), | 148 file_system_.reset(new DriveFileSystem(profile_.get(), |
| 150 cache_.get(), | 149 cache_.get(), |
| 151 fake_drive_service_.get(), | 150 fake_drive_service_.get(), |
| 152 drive_webapps_registry_.get(), | 151 drive_webapps_registry_.get(), |
| 153 resource_metadata_.get(), | 152 resource_metadata_.get(), |
| 154 blocking_task_runner_)); | 153 blocking_task_runner_)); |
| 155 file_system_->AddObserver(mock_directory_observer_.get()); | 154 file_system_->AddObserver(mock_directory_observer_.get()); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 312 // equal to that of "account_metadata.json" test data, indicating the cache is | 311 // equal to that of "account_metadata.json" test data, indicating the cache is |
| 313 // holding the latest file system info. | 312 // holding the latest file system info. |
| 314 bool SaveTestFileSystem(SaveTestFileSystemParam param) { | 313 bool SaveTestFileSystem(SaveTestFileSystemParam param) { |
| 315 // Destroy the existing resource metadata to close DB. | 314 // Destroy the existing resource metadata to close DB. |
| 316 resource_metadata_.reset(); | 315 resource_metadata_.reset(); |
| 317 | 316 |
| 318 const std::string root_resource_id = | 317 const std::string root_resource_id = |
| 319 fake_drive_service_->GetRootResourceId(); | 318 fake_drive_service_->GetRootResourceId(); |
| 320 scoped_ptr<DriveResourceMetadata, test_util::DestroyHelperForTests> | 319 scoped_ptr<DriveResourceMetadata, test_util::DestroyHelperForTests> |
| 321 resource_metadata(new DriveResourceMetadata( | 320 resource_metadata(new DriveResourceMetadata( |
| 322 root_resource_id, | |
| 323 cache_->GetCacheDirectoryPath(DriveCache::CACHE_TYPE_META), | 321 cache_->GetCacheDirectoryPath(DriveCache::CACHE_TYPE_META), |
| 324 blocking_task_runner_)); | 322 blocking_task_runner_)); |
| 325 | 323 |
| 326 DriveFileError error = DRIVE_FILE_ERROR_FAILED; | 324 DriveFileError error = DRIVE_FILE_ERROR_FAILED; |
| 327 resource_metadata->Initialize( | 325 resource_metadata->Initialize( |
| 328 google_apis::test_util::CreateCopyResultCallback(&error)); | 326 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 329 google_apis::test_util::RunBlockingPoolTask(); | 327 google_apis::test_util::RunBlockingPoolTask(); |
| 330 if (error != DRIVE_FILE_OK) | 328 if (error != DRIVE_FILE_OK) |
| 331 return false; | 329 return false; |
| 332 | 330 |
| 333 resource_metadata->SetLargestChangestamp( | 331 resource_metadata->SetLargestChangestamp( |
| 334 param == USE_SERVER_TIMESTAMP ? 654321 : 1, | 332 param == USE_SERVER_TIMESTAMP ? 654321 : 1, |
| 335 google_apis::test_util::CreateCopyResultCallback(&error)); | 333 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 336 google_apis::test_util::RunBlockingPoolTask(); | 334 google_apis::test_util::RunBlockingPoolTask(); |
| 337 if (error != DRIVE_FILE_OK) | 335 if (error != DRIVE_FILE_OK) |
| 338 return false; | 336 return false; |
| 339 | 337 |
| 340 // drive/root is already prepared by DriveResourceMetadata. | 338 // drive/root is already prepared by DriveResourceMetadata. |
| 341 // TODO(haruki): Create drive/root here when we start creating it in | 339 // TODO(haruki): Create drive/root here when we start creating it in |
|
Haruki Sato
2013/04/10 03:44:35
Could you remove this TODO?
Thanks!
hidehiko
2013/04/10 06:11:19
Done.
| |
| 342 // ChangeListLoader. | 340 // ChangeListLoader. |
| 343 base::FilePath file_path; | 341 base::FilePath file_path; |
| 344 | 342 |
| 343 // drive/root | |
| 344 resource_metadata->AddEntry( | |
| 345 util::CreateMyDriveRootEntry(root_resource_id), | |
| 346 google_apis::test_util::CreateCopyResultCallback(&error, &file_path)); | |
| 347 google_apis::test_util::RunBlockingPoolTask(); | |
| 348 if (error != DRIVE_FILE_OK) | |
| 349 return false; | |
| 350 | |
| 345 // drive/root/File1 | 351 // drive/root/File1 |
| 346 DriveEntryProto file1; | 352 DriveEntryProto file1; |
| 347 file1.set_title("File1"); | 353 file1.set_title("File1"); |
| 348 file1.set_resource_id("resource_id:File1"); | 354 file1.set_resource_id("resource_id:File1"); |
| 349 file1.set_parent_resource_id(root_resource_id); | 355 file1.set_parent_resource_id(root_resource_id); |
| 350 file1.mutable_file_specific_info()->set_file_md5("md5"); | 356 file1.mutable_file_specific_info()->set_file_md5("md5"); |
| 351 file1.mutable_file_info()->set_is_directory(false); | 357 file1.mutable_file_info()->set_is_directory(false); |
| 352 file1.mutable_file_info()->set_size(1048576); | 358 file1.mutable_file_info()->set_size(1048576); |
| 353 resource_metadata->AddEntry( | 359 resource_metadata->AddEntry( |
| 354 file1, | 360 file1, |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 474 scoped_ptr<DriveEntryProtoVector> entries) { | 480 scoped_ptr<DriveEntryProtoVector> entries) { |
| 475 ASSERT_EQ(DRIVE_FILE_OK, error); | 481 ASSERT_EQ(DRIVE_FILE_OK, error); |
| 476 ASSERT_TRUE(entries.get()); | 482 ASSERT_TRUE(entries.get()); |
| 477 ASSERT_FALSE(entries->empty()); | 483 ASSERT_FALSE(entries->empty()); |
| 478 | 484 |
| 479 (*counter)++; | 485 (*counter)++; |
| 480 if (*counter >= expected_counter) | 486 if (*counter >= expected_counter) |
| 481 message_loop->Quit(); | 487 message_loop->Quit(); |
| 482 } | 488 } |
| 483 | 489 |
| 484 TEST_F(DriveFileSystemTest, DuplicatedAsyncInitialization) { | 490 TEST_F(DriveFileSystemTest, DuplicatedAsyncInitialization) { |
|
kinaba
2013/04/10 04:34:44
As far as I recall, original intent of this test w
hidehiko
2013/04/10 06:11:19
Good to know. Done. Also removed EXPECT_CALL below
| |
| 485 // The root directory will be loaded that triggers the event. | 491 // The root directory will be loaded that triggers the event. |
| 486 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 492 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 487 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); | 493 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); |
| 488 | 494 |
| 489 int counter = 0; | 495 int counter = 0; |
| 490 ReadDirectoryWithSettingCallback callback = base::Bind( | 496 ReadDirectoryWithSettingCallback callback = base::Bind( |
| 491 &AsyncInitializationCallback, | 497 &AsyncInitializationCallback, |
| 492 &counter, | 498 &counter, |
| 493 2, | 499 2, |
| 494 &message_loop_); | 500 &message_loop_); |
| 495 | 501 |
| 496 file_system_->ReadDirectoryByPath( | 502 file_system_->ReadDirectoryByPath( |
| 497 base::FilePath(FILE_PATH_LITERAL("drive/root")), callback); | 503 base::FilePath(FILE_PATH_LITERAL("drive")), callback); |
| 498 file_system_->ReadDirectoryByPath( | 504 file_system_->ReadDirectoryByPath( |
| 499 base::FilePath(FILE_PATH_LITERAL("drive/root")), callback); | 505 base::FilePath(FILE_PATH_LITERAL("drive")), callback); |
| 500 message_loop_.Run(); // Wait to get our result | 506 message_loop_.Run(); // Wait to get our result |
| 501 EXPECT_EQ(2, counter); | 507 EXPECT_EQ(2, counter); |
| 502 | 508 |
| 503 // ReadDirectoryByPath() was called twice, but the account metadata should | 509 // ReadDirectoryByPath() was called twice, but the account metadata should |
| 504 // only be loaded once. In the past, there was a bug that caused it to be | 510 // only be loaded once. In the past, there was a bug that caused it to be |
| 505 // loaded twice. | 511 // loaded twice. |
| 506 EXPECT_EQ(1, fake_drive_service_->about_resource_load_count()); | 512 // The actual number of GetAboutResource invocation should be two; |
| 513 // one for checking if it is necessary to load the data from server or not, | |
| 514 // and the other for creating mydrive root entry. | |
| 515 EXPECT_EQ(2, fake_drive_service_->about_resource_load_count()); | |
| 507 // On the other hand, the resource list could be loaded twice. One for | 516 // On the other hand, the resource list could be loaded twice. One for |
| 508 // just the directory contents, and one for the entire resource list. | 517 // just the directory contents, and one for the entire resource list. |
| 509 // | 518 // |
| 510 // The |callback| function gets called back soon after the directory content | 519 // The |callback| function gets called back soon after the directory content |
| 511 // is loaded, and the full resource load is done in background asynchronously. | 520 // is loaded, and the full resource load is done in background asynchronously. |
| 512 // So it depends on timing whether we receive the full resource load request | 521 // So it depends on timing whether we receive the full resource load request |
| 513 // at this point. | 522 // at this point. |
| 514 EXPECT_TRUE(fake_drive_service_->resource_list_load_count() == 1 || | 523 EXPECT_TRUE(fake_drive_service_->resource_list_load_count() == 1 || |
| 515 fake_drive_service_->resource_list_load_count() == 2) | 524 fake_drive_service_->resource_list_load_count() == 2) |
|
kinaba
2013/04/10 04:34:44
Besides, this ambiguity will go if we switch to Ge
hidehiko
2013/04/10 06:11:19
Done.
| |
| 516 << ": " << fake_drive_service_->resource_list_load_count(); | 525 << ": " << fake_drive_service_->resource_list_load_count(); |
| 517 } | 526 } |
| 518 | 527 |
| 519 TEST_F(DriveFileSystemTest, GetGrandRootEntry) { | 528 TEST_F(DriveFileSystemTest, GetGrandRootEntry) { |
| 520 const base::FilePath kFilePath = | 529 const base::FilePath kFilePath = |
| 521 base::FilePath(FILE_PATH_LITERAL("drive")); | 530 base::FilePath(FILE_PATH_LITERAL("drive")); |
| 522 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath); | 531 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath); |
| 523 ASSERT_TRUE(entry.get()); | 532 ASSERT_TRUE(entry.get()); |
| 524 EXPECT_EQ(util::kDriveGrandRootSpecialResourceId, entry->resource_id()); | 533 EXPECT_EQ(util::kDriveGrandRootSpecialResourceId, entry->resource_id()); |
| 525 | 534 |
| 526 // Getting the grand root entry should not cause the resource load to happen. | 535 // Getting the grand root entry should not cause the resource load to happen. |
| 527 EXPECT_EQ(0, fake_drive_service_->about_resource_load_count()); | 536 EXPECT_EQ(0, fake_drive_service_->about_resource_load_count()); |
| 528 EXPECT_EQ(0, fake_drive_service_->resource_list_load_count()); | 537 EXPECT_EQ(0, fake_drive_service_->resource_list_load_count()); |
| 529 } | 538 } |
| 530 | 539 |
| 531 TEST_F(DriveFileSystemTest, GetMyDriveRootEntry) { | 540 TEST_F(DriveFileSystemTest, GetMyDriveRootEntry) { |
| 532 const base::FilePath kFilePath = | 541 const base::FilePath kFilePath = |
| 533 base::FilePath(FILE_PATH_LITERAL("drive/root")); | 542 base::FilePath(FILE_PATH_LITERAL("drive/root")); |
| 534 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath); | 543 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath); |
| 535 ASSERT_TRUE(entry.get()); | 544 ASSERT_TRUE(entry.get()); |
| 536 EXPECT_EQ(fake_drive_service_->GetRootResourceId(), entry->resource_id()); | 545 EXPECT_EQ(fake_drive_service_->GetRootResourceId(), entry->resource_id()); |
| 537 | 546 |
| 538 // Getting the "My Drive" root entry should not cause the resource load to | 547 // Getting the "My Drive" root entry should cause the resource load to happen. |
|
kinaba
2013/04/10 04:34:44
As far as I recall, original intent of this test w
hidehiko
2013/04/10 06:11:19
Good to know. Just removed this case. Note that th
| |
| 539 // happen. | 548 EXPECT_EQ(1, fake_drive_service_->about_resource_load_count()); |
| 540 EXPECT_EQ(0, fake_drive_service_->about_resource_load_count()); | 549 EXPECT_EQ(1, fake_drive_service_->resource_list_load_count()); |
| 541 EXPECT_EQ(0, fake_drive_service_->resource_list_load_count()); | |
| 542 } | 550 } |
| 543 | 551 |
| 544 TEST_F(DriveFileSystemTest, GetOtherDirEntry) { | 552 TEST_F(DriveFileSystemTest, GetOtherDirEntry) { |
| 545 const base::FilePath kFilePath = | 553 const base::FilePath kFilePath = |
| 546 base::FilePath(FILE_PATH_LITERAL("drive/other")); | 554 base::FilePath(FILE_PATH_LITERAL("drive/other")); |
| 547 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath); | 555 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath); |
| 548 ASSERT_TRUE(entry.get()); | 556 ASSERT_TRUE(entry.get()); |
| 549 EXPECT_EQ(util::kDriveOtherDirSpecialResourceId, entry->resource_id()); | 557 EXPECT_EQ(util::kDriveOtherDirSpecialResourceId, entry->resource_id()); |
| 550 | 558 |
| 551 // Getting the "other" directory entry should not cause the resource load to | 559 // Getting the "other" directory entry should not cause the resource load to |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 718 | 726 |
| 719 const base::FilePath kFilePath = base::FilePath( | 727 const base::FilePath kFilePath = base::FilePath( |
| 720 FILE_PATH_LITERAL("drive/other/Orphan File 1.txt")); | 728 FILE_PATH_LITERAL("drive/other/Orphan File 1.txt")); |
| 721 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath); | 729 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath); |
| 722 ASSERT_TRUE(entry.get()); | 730 ASSERT_TRUE(entry.get()); |
| 723 EXPECT_EQ("file:1_orphanfile_resource_id", entry->resource_id()); | 731 EXPECT_EQ("file:1_orphanfile_resource_id", entry->resource_id()); |
| 724 } | 732 } |
| 725 | 733 |
| 726 TEST_F(DriveFileSystemTest, ReadDirectoryByPath_Root) { | 734 TEST_F(DriveFileSystemTest, ReadDirectoryByPath_Root) { |
| 727 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 735 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 728 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); | 736 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); |
| 729 | 737 |
| 730 // ReadDirectoryByPath() should kick off the resource list loading. | 738 // ReadDirectoryByPath() should kick off the resource list loading. |
| 731 scoped_ptr<DriveEntryProtoVector> entries( | 739 scoped_ptr<DriveEntryProtoVector> entries( |
| 732 ReadDirectoryByPathSync(base::FilePath::FromUTF8Unsafe("drive/root"))); | 740 ReadDirectoryByPathSync(base::FilePath::FromUTF8Unsafe("drive"))); |
| 733 // The root directory should be read correctly. | 741 // The root directory should be read correctly. |
| 734 ASSERT_TRUE(entries.get()); | 742 ASSERT_TRUE(entries.get()); |
| 735 EXPECT_EQ(8U, entries->size()); | 743 EXPECT_EQ(2U, entries->size()); |
| 736 } | 744 } |
|
kinaba
2013/04/10 04:34:44
May want to add a test verifying that "drive/root"
hidehiko
2013/04/10 06:11:19
Done.
| |
| 737 | 745 |
| 738 TEST_F(DriveFileSystemTest, ReadDirectoryByPath_NonRootDirectory) { | 746 TEST_F(DriveFileSystemTest, ReadDirectoryByPath_NonRootDirectory) { |
| 739 // ReadDirectoryByPath() should kick off the resource list loading. | 747 // ReadDirectoryByPath() should kick off the resource list loading. |
| 740 scoped_ptr<DriveEntryProtoVector> entries( | 748 scoped_ptr<DriveEntryProtoVector> entries( |
| 741 ReadDirectoryByPathSync( | 749 ReadDirectoryByPathSync( |
| 742 base::FilePath::FromUTF8Unsafe("drive/root/Directory 1"))); | 750 base::FilePath::FromUTF8Unsafe("drive/root/Directory 1"))); |
| 743 // The non root directory should also be read correctly. | 751 // The non root directory should also be read correctly. |
| 744 // There was a bug (crbug.com/181487), which broke this behavior. | 752 // There was a bug (crbug.com/181487), which broke this behavior. |
| 745 // Make sure this is fixed. | 753 // Make sure this is fixed. |
| 746 ASSERT_TRUE(entries.get()); | 754 ASSERT_TRUE(entries.get()); |
| (...skipping 1435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2182 | 2190 |
| 2183 // An app for foo.exe should now be found, as the registry was loaded. | 2191 // An app for foo.exe should now be found, as the registry was loaded. |
| 2184 drive_webapps_registry_->GetWebAppsForFile( | 2192 drive_webapps_registry_->GetWebAppsForFile( |
| 2185 base::FilePath(FILE_PATH_LITERAL("foo.exe")), | 2193 base::FilePath(FILE_PATH_LITERAL("foo.exe")), |
| 2186 "" /* mime_type */, | 2194 "" /* mime_type */, |
| 2187 &apps); | 2195 &apps); |
| 2188 EXPECT_EQ(1U, apps.size()); | 2196 EXPECT_EQ(1U, apps.size()); |
| 2189 } | 2197 } |
| 2190 | 2198 |
| 2191 } // namespace drive | 2199 } // namespace drive |
| OLD | NEW |