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

Side by Side Diff: chrome/browser/sync/profile_sync_service_harness.cc

Issue 7753023: [Sync] Add tests for migration triggered by notifications (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 9 years, 3 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/sync/profile_sync_service_harness.h" 5 #include "chrome/browser/sync/profile_sync_service_harness.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <algorithm> 8 #include <algorithm>
9 #include <iterator> 9 #include <iterator>
10 #include <ostream> 10 #include <ostream>
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 88
89 bool StateChangeTimeoutEvent::Abort() { 89 bool StateChangeTimeoutEvent::Abort() {
90 aborted_ = true; 90 aborted_ = true;
91 caller_ = NULL; 91 caller_ = NULL;
92 return !did_timeout_; 92 return !did_timeout_;
93 } 93 }
94 94
95 ProfileSyncServiceHarness::ProfileSyncServiceHarness( 95 ProfileSyncServiceHarness::ProfileSyncServiceHarness(
96 Profile* profile, 96 Profile* profile,
97 const std::string& username, 97 const std::string& username,
98 const std::string& password, 98 const std::string& password)
99 bool expected_notifications_enabled)
100 : waiting_for_encryption_type_(syncable::UNSPECIFIED), 99 : waiting_for_encryption_type_(syncable::UNSPECIFIED),
101 wait_state_(INITIAL_WAIT_STATE), 100 wait_state_(INITIAL_WAIT_STATE),
102 profile_(profile), 101 profile_(profile),
103 service_(NULL), 102 service_(NULL),
104 timestamp_match_partner_(NULL), 103 timestamp_match_partner_(NULL),
105 username_(username), 104 username_(username),
106 password_(password), 105 password_(password),
107 expected_notifications_enabled_(expected_notifications_enabled),
108 profile_debug_name_(profile->GetDebugName()) { 106 profile_debug_name_(profile->GetDebugName()) {
109 if (IsSyncAlreadySetup()) { 107 if (IsSyncAlreadySetup()) {
110 service_ = profile_->GetProfileSyncService(); 108 service_ = profile_->GetProfileSyncService();
111 service_->AddObserver(this); 109 service_->AddObserver(this);
112 wait_state_ = FULLY_SYNCED; 110 wait_state_ = FULLY_SYNCED;
113 } 111 }
114 } 112 }
115 113
116 ProfileSyncServiceHarness::~ProfileSyncServiceHarness() {} 114 ProfileSyncServiceHarness::~ProfileSyncServiceHarness() {}
117 115
118 // static 116 // static
119 ProfileSyncServiceHarness* ProfileSyncServiceHarness::CreateAndAttach( 117 ProfileSyncServiceHarness* ProfileSyncServiceHarness::CreateAndAttach(
120 Profile* profile) { 118 Profile* profile) {
121 if (!profile->HasProfileSyncService()) { 119 if (!profile->HasProfileSyncService()) {
122 NOTREACHED() << "Profile has never signed into sync."; 120 NOTREACHED() << "Profile has never signed into sync.";
123 return NULL; 121 return NULL;
124 } 122 }
125 return new ProfileSyncServiceHarness( 123 return new ProfileSyncServiceHarness(profile, "", "");
126 profile, "", "",
127 /* expected_notifications_enabled */ true);
128 } 124 }
129 125
130 void ProfileSyncServiceHarness::SetCredentials(const std::string& username, 126 void ProfileSyncServiceHarness::SetCredentials(const std::string& username,
131 const std::string& password) { 127 const std::string& password) {
132 username_ = username; 128 username_ = username;
133 password_ = password; 129 password_ = password;
134 } 130 }
135 131
136 bool ProfileSyncServiceHarness::IsSyncAlreadySetup() { 132 bool ProfileSyncServiceHarness::IsSyncAlreadySetup() {
137 return profile_->HasProfileSyncService(); 133 return profile_->HasProfileSyncService();
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 if (wait_state_ == SYNC_DISABLED) { 462 if (wait_state_ == SYNC_DISABLED) {
467 LOG(ERROR) << "Sync disabled for " << profile_debug_name_ << "."; 463 LOG(ERROR) << "Sync disabled for " << profile_debug_name_ << ".";
468 return false; 464 return false;
469 } 465 }
470 466
471 if (IsSynced()) { 467 if (IsSynced()) {
472 // Client is already synced; don't wait. 468 // Client is already synced; don't wait.
473 return true; 469 return true;
474 } 470 }
475 471
472 return AwaitSyncCycleCompletionHelper(reason);
473 }
474
475 bool ProfileSyncServiceHarness::AwaitNextSyncCycleCompletion(
476 const std::string& reason) {
477 VLOG(1) << GetClientInfoString("AwaitNextSyncCycleCompletion");
478 return AwaitSyncCycleCompletionHelper(reason);
479 }
480
481 bool ProfileSyncServiceHarness::AwaitSyncCycleCompletionHelper(
482 const std::string& reason) {
476 if (wait_state_ == SERVER_UNREACHABLE) { 483 if (wait_state_ == SERVER_UNREACHABLE) {
477 // Client was offline; wait for it to go online, and then wait for sync. 484 // Client was offline; wait for it to go online, and then wait for sync.
478 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); 485 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason);
479 DCHECK_EQ(wait_state_, WAITING_FOR_SYNC_TO_FINISH); 486 DCHECK_EQ(wait_state_, WAITING_FOR_SYNC_TO_FINISH);
480 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); 487 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason);
481 } 488 }
482 489
483 DCHECK(service()->sync_initialized()); 490 DCHECK(service()->sync_initialized());
484 wait_state_ = WAITING_FOR_SYNC_TO_FINISH; 491 wait_state_ = WAITING_FOR_SYNC_TO_FINISH;
485 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); 492 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason);
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 if (service() == NULL) { 620 if (service() == NULL) {
614 VLOG(1) << GetClientInfoString("IsSynced: false"); 621 VLOG(1) << GetClientInfoString("IsSynced: false");
615 return false; 622 return false;
616 } 623 }
617 const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); 624 const SyncSessionSnapshot* snap = GetLastSessionSnapshot();
618 // TODO(rsimha): Remove additional checks of snap->has_more_to_sync and 625 // TODO(rsimha): Remove additional checks of snap->has_more_to_sync and
619 // snap->unsynced_count once http://crbug.com/48989 is fixed. 626 // snap->unsynced_count once http://crbug.com/48989 is fixed.
620 bool is_synced = snap && 627 bool is_synced = snap &&
621 snap->num_blocking_conflicting_updates == 0 && 628 snap->num_blocking_conflicting_updates == 0 &&
622 ServiceIsPushingChanges() && 629 ServiceIsPushingChanges() &&
623 (GetStatus().notifications_enabled == 630 GetStatus().notifications_enabled &&
624 expected_notifications_enabled_) &&
625 !service()->HasUnsyncedItems() && 631 !service()->HasUnsyncedItems() &&
626 !snap->has_more_to_sync && 632 !snap->has_more_to_sync &&
627 snap->unsynced_count == 0 && 633 snap->unsynced_count == 0 &&
628 !service()->HasPendingBackendMigration() && 634 !service()->HasPendingBackendMigration() &&
629 service()->passphrase_required_reason() != 635 service()->passphrase_required_reason() !=
630 sync_api::REASON_SET_PASSPHRASE_FAILED; 636 sync_api::REASON_SET_PASSPHRASE_FAILED;
631 VLOG(1) << GetClientInfoString( 637 VLOG(1) << GetClientInfoString(
632 is_synced ? "IsSynced: true" : "IsSynced: false"); 638 is_synced ? "IsSynced: true" : "IsSynced: false");
633 return is_synced; 639 return is_synced;
634 } 640 }
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 return (synced_types.count(type) != 0); 895 return (synced_types.count(type) != 0);
890 } 896 }
891 897
892 std::string ProfileSyncServiceHarness::GetServiceStatus() { 898 std::string ProfileSyncServiceHarness::GetServiceStatus() {
893 DictionaryValue value; 899 DictionaryValue value;
894 sync_ui_util::ConstructAboutInformation(service_, &value); 900 sync_ui_util::ConstructAboutInformation(service_, &value);
895 std::string service_status; 901 std::string service_status;
896 base::JSONWriter::Write(&value, true, &service_status); 902 base::JSONWriter::Write(&value, true, &service_status);
897 return service_status; 903 return service_status;
898 } 904 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_service_harness.h ('k') | chrome/test/live_sync/live_sync_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698