| OLD | NEW |
| 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 "chrome/browser/chromeos/drive/change_list_loader.h" | 5 #include "chrome/browser/chromeos/drive/change_list_loader.h" |
| 6 | 6 |
| 7 #include "base/callback_helpers.h" |
| 7 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/prefs/testing_pref_service.h" | 10 #include "base/prefs/testing_pref_service.h" |
| 10 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 11 #include "chrome/browser/chromeos/drive/change_list_loader_observer.h" | 12 #include "chrome/browser/chromeos/drive/change_list_loader_observer.h" |
| 12 #include "chrome/browser/chromeos/drive/file_cache.h" | 13 #include "chrome/browser/chromeos/drive/file_cache.h" |
| 13 #include "chrome/browser/chromeos/drive/file_system_util.h" | 14 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 14 #include "chrome/browser/chromeos/drive/job_scheduler.h" | 15 #include "chrome/browser/chromeos/drive/job_scheduler.h" |
| 15 #include "chrome/browser/chromeos/drive/resource_metadata.h" | 16 #include "chrome/browser/chromeos/drive/resource_metadata.h" |
| 16 #include "chrome/browser/chromeos/drive/test_util.h" | 17 #include "chrome/browser/chromeos/drive/test_util.h" |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 util::GetDriveMyDriveRootPath())); | 421 util::GetDriveMyDriveRootPath())); |
| 421 | 422 |
| 422 // The new file is found in the local metadata. | 423 // The new file is found in the local metadata. |
| 423 base::FilePath new_file_path = | 424 base::FilePath new_file_path = |
| 424 util::GetDriveMyDriveRootPath().AppendASCII(gdata_entry->title()); | 425 util::GetDriveMyDriveRootPath().AppendASCII(gdata_entry->title()); |
| 425 ResourceEntry entry; | 426 ResourceEntry entry; |
| 426 EXPECT_EQ(FILE_ERROR_OK, | 427 EXPECT_EQ(FILE_ERROR_OK, |
| 427 metadata_->GetResourceEntryByPath(new_file_path, &entry)); | 428 metadata_->GetResourceEntryByPath(new_file_path, &entry)); |
| 428 } | 429 } |
| 429 | 430 |
| 431 TEST_F(ChangeListLoaderTest, Lock) { |
| 432 FileError error = FILE_ERROR_FAILED; |
| 433 change_list_loader_->LoadForTesting( |
| 434 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 435 base::RunLoop().RunUntilIdle(); |
| 436 EXPECT_EQ(FILE_ERROR_OK, error); |
| 437 |
| 438 // Add a new file. |
| 439 scoped_ptr<google_apis::ResourceEntry> file = AddNewFile("New File"); |
| 440 ASSERT_TRUE(file); |
| 441 |
| 442 // Lock the loader. |
| 443 scoped_ptr<base::ScopedClosureRunner> lock = change_list_loader_->GetLock(); |
| 444 |
| 445 // Start update. |
| 446 TestChangeListLoaderObserver observer(change_list_loader_.get()); |
| 447 FileError check_for_updates_error = FILE_ERROR_FAILED; |
| 448 change_list_loader_->CheckForUpdates( |
| 449 google_apis::test_util::CreateCopyResultCallback( |
| 450 &check_for_updates_error)); |
| 451 base::RunLoop().RunUntilIdle(); |
| 452 |
| 453 // Update is pending due to the lock. |
| 454 EXPECT_TRUE(observer.changed_directories().empty()); |
| 455 |
| 456 // Unlock the loader, this should resume the pending udpate. |
| 457 lock.reset(); |
| 458 base::RunLoop().RunUntilIdle(); |
| 459 EXPECT_EQ(1U, observer.changed_directories().count( |
| 460 util::GetDriveMyDriveRootPath())); |
| 461 } |
| 462 |
| 430 } // namespace internal | 463 } // namespace internal |
| 431 } // namespace drive | 464 } // namespace drive |
| OLD | NEW |