OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/message_loop.h" | 5 #include "base/message_loop.h" |
6 #include "chrome/browser/browser.h" | 6 #include "chrome/browser/browser.h" |
7 #include "chrome/browser/pref_service.h" | 7 #include "chrome/browser/pref_service.h" |
8 #include "chrome/browser/profile.h" | 8 #include "chrome/browser/profile.h" |
9 #include "chrome/browser/sync/glue/sync_backend_host.h" | 9 #include "chrome/browser/sync/glue/sync_backend_host.h" |
10 #include "chrome/browser/sync/sessions/session_state.h" | 10 #include "chrome/browser/sync/sessions/session_state.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 } | 77 } |
78 | 78 |
79 bool StateChangeTimeoutEvent::Abort() { | 79 bool StateChangeTimeoutEvent::Abort() { |
80 aborted_ = true; | 80 aborted_ = true; |
81 caller_ = NULL; | 81 caller_ = NULL; |
82 return !did_timeout_; | 82 return !did_timeout_; |
83 } | 83 } |
84 | 84 |
85 ProfileSyncServiceTestHarness::ProfileSyncServiceTestHarness( | 85 ProfileSyncServiceTestHarness::ProfileSyncServiceTestHarness( |
86 Profile* p, const std::string& username, const std::string& password) | 86 Profile* p, const std::string& username, const std::string& password) |
87 : wait_state_(WAITING_FOR_INITIAL_CALLBACK), profile_(p), service_(NULL), | 87 : wait_state_(WAITING_FOR_ON_AUTH_ERROR), profile_(p), service_(NULL), |
88 last_status_(kInvalidStatus), | 88 last_status_(kInvalidStatus), |
89 last_timestamp_(0), | 89 last_timestamp_(0), |
90 min_timestamp_needed_(kMinTimestampNeededNone), | 90 min_timestamp_needed_(kMinTimestampNeededNone), |
91 username_(username), password_(password) { | 91 username_(username), password_(password) { |
92 // Ensure the profile has enough prefs registered for use by sync. | 92 // Ensure the profile has enough prefs registered for use by sync. |
93 if (!p->GetPrefs()->FindPreference(prefs::kAcceptLanguages)) | 93 if (!p->GetPrefs()->FindPreference(prefs::kAcceptLanguages)) |
94 TabContents::RegisterUserPrefs(p->GetPrefs()); | 94 TabContents::RegisterUserPrefs(p->GetPrefs()); |
95 } | 95 } |
96 | 96 |
97 bool ProfileSyncServiceTestHarness::SetupSync() { | 97 bool ProfileSyncServiceTestHarness::SetupSync() { |
| 98 syncable::ModelTypeSet set; |
| 99 for (int i = syncable::FIRST_REAL_MODEL_TYPE; |
| 100 i < syncable::MODEL_TYPE_COUNT; ++i) { |
| 101 set.insert(syncable::ModelTypeFromInt(i)); |
| 102 } |
| 103 |
98 service_ = profile_->GetProfileSyncService(); | 104 service_ = profile_->GetProfileSyncService(); |
99 service_->SetSyncSetupCompleted(); | 105 service_->StartUp(); |
100 service_->EnableForUser(); | 106 service_->OnUserChoseDatatypes(true, set); |
101 | |
102 // Needed to avoid showing the login dialog. Well aware this is egregious. | |
103 service_->expecting_first_run_auth_needed_event_ = false; | |
104 service_->AddObserver(this); | 107 service_->AddObserver(this); |
105 return WaitForServiceInit(); | 108 return WaitForServiceInit(); |
106 } | 109 } |
107 | 110 |
108 void ProfileSyncServiceTestHarness::SignalStateCompleteWithNextState( | 111 void ProfileSyncServiceTestHarness::SignalStateCompleteWithNextState( |
109 WaitState next_state) { | 112 WaitState next_state) { |
110 | 113 |
111 wait_state_ = next_state; | 114 wait_state_ = next_state; |
112 SignalStateComplete(); | 115 SignalStateComplete(); |
113 } | 116 } |
114 | 117 |
115 void ProfileSyncServiceTestHarness::SignalStateComplete() { | 118 void ProfileSyncServiceTestHarness::SignalStateComplete() { |
116 MessageLoopForUI::current()->Quit(); | 119 MessageLoopForUI::current()->Quit(); |
117 } | 120 } |
118 | 121 |
119 bool ProfileSyncServiceTestHarness::RunStateChangeMachine() { | 122 bool ProfileSyncServiceTestHarness::RunStateChangeMachine() { |
120 WaitState state = wait_state_; | 123 WaitState state = wait_state_; |
121 ProfileSyncService::Status status(service_->QueryDetailedSyncStatus()); | 124 ProfileSyncService::Status status(service_->QueryDetailedSyncStatus()); |
122 switch (wait_state_) { | 125 switch (wait_state_) { |
123 case WAITING_FOR_INITIAL_CALLBACK: | 126 case WAITING_FOR_ON_AUTH_ERROR: { |
124 SignalStateCompleteWithNextState(WAITING_FOR_READY_TO_PROCESS_CHANGES); | 127 SignalStateCompleteWithNextState(WAITING_FOR_NOTIFICATIONS_ENABLED); |
125 break; | 128 break; |
126 case WAITING_FOR_READY_TO_PROCESS_CHANGES: | 129 } |
127 if (service_->ShouldPushChanges()) { | 130 case WAITING_FOR_NOTIFICATIONS_ENABLED: { |
128 SignalStateCompleteWithNextState(WAITING_FOR_NOTHING); | 131 if (status.notifications_enabled) { |
| 132 SignalStateCompleteWithNextState(FULLY_SYNCED); |
129 } | 133 } |
130 break; | 134 break; |
| 135 } |
131 case WAITING_FOR_SYNC_TO_FINISH: { | 136 case WAITING_FOR_SYNC_TO_FINISH: { |
132 const SyncSessionSnapshot* snap = | 137 const SyncSessionSnapshot* snap = |
133 service_->backend()->GetLastSessionSnapshot(); | 138 service_->backend()->GetLastSessionSnapshot(); |
134 DCHECK(snap) << "Should have been at least one sync session by now"; | 139 DCHECK(snap) << "Should have been at least one sync session by now"; |
135 if (snap->has_more_to_sync) | 140 if (snap->has_more_to_sync) |
136 break; | 141 break; |
137 | 142 |
138 EXPECT_LE(last_timestamp_, snap->max_local_timestamp); | 143 EXPECT_LE(last_timestamp_, snap->max_local_timestamp); |
139 last_timestamp_ = snap->max_local_timestamp; | 144 last_timestamp_ = snap->max_local_timestamp; |
140 SignalStateCompleteWithNextState(WAITING_FOR_NOTHING); | 145 SignalStateCompleteWithNextState(FULLY_SYNCED); |
141 break; | 146 break; |
142 } | 147 } |
143 case WAITING_FOR_UPDATES: { | 148 case WAITING_FOR_UPDATES: { |
144 const SyncSessionSnapshot* snap = | 149 const SyncSessionSnapshot* snap = |
145 service_->backend()->GetLastSessionSnapshot(); | 150 service_->backend()->GetLastSessionSnapshot(); |
146 DCHECK(snap) << "Should have been at least one sync session by now"; | 151 DCHECK(snap) << "Should have been at least one sync session by now"; |
147 if (snap->max_local_timestamp < min_timestamp_needed_) | 152 if (snap->max_local_timestamp < min_timestamp_needed_) |
148 break; | 153 break; |
149 | 154 |
150 SignalStateCompleteWithNextState(WAITING_FOR_NOTHING); | 155 SignalStateCompleteWithNextState(FULLY_SYNCED); |
151 break; | 156 break; |
152 } | 157 } |
153 case WAITING_FOR_NOTHING: | 158 case FULLY_SYNCED: |
154 default: | 159 default: |
155 // Invalid state during observer callback which may be triggered by other | 160 // Invalid state during observer callback which may be triggered by other |
156 // classes using the the UI message loop. Defer to their handling. | 161 // classes using the the UI message loop. Defer to their handling. |
157 break; | 162 break; |
158 } | 163 } |
159 last_status_ = status; | 164 last_status_ = status; |
160 return state != wait_state_; | 165 return state != wait_state_; |
161 } | 166 } |
162 | 167 |
163 void ProfileSyncServiceTestHarness::OnStateChanged() { | 168 void ProfileSyncServiceTestHarness::OnStateChanged() { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 loop->PostDelayedTask( | 201 loop->PostDelayedTask( |
197 FROM_HERE, | 202 FROM_HERE, |
198 NewRunnableMethod(timeout_signal.get(), | 203 NewRunnableMethod(timeout_signal.get(), |
199 &StateChangeTimeoutEvent::Callback), | 204 &StateChangeTimeoutEvent::Callback), |
200 1000 * timeout_seconds); | 205 1000 * timeout_seconds); |
201 ui_test_utils::RunMessageLoop(); | 206 ui_test_utils::RunMessageLoop(); |
202 return timeout_signal->Abort(); | 207 return timeout_signal->Abort(); |
203 } | 208 } |
204 | 209 |
205 bool ProfileSyncServiceTestHarness::WaitForServiceInit() { | 210 bool ProfileSyncServiceTestHarness::WaitForServiceInit() { |
206 // Wait for the initial (auth needed) callback. | 211 // Wait for the OnAuthError() callback. |
207 EXPECT_EQ(wait_state_, WAITING_FOR_INITIAL_CALLBACK); | 212 EXPECT_EQ(wait_state_, WAITING_FOR_ON_AUTH_ERROR); |
208 if (!AwaitStatusChangeWithTimeout(30, "Waiting for authwatcher calback.")) { | 213 if (!AwaitStatusChangeWithTimeout(30, |
| 214 "Waiting for the OnAuthError() callback.")) { |
209 return false; | 215 return false; |
210 } | 216 } |
211 | 217 |
212 // Wait for the OnBackendInitialized callback. | 218 // Enter GAIA credentials and wait for notifications_enabled to be set to |
| 219 // true. |
213 service_->backend()->Authenticate(username_, password_, std::string()); | 220 service_->backend()->Authenticate(username_, password_, std::string()); |
214 EXPECT_EQ(wait_state_, WAITING_FOR_READY_TO_PROCESS_CHANGES); | 221 EXPECT_EQ(wait_state_, WAITING_FOR_NOTIFICATIONS_ENABLED); |
215 if (!AwaitStatusChangeWithTimeout(30, "Waiting on backend initialization.")) { | 222 if (!AwaitStatusChangeWithTimeout(30, |
| 223 "Waiting for notifications_enabled to be set to true.")) { |
216 return false; | 224 return false; |
217 } | 225 } |
| 226 |
218 return service_->sync_initialized(); | 227 return service_->sync_initialized(); |
219 } | 228 } |
OLD | NEW |