summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrsimha@chromium.org <rsimha@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-02 05:04:24 +0000
committerrsimha@chromium.org <rsimha@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-02 05:04:24 +0000
commit638c48f806e23adf510ea2006f66f84f4d43c5de (patch)
tree3d674d6a26379686be50ccadbb7cc2f5c3404f54
parent0a5275736f8d41119fcfe3298997eed39ee37f15 (diff)
downloadchromium_src-638c48f806e23adf510ea2006f66f84f4d43c5de.zip
chromium_src-638c48f806e23adf510ea2006f66f84f4d43c5de.tar.gz
chromium_src-638c48f806e23adf510ea2006f66f84f4d43c5de.tar.bz2
Refactor the wait code in ProfileSyncServiceTestHarness.
The sync integration tests use the methods defined in the ProfileSyncServiceTestHarness class to coordinate various sync related activities carried out by each test case. The sync codebase has ungergone significant change since this class was originally implemented. In this checkin, the class has been refactored to match the sync codebase. The pass rate for integration tests went up from ~20% to 90+% with this checkin. BUG=44957 TEST=sync_integration_tests Review URL: http://codereview.chromium.org/2876029 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51500 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/test/live_sync/live_sync_test.h4
-rw-r--r--chrome/test/live_sync/profile_sync_service_test_harness.cc49
-rw-r--r--chrome/test/live_sync/profile_sync_service_test_harness.h13
3 files changed, 42 insertions, 24 deletions
diff --git a/chrome/test/live_sync/live_sync_test.h b/chrome/test/live_sync/live_sync_test.h
index dcc4eb5..71dbbdc 100644
--- a/chrome/test/live_sync/live_sync_test.h
+++ b/chrome/test/live_sync/live_sync_test.h
@@ -26,6 +26,9 @@ extern const wchar_t kSyncUserForTest[];
extern const wchar_t kSyncPasswordForTest[];
}
+// Live sync tests are allowed to run for up to 5 minutes.
+const int kTestTimeoutInMS = 300000;
+
// This is the base class for integration tests for all sync data types. Derived
// classes must be defined for each sync data type. Individual tests are defined
// using the IN_PROC_BROWSER_TEST_F macro.
@@ -56,6 +59,7 @@ class LiveSyncTest : public InProcessBrowserTest {
num_clients_(-1),
started_local_test_server_(false) {
InProcessBrowserTest::set_show_window(true);
+ InProcessBrowserTest::SetInitialTimeoutInMS(kTestTimeoutInMS);
switch (test_type_) {
case SINGLE_CLIENT: {
num_clients_ = 1;
diff --git a/chrome/test/live_sync/profile_sync_service_test_harness.cc b/chrome/test/live_sync/profile_sync_service_test_harness.cc
index 6225cf0..de928fc 100644
--- a/chrome/test/live_sync/profile_sync_service_test_harness.cc
+++ b/chrome/test/live_sync/profile_sync_service_test_harness.cc
@@ -84,7 +84,7 @@ bool StateChangeTimeoutEvent::Abort() {
ProfileSyncServiceTestHarness::ProfileSyncServiceTestHarness(
Profile* p, const std::string& username, const std::string& password)
- : wait_state_(WAITING_FOR_INITIAL_CALLBACK), profile_(p), service_(NULL),
+ : wait_state_(WAITING_FOR_ON_AUTH_ERROR), profile_(p), service_(NULL),
last_status_(kInvalidStatus),
last_timestamp_(0),
min_timestamp_needed_(kMinTimestampNeededNone),
@@ -95,12 +95,15 @@ ProfileSyncServiceTestHarness::ProfileSyncServiceTestHarness(
}
bool ProfileSyncServiceTestHarness::SetupSync() {
- service_ = profile_->GetProfileSyncService();
- service_->SetSyncSetupCompleted();
- service_->EnableForUser();
+ syncable::ModelTypeSet set;
+ for (int i = syncable::FIRST_REAL_MODEL_TYPE;
+ i < syncable::MODEL_TYPE_COUNT; ++i) {
+ set.insert(syncable::ModelTypeFromInt(i));
+ }
- // Needed to avoid showing the login dialog. Well aware this is egregious.
- service_->expecting_first_run_auth_needed_event_ = false;
+ service_ = profile_->GetProfileSyncService();
+ service_->StartUp();
+ service_->OnUserChoseDatatypes(true, set);
service_->AddObserver(this);
return WaitForServiceInit();
}
@@ -120,14 +123,16 @@ bool ProfileSyncServiceTestHarness::RunStateChangeMachine() {
WaitState state = wait_state_;
ProfileSyncService::Status status(service_->QueryDetailedSyncStatus());
switch (wait_state_) {
- case WAITING_FOR_INITIAL_CALLBACK:
- SignalStateCompleteWithNextState(WAITING_FOR_READY_TO_PROCESS_CHANGES);
+ case WAITING_FOR_ON_AUTH_ERROR: {
+ SignalStateCompleteWithNextState(WAITING_FOR_NOTIFICATIONS_ENABLED);
break;
- case WAITING_FOR_READY_TO_PROCESS_CHANGES:
- if (service_->ShouldPushChanges()) {
- SignalStateCompleteWithNextState(WAITING_FOR_NOTHING);
+ }
+ case WAITING_FOR_NOTIFICATIONS_ENABLED: {
+ if (status.notifications_enabled) {
+ SignalStateCompleteWithNextState(FULLY_SYNCED);
}
break;
+ }
case WAITING_FOR_SYNC_TO_FINISH: {
const SyncSessionSnapshot* snap =
service_->backend()->GetLastSessionSnapshot();
@@ -137,7 +142,7 @@ bool ProfileSyncServiceTestHarness::RunStateChangeMachine() {
EXPECT_LE(last_timestamp_, snap->max_local_timestamp);
last_timestamp_ = snap->max_local_timestamp;
- SignalStateCompleteWithNextState(WAITING_FOR_NOTHING);
+ SignalStateCompleteWithNextState(FULLY_SYNCED);
break;
}
case WAITING_FOR_UPDATES: {
@@ -147,10 +152,10 @@ bool ProfileSyncServiceTestHarness::RunStateChangeMachine() {
if (snap->max_local_timestamp < min_timestamp_needed_)
break;
- SignalStateCompleteWithNextState(WAITING_FOR_NOTHING);
+ SignalStateCompleteWithNextState(FULLY_SYNCED);
break;
}
- case WAITING_FOR_NOTHING:
+ case FULLY_SYNCED:
default:
// Invalid state during observer callback which may be triggered by other
// classes using the the UI message loop. Defer to their handling.
@@ -203,17 +208,21 @@ bool ProfileSyncServiceTestHarness::AwaitStatusChangeWithTimeout(
}
bool ProfileSyncServiceTestHarness::WaitForServiceInit() {
- // Wait for the initial (auth needed) callback.
- EXPECT_EQ(wait_state_, WAITING_FOR_INITIAL_CALLBACK);
- if (!AwaitStatusChangeWithTimeout(30, "Waiting for authwatcher calback.")) {
+ // Wait for the OnAuthError() callback.
+ EXPECT_EQ(wait_state_, WAITING_FOR_ON_AUTH_ERROR);
+ if (!AwaitStatusChangeWithTimeout(30,
+ "Waiting for the OnAuthError() callback.")) {
return false;
}
- // Wait for the OnBackendInitialized callback.
+ // Enter GAIA credentials and wait for notifications_enabled to be set to
+ // true.
service_->backend()->Authenticate(username_, password_, std::string());
- EXPECT_EQ(wait_state_, WAITING_FOR_READY_TO_PROCESS_CHANGES);
- if (!AwaitStatusChangeWithTimeout(30, "Waiting on backend initialization.")) {
+ EXPECT_EQ(wait_state_, WAITING_FOR_NOTIFICATIONS_ENABLED);
+ if (!AwaitStatusChangeWithTimeout(30,
+ "Waiting for notifications_enabled to be set to true.")) {
return false;
}
+
return service_->sync_initialized();
}
diff --git a/chrome/test/live_sync/profile_sync_service_test_harness.h b/chrome/test/live_sync/profile_sync_service_test_harness.h
index 7ebf477..bcce77f 100644
--- a/chrome/test/live_sync/profile_sync_service_test_harness.h
+++ b/chrome/test/live_sync/profile_sync_service_test_harness.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -54,11 +54,16 @@ class ProfileSyncServiceTestHarness : public ProfileSyncServiceObserver {
friend class StateChangeTimeoutEvent;
enum WaitState {
- WAITING_FOR_INITIAL_CALLBACK = 0,
- WAITING_FOR_READY_TO_PROCESS_CHANGES,
+ // The sync client awaits the OnAuthError() callback.
+ WAITING_FOR_ON_AUTH_ERROR = 0,
+ // The sync client is waiting for notifications_enabled to become true.
+ WAITING_FOR_NOTIFICATIONS_ENABLED,
+ // The sync client is waiting for an ongoing sync cycle to complete.
WAITING_FOR_SYNC_TO_FINISH,
+ // The sync client anticipates incoming updates leading to a new sync cycle.
WAITING_FOR_UPDATES,
- WAITING_FOR_NOTHING,
+ // The sync client is fully synced and there are no pending updates.
+ FULLY_SYNCED,
NUMBER_OF_STATES
};