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 "components/drive/change_list_loader.h" | 5 #include "components/drive/change_list_loader.h" |
6 | 6 |
| 7 #include <stdint.h> |
| 8 |
7 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
8 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| 11 #include "base/macros.h" |
9 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
10 #include "base/prefs/testing_pref_service.h" | 13 #include "base/prefs/testing_pref_service.h" |
11 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
12 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
13 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
14 #include "components/drive/change_list_loader_observer.h" | 17 #include "components/drive/change_list_loader_observer.h" |
15 #include "components/drive/drive_test_util.h" | 18 #include "components/drive/drive_test_util.h" |
16 #include "components/drive/event_logger.h" | 19 #include "components/drive/event_logger.h" |
17 #include "components/drive/file_cache.h" | 20 #include "components/drive/file_cache.h" |
18 #include "components/drive/file_change.h" | 21 #include "components/drive/file_change.h" |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 // Since no resource is cached, this "Get" should trigger the update. | 155 // Since no resource is cached, this "Get" should trigger the update. |
153 about_resource_loader_->GetAboutResource( | 156 about_resource_loader_->GetAboutResource( |
154 google_apis::test_util::CreateCopyResultCallback(error + 0, about + 0)); | 157 google_apis::test_util::CreateCopyResultCallback(error + 0, about + 0)); |
155 // Since there is one in-flight update, the next "Get" just wait for it. | 158 // Since there is one in-flight update, the next "Get" just wait for it. |
156 about_resource_loader_->GetAboutResource( | 159 about_resource_loader_->GetAboutResource( |
157 google_apis::test_util::CreateCopyResultCallback(error + 1, about + 1)); | 160 google_apis::test_util::CreateCopyResultCallback(error + 1, about + 1)); |
158 | 161 |
159 base::RunLoop().RunUntilIdle(); | 162 base::RunLoop().RunUntilIdle(); |
160 EXPECT_EQ(google_apis::HTTP_SUCCESS, error[0]); | 163 EXPECT_EQ(google_apis::HTTP_SUCCESS, error[0]); |
161 EXPECT_EQ(google_apis::HTTP_SUCCESS, error[1]); | 164 EXPECT_EQ(google_apis::HTTP_SUCCESS, error[1]); |
162 const int64 first_changestamp = about[0]->largest_change_id(); | 165 const int64_t first_changestamp = about[0]->largest_change_id(); |
163 EXPECT_EQ(first_changestamp, about[1]->largest_change_id()); | 166 EXPECT_EQ(first_changestamp, about[1]->largest_change_id()); |
164 ASSERT_TRUE(about_resource_loader_->cached_about_resource()); | 167 ASSERT_TRUE(about_resource_loader_->cached_about_resource()); |
165 EXPECT_EQ( | 168 EXPECT_EQ( |
166 first_changestamp, | 169 first_changestamp, |
167 about_resource_loader_->cached_about_resource()->largest_change_id()); | 170 about_resource_loader_->cached_about_resource()->largest_change_id()); |
168 | 171 |
169 // Increment changestamp by 1. | 172 // Increment changestamp by 1. |
170 AddNewFile("temp"); | 173 AddNewFile("temp"); |
171 // Explicitly calling UpdateAboutResource will start another API call. | 174 // Explicitly calling UpdateAboutResource will start another API call. |
172 about_resource_loader_->UpdateAboutResource( | 175 about_resource_loader_->UpdateAboutResource( |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 EXPECT_EQ(0, drive_service_->about_resource_load_count()); | 218 EXPECT_EQ(0, drive_service_->about_resource_load_count()); |
216 | 219 |
217 FileError error = FILE_ERROR_FAILED; | 220 FileError error = FILE_ERROR_FAILED; |
218 change_list_loader_->LoadIfNeeded( | 221 change_list_loader_->LoadIfNeeded( |
219 google_apis::test_util::CreateCopyResultCallback(&error)); | 222 google_apis::test_util::CreateCopyResultCallback(&error)); |
220 EXPECT_TRUE(change_list_loader_->IsRefreshing()); | 223 EXPECT_TRUE(change_list_loader_->IsRefreshing()); |
221 base::RunLoop().RunUntilIdle(); | 224 base::RunLoop().RunUntilIdle(); |
222 EXPECT_EQ(FILE_ERROR_OK, error); | 225 EXPECT_EQ(FILE_ERROR_OK, error); |
223 | 226 |
224 EXPECT_FALSE(change_list_loader_->IsRefreshing()); | 227 EXPECT_FALSE(change_list_loader_->IsRefreshing()); |
225 int64 changestamp = 0; | 228 int64_t changestamp = 0; |
226 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetLargestChangestamp(&changestamp)); | 229 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetLargestChangestamp(&changestamp)); |
227 EXPECT_LT(0, changestamp); | 230 EXPECT_LT(0, changestamp); |
228 EXPECT_EQ(1, drive_service_->file_list_load_count()); | 231 EXPECT_EQ(1, drive_service_->file_list_load_count()); |
229 EXPECT_EQ(1, drive_service_->about_resource_load_count()); | 232 EXPECT_EQ(1, drive_service_->about_resource_load_count()); |
230 EXPECT_EQ(1, observer.initial_load_complete_count()); | 233 EXPECT_EQ(1, observer.initial_load_complete_count()); |
231 EXPECT_EQ(1, observer.load_from_server_complete_count()); | 234 EXPECT_EQ(1, observer.load_from_server_complete_count()); |
232 EXPECT_TRUE(observer.changed_files().empty()); | 235 EXPECT_TRUE(observer.changed_files().empty()); |
233 | 236 |
234 base::FilePath file_path = | 237 base::FilePath file_path = |
235 util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt"); | 238 util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt"); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 change_list_loader_->LoadIfNeeded( | 272 change_list_loader_->LoadIfNeeded( |
270 google_apis::test_util::CreateCopyResultCallback(&error)); | 273 google_apis::test_util::CreateCopyResultCallback(&error)); |
271 EXPECT_TRUE(change_list_loader_->IsRefreshing()); | 274 EXPECT_TRUE(change_list_loader_->IsRefreshing()); |
272 base::RunLoop().RunUntilIdle(); | 275 base::RunLoop().RunUntilIdle(); |
273 EXPECT_EQ(FILE_ERROR_OK, error); | 276 EXPECT_EQ(FILE_ERROR_OK, error); |
274 EXPECT_EQ(previous_file_list_load_count, | 277 EXPECT_EQ(previous_file_list_load_count, |
275 drive_service_->file_list_load_count()); | 278 drive_service_->file_list_load_count()); |
276 EXPECT_EQ(1, observer.initial_load_complete_count()); | 279 EXPECT_EQ(1, observer.initial_load_complete_count()); |
277 | 280 |
278 // Update should be checked by Load(). | 281 // Update should be checked by Load(). |
279 int64 changestamp = 0; | 282 int64_t changestamp = 0; |
280 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetLargestChangestamp(&changestamp)); | 283 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetLargestChangestamp(&changestamp)); |
281 EXPECT_EQ(drive_service_->about_resource().largest_change_id(), changestamp); | 284 EXPECT_EQ(drive_service_->about_resource().largest_change_id(), changestamp); |
282 EXPECT_EQ(1, drive_service_->change_list_load_count()); | 285 EXPECT_EQ(1, drive_service_->change_list_load_count()); |
283 EXPECT_EQ(1, observer.load_from_server_complete_count()); | 286 EXPECT_EQ(1, observer.load_from_server_complete_count()); |
284 EXPECT_TRUE( | 287 EXPECT_TRUE( |
285 observer.changed_files().CountDirectory(util::GetDriveMyDriveRootPath())); | 288 observer.changed_files().CountDirectory(util::GetDriveMyDriveRootPath())); |
286 | 289 |
287 base::FilePath file_path = | 290 base::FilePath file_path = |
288 util::GetDriveMyDriveRootPath().AppendASCII(gdata_entry->title()); | 291 util::GetDriveMyDriveRootPath().AppendASCII(gdata_entry->title()); |
289 ResourceEntry entry; | 292 ResourceEntry entry; |
290 EXPECT_EQ(FILE_ERROR_OK, | 293 EXPECT_EQ(FILE_ERROR_OK, |
291 metadata_->GetResourceEntryByPath(file_path, &entry)); | 294 metadata_->GetResourceEntryByPath(file_path, &entry)); |
292 } | 295 } |
293 | 296 |
294 TEST_F(ChangeListLoaderTest, CheckForUpdates) { | 297 TEST_F(ChangeListLoaderTest, CheckForUpdates) { |
295 // CheckForUpdates() results in no-op before load. | 298 // CheckForUpdates() results in no-op before load. |
296 FileError check_for_updates_error = FILE_ERROR_FAILED; | 299 FileError check_for_updates_error = FILE_ERROR_FAILED; |
297 change_list_loader_->CheckForUpdates( | 300 change_list_loader_->CheckForUpdates( |
298 google_apis::test_util::CreateCopyResultCallback( | 301 google_apis::test_util::CreateCopyResultCallback( |
299 &check_for_updates_error)); | 302 &check_for_updates_error)); |
300 EXPECT_FALSE(change_list_loader_->IsRefreshing()); | 303 EXPECT_FALSE(change_list_loader_->IsRefreshing()); |
301 base::RunLoop().RunUntilIdle(); | 304 base::RunLoop().RunUntilIdle(); |
302 EXPECT_EQ(FILE_ERROR_FAILED, | 305 EXPECT_EQ(FILE_ERROR_FAILED, |
303 check_for_updates_error); // Callback was not run. | 306 check_for_updates_error); // Callback was not run. |
304 int64 changestamp = 0; | 307 int64_t changestamp = 0; |
305 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetLargestChangestamp(&changestamp)); | 308 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetLargestChangestamp(&changestamp)); |
306 EXPECT_EQ(0, changestamp); | 309 EXPECT_EQ(0, changestamp); |
307 EXPECT_EQ(0, drive_service_->file_list_load_count()); | 310 EXPECT_EQ(0, drive_service_->file_list_load_count()); |
308 EXPECT_EQ(0, drive_service_->about_resource_load_count()); | 311 EXPECT_EQ(0, drive_service_->about_resource_load_count()); |
309 | 312 |
310 // Start initial load. | 313 // Start initial load. |
311 FileError load_error = FILE_ERROR_FAILED; | 314 FileError load_error = FILE_ERROR_FAILED; |
312 change_list_loader_->LoadIfNeeded( | 315 change_list_loader_->LoadIfNeeded( |
313 google_apis::test_util::CreateCopyResultCallback(&load_error)); | 316 google_apis::test_util::CreateCopyResultCallback(&load_error)); |
314 EXPECT_TRUE(change_list_loader_->IsRefreshing()); | 317 EXPECT_TRUE(change_list_loader_->IsRefreshing()); |
315 | 318 |
316 // CheckForUpdates() while loading. | 319 // CheckForUpdates() while loading. |
317 change_list_loader_->CheckForUpdates( | 320 change_list_loader_->CheckForUpdates( |
318 google_apis::test_util::CreateCopyResultCallback( | 321 google_apis::test_util::CreateCopyResultCallback( |
319 &check_for_updates_error)); | 322 &check_for_updates_error)); |
320 | 323 |
321 base::RunLoop().RunUntilIdle(); | 324 base::RunLoop().RunUntilIdle(); |
322 EXPECT_FALSE(change_list_loader_->IsRefreshing()); | 325 EXPECT_FALSE(change_list_loader_->IsRefreshing()); |
323 EXPECT_EQ(FILE_ERROR_OK, load_error); | 326 EXPECT_EQ(FILE_ERROR_OK, load_error); |
324 EXPECT_EQ(FILE_ERROR_OK, check_for_updates_error); | 327 EXPECT_EQ(FILE_ERROR_OK, check_for_updates_error); |
325 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetLargestChangestamp(&changestamp)); | 328 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetLargestChangestamp(&changestamp)); |
326 EXPECT_LT(0, changestamp); | 329 EXPECT_LT(0, changestamp); |
327 EXPECT_EQ(1, drive_service_->file_list_load_count()); | 330 EXPECT_EQ(1, drive_service_->file_list_load_count()); |
328 | 331 |
329 int64 previous_changestamp = 0; | 332 int64_t previous_changestamp = 0; |
330 EXPECT_EQ(FILE_ERROR_OK, | 333 EXPECT_EQ(FILE_ERROR_OK, |
331 metadata_->GetLargestChangestamp(&previous_changestamp)); | 334 metadata_->GetLargestChangestamp(&previous_changestamp)); |
332 // CheckForUpdates() results in no update. | 335 // CheckForUpdates() results in no update. |
333 change_list_loader_->CheckForUpdates( | 336 change_list_loader_->CheckForUpdates( |
334 google_apis::test_util::CreateCopyResultCallback( | 337 google_apis::test_util::CreateCopyResultCallback( |
335 &check_for_updates_error)); | 338 &check_for_updates_error)); |
336 EXPECT_TRUE(change_list_loader_->IsRefreshing()); | 339 EXPECT_TRUE(change_list_loader_->IsRefreshing()); |
337 base::RunLoop().RunUntilIdle(); | 340 base::RunLoop().RunUntilIdle(); |
338 EXPECT_FALSE(change_list_loader_->IsRefreshing()); | 341 EXPECT_FALSE(change_list_loader_->IsRefreshing()); |
339 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetLargestChangestamp(&changestamp)); | 342 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetLargestChangestamp(&changestamp)); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 | 395 |
393 // Unlock the loader, this should resume the pending update. | 396 // Unlock the loader, this should resume the pending update. |
394 lock.reset(); | 397 lock.reset(); |
395 base::RunLoop().RunUntilIdle(); | 398 base::RunLoop().RunUntilIdle(); |
396 EXPECT_TRUE( | 399 EXPECT_TRUE( |
397 observer.changed_files().CountDirectory(util::GetDriveMyDriveRootPath())); | 400 observer.changed_files().CountDirectory(util::GetDriveMyDriveRootPath())); |
398 } | 401 } |
399 | 402 |
400 } // namespace internal | 403 } // namespace internal |
401 } // namespace drive | 404 } // namespace drive |
OLD | NEW |