| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/directory_loader.h" | 5 #include "chrome/browser/chromeos/drive/directory_loader.h" |
| 6 | 6 |
| 7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
| 8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/prefs/testing_pref_service.h" | 10 #include "base/prefs/testing_pref_service.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| 32 class TestDirectoryLoaderObserver : public ChangeListLoaderObserver { | 32 class TestDirectoryLoaderObserver : public ChangeListLoaderObserver { |
| 33 public: | 33 public: |
| 34 explicit TestDirectoryLoaderObserver(DirectoryLoader* loader) | 34 explicit TestDirectoryLoaderObserver(DirectoryLoader* loader) |
| 35 : loader_(loader) { | 35 : loader_(loader) { |
| 36 loader_->AddObserver(this); | 36 loader_->AddObserver(this); |
| 37 } | 37 } |
| 38 | 38 |
| 39 virtual ~TestDirectoryLoaderObserver() { | 39 ~TestDirectoryLoaderObserver() override { loader_->RemoveObserver(this); } |
| 40 loader_->RemoveObserver(this); | |
| 41 } | |
| 42 | 40 |
| 43 const std::set<base::FilePath>& changed_directories() const { | 41 const std::set<base::FilePath>& changed_directories() const { |
| 44 return changed_directories_; | 42 return changed_directories_; |
| 45 } | 43 } |
| 46 void clear_changed_directories() { changed_directories_.clear(); } | 44 void clear_changed_directories() { changed_directories_.clear(); } |
| 47 | 45 |
| 48 // ChageListObserver overrides: | 46 // ChageListObserver overrides: |
| 49 virtual void OnDirectoryReloaded( | 47 void OnDirectoryReloaded(const base::FilePath& directory_path) override { |
| 50 const base::FilePath& directory_path) override { | |
| 51 changed_directories_.insert(directory_path); | 48 changed_directories_.insert(directory_path); |
| 52 } | 49 } |
| 53 | 50 |
| 54 private: | 51 private: |
| 55 DirectoryLoader* loader_; | 52 DirectoryLoader* loader_; |
| 56 std::set<base::FilePath> changed_directories_; | 53 std::set<base::FilePath> changed_directories_; |
| 57 | 54 |
| 58 DISALLOW_COPY_AND_ASSIGN(TestDirectoryLoaderObserver); | 55 DISALLOW_COPY_AND_ASSIGN(TestDirectoryLoaderObserver); |
| 59 }; | 56 }; |
| 60 | 57 |
| 61 void AccumulateReadDirectoryResult(ResourceEntryVector* out_entries, | 58 void AccumulateReadDirectoryResult(ResourceEntryVector* out_entries, |
| 62 scoped_ptr<ResourceEntryVector> entries) { | 59 scoped_ptr<ResourceEntryVector> entries) { |
| 63 ASSERT_TRUE(entries); | 60 ASSERT_TRUE(entries); |
| 64 out_entries->insert(out_entries->end(), entries->begin(), entries->end()); | 61 out_entries->insert(out_entries->end(), entries->begin(), entries->end()); |
| 65 } | 62 } |
| 66 | 63 |
| 67 } // namespace | 64 } // namespace |
| 68 | 65 |
| 69 class DirectoryLoaderTest : public testing::Test { | 66 class DirectoryLoaderTest : public testing::Test { |
| 70 protected: | 67 protected: |
| 71 virtual void SetUp() override { | 68 void SetUp() override { |
| 72 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 69 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 73 pref_service_.reset(new TestingPrefServiceSimple); | 70 pref_service_.reset(new TestingPrefServiceSimple); |
| 74 test_util::RegisterDrivePrefs(pref_service_->registry()); | 71 test_util::RegisterDrivePrefs(pref_service_->registry()); |
| 75 | 72 |
| 76 logger_.reset(new EventLogger); | 73 logger_.reset(new EventLogger); |
| 77 | 74 |
| 78 drive_service_.reset(new FakeDriveService); | 75 drive_service_.reset(new FakeDriveService); |
| 79 ASSERT_TRUE(test_util::SetUpTestEntries(drive_service_.get())); | 76 ASSERT_TRUE(test_util::SetUpTestEntries(drive_service_.get())); |
| 80 | 77 |
| 81 scheduler_.reset(new JobScheduler(pref_service_.get(), | 78 scheduler_.reset(new JobScheduler(pref_service_.get(), |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 | 240 |
| 244 // Unlock the loader, this should resume the pending udpate. | 241 // Unlock the loader, this should resume the pending udpate. |
| 245 lock.reset(); | 242 lock.reset(); |
| 246 base::RunLoop().RunUntilIdle(); | 243 base::RunLoop().RunUntilIdle(); |
| 247 EXPECT_EQ(1U, observer.changed_directories().count( | 244 EXPECT_EQ(1U, observer.changed_directories().count( |
| 248 util::GetDriveMyDriveRootPath())); | 245 util::GetDriveMyDriveRootPath())); |
| 249 } | 246 } |
| 250 | 247 |
| 251 } // namespace internal | 248 } // namespace internal |
| 252 } // namespace drive | 249 } // namespace drive |
| OLD | NEW |