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

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

Issue 11620007: Switch from OnIPAddressChanged and OnConnectionTypeChange to OnNetworkChanged Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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/drive_sync_client.h" 5 #include "chrome/browser/chromeos/drive/drive_sync_client.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 } 144 }
145 145
146 // Sets up MockNetworkChangeNotifier as if it's connected to a network with 146 // Sets up MockNetworkChangeNotifier as if it's connected to a network with
147 // the specified connection type. 147 // the specified connection type.
148 void ChangeConnectionType(net::NetworkChangeNotifier::ConnectionType type) { 148 void ChangeConnectionType(net::NetworkChangeNotifier::ConnectionType type) {
149 EXPECT_CALL(*mock_network_change_notifier_, GetCurrentConnectionType()) 149 EXPECT_CALL(*mock_network_change_notifier_, GetCurrentConnectionType())
150 .WillRepeatedly(Return(type)); 150 .WillRepeatedly(Return(type));
151 // Notify the sync client that the network is changed. This is done via 151 // Notify the sync client that the network is changed. This is done via
152 // NetworkChangeNotifier in production, but here, we simulate the behavior 152 // NetworkChangeNotifier in production, but here, we simulate the behavior
153 // by directly calling OnConnectionTypeChanged(). 153 // by directly calling OnConnectionTypeChanged().
154 sync_client_->OnConnectionTypeChanged(type); 154 sync_client_->OnNetworkChanged(type);
155 } 155 }
156 156
157 // Sets up MockNetworkChangeNotifier as if it's connected to wifi network. 157 // Sets up MockNetworkChangeNotifier as if it's connected to wifi network.
158 void ConnectToWifi() { 158 void ConnectToWifi() {
159 ChangeConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); 159 ChangeConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
160 } 160 }
161 161
162 // Sets up MockNetworkChangeNotifier as if it's connected to cellular network. 162 // Sets up MockNetworkChangeNotifier as if it's connected to cellular network.
163 void ConnectToCellular() { 163 void ConnectToCellular() {
164 ChangeConnectionType(net::NetworkChangeNotifier::CONNECTION_2G); 164 ChangeConnectionType(net::NetworkChangeNotifier::CONNECTION_2G);
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 AddResourceIdToFetch("resource_id_not_fetched_baz"); 377 AddResourceIdToFetch("resource_id_not_fetched_baz");
378 AddResourceIdToUpload("resource_id_dirty"); 378 AddResourceIdToUpload("resource_id_dirty");
379 379
380 // These files will be fetched or uploaded by DriveFileSystem, once 380 // These files will be fetched or uploaded by DriveFileSystem, once
381 // StartSyncLoop() starts. 381 // StartSyncLoop() starts.
382 SetExpectationForGetFileByResourceId("resource_id_not_fetched_foo"); 382 SetExpectationForGetFileByResourceId("resource_id_not_fetched_foo");
383 SetExpectationForGetFileByResourceId("resource_id_not_fetched_bar"); 383 SetExpectationForGetFileByResourceId("resource_id_not_fetched_bar");
384 SetExpectationForGetFileByResourceId("resource_id_not_fetched_baz"); 384 SetExpectationForGetFileByResourceId("resource_id_not_fetched_baz");
385 SetExpectationForUpdateFileByResourceId("resource_id_dirty"); 385 SetExpectationForUpdateFileByResourceId("resource_id_dirty");
386 386
387 sync_client_->StartSyncLoop(); 387 sync_client_->StartSyncLoop(false);
388 } 388 }
389 389
390 TEST_F(DriveSyncClientTest, StartSyncLoop_Offline) { 390 TEST_F(DriveSyncClientTest, StartSyncLoop_Offline) {
391 ConnectToNone(); 391 ConnectToNone();
392 392
393 AddResourceIdToFetch("resource_id_not_fetched_foo"); 393 AddResourceIdToFetch("resource_id_not_fetched_foo");
394 AddResourceIdToFetch("resource_id_not_fetched_bar"); 394 AddResourceIdToFetch("resource_id_not_fetched_bar");
395 AddResourceIdToFetch("resource_id_not_fetched_baz"); 395 AddResourceIdToFetch("resource_id_not_fetched_baz");
396 AddResourceIdToUpload("resource_id_dirty"); 396 AddResourceIdToUpload("resource_id_dirty");
397 397
398 // These files will be neither fetched nor uploaded not by DriveFileSystem, 398 // These files will be neither fetched nor uploaded not by DriveFileSystem,
399 // as network is not connected. 399 // as network is not connected.
400 400
401 sync_client_->StartSyncLoop(); 401 sync_client_->StartSyncLoop(false);
402 } 402 }
403 403
404 TEST_F(DriveSyncClientTest, StartSyncLoop_ResumedConnection) { 404 TEST_F(DriveSyncClientTest, StartSyncLoop_ResumedConnection) {
405 const std::string resource_id("resource_id_not_fetched_foo"); 405 const std::string resource_id("resource_id_not_fetched_foo");
406 const FilePath file_path( 406 const FilePath file_path(
407 FilePath::FromUTF8Unsafe("local_path_does_not_matter")); 407 FilePath::FromUTF8Unsafe("local_path_does_not_matter"));
408 const std::string mime_type("mime_type_does_not_matter"); 408 const std::string mime_type("mime_type_does_not_matter");
409 ConnectToWifi(); 409 ConnectToWifi();
410 AddResourceIdToFetch(resource_id); 410 AddResourceIdToFetch(resource_id);
411 411
412 // Disconnect from network on fetch try. 412 // Disconnect from network on fetch try.
413 SetDisconnectingExpectationForGetFileByResourceId(resource_id); 413 SetDisconnectingExpectationForGetFileByResourceId(resource_id);
414 414
415 sync_client_->StartSyncLoop(); 415 sync_client_->StartSyncLoop(false);
416 416
417 // Expect fetch retry on network reconnection. 417 // Expect fetch retry on network reconnection.
418 EXPECT_CALL(*mock_file_system_, GetFileByResourceId(resource_id, _, _)) 418 EXPECT_CALL(*mock_file_system_, GetFileByResourceId(resource_id, _, _))
419 .WillOnce(MockGetFileByResourceId( 419 .WillOnce(MockGetFileByResourceId(
420 DRIVE_FILE_OK, file_path, mime_type, REGULAR_FILE)); 420 DRIVE_FILE_OK, file_path, mime_type, REGULAR_FILE));
421 421
422 ConnectToWifi(); 422 ConnectToWifi();
423 } 423 }
424 424
425 TEST_F(DriveSyncClientTest, StartSyncLoop_CelluarDisabled) { 425 TEST_F(DriveSyncClientTest, StartSyncLoop_CelluarDisabled) {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 profile_->GetPrefs()->SetBoolean(prefs::kDisableDrive, true); 503 profile_->GetPrefs()->SetBoolean(prefs::kDisableDrive, true);
504 504
505 AddResourceIdToFetch("resource_id_not_fetched_foo"); 505 AddResourceIdToFetch("resource_id_not_fetched_foo");
506 AddResourceIdToFetch("resource_id_not_fetched_bar"); 506 AddResourceIdToFetch("resource_id_not_fetched_bar");
507 AddResourceIdToFetch("resource_id_not_fetched_baz"); 507 AddResourceIdToFetch("resource_id_not_fetched_baz");
508 AddResourceIdToUpload("resource_id_dirty"); 508 AddResourceIdToUpload("resource_id_dirty");
509 509
510 // These files will be neither fetched nor uploaded not by DriveFileSystem, 510 // These files will be neither fetched nor uploaded not by DriveFileSystem,
511 // as the Drive feature is disabled. 511 // as the Drive feature is disabled.
512 512
513 sync_client_->StartSyncLoop(); 513 sync_client_->StartSyncLoop(false);
514 } 514 }
515 515
516 TEST_F(DriveSyncClientTest, OnCachePinned) { 516 TEST_F(DriveSyncClientTest, OnCachePinned) {
517 ConnectToWifi(); 517 ConnectToWifi();
518 518
519 // This file will be fetched by GetFileByResourceId() as OnCachePinned() 519 // This file will be fetched by GetFileByResourceId() as OnCachePinned()
520 // will kick off the sync loop. 520 // will kick off the sync loop.
521 SetExpectationForGetFileByResourceId("resource_id_not_fetched_foo"); 521 SetExpectationForGetFileByResourceId("resource_id_not_fetched_foo");
522 522
523 sync_client_->OnCachePinned("resource_id_not_fetched_foo", "md5"); 523 sync_client_->OnCachePinned("resource_id_not_fetched_foo", "md5");
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 SetExpectationForGetFileByResourceId("resource_id_foo"); 675 SetExpectationForGetFileByResourceId("resource_id_foo");
676 676
677 ConnectToWifi(); 677 ConnectToWifi();
678 EXPECT_EQ(TestObserver::IDLE, observer_.state()); 678 EXPECT_EQ(TestObserver::IDLE, observer_.state());
679 679
680 // Disconnection during the sync loop should be notified. 680 // Disconnection during the sync loop should be notified.
681 AddResourceIdToFetch("resource_id_bar"); 681 AddResourceIdToFetch("resource_id_bar");
682 AddResourceIdToFetch("resource_id_buz"); 682 AddResourceIdToFetch("resource_id_buz");
683 SetDisconnectingExpectationForGetFileByResourceId("resource_id_bar"); 683 SetDisconnectingExpectationForGetFileByResourceId("resource_id_bar");
684 684
685 sync_client_->StartSyncLoop(); 685 sync_client_->StartSyncLoop(false);
686 EXPECT_EQ(TestObserver::STOPPED, observer_.state()); 686 EXPECT_EQ(TestObserver::STOPPED, observer_.state());
687 687
688 // So as the resume from the disconnection. 688 // So as the resume from the disconnection.
689 SetExpectationForGetFileByResourceId("resource_id_bar"); 689 SetExpectationForGetFileByResourceId("resource_id_bar");
690 SetExpectationForGetFileByResourceId("resource_id_buz"); 690 SetExpectationForGetFileByResourceId("resource_id_buz");
691 ConnectToWifi(); 691 ConnectToWifi();
692 EXPECT_EQ(TestObserver::IDLE, observer_.state()); 692 EXPECT_EQ(TestObserver::IDLE, observer_.state());
693 } 693 }
694 694
695 } // namespace drive 695 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698