Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1369)

Side by Side Diff: chrome/browser/chromeos/drive/sync_client_unittest.cc

Issue 276313002: drive: Change FileCache::GetCacheEntry's return type to FileError (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/sync_client.h" 5 #include "chrome/browser/chromeos/drive/sync_client.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 269
270 std::map<std::string, std::string> resource_ids_; // Name-to-id map. 270 std::map<std::string, std::string> resource_ids_; // Name-to-id map.
271 }; 271 };
272 272
273 TEST_F(SyncClientTest, StartProcessingBacklog) { 273 TEST_F(SyncClientTest, StartProcessingBacklog) {
274 sync_client_->StartProcessingBacklog(); 274 sync_client_->StartProcessingBacklog();
275 base::RunLoop().RunUntilIdle(); 275 base::RunLoop().RunUntilIdle();
276 276
277 FileCacheEntry cache_entry; 277 FileCacheEntry cache_entry;
278 // Pinned files get downloaded. 278 // Pinned files get downloaded.
279 EXPECT_TRUE(cache_->GetCacheEntry(GetLocalId("foo"), &cache_entry)); 279 EXPECT_EQ(FILE_ERROR_OK,
280 cache_->GetCacheEntry(GetLocalId("foo"), &cache_entry));
280 EXPECT_TRUE(cache_entry.is_present()); 281 EXPECT_TRUE(cache_entry.is_present());
281 282
282 EXPECT_TRUE(cache_->GetCacheEntry(GetLocalId("bar"), &cache_entry)); 283 EXPECT_EQ(FILE_ERROR_OK,
284 cache_->GetCacheEntry(GetLocalId("bar"), &cache_entry));
283 EXPECT_TRUE(cache_entry.is_present()); 285 EXPECT_TRUE(cache_entry.is_present());
284 286
285 EXPECT_TRUE(cache_->GetCacheEntry(GetLocalId("baz"), &cache_entry)); 287 EXPECT_EQ(FILE_ERROR_OK,
288 cache_->GetCacheEntry(GetLocalId("baz"), &cache_entry));
286 EXPECT_TRUE(cache_entry.is_present()); 289 EXPECT_TRUE(cache_entry.is_present());
287 290
288 // Dirty file gets uploaded. 291 // Dirty file gets uploaded.
289 EXPECT_TRUE(cache_->GetCacheEntry(GetLocalId("dirty"), &cache_entry)); 292 EXPECT_EQ(FILE_ERROR_OK,
293 cache_->GetCacheEntry(GetLocalId("dirty"), &cache_entry));
290 EXPECT_FALSE(cache_entry.is_dirty()); 294 EXPECT_FALSE(cache_entry.is_dirty());
291 295
292 // Removed entry is not found. 296 // Removed entry is not found.
293 google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR; 297 google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR;
294 scoped_ptr<google_apis::ResourceEntry> resource_entry; 298 scoped_ptr<google_apis::ResourceEntry> resource_entry;
295 drive_service_->GetResourceEntry( 299 drive_service_->GetResourceEntry(
296 resource_ids_["removed"], 300 resource_ids_["removed"],
297 google_apis::test_util::CreateCopyResultCallback(&status, 301 google_apis::test_util::CreateCopyResultCallback(&status,
298 &resource_entry)); 302 &resource_entry));
299 base::RunLoop().RunUntilIdle(); 303 base::RunLoop().RunUntilIdle();
(...skipping 11 matching lines...) Expand all
311 EXPECT_EQ(google_apis::HTTP_SUCCESS, status); 315 EXPECT_EQ(google_apis::HTTP_SUCCESS, status);
312 ASSERT_TRUE(resource_entry); 316 ASSERT_TRUE(resource_entry);
313 EXPECT_EQ("moved_new_title", resource_entry->title()); 317 EXPECT_EQ("moved_new_title", resource_entry->title());
314 } 318 }
315 319
316 TEST_F(SyncClientTest, AddFetchTask) { 320 TEST_F(SyncClientTest, AddFetchTask) {
317 sync_client_->AddFetchTask(GetLocalId("foo")); 321 sync_client_->AddFetchTask(GetLocalId("foo"));
318 base::RunLoop().RunUntilIdle(); 322 base::RunLoop().RunUntilIdle();
319 323
320 FileCacheEntry cache_entry; 324 FileCacheEntry cache_entry;
321 EXPECT_TRUE(cache_->GetCacheEntry(GetLocalId("foo"), &cache_entry)); 325 EXPECT_EQ(FILE_ERROR_OK,
326 cache_->GetCacheEntry(GetLocalId("foo"), &cache_entry));
322 EXPECT_TRUE(cache_entry.is_present()); 327 EXPECT_TRUE(cache_entry.is_present());
323 } 328 }
324 329
325 TEST_F(SyncClientTest, AddFetchTaskAndCancelled) { 330 TEST_F(SyncClientTest, AddFetchTaskAndCancelled) {
326 // Trigger fetching of a file which results in cancellation. 331 // Trigger fetching of a file which results in cancellation.
327 drive_service_->set_resource_id_to_be_cancelled(resource_ids_["foo"]); 332 drive_service_->set_resource_id_to_be_cancelled(resource_ids_["foo"]);
328 sync_client_->AddFetchTask(GetLocalId("foo")); 333 sync_client_->AddFetchTask(GetLocalId("foo"));
329 base::RunLoop().RunUntilIdle(); 334 base::RunLoop().RunUntilIdle();
330 335
331 // The file should be unpinned if the user wants the download to be cancelled. 336 // The file should be unpinned if the user wants the download to be cancelled.
332 FileCacheEntry cache_entry; 337 FileCacheEntry cache_entry;
333 EXPECT_FALSE(cache_->GetCacheEntry(GetLocalId("foo"), &cache_entry)); 338 EXPECT_EQ(FILE_ERROR_NOT_FOUND,
339 cache_->GetCacheEntry(GetLocalId("foo"), &cache_entry));
334 } 340 }
335 341
336 TEST_F(SyncClientTest, RemoveFetchTask) { 342 TEST_F(SyncClientTest, RemoveFetchTask) {
337 sync_client_->AddFetchTask(GetLocalId("foo")); 343 sync_client_->AddFetchTask(GetLocalId("foo"));
338 sync_client_->AddFetchTask(GetLocalId("bar")); 344 sync_client_->AddFetchTask(GetLocalId("bar"));
339 sync_client_->AddFetchTask(GetLocalId("baz")); 345 sync_client_->AddFetchTask(GetLocalId("baz"));
340 346
341 sync_client_->RemoveFetchTask(GetLocalId("foo")); 347 sync_client_->RemoveFetchTask(GetLocalId("foo"));
342 sync_client_->RemoveFetchTask(GetLocalId("baz")); 348 sync_client_->RemoveFetchTask(GetLocalId("baz"));
343 base::RunLoop().RunUntilIdle(); 349 base::RunLoop().RunUntilIdle();
344 350
345 // Only "bar" should be fetched. 351 // Only "bar" should be fetched.
346 FileCacheEntry cache_entry; 352 FileCacheEntry cache_entry;
347 EXPECT_TRUE(cache_->GetCacheEntry(GetLocalId("foo"), &cache_entry)); 353 EXPECT_EQ(FILE_ERROR_OK,
354 cache_->GetCacheEntry(GetLocalId("foo"), &cache_entry));
348 EXPECT_FALSE(cache_entry.is_present()); 355 EXPECT_FALSE(cache_entry.is_present());
349 356
350 EXPECT_TRUE(cache_->GetCacheEntry(GetLocalId("bar"), &cache_entry)); 357 EXPECT_EQ(FILE_ERROR_OK,
358 cache_->GetCacheEntry(GetLocalId("bar"), &cache_entry));
351 EXPECT_TRUE(cache_entry.is_present()); 359 EXPECT_TRUE(cache_entry.is_present());
352 360
353 EXPECT_TRUE(cache_->GetCacheEntry(GetLocalId("baz"), &cache_entry)); 361 EXPECT_EQ(FILE_ERROR_OK,
362 cache_->GetCacheEntry(GetLocalId("baz"), &cache_entry));
354 EXPECT_FALSE(cache_entry.is_present()); 363 EXPECT_FALSE(cache_entry.is_present());
355 364
356 } 365 }
357 366
358 TEST_F(SyncClientTest, ExistingPinnedFiles) { 367 TEST_F(SyncClientTest, ExistingPinnedFiles) {
359 // Start checking the existing pinned files. This will collect the resource 368 // Start checking the existing pinned files. This will collect the resource
360 // IDs of pinned files, with stale local cache files. 369 // IDs of pinned files, with stale local cache files.
361 sync_client_->StartCheckingExistingPinnedFiles(); 370 sync_client_->StartCheckingExistingPinnedFiles();
362 base::RunLoop().RunUntilIdle(); 371 base::RunLoop().RunUntilIdle();
363 372
(...skipping 26 matching lines...) Expand all
390 TestTimeouts::tiny_timeout()); 399 TestTimeouts::tiny_timeout());
391 400
392 // Try fetch and upload. 401 // Try fetch and upload.
393 sync_client_->AddFetchTask(GetLocalId("foo")); 402 sync_client_->AddFetchTask(GetLocalId("foo"));
394 sync_client_->AddUpdateTask(ClientContext(USER_INITIATED), 403 sync_client_->AddUpdateTask(ClientContext(USER_INITIATED),
395 GetLocalId("dirty")); 404 GetLocalId("dirty"));
396 base::RunLoop().RunUntilIdle(); 405 base::RunLoop().RunUntilIdle();
397 406
398 // Not yet fetched nor uploaded. 407 // Not yet fetched nor uploaded.
399 FileCacheEntry cache_entry; 408 FileCacheEntry cache_entry;
400 EXPECT_TRUE(cache_->GetCacheEntry(GetLocalId("foo"), &cache_entry)); 409 EXPECT_EQ(FILE_ERROR_OK,
410 cache_->GetCacheEntry(GetLocalId("foo"), &cache_entry));
401 EXPECT_FALSE(cache_entry.is_present()); 411 EXPECT_FALSE(cache_entry.is_present());
402 EXPECT_TRUE(cache_->GetCacheEntry(GetLocalId("dirty"), &cache_entry)); 412 EXPECT_EQ(FILE_ERROR_OK,
413 cache_->GetCacheEntry(GetLocalId("dirty"), &cache_entry));
403 EXPECT_TRUE(cache_entry.is_dirty()); 414 EXPECT_TRUE(cache_entry.is_dirty());
404 415
405 // Switch to online. 416 // Switch to online.
406 fake_network_change_notifier_->SetConnectionType( 417 fake_network_change_notifier_->SetConnectionType(
407 net::NetworkChangeNotifier::CONNECTION_WIFI); 418 net::NetworkChangeNotifier::CONNECTION_WIFI);
408 drive_service_->set_offline(false); 419 drive_service_->set_offline(false);
409 base::RunLoop().RunUntilIdle(); 420 base::RunLoop().RunUntilIdle();
410 421
411 // Fetched and uploaded. 422 // Fetched and uploaded.
412 EXPECT_TRUE(cache_->GetCacheEntry(GetLocalId("foo"), &cache_entry)); 423 EXPECT_EQ(FILE_ERROR_OK,
424 cache_->GetCacheEntry(GetLocalId("foo"), &cache_entry));
413 EXPECT_TRUE(cache_entry.is_present()); 425 EXPECT_TRUE(cache_entry.is_present());
414 EXPECT_TRUE(cache_->GetCacheEntry(GetLocalId("dirty"), &cache_entry)); 426 EXPECT_EQ(FILE_ERROR_OK,
427 cache_->GetCacheEntry(GetLocalId("dirty"), &cache_entry));
415 EXPECT_FALSE(cache_entry.is_dirty()); 428 EXPECT_FALSE(cache_entry.is_dirty());
416 } 429 }
417 430
418 TEST_F(SyncClientTest, ScheduleRerun) { 431 TEST_F(SyncClientTest, ScheduleRerun) {
419 // Add a fetch task for "foo", this should result in being paused. 432 // Add a fetch task for "foo", this should result in being paused.
420 drive_service_->set_resource_id_to_be_paused(resource_ids_["foo"]); 433 drive_service_->set_resource_id_to_be_paused(resource_ids_["foo"]);
421 sync_client_->AddFetchTask(GetLocalId("foo")); 434 sync_client_->AddFetchTask(GetLocalId("foo"));
422 base::RunLoop().RunUntilIdle(); 435 base::RunLoop().RunUntilIdle();
423 436
424 // While the first task is paused, add a task again. 437 // While the first task is paused, add a task again.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 483
471 // Both entries are synced. 484 // Both entries are synced.
472 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetResourceEntryById(local_id1, &entry1)); 485 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetResourceEntryById(local_id1, &entry1));
473 EXPECT_EQ(ResourceEntry::CLEAN, entry1.metadata_edit_state()); 486 EXPECT_EQ(ResourceEntry::CLEAN, entry1.metadata_edit_state());
474 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetResourceEntryById(local_id2, &entry2)); 487 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetResourceEntryById(local_id2, &entry2));
475 EXPECT_EQ(ResourceEntry::CLEAN, entry2.metadata_edit_state()); 488 EXPECT_EQ(ResourceEntry::CLEAN, entry2.metadata_edit_state());
476 } 489 }
477 490
478 } // namespace internal 491 } // namespace internal
479 } // namespace drive 492 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698