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/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/prefs/testing_pref_service.h" | 9 #include "base/prefs/testing_pref_service.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 | 62 |
63 private: | 63 private: |
64 ChangeListLoader* loader_; | 64 ChangeListLoader* loader_; |
65 std::set<base::FilePath> changed_directories_; | 65 std::set<base::FilePath> changed_directories_; |
66 int load_from_server_complete_count_; | 66 int load_from_server_complete_count_; |
67 int initial_load_complete_count_; | 67 int initial_load_complete_count_; |
68 | 68 |
69 DISALLOW_COPY_AND_ASSIGN(TestChangeListLoaderObserver); | 69 DISALLOW_COPY_AND_ASSIGN(TestChangeListLoaderObserver); |
70 }; | 70 }; |
71 | 71 |
72 class TestDriveService : public FakeDriveService { | |
73 public: | |
74 TestDriveService() : never_return_all_resource_list_(false), | |
75 blocked_call_count_(0) {} | |
76 | |
77 void set_never_return_all_resource_list(bool value) { | |
78 never_return_all_resource_list_ = value; | |
79 } | |
80 | |
81 int blocked_call_count() const { return blocked_call_count_; } | |
82 | |
83 // FakeDriveService override. | |
84 virtual google_apis::CancelCallback GetAllResourceList( | |
85 const google_apis::GetResourceListCallback& callback) OVERRIDE { | |
86 if (never_return_all_resource_list_) { | |
87 ++blocked_call_count_; | |
88 return google_apis::CancelCallback(); | |
89 } | |
90 return FakeDriveService::GetAllResourceList(callback); | |
91 } | |
92 | |
93 private: | |
94 // GetAllResourceList never returns result when this is set to true. | |
95 // Used to emulate the real server's slowness. | |
96 bool never_return_all_resource_list_; | |
97 | |
98 int blocked_call_count_; // Number of blocked method calls. | |
99 }; | |
100 | |
101 class ChangeListLoaderTest : public testing::Test { | 72 class ChangeListLoaderTest : public testing::Test { |
102 protected: | 73 protected: |
103 virtual void SetUp() OVERRIDE { | 74 virtual void SetUp() OVERRIDE { |
104 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 75 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
105 pref_service_.reset(new TestingPrefServiceSimple); | 76 pref_service_.reset(new TestingPrefServiceSimple); |
106 test_util::RegisterDrivePrefs(pref_service_->registry()); | 77 test_util::RegisterDrivePrefs(pref_service_->registry()); |
107 | 78 |
108 drive_service_.reset(new TestDriveService); | 79 drive_service_.reset(new FakeDriveService); |
109 ASSERT_TRUE(drive_service_->LoadResourceListForWapi( | 80 ASSERT_TRUE(drive_service_->LoadResourceListForWapi( |
110 "gdata/root_feed.json")); | 81 "gdata/root_feed.json")); |
111 ASSERT_TRUE(drive_service_->LoadAccountMetadataForWapi( | 82 ASSERT_TRUE(drive_service_->LoadAccountMetadataForWapi( |
112 "gdata/account_metadata.json")); | 83 "gdata/account_metadata.json")); |
113 | 84 |
114 scheduler_.reset(new JobScheduler(pref_service_.get(), | 85 scheduler_.reset(new JobScheduler(pref_service_.get(), |
115 drive_service_.get(), | 86 drive_service_.get(), |
116 base::MessageLoopProxy::current().get())); | 87 base::MessageLoopProxy::current().get())); |
117 metadata_storage_.reset(new ResourceMetadataStorage( | 88 metadata_storage_.reset(new ResourceMetadataStorage( |
118 temp_dir_.path(), base::MessageLoopProxy::current().get())); | 89 temp_dir_.path(), base::MessageLoopProxy::current().get())); |
(...skipping 28 matching lines...) Expand all Loading... |
147 false, // shared_with_me | 118 false, // shared_with_me |
148 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); | 119 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); |
149 base::RunLoop().RunUntilIdle(); | 120 base::RunLoop().RunUntilIdle(); |
150 EXPECT_EQ(google_apis::HTTP_CREATED, error); | 121 EXPECT_EQ(google_apis::HTTP_CREATED, error); |
151 return entry.Pass(); | 122 return entry.Pass(); |
152 } | 123 } |
153 | 124 |
154 content::TestBrowserThreadBundle thread_bundle_; | 125 content::TestBrowserThreadBundle thread_bundle_; |
155 base::ScopedTempDir temp_dir_; | 126 base::ScopedTempDir temp_dir_; |
156 scoped_ptr<TestingPrefServiceSimple> pref_service_; | 127 scoped_ptr<TestingPrefServiceSimple> pref_service_; |
157 scoped_ptr<TestDriveService> drive_service_; | 128 scoped_ptr<FakeDriveService> drive_service_; |
158 scoped_ptr<JobScheduler> scheduler_; | 129 scoped_ptr<JobScheduler> scheduler_; |
159 scoped_ptr<ResourceMetadataStorage, | 130 scoped_ptr<ResourceMetadataStorage, |
160 test_util::DestroyHelperForTests> metadata_storage_; | 131 test_util::DestroyHelperForTests> metadata_storage_; |
161 scoped_ptr<ResourceMetadata, test_util::DestroyHelperForTests> metadata_; | 132 scoped_ptr<ResourceMetadata, test_util::DestroyHelperForTests> metadata_; |
162 scoped_ptr<FileCache, test_util::DestroyHelperForTests> cache_; | 133 scoped_ptr<FileCache, test_util::DestroyHelperForTests> cache_; |
163 scoped_ptr<ChangeListLoader> change_list_loader_; | 134 scoped_ptr<ChangeListLoader> change_list_loader_; |
164 }; | 135 }; |
165 | 136 |
166 TEST_F(ChangeListLoaderTest, LoadIfNeeded) { | 137 TEST_F(ChangeListLoaderTest, LoadIfNeeded) { |
167 EXPECT_FALSE(change_list_loader_->IsRefreshing()); | 138 EXPECT_FALSE(change_list_loader_->IsRefreshing()); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 change_list_loader_->LoadIfNeeded( | 240 change_list_loader_->LoadIfNeeded( |
270 DirectoryFetchInfo(util::kDriveGrandRootSpecialResourceId, 0), | 241 DirectoryFetchInfo(util::kDriveGrandRootSpecialResourceId, 0), |
271 google_apis::test_util::CreateCopyResultCallback(&error)); | 242 google_apis::test_util::CreateCopyResultCallback(&error)); |
272 base::RunLoop().RunUntilIdle(); | 243 base::RunLoop().RunUntilIdle(); |
273 EXPECT_EQ(FILE_ERROR_OK, error); | 244 EXPECT_EQ(FILE_ERROR_OK, error); |
274 EXPECT_EQ(1U, observer.changed_directories().count( | 245 EXPECT_EQ(1U, observer.changed_directories().count( |
275 util::GetDriveGrandRootPath())); | 246 util::GetDriveGrandRootPath())); |
276 observer.clear_changed_directories(); | 247 observer.clear_changed_directories(); |
277 | 248 |
278 // GetAllResourceList() was called. | 249 // GetAllResourceList() was called. |
279 EXPECT_EQ(1, drive_service_->blocked_call_count()); | 250 EXPECT_EQ(1, drive_service_->blocked_resource_list_load_count()); |
280 | 251 |
281 // My Drive is present in the local metadata, but its child is not. | 252 // My Drive is present in the local metadata, but its child is not. |
282 ResourceEntry entry; | 253 ResourceEntry entry; |
283 EXPECT_EQ(FILE_ERROR_OK, | 254 EXPECT_EQ(FILE_ERROR_OK, |
284 metadata_->GetResourceEntryByPath(util::GetDriveMyDriveRootPath(), | 255 metadata_->GetResourceEntryByPath(util::GetDriveMyDriveRootPath(), |
285 &entry)); | 256 &entry)); |
286 const int64 mydrive_changestamp = | 257 const int64 mydrive_changestamp = |
287 entry.directory_specific_info().changestamp(); | 258 entry.directory_specific_info().changestamp(); |
288 | 259 |
289 base::FilePath file_path = | 260 base::FilePath file_path = |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 // The new file is found in the local metadata. | 407 // The new file is found in the local metadata. |
437 base::FilePath new_file_path = | 408 base::FilePath new_file_path = |
438 util::GetDriveMyDriveRootPath().AppendASCII(gdata_entry->title()); | 409 util::GetDriveMyDriveRootPath().AppendASCII(gdata_entry->title()); |
439 ResourceEntry entry; | 410 ResourceEntry entry; |
440 EXPECT_EQ(FILE_ERROR_OK, | 411 EXPECT_EQ(FILE_ERROR_OK, |
441 metadata_->GetResourceEntryByPath(new_file_path, &entry)); | 412 metadata_->GetResourceEntryByPath(new_file_path, &entry)); |
442 } | 413 } |
443 | 414 |
444 } // namespace internal | 415 } // namespace internal |
445 } // namespace drive | 416 } // namespace drive |
OLD | NEW |