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

Side by Side Diff: chrome/test/live_sync/profile_sync_service_test_harness.cc

Issue 3078031: Simple offline startup integration test. (Closed)
Patch Set: Disable test. Created 10 years, 4 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
OLDNEW
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/google_service_auth_error.h"
7 #include "chrome/browser/pref_service.h" 8 #include "chrome/browser/pref_service.h"
8 #include "chrome/browser/profile.h" 9 #include "chrome/browser/profile.h"
9 #include "chrome/browser/sync/glue/sync_backend_host.h" 10 #include "chrome/browser/sync/glue/sync_backend_host.h"
10 #include "chrome/browser/sync/sessions/session_state.h" 11 #include "chrome/browser/sync/sessions/session_state.h"
11 #include "chrome/browser/tab_contents/tab_contents.h" 12 #include "chrome/browser/tab_contents/tab_contents.h"
12 #include "chrome/common/pref_names.h" 13 #include "chrome/common/pref_names.h"
13 #include "chrome/test/live_sync/profile_sync_service_test_harness.h" 14 #include "chrome/test/live_sync/profile_sync_service_test_harness.h"
14 #include "chrome/test/ui_test_utils.h" 15 #include "chrome/test/ui_test_utils.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 17
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 username_(username), password_(password) { 90 username_(username), password_(password) {
90 // Ensure the profile has enough prefs registered for use by sync. 91 // Ensure the profile has enough prefs registered for use by sync.
91 if (!p->GetPrefs()->FindPreference(prefs::kAcceptLanguages)) 92 if (!p->GetPrefs()->FindPreference(prefs::kAcceptLanguages))
92 TabContents::RegisterUserPrefs(p->GetPrefs()); 93 TabContents::RegisterUserPrefs(p->GetPrefs());
93 } 94 }
94 95
95 bool ProfileSyncServiceTestHarness::SetupSync() { 96 bool ProfileSyncServiceTestHarness::SetupSync() {
96 service_ = profile_->GetProfileSyncService(); 97 service_ = profile_->GetProfileSyncService();
97 service_->StartUp(); 98 service_->StartUp();
98 service_->AddObserver(this); 99 service_->AddObserver(this);
99 return WaitForServiceInit(); 100 return WaitForServiceInit(false);
101 }
102
103 bool ProfileSyncServiceTestHarness::RetryAuthentication() {
104 wait_state_ = WAITING_FOR_ON_BACKEND_INITIALIZED;
105 return WaitForServiceInit(true);
100 } 106 }
101 107
102 void ProfileSyncServiceTestHarness::SignalStateCompleteWithNextState( 108 void ProfileSyncServiceTestHarness::SignalStateCompleteWithNextState(
103 WaitState next_state) { 109 WaitState next_state) {
104 110
105 wait_state_ = next_state; 111 wait_state_ = next_state;
106 SignalStateComplete(); 112 SignalStateComplete();
107 } 113 }
108 114
109 void ProfileSyncServiceTestHarness::SignalStateComplete() { 115 void ProfileSyncServiceTestHarness::SignalStateComplete() {
110 MessageLoopForUI::current()->Quit(); 116 MessageLoopForUI::current()->Quit();
111 } 117 }
112 118
113 bool ProfileSyncServiceTestHarness::RunStateChangeMachine() { 119 bool ProfileSyncServiceTestHarness::RunStateChangeMachine() {
114 WaitState state = wait_state_; 120 WaitState state = wait_state_;
115 ProfileSyncService::Status status(service_->QueryDetailedSyncStatus()); 121 ProfileSyncService::Status status(service_->QueryDetailedSyncStatus());
116 switch (wait_state_) { 122 switch (wait_state_) {
117 case WAITING_FOR_ON_AUTH_ERROR: { 123 case WAITING_FOR_ON_AUTH_ERROR: {
118 SignalStateCompleteWithNextState(WAITING_FOR_ON_BACKEND_INITIALIZED); 124 SignalStateCompleteWithNextState(WAITING_FOR_ON_BACKEND_INITIALIZED);
119 break; 125 break;
120 } 126 }
121 case WAITING_FOR_ON_BACKEND_INITIALIZED: { 127 case WAITING_FOR_ON_BACKEND_INITIALIZED: {
128 if (service_->GetAuthError().state() != GoogleServiceAuthError::NONE) {
129 SignalStateCompleteWithNextState(AUTH_ERROR);
130 }
122 if (service_->sync_initialized()) { 131 if (service_->sync_initialized()) {
123 SignalStateCompleteWithNextState(WAITING_FOR_NOTIFICATIONS_ENABLED); 132 SignalStateCompleteWithNextState(WAITING_FOR_NOTIFICATIONS_ENABLED);
124 } 133 }
125 break; 134 break;
126 } 135 }
127 case WAITING_FOR_NOTIFICATIONS_ENABLED: { 136 case WAITING_FOR_NOTIFICATIONS_ENABLED: {
128 if (status.notifications_enabled) { 137 if (status.notifications_enabled) {
129 SignalStateCompleteWithNextState(FULLY_SYNCED); 138 SignalStateCompleteWithNextState(FULLY_SYNCED);
130 } 139 }
131 break; 140 break;
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 MessageLoopForUI* loop = MessageLoopForUI::current(); 258 MessageLoopForUI* loop = MessageLoopForUI::current();
250 loop->PostDelayedTask( 259 loop->PostDelayedTask(
251 FROM_HERE, 260 FROM_HERE,
252 NewRunnableMethod(timeout_signal.get(), 261 NewRunnableMethod(timeout_signal.get(),
253 &StateChangeTimeoutEvent::Callback), 262 &StateChangeTimeoutEvent::Callback),
254 1000 * timeout_seconds); 263 1000 * timeout_seconds);
255 ui_test_utils::RunMessageLoop(); 264 ui_test_utils::RunMessageLoop();
256 return timeout_signal->Abort(); 265 return timeout_signal->Abort();
257 } 266 }
258 267
259 bool ProfileSyncServiceTestHarness::WaitForServiceInit() { 268 bool ProfileSyncServiceTestHarness::WaitForServiceInit(bool is_auth_retry) {
260 // Wait for the OnAuthError() callback. 269 if (!is_auth_retry) {
261 EXPECT_EQ(wait_state_, WAITING_FOR_ON_AUTH_ERROR); 270 // Wait for the OnAuthError() callback.
262 EXPECT_TRUE(AwaitStatusChangeWithTimeout(30, 271 EXPECT_EQ(wait_state_, WAITING_FOR_ON_AUTH_ERROR);
263 "Waiting for the OnAuthError() callback.")) << 272 EXPECT_TRUE(AwaitStatusChangeWithTimeout(30,
264 "OnAuthError() not seen after 30 seconds."; 273 "Waiting for the OnAuthError() callback.")) <<
274 "OnAuthError() not seen after 30 seconds.";
275 }
265 276
266 // Enter GAIA credentials and wait for the OnBackendInitialized() callback. 277 // Enter GAIA credentials and wait for the OnBackendInitialized() callback.
267 service_->backend()->Authenticate(username_, password_, std::string()); 278 service_->backend()->Authenticate(username_, password_, std::string());
268 EXPECT_EQ(wait_state_, WAITING_FOR_ON_BACKEND_INITIALIZED); 279 EXPECT_EQ(wait_state_, WAITING_FOR_ON_BACKEND_INITIALIZED);
269 EXPECT_TRUE(AwaitStatusChangeWithTimeout(30, 280 EXPECT_TRUE(AwaitStatusChangeWithTimeout(30,
270 "Waiting for OnBackendInitialized().")) << 281 "Waiting for OnBackendInitialized().")) <<
271 "OnBackendInitialized() not seen after 30 seconds."; 282 "OnBackendInitialized() not seen after 30 seconds.";
272 283
284 if (wait_state_ == AUTH_ERROR) {
285 return false;
286 }
287
273 // Choose datatypes to be synced and wait for notifications_enabled to be set 288 // Choose datatypes to be synced and wait for notifications_enabled to be set
274 // to true. 289 // to true.
275 syncable::ModelTypeSet set; 290 syncable::ModelTypeSet set;
276 for (int i = syncable::FIRST_REAL_MODEL_TYPE; 291 for (int i = syncable::FIRST_REAL_MODEL_TYPE;
277 i < syncable::MODEL_TYPE_COUNT; ++i) { 292 i < syncable::MODEL_TYPE_COUNT; ++i) {
278 set.insert(syncable::ModelTypeFromInt(i)); 293 set.insert(syncable::ModelTypeFromInt(i));
279 } 294 }
280 service_->OnUserChoseDatatypes(true, set); 295 service_->OnUserChoseDatatypes(true, set);
281 EXPECT_EQ(wait_state_, WAITING_FOR_NOTIFICATIONS_ENABLED); 296 EXPECT_EQ(wait_state_, WAITING_FOR_NOTIFICATIONS_ENABLED);
282 EXPECT_TRUE(AwaitStatusChangeWithTimeout(30, 297 EXPECT_TRUE(AwaitStatusChangeWithTimeout(30,
283 "Waiting for notifications_enabled to be set to true.")) << 298 "Waiting for notifications_enabled to be set to true.")) <<
284 "notifications_enabled not set to true after 30 seconds."; 299 "notifications_enabled not set to true after 30 seconds.";
285 300
286 return true; 301 return true;
287 } 302 }
288 303
289 const SyncSessionSnapshot* 304 const SyncSessionSnapshot*
290 ProfileSyncServiceTestHarness::GetLastSessionSnapshot() const { 305 ProfileSyncServiceTestHarness::GetLastSessionSnapshot() const {
291 EXPECT_FALSE(service_ == NULL) << "Sync service has not yet been set up."; 306 EXPECT_FALSE(service_ == NULL) << "Sync service has not yet been set up.";
292 return service_->backend()->GetLastSessionSnapshot(); 307 return service_->backend()->GetLastSessionSnapshot();
293 } 308 }
OLDNEW
« no previous file with comments | « chrome/test/live_sync/profile_sync_service_test_harness.h ('k') | net/tools/testserver/chromiumsync.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698