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/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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 scoped_ptr<JobScheduler> scheduler_; | 136 scoped_ptr<JobScheduler> scheduler_; |
137 scoped_ptr<ResourceMetadataStorage, | 137 scoped_ptr<ResourceMetadataStorage, |
138 test_util::DestroyHelperForTests> metadata_storage_; | 138 test_util::DestroyHelperForTests> metadata_storage_; |
139 scoped_ptr<FileCache, test_util::DestroyHelperForTests> cache_; | 139 scoped_ptr<FileCache, test_util::DestroyHelperForTests> cache_; |
140 scoped_ptr<ResourceMetadata, test_util::DestroyHelperForTests> metadata_; | 140 scoped_ptr<ResourceMetadata, test_util::DestroyHelperForTests> metadata_; |
141 scoped_ptr<AboutResourceLoader> about_resource_loader_; | 141 scoped_ptr<AboutResourceLoader> about_resource_loader_; |
142 scoped_ptr<LoaderController> loader_controller_; | 142 scoped_ptr<LoaderController> loader_controller_; |
143 scoped_ptr<ChangeListLoader> change_list_loader_; | 143 scoped_ptr<ChangeListLoader> change_list_loader_; |
144 }; | 144 }; |
145 | 145 |
| 146 TEST_F(ChangeListLoaderTest, AboutResourceLoader) { |
| 147 google_apis::GDataErrorCode error[6] = {}; |
| 148 scoped_ptr<google_apis::AboutResource> about[6]; |
| 149 |
| 150 // No resource is cached at the beginning. |
| 151 ASSERT_FALSE(about_resource_loader_->cached_about_resource()); |
| 152 |
| 153 // Since no resource is cached, this "Get" should trigger the update. |
| 154 about_resource_loader_->GetAboutResource( |
| 155 google_apis::test_util::CreateCopyResultCallback(error + 0, about + 0)); |
| 156 // Since there is one in-flight update, the next "Get" just wait for it. |
| 157 about_resource_loader_->GetAboutResource( |
| 158 google_apis::test_util::CreateCopyResultCallback(error + 1, about + 1)); |
| 159 |
| 160 base::RunLoop().RunUntilIdle(); |
| 161 EXPECT_EQ(google_apis::HTTP_SUCCESS, error[0]); |
| 162 EXPECT_EQ(google_apis::HTTP_SUCCESS, error[1]); |
| 163 const int64 first_changestamp = about[0]->largest_change_id(); |
| 164 EXPECT_EQ(first_changestamp, about[1]->largest_change_id()); |
| 165 ASSERT_TRUE(about_resource_loader_->cached_about_resource()); |
| 166 EXPECT_EQ( |
| 167 first_changestamp, |
| 168 about_resource_loader_->cached_about_resource()->largest_change_id()); |
| 169 |
| 170 // Increment changestamp by 1. |
| 171 AddNewFile("temp"); |
| 172 // Explicitly calling UpdateAboutResource will start another API call. |
| 173 about_resource_loader_->UpdateAboutResource( |
| 174 google_apis::test_util::CreateCopyResultCallback(error + 2, about + 2)); |
| 175 // It again waits for the in-flight UpdateAboutResoure call, even though this |
| 176 // time there is a cached result. |
| 177 about_resource_loader_->GetAboutResource( |
| 178 google_apis::test_util::CreateCopyResultCallback(error + 3, about + 3)); |
| 179 |
| 180 base::RunLoop().RunUntilIdle(); |
| 181 EXPECT_EQ(google_apis::HTTP_SUCCESS, error[2]); |
| 182 EXPECT_EQ(google_apis::HTTP_SUCCESS, error[3]); |
| 183 EXPECT_EQ(first_changestamp + 1, about[2]->largest_change_id()); |
| 184 EXPECT_EQ(first_changestamp + 1, about[3]->largest_change_id()); |
| 185 EXPECT_EQ( |
| 186 first_changestamp + 1, |
| 187 about_resource_loader_->cached_about_resource()->largest_change_id()); |
| 188 |
| 189 // Increment changestamp by 1. |
| 190 AddNewFile("temp2"); |
| 191 // Now no UpdateAboutResource task is running. Returns the cached result. |
| 192 about_resource_loader_->GetAboutResource( |
| 193 google_apis::test_util::CreateCopyResultCallback(error + 4, about + 4)); |
| 194 // Explicitly calling UpdateAboutResource will start another API call. |
| 195 about_resource_loader_->UpdateAboutResource( |
| 196 google_apis::test_util::CreateCopyResultCallback(error + 5, about + 5)); |
| 197 |
| 198 base::RunLoop().RunUntilIdle(); |
| 199 EXPECT_EQ(google_apis::HTTP_NO_CONTENT, error[4]); |
| 200 EXPECT_EQ(google_apis::HTTP_SUCCESS, error[5]); |
| 201 EXPECT_EQ(first_changestamp + 1, about[4]->largest_change_id()); |
| 202 EXPECT_EQ(first_changestamp + 2, about[5]->largest_change_id()); |
| 203 EXPECT_EQ( |
| 204 first_changestamp + 2, |
| 205 about_resource_loader_->cached_about_resource()->largest_change_id()); |
| 206 |
| 207 EXPECT_EQ(3, drive_service_->about_resource_load_count()); |
| 208 } |
| 209 |
146 TEST_F(ChangeListLoaderTest, Load) { | 210 TEST_F(ChangeListLoaderTest, Load) { |
147 EXPECT_FALSE(change_list_loader_->IsRefreshing()); | 211 EXPECT_FALSE(change_list_loader_->IsRefreshing()); |
148 | 212 |
149 // Start initial load. | 213 // Start initial load. |
150 TestChangeListLoaderObserver observer(change_list_loader_.get()); | 214 TestChangeListLoaderObserver observer(change_list_loader_.get()); |
151 | 215 |
152 EXPECT_EQ(0, drive_service_->about_resource_load_count()); | 216 EXPECT_EQ(0, drive_service_->about_resource_load_count()); |
153 | 217 |
154 FileError error = FILE_ERROR_FAILED; | 218 FileError error = FILE_ERROR_FAILED; |
155 change_list_loader_->LoadIfNeeded( | 219 change_list_loader_->LoadIfNeeded( |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 | 392 |
329 // Unlock the loader, this should resume the pending udpate. | 393 // Unlock the loader, this should resume the pending udpate. |
330 lock.reset(); | 394 lock.reset(); |
331 base::RunLoop().RunUntilIdle(); | 395 base::RunLoop().RunUntilIdle(); |
332 EXPECT_TRUE( | 396 EXPECT_TRUE( |
333 observer.changed_files().CountDirectory(util::GetDriveMyDriveRootPath())); | 397 observer.changed_files().CountDirectory(util::GetDriveMyDriveRootPath())); |
334 } | 398 } |
335 | 399 |
336 } // namespace internal | 400 } // namespace internal |
337 } // namespace drive | 401 } // namespace drive |
OLD | NEW |