summaryrefslogtreecommitdiffstats
path: root/chrome/test/live_sync
diff options
context:
space:
mode:
authorrsimha@chromium.org <rsimha@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-16 19:33:40 +0000
committerrsimha@chromium.org <rsimha@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-16 19:33:40 +0000
commitefa0151b9f7a4389a86334ef75fa0ce138c9778e (patch)
treef459f4de4ca342dd92f9c7b36b748a89989a0f33 /chrome/test/live_sync
parent662183140166357f5088c40b34d1096d7a56fba7 (diff)
downloadchromium_src-efa0151b9f7a4389a86334ef75fa0ce138c9778e.zip
chromium_src-efa0151b9f7a4389a86334ef75fa0ce138c9778e.tar.gz
chromium_src-efa0151b9f7a4389a86334ef75fa0ce138c9778e.tar.bz2
This checkin contains 2 new types of sync integration tests.
The first type of tests ("multiple client") creates a small number of clients (3) that make simultaneous, sometimes conflicting updates to a sync item and verifies that the system reaches a sane state in spite of racy conditions. The second type of tests ("many client") creates several clients (10) that all sync to the same account and process updates sent out due to one or more of them syncing a change, and verifies that the system reaches a known sane state at the end of the test. BUG=49035 TEST=sync_integration_tests Review URL: http://codereview.chromium.org/2897017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52724 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/live_sync')
-rw-r--r--chrome/test/live_sync/live_bookmarks_sync_test.h21
-rw-r--r--chrome/test/live_sync/live_preferences_sync_test.h19
-rw-r--r--chrome/test/live_sync/live_sync_test.h7
-rw-r--r--chrome/test/live_sync/many_client_live_bookmarks_sync_test.cc18
-rw-r--r--chrome/test/live_sync/many_client_live_preferences_sync_test.cc21
-rw-r--r--chrome/test/live_sync/multiple_client_live_bookmarks_sync_test.cc23
-rw-r--r--chrome/test/live_sync/multiple_client_live_preferences_sync_test.cc28
-rw-r--r--chrome/test/live_sync/profile_sync_service_test_harness.cc36
-rw-r--r--chrome/test/live_sync/profile_sync_service_test_harness.h7
9 files changed, 176 insertions, 4 deletions
diff --git a/chrome/test/live_sync/live_bookmarks_sync_test.h b/chrome/test/live_sync/live_bookmarks_sync_test.h
index f8f0cc9..632d4f4 100644
--- a/chrome/test/live_sync/live_bookmarks_sync_test.h
+++ b/chrome/test/live_sync/live_bookmarks_sync_test.h
@@ -62,7 +62,6 @@ class LiveBookmarksSyncTest : public LiveSyncTest {
return verifier_helper_.get();
}
-
// Helper to get a handle on a bookmark in |m| when the url is known to be
// unique.
static const BookmarkNode* GetByUniqueURL(BookmarkModel* m, const GURL& url) {
@@ -102,4 +101,24 @@ class TwoClientLiveBookmarksSyncTest : public LiveBookmarksSyncTest {
DISALLOW_COPY_AND_ASSIGN(TwoClientLiveBookmarksSyncTest);
};
+class MultipleClientLiveBookmarksSyncTest : public LiveBookmarksSyncTest {
+ public:
+ MultipleClientLiveBookmarksSyncTest()
+ : LiveBookmarksSyncTest(MULTIPLE_CLIENT) {}
+ ~MultipleClientLiveBookmarksSyncTest() {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MultipleClientLiveBookmarksSyncTest);
+};
+
+class ManyClientLiveBookmarksSyncTest : public LiveBookmarksSyncTest {
+ public:
+ ManyClientLiveBookmarksSyncTest()
+ : LiveBookmarksSyncTest(MANY_CLIENT) {}
+ ~ManyClientLiveBookmarksSyncTest() {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ManyClientLiveBookmarksSyncTest);
+};
+
#endif // CHROME_TEST_LIVE_SYNC_LIVE_BOOKMARKS_SYNC_TEST_H_
diff --git a/chrome/test/live_sync/live_preferences_sync_test.h b/chrome/test/live_sync/live_preferences_sync_test.h
index 5ff8cf0..1ffb808 100644
--- a/chrome/test/live_sync/live_preferences_sync_test.h
+++ b/chrome/test/live_sync/live_preferences_sync_test.h
@@ -49,4 +49,23 @@ class TwoClientLivePreferencesSyncTest : public LivePreferencesSyncTest {
DISALLOW_COPY_AND_ASSIGN(TwoClientLivePreferencesSyncTest);
};
+class MultipleClientLivePreferencesSyncTest : public LivePreferencesSyncTest {
+ public:
+ MultipleClientLivePreferencesSyncTest()
+ : LivePreferencesSyncTest(MULTIPLE_CLIENT) {}
+ virtual ~MultipleClientLivePreferencesSyncTest() {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MultipleClientLivePreferencesSyncTest);
+};
+
+class ManyClientLivePreferencesSyncTest : public LivePreferencesSyncTest {
+ public:
+ ManyClientLivePreferencesSyncTest() : LivePreferencesSyncTest(MANY_CLIENT) {}
+ virtual ~ManyClientLivePreferencesSyncTest() {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ManyClientLivePreferencesSyncTest);
+};
+
#endif // CHROME_TEST_LIVE_SYNC_LIVE_PREFERENCES_SYNC_TEST_H_
diff --git a/chrome/test/live_sync/live_sync_test.h b/chrome/test/live_sync/live_sync_test.h
index 21a305e..e953170 100644
--- a/chrome/test/live_sync/live_sync_test.h
+++ b/chrome/test/live_sync/live_sync_test.h
@@ -16,6 +16,7 @@
#include "net/socket/ssl_test_util.h"
#include <string>
+#include <vector>
class CommandLine;
class Profile;
@@ -102,6 +103,12 @@ class LiveSyncTest : public InProcessBrowserTest {
// and manages its lifetime.
ProfileSyncServiceTestHarness* GetClient(int index);
+ // Returns a reference to the collection of sync clients. Callee owns the
+ // object and manages its lifetime.
+ std::vector<ProfileSyncServiceTestHarness*>& clients() {
+ return clients_.get();
+ }
+
// Returns a pointer to the sync profile that is used to verify changes to
// individual sync profiles. Callee owns the object and manages its lifetime.
Profile* verifier();
diff --git a/chrome/test/live_sync/many_client_live_bookmarks_sync_test.cc b/chrome/test/live_sync/many_client_live_bookmarks_sync_test.cc
new file mode 100644
index 0000000..2736537
--- /dev/null
+++ b/chrome/test/live_sync/many_client_live_bookmarks_sync_test.cc
@@ -0,0 +1,18 @@
+// 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.
+
+#include "chrome/browser/bookmarks/bookmark_utils.h"
+#include "chrome/test/live_sync/live_bookmarks_sync_test.h"
+
+IN_PROC_BROWSER_TEST_F(ManyClientLiveBookmarksSyncTest, Sanity) {
+ ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
+ BookmarkModelVerifier* v = verifier_helper();
+ v->AddURL(GetBookmarkModel(0), GetBookmarkBarNode(0), 0, L"Google URL",
+ GURL("http://www.google.com/"));
+ GetClient(0)->AwaitGroupSyncCycleCompletion(clients());
+
+ for (int i = 0; i < num_clients(); ++i) {
+ v->ExpectMatch(GetBookmarkModel(i));
+ }
+}
diff --git a/chrome/test/live_sync/many_client_live_preferences_sync_test.cc b/chrome/test/live_sync/many_client_live_preferences_sync_test.cc
new file mode 100644
index 0000000..1b28f39
--- /dev/null
+++ b/chrome/test/live_sync/many_client_live_preferences_sync_test.cc
@@ -0,0 +1,21 @@
+// 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.
+
+#include "chrome/test/live_sync/live_preferences_sync_test.h"
+
+IN_PROC_BROWSER_TEST_F(ManyClientLivePreferencesSyncTest, Sanity) {
+ ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
+
+ bool new_value = !GetVerifierPrefs()->GetBoolean(
+ prefs::kHomePageIsNewTabPage);
+ GetVerifierPrefs()->SetBoolean(prefs::kHomePageIsNewTabPage, new_value);
+ GetPrefs(0)->SetBoolean(prefs::kHomePageIsNewTabPage, new_value);
+
+ GetClient(0)->AwaitGroupSyncCycleCompletion(clients());
+
+ for (int i = 0; i < num_clients(); ++i) {
+ EXPECT_EQ(GetVerifierPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage),
+ GetPrefs(i)->GetBoolean(prefs::kHomePageIsNewTabPage));
+ }
+}
diff --git a/chrome/test/live_sync/multiple_client_live_bookmarks_sync_test.cc b/chrome/test/live_sync/multiple_client_live_bookmarks_sync_test.cc
new file mode 100644
index 0000000..c0b56a1
--- /dev/null
+++ b/chrome/test/live_sync/multiple_client_live_bookmarks_sync_test.cc
@@ -0,0 +1,23 @@
+// 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.
+
+#include "base/string_util.h"
+#include "chrome/browser/bookmarks/bookmark_utils.h"
+#include "chrome/test/live_sync/live_bookmarks_sync_test.h"
+
+IN_PROC_BROWSER_TEST_F(MultipleClientLiveBookmarksSyncTest, Sanity) {
+ ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
+ BookmarkModelVerifier* v = verifier_helper();
+ for (int i = 0; i < num_clients(); ++i) {
+ v->AddURL(GetBookmarkModel(i), GetBookmarkBarNode(i), 0,
+ StringPrintf(L"Google URL %d", i),
+ GURL(StringPrintf("http://www.google.com/%d", i)));
+ }
+ for (int i = 0; i < num_clients(); ++i) {
+ GetClient(i)->AwaitGroupSyncCycleCompletion(clients());
+ }
+ for (int i = 0; i < num_clients(); ++i) {
+ v->ExpectMatch(GetBookmarkModel(i));
+ }
+}
diff --git a/chrome/test/live_sync/multiple_client_live_preferences_sync_test.cc b/chrome/test/live_sync/multiple_client_live_preferences_sync_test.cc
new file mode 100644
index 0000000..63fcb57
--- /dev/null
+++ b/chrome/test/live_sync/multiple_client_live_preferences_sync_test.cc
@@ -0,0 +1,28 @@
+// 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.
+
+#include "base/scoped_ptr.h"
+#include "chrome/test/live_sync/live_preferences_sync_test.h"
+#include "chrome/browser/scoped_pref_update.h"
+
+IN_PROC_BROWSER_TEST_F(MultipleClientLivePreferencesSyncTest, Sanity) {
+ ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
+ scoped_array<ListValue*> client_urls(new ListValue*[num_clients()]);
+ for (int i = 0; i < num_clients(); ++i) {
+ client_urls[i] = GetPrefs(i)->GetMutableList(
+ prefs::kURLsToRestoreOnStartup);
+ }
+ for (int i = 0; i < num_clients(); ++i) {
+ client_urls[i]->Append(Value::CreateStringValue(StringPrintf(
+ "http://www.google.com/%d", i)));
+ ScopedPrefUpdate update(GetPrefs(i), prefs::kURLsToRestoreOnStartup);
+ }
+ for (int i = 0; i < num_clients(); ++i) {
+ GetClient(i)->AwaitGroupSyncCycleCompletion(clients());
+ }
+ for (int i = 1; i < num_clients(); ++i) {
+ EXPECT_TRUE(GetPrefs(0)->GetMutableList(prefs::kURLsToRestoreOnStartup)->
+ Equals(GetPrefs(i)->GetMutableList(prefs::kURLsToRestoreOnStartup)));
+ }
+}
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 de928fc..958ba4d 100644
--- a/chrome/test/live_sync/profile_sync_service_test_harness.cc
+++ b/chrome/test/live_sync/profile_sync_service_test_harness.cc
@@ -137,8 +137,13 @@ bool ProfileSyncServiceTestHarness::RunStateChangeMachine() {
const SyncSessionSnapshot* snap =
service_->backend()->GetLastSessionSnapshot();
DCHECK(snap) << "Should have been at least one sync session by now";
- if (snap->has_more_to_sync)
+ // TODO(rsimha): In an ideal world, snap->has_more_to_sync == false should
+ // be a sufficient condition for sync to have completed. However, the
+ // additional check of snap->unsynced_count is required due to
+ // http://crbug.com/48989.
+ if (snap->has_more_to_sync || snap->unsynced_count != 0) {
break;
+ }
EXPECT_LE(last_timestamp_, snap->max_local_timestamp);
last_timestamp_ = snap->max_local_timestamp;
@@ -185,11 +190,36 @@ bool ProfileSyncServiceTestHarness::AwaitMutualSyncCycleCompletion(
"Sync cycle completion on passive client.");
}
+bool ProfileSyncServiceTestHarness::AwaitGroupSyncCycleCompletion(
+ std::vector<ProfileSyncServiceTestHarness*>& partners) {
+ bool success = AwaitSyncCycleCompletion(
+ "Sync cycle completion on active client.");
+ if (!success)
+ return false;
+ bool return_value = true;
+ for (std::vector<ProfileSyncServiceTestHarness*>::iterator it =
+ partners.begin(); it != partners.end(); ++it) {
+ if (this != *it) {
+ return_value = return_value &&
+ (*it)->WaitUntilTimestampIsAtLeast(last_timestamp_,
+ "Sync cycle completion on partner client.");
+ }
+ }
+ return return_value;
+}
+
bool ProfileSyncServiceTestHarness::WaitUntilTimestampIsAtLeast(
int64 timestamp, const std::string& reason) {
- wait_state_ = WAITING_FOR_UPDATES;
min_timestamp_needed_ = timestamp;
- return AwaitStatusChangeWithTimeout(60, reason);
+ const SyncSessionSnapshot* snap =
+ service_->backend()->GetLastSessionSnapshot();
+ DCHECK(snap) << "Should have been at least one sync session by now";
+ if (snap->max_local_timestamp < min_timestamp_needed_) {
+ wait_state_ = WAITING_FOR_UPDATES;
+ return AwaitStatusChangeWithTimeout(60, reason);
+ } else {
+ return true;
+ }
}
bool ProfileSyncServiceTestHarness::AwaitStatusChangeWithTimeout(
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 bcce77f..fc91cfa 100644
--- a/chrome/test/live_sync/profile_sync_service_test_harness.h
+++ b/chrome/test/live_sync/profile_sync_service_test_harness.h
@@ -6,6 +6,7 @@
#define CHROME_TEST_LIVE_SYNC_PROFILE_SYNC_SERVICE_TEST_HARNESS_H_
#include <string>
+#include <vector>
#include "base/time.h"
#include "chrome/browser/sync/profile_sync_service.h"
@@ -45,6 +46,12 @@ class ProfileSyncServiceTestHarness : public ProfileSyncServiceObserver {
// from the message queue. Returns true if two sync cycles have completed.
bool AwaitMutualSyncCycleCompletion(ProfileSyncServiceTestHarness* partner);
+ // Blocks the caller until |this| completes its ongoing sync cycle and every
+ // other client in |partners| has a timestamp that is greater than or equal to
+ // the timestamp of |this|.
+ bool AwaitGroupSyncCycleCompletion(
+ std::vector<ProfileSyncServiceTestHarness*>& partners);
+
ProfileSyncService* service() { return service_; }
// See ProfileSyncService::ShouldPushChanges().