Commit b1292c8d authored by rsimha@chromium.org's avatar rsimha@chromium.org

Allow sync integration tests to operate on multiple datatypes: Typed Urls

The sync integration tests currently use a class hierarchy where the test classes for each datatype are subclasses of LiveSyncTest. While this design worked in the past, it allows tests to work with only one datatype at a time, and therefore doesn't allow us to test the interplay between datatypes.

This patch is another in the series of patches that will move away from an inheritance model to one where test cases can operate on more than one datatype. It updates the Typed Urls datatype to the new model, and contains the following changes:

- LiveTypedUrlsSyncTest is no longer a class that inherits from LiveSyncTest, but is now a namespace called typed_urls_helper, and contains a bunch of methods that perform various operations related to Typed Urls.
- SingleClientLiveTypedUrlsSyncTest is renamed to SingleClientTypedUrlsSyncTest, and is a subclass of LiveSyncTest. It uses the methods in namespace typed_urls_helper by including its header file and attaching itself to the helper.

In addition, bookmarks, preferences and autofill helpers and the SyncDatatypeHelper were originally implemented as static classes. Based on the code review feedback in this patch, they have been modified to the "functions-in-a-namespace" model similar to typed urls. This patch consists of those changes too.

BUG=88510
TEST=sync_integration_tests, sync_performance_tests

Review URL: http://codereview.chromium.org/7461109

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@95862 0039d316-1c4b-4281-b951-d872f2087c98
parent 6bed0851
...@@ -26,6 +26,10 @@ class AutofillMetrics; ...@@ -26,6 +26,10 @@ class AutofillMetrics;
class FormStructure; class FormStructure;
class Profile; class Profile;
namespace autofill_helper {
void SetProfiles(int, std::vector<AutofillProfile>*);
}
// Handles loading and saving Autofill profile information to the web database. // Handles loading and saving Autofill profile information to the web database.
// This class also stores the profiles loaded from the database for use during // This class also stores the profiles loaded from the database for use during
// Autofill. // Autofill.
...@@ -141,12 +145,12 @@ class PersonalDataManager ...@@ -141,12 +145,12 @@ class PersonalDataManager
// Make sure that only Profile and certain tests can create an instance of // Make sure that only Profile and certain tests can create an instance of
// PersonalDataManager. // PersonalDataManager.
friend class base::RefCountedThreadSafe<PersonalDataManager>; friend class base::RefCountedThreadSafe<PersonalDataManager>;
friend class AutofillHelper;
friend class AutofillMergeTest; friend class AutofillMergeTest;
friend class PersonalDataManagerTest; friend class PersonalDataManagerTest;
friend class ProfileImpl; friend class ProfileImpl;
friend class ProfileSyncServiceAutofillTest; friend class ProfileSyncServiceAutofillTest;
friend class TestingAutomationProvider; friend class TestingAutomationProvider;
friend void autofill_helper::SetProfiles(int, std::vector<AutofillProfile>*);
PersonalDataManager(); PersonalDataManager();
virtual ~PersonalDataManager(); virtual ~PersonalDataManager();
......
...@@ -3291,8 +3291,6 @@ ...@@ -3291,8 +3291,6 @@
'test/live_sync/live_sessions_sync_test.h', 'test/live_sync/live_sessions_sync_test.h',
'test/live_sync/live_themes_sync_test.cc', 'test/live_sync/live_themes_sync_test.cc',
'test/live_sync/live_themes_sync_test.h', 'test/live_sync/live_themes_sync_test.h',
'test/live_sync/live_typed_urls_sync_test.cc',
'test/live_sync/live_typed_urls_sync_test.h',
'test/live_sync/live_sync_extension_helper.cc', 'test/live_sync/live_sync_extension_helper.cc',
'test/live_sync/live_sync_extension_helper.h', 'test/live_sync/live_sync_extension_helper.h',
'test/live_sync/live_sync_test.cc', 'test/live_sync/live_sync_test.cc',
...@@ -3304,8 +3302,8 @@ ...@@ -3304,8 +3302,8 @@
'test/live_sync/multiple_client_bookmarks_sync_test.cc', 'test/live_sync/multiple_client_bookmarks_sync_test.cc',
'test/live_sync/multiple_client_live_passwords_sync_test.cc', 'test/live_sync/multiple_client_live_passwords_sync_test.cc',
'test/live_sync/multiple_client_live_sessions_sync_test.cc', 'test/live_sync/multiple_client_live_sessions_sync_test.cc',
'test/live_sync/multiple_client_live_typed_urls_sync_test.cc',
'test/live_sync/multiple_client_preferences_sync_test.cc', 'test/live_sync/multiple_client_preferences_sync_test.cc',
'test/live_sync/multiple_client_typed_urls_sync_test.cc',
'test/live_sync/preferences_helper.cc', 'test/live_sync/preferences_helper.cc',
'test/live_sync/preferences_helper.h', 'test/live_sync/preferences_helper.h',
'test/live_sync/single_client_bookmarks_sync_test.cc', 'test/live_sync/single_client_bookmarks_sync_test.cc',
...@@ -3314,8 +3312,8 @@ ...@@ -3314,8 +3312,8 @@
'test/live_sync/single_client_live_passwords_sync_test.cc', 'test/live_sync/single_client_live_passwords_sync_test.cc',
'test/live_sync/single_client_live_sessions_sync_test.cc', 'test/live_sync/single_client_live_sessions_sync_test.cc',
'test/live_sync/single_client_live_themes_sync_test.cc', 'test/live_sync/single_client_live_themes_sync_test.cc',
'test/live_sync/single_client_live_typed_urls_sync_test.cc',
'test/live_sync/single_client_preferences_sync_test.cc', 'test/live_sync/single_client_preferences_sync_test.cc',
'test/live_sync/single_client_typed_urls_sync_test.cc',
'test/live_sync/sync_datatype_helper.cc', 'test/live_sync/sync_datatype_helper.cc',
'test/live_sync/sync_datatype_helper.h', 'test/live_sync/sync_datatype_helper.h',
'test/live_sync/sync_errors_test.cc', 'test/live_sync/sync_errors_test.cc',
...@@ -3326,8 +3324,10 @@ ...@@ -3326,8 +3324,10 @@
'test/live_sync/two_client_live_passwords_sync_test.cc', 'test/live_sync/two_client_live_passwords_sync_test.cc',
'test/live_sync/two_client_live_sessions_sync_test.cc', 'test/live_sync/two_client_live_sessions_sync_test.cc',
'test/live_sync/two_client_live_themes_sync_test.cc', 'test/live_sync/two_client_live_themes_sync_test.cc',
'test/live_sync/two_client_live_typed_urls_sync_test.cc',
'test/live_sync/two_client_preferences_sync_test.cc', 'test/live_sync/two_client_preferences_sync_test.cc',
'test/live_sync/two_client_typed_urls_sync_test.cc',
'test/live_sync/typed_urls_helper.cc',
'test/live_sync/typed_urls_helper.h',
], ],
'conditions': [ 'conditions': [
['toolkit_uses_gtk == 1', { ['toolkit_uses_gtk == 1', {
...@@ -3424,8 +3424,6 @@ ...@@ -3424,8 +3424,6 @@
'test/live_sync/live_passwords_sync_test.h', 'test/live_sync/live_passwords_sync_test.h',
'test/live_sync/live_sessions_sync_test.cc', 'test/live_sync/live_sessions_sync_test.cc',
'test/live_sync/live_sessions_sync_test.h', 'test/live_sync/live_sessions_sync_test.h',
'test/live_sync/live_typed_urls_sync_test.cc',
'test/live_sync/live_typed_urls_sync_test.h',
'test/live_sync/live_sync_extension_helper.cc', 'test/live_sync/live_sync_extension_helper.cc',
'test/live_sync/live_sync_extension_helper.h', 'test/live_sync/live_sync_extension_helper.h',
'test/live_sync/live_sync_test.cc', 'test/live_sync/live_sync_test.cc',
...@@ -3440,6 +3438,8 @@ ...@@ -3440,6 +3438,8 @@
'test/live_sync/performance/typed_urls_sync_perf_test.cc', 'test/live_sync/performance/typed_urls_sync_perf_test.cc',
'test/live_sync/sync_datatype_helper.cc', 'test/live_sync/sync_datatype_helper.cc',
'test/live_sync/sync_datatype_helper.h', 'test/live_sync/sync_datatype_helper.h',
'test/live_sync/typed_urls_helper.cc',
'test/live_sync/typed_urls_helper.h',
], ],
'conditions': [ 'conditions': [
['toolkit_uses_gtk == 1', { ['toolkit_uses_gtk == 1', {
......
...@@ -15,13 +15,16 @@ ...@@ -15,13 +15,16 @@
#include "chrome/browser/webdata/web_database.h" #include "chrome/browser/webdata/web_database.h"
#include "chrome/common/chrome_notification_types.h" #include "chrome/common/chrome_notification_types.h"
#include "chrome/test/live_sync/live_sync_test.h" #include "chrome/test/live_sync/live_sync_test.h"
#include "chrome/test/live_sync/sync_datatype_helper.h"
#include "chrome/test/base/thread_observer_helper.h" #include "chrome/test/base/thread_observer_helper.h"
#include "webkit/glue/form_field.h" #include "webkit/glue/form_field.h"
using base::WaitableEvent; using base::WaitableEvent;
using sync_datatype_helper::test;
using testing::_; using testing::_;
namespace { namespace {
class GetAllAutofillEntries class GetAllAutofillEntries
: public base::RefCountedThreadSafe<GetAllAutofillEntries> { : public base::RefCountedThreadSafe<GetAllAutofillEntries> {
public: public:
...@@ -80,12 +83,9 @@ class MockPersonalDataManagerObserver : public PersonalDataManager::Observer { ...@@ -80,12 +83,9 @@ class MockPersonalDataManagerObserver : public PersonalDataManager::Observer {
} // namespace } // namespace
AutofillHelper::AutofillHelper() {} namespace autofill_helper {
AutofillHelper::~AutofillHelper() {}
// static AutofillProfile CreateAutofillProfile(ProfileType type) {
AutofillProfile AutofillHelper::CreateAutofillProfile(ProfileType type) {
AutofillProfile profile; AutofillProfile profile;
switch (type) { switch (type) {
case PROFILE_MARION: case PROFILE_MARION:
...@@ -120,18 +120,15 @@ AutofillProfile AutofillHelper::CreateAutofillProfile(ProfileType type) { ...@@ -120,18 +120,15 @@ AutofillProfile AutofillHelper::CreateAutofillProfile(ProfileType type) {
return profile; return profile;
} }
// static WebDataService* GetWebDataService(int index) {
WebDataService* AutofillHelper::GetWebDataService(int index) {
return test()->GetProfile(index)->GetWebDataService(Profile::EXPLICIT_ACCESS); return test()->GetProfile(index)->GetWebDataService(Profile::EXPLICIT_ACCESS);
} }
// static PersonalDataManager* GetPersonalDataManager(int index) {
PersonalDataManager* AutofillHelper::GetPersonalDataManager(int index) {
return test()->GetProfile(index)->GetPersonalDataManager(); return test()->GetProfile(index)->GetPersonalDataManager();
} }
// static void AddKeys(int profile,
void AutofillHelper::AddKeys(int profile,
const std::set<AutofillKey>& keys) { const std::set<AutofillKey>& keys) {
std::vector<webkit_glue::FormField> form_fields; std::vector<webkit_glue::FormField> form_fields;
for (std::set<AutofillKey>::const_iterator i = keys.begin(); for (std::set<AutofillKey>::const_iterator i = keys.begin();
...@@ -157,8 +154,7 @@ void AutofillHelper::AddKeys(int profile, ...@@ -157,8 +154,7 @@ void AutofillHelper::AddKeys(int profile,
done_event.Wait(); done_event.Wait();
} }
// static void RemoveKey(int profile, const AutofillKey& key) {
void AutofillHelper::RemoveKey(int profile, const AutofillKey& key) {
WaitableEvent done_event(false, false); WaitableEvent done_event(false, false);
scoped_refptr<AutofillDBThreadObserverHelper> observer_helper( scoped_refptr<AutofillDBThreadObserverHelper> observer_helper(
new AutofillDBThreadObserverHelper()); new AutofillDBThreadObserverHelper());
...@@ -171,8 +167,7 @@ void AutofillHelper::RemoveKey(int profile, const AutofillKey& key) { ...@@ -171,8 +167,7 @@ void AutofillHelper::RemoveKey(int profile, const AutofillKey& key) {
done_event.Wait(); done_event.Wait();
} }
// static std::set<AutofillEntry> GetAllKeys(int profile) {
std::set<AutofillEntry> AutofillHelper::GetAllKeys(int profile) {
WebDataService* wds = GetWebDataService(profile); WebDataService* wds = GetWebDataService(profile);
scoped_refptr<GetAllAutofillEntries> get_all_entries = scoped_refptr<GetAllAutofillEntries> get_all_entries =
new GetAllAutofillEntries(wds); new GetAllAutofillEntries(wds);
...@@ -186,14 +181,11 @@ std::set<AutofillEntry> AutofillHelper::GetAllKeys(int profile) { ...@@ -186,14 +181,11 @@ std::set<AutofillEntry> AutofillHelper::GetAllKeys(int profile) {
return all_keys; return all_keys;
} }
// static bool KeysMatch(int profile_a, int profile_b) {
bool AutofillHelper::KeysMatch(int profile_a, int profile_b) {
return GetAllKeys(profile_a) == GetAllKeys(profile_b); return GetAllKeys(profile_a) == GetAllKeys(profile_b);
} }
// static void SetProfiles(int profile, std::vector<AutofillProfile>* autofill_profiles) {
void AutofillHelper::SetProfiles(
int profile, std::vector<AutofillProfile>* autofill_profiles) {
MockPersonalDataManagerObserver observer; MockPersonalDataManagerObserver observer;
EXPECT_CALL(observer, OnPersonalDataChanged()). EXPECT_CALL(observer, OnPersonalDataChanged()).
WillOnce(QuitUIMessageLoop()); WillOnce(QuitUIMessageLoop());
...@@ -204,30 +196,26 @@ void AutofillHelper::SetProfiles( ...@@ -204,30 +196,26 @@ void AutofillHelper::SetProfiles(
pdm->RemoveObserver(&observer); pdm->RemoveObserver(&observer);
} }
// static void AddProfile(int profile, const AutofillProfile& autofill_profile) {
void AutofillHelper::AddProfile(int profile,
const AutofillProfile& autofill_profile) {
const std::vector<AutofillProfile*>& all_profiles = GetAllProfiles(profile); const std::vector<AutofillProfile*>& all_profiles = GetAllProfiles(profile);
std::vector<AutofillProfile> autofill_profiles; std::vector<AutofillProfile> autofill_profiles;
for (size_t i = 0; i < all_profiles.size(); ++i) for (size_t i = 0; i < all_profiles.size(); ++i)
autofill_profiles.push_back(*all_profiles[i]); autofill_profiles.push_back(*all_profiles[i]);
autofill_profiles.push_back(autofill_profile); autofill_profiles.push_back(autofill_profile);
SetProfiles(profile, &autofill_profiles); autofill_helper::SetProfiles(profile, &autofill_profiles);
} }
// static void RemoveProfile(int profile, const std::string& guid) {
void AutofillHelper::RemoveProfile(int profile, const std::string& guid) {
const std::vector<AutofillProfile*>& all_profiles = GetAllProfiles(profile); const std::vector<AutofillProfile*>& all_profiles = GetAllProfiles(profile);
std::vector<AutofillProfile> autofill_profiles; std::vector<AutofillProfile> autofill_profiles;
for (size_t i = 0; i < all_profiles.size(); ++i) { for (size_t i = 0; i < all_profiles.size(); ++i) {
if (all_profiles[i]->guid() != guid) if (all_profiles[i]->guid() != guid)
autofill_profiles.push_back(*all_profiles[i]); autofill_profiles.push_back(*all_profiles[i]);
} }
SetProfiles(profile, &autofill_profiles); autofill_helper::SetProfiles(profile, &autofill_profiles);
} }
// static void UpdateProfile(int profile,
void AutofillHelper::UpdateProfile(int profile,
const std::string& guid, const std::string& guid,
const AutofillType& type, const AutofillType& type,
const string16& value) { const string16& value) {
...@@ -238,11 +226,10 @@ void AutofillHelper::UpdateProfile(int profile, ...@@ -238,11 +226,10 @@ void AutofillHelper::UpdateProfile(int profile,
if (all_profiles[i]->guid() == guid) if (all_profiles[i]->guid() == guid)
profiles.back().SetInfo(type.field_type(), value); profiles.back().SetInfo(type.field_type(), value);
} }
SetProfiles(profile, &profiles); autofill_helper::SetProfiles(profile, &profiles);
} }
// static const std::vector<AutofillProfile*>& GetAllProfiles(
const std::vector<AutofillProfile*>& AutofillHelper::GetAllProfiles(
int profile) { int profile) {
MockPersonalDataManagerObserver observer; MockPersonalDataManagerObserver observer;
EXPECT_CALL(observer, OnPersonalDataChanged()). EXPECT_CALL(observer, OnPersonalDataChanged()).
...@@ -255,13 +242,11 @@ const std::vector<AutofillProfile*>& AutofillHelper::GetAllProfiles( ...@@ -255,13 +242,11 @@ const std::vector<AutofillProfile*>& AutofillHelper::GetAllProfiles(
return pdm->web_profiles(); return pdm->web_profiles();
} }
// static int GetProfileCount(int profile) {
int AutofillHelper::GetProfileCount(int profile) {
return GetAllProfiles(profile).size(); return GetAllProfiles(profile).size();
} }
// static bool ProfilesMatch(int profile_a, int profile_b) {
bool AutofillHelper::ProfilesMatch(int profile_a, int profile_b) {
const std::vector<AutofillProfile*>& autofill_profiles_a = const std::vector<AutofillProfile*>& autofill_profiles_a =
GetAllProfiles(profile_a); GetAllProfiles(profile_a);
std::map<std::string, AutofillProfile> autofill_profiles_a_map; std::map<std::string, AutofillProfile> autofill_profiles_a_map;
...@@ -296,8 +281,7 @@ bool AutofillHelper::ProfilesMatch(int profile_a, int profile_b) { ...@@ -296,8 +281,7 @@ bool AutofillHelper::ProfilesMatch(int profile_a, int profile_b) {
return true; return true;
} }
// static bool AllProfilesMatch() {
bool AutofillHelper::AllProfilesMatch() {
for (int i = 1; i < test()->num_clients(); ++i) { for (int i = 1; i < test()->num_clients(); ++i) {
if (!ProfilesMatch(0, i)) { if (!ProfilesMatch(0, i)) {
LOG(ERROR) << "Profile " << i << "does not contain the same autofill " LOG(ERROR) << "Profile " << i << "does not contain the same autofill "
...@@ -307,3 +291,5 @@ bool AutofillHelper::AllProfilesMatch() { ...@@ -307,3 +291,5 @@ bool AutofillHelper::AllProfilesMatch() {
} }
return true; return true;
} }
} // namespace autofill_helper
...@@ -11,88 +11,80 @@ ...@@ -11,88 +11,80 @@
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "chrome/browser/autofill/personal_data_manager.h" #include "chrome/browser/autofill/personal_data_manager.h"
#include "chrome/test/live_sync/sync_datatype_helper.h"
class AutofillEntry; class AutofillEntry;
class AutofillKey; class AutofillKey;
class AutofillProfile; class AutofillProfile;
class WebDataService; class WebDataService;
class AutofillHelper : public SyncDatatypeHelper { namespace autofill_helper {
public:
enum ProfileType { enum ProfileType {
PROFILE_MARION, PROFILE_MARION,
PROFILE_HOMER, PROFILE_HOMER,
PROFILE_FRASIER, PROFILE_FRASIER,
PROFILE_NULL PROFILE_NULL
};
// Used to access the web data service within a particular sync profile.
static WebDataService* GetWebDataService(int index) WARN_UNUSED_RESULT;
// Used to access the personal data manager within a particular sync profile.
static PersonalDataManager* GetPersonalDataManager(
int index) WARN_UNUSED_RESULT;
// Adds the form fields in |keys| to the WebDataService of sync profile
// |profile|.
static void AddKeys(int profile, const std::set<AutofillKey>& keys);
// Removes the form field in |key| from the WebDataService of sync profile
// |profile|.
static void RemoveKey(int profile, const AutofillKey& key);
// Gets all the form fields in the WebDataService of sync profile |profile|.
static std::set<AutofillEntry> GetAllKeys(int profile) WARN_UNUSED_RESULT;
// Compares the form fields in the WebDataServices of sync profiles
// |profile_a| and |profile_b|. Returns true if they match.
static bool KeysMatch(int profile_a, int profile_b) WARN_UNUSED_RESULT;
// Replaces the Autofill profiles in sync profile |profile| with
// |autofill_profiles|.
static void SetProfiles(int profile,
std::vector<AutofillProfile>* autofill_profiles);
// Adds the autofill profile |autofill_profile| to sync profile |profile|.
static void AddProfile(int profile, const AutofillProfile& autofill_profile);
// Removes the autofill profile with guid |guid| from sync profile
// |profile|.
static void RemoveProfile(int profile, const std::string& guid);
// Updates the autofill profile with guid |guid| in sync profile |profile|
// to |type| and |value|.
static void UpdateProfile(int profile,
const std::string& guid,
const AutofillType& type,
const string16& value);
// Gets all the Autofill profiles in the PersonalDataManager of sync profile
// |profile|.
static const std::vector<AutofillProfile*>& GetAllProfiles(
int profile) WARN_UNUSED_RESULT;
// Returns the number of autofill profiles contained by sync profile
// |profile|.
static int GetProfileCount(int profile);
// Compares the Autofill profiles in the PersonalDataManagers of sync profiles
// |profile_a| and |profile_b|. Returns true if they match.
static bool ProfilesMatch(int profile_a, int profile_b) WARN_UNUSED_RESULT;
// Compares the autofill profiles for all sync profiles, and returns true if
// they all match.
static bool AllProfilesMatch() WARN_UNUSED_RESULT;
// Creates a test autofill profile based on the persona specified in |type|.
static AutofillProfile CreateAutofillProfile(ProfileType type);
protected:
AutofillHelper();
virtual ~AutofillHelper();
private:
DISALLOW_COPY_AND_ASSIGN(AutofillHelper);
}; };
// Used to access the web data service within a particular sync profile.
WebDataService* GetWebDataService(int index) WARN_UNUSED_RESULT;
// Used to access the personal data manager within a particular sync profile.
PersonalDataManager* GetPersonalDataManager(int index) WARN_UNUSED_RESULT;
// Adds the form fields in |keys| to the WebDataService of sync profile
// |profile|.
void AddKeys(int profile, const std::set<AutofillKey>& keys);
// Removes the form field in |key| from the WebDataService of sync profile
// |profile|.
void RemoveKey(int profile, const AutofillKey& key);
// Gets all the form fields in the WebDataService of sync profile |profile|.
std::set<AutofillEntry> GetAllKeys(int profile) WARN_UNUSED_RESULT;
// Compares the form fields in the WebDataServices of sync profiles
// |profile_a| and |profile_b|. Returns true if they match.
bool KeysMatch(int profile_a, int profile_b) WARN_UNUSED_RESULT;
// Replaces the Autofill profiles in sync profile |profile| with
// |autofill_profiles|.
void SetProfiles(int profile, std::vector<AutofillProfile>* autofill_profiles);
// Adds the autofill profile |autofill_profile| to sync profile |profile|.
void AddProfile(int profile, const AutofillProfile& autofill_profile);
// Removes the autofill profile with guid |guid| from sync profile
// |profile|.
void RemoveProfile(int profile, const std::string& guid);
// Updates the autofill profile with guid |guid| in sync profile |profile|
// to |type| and |value|.
void UpdateProfile(int profile,
const std::string& guid,
const AutofillType& type,
const string16& value);
// Gets all the Autofill profiles in the PersonalDataManager of sync profile
// |profile|.
const std::vector<AutofillProfile*>& GetAllProfiles(
int profile) WARN_UNUSED_RESULT;
// Returns the number of autofill profiles contained by sync profile
// |profile|.
int GetProfileCount(int profile);
// Compares the Autofill profiles in the PersonalDataManagers of sync profiles
// |profile_a| and |profile_b|. Returns true if they match.
bool ProfilesMatch(int profile_a, int profile_b) WARN_UNUSED_RESULT;
// Compares the autofill profiles for all sync profiles, and returns true if
// they all match.
bool AllProfilesMatch() WARN_UNUSED_RESULT;
// Creates a test autofill profile based on the persona specified in |type|.
AutofillProfile CreateAutofillProfile(ProfileType type);
} // namespace autofill_helper
#endif // CHROME_TEST_LIVE_SYNC_AUTOFILL_HELPER_H_ #endif // CHROME_TEST_LIVE_SYNC_AUTOFILL_HELPER_H_
This diff is collapsed.
This diff is collapsed.
...@@ -114,7 +114,7 @@ LiveSyncTest::LiveSyncTest(TestType test_type) ...@@ -114,7 +114,7 @@ LiveSyncTest::LiveSyncTest(TestType test_type)
use_verifier_(true), use_verifier_(true),
test_server_handle_(base::kNullProcessHandle) { test_server_handle_(base::kNullProcessHandle) {
InProcessBrowserTest::set_show_window(true); InProcessBrowserTest::set_show_window(true);
SyncDatatypeHelper::AssociateWithTest(this); sync_datatype_helper::AssociateWithTest(this);
switch (test_type_) { switch (test_type_) {
case SINGLE_CLIENT: { case SINGLE_CLIENT: {
num_clients_ = 1; num_clients_ = 1;
......
// Copyright (c) 2011 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.
#ifndef CHROME_TEST_LIVE_SYNC_LIVE_TYPED_URLS_SYNC_TEST_H_
#define CHROME_TEST_LIVE_SYNC_LIVE_TYPED_URLS_SYNC_TEST_H_
#pragma once
#include <vector>
#include "chrome/browser/history/history_types.h"
#include "chrome/test/live_sync/live_sync_test.h"
namespace base {
class Time;
}
class HistoryService;
class LiveTypedUrlsSyncTest : public LiveSyncTest {
public:
explicit LiveTypedUrlsSyncTest(TestType test_type);
virtual ~LiveTypedUrlsSyncTest();
// Gets the typed URLs from a specific sync profile.
std::vector<history::URLRow> GetTypedUrlsFromClient(int index);
// Adds a URL to the history DB for a specific sync profile (just registers a
// new visit if the URL already exists).
void AddUrlToHistory(int index, const GURL& url);
// Deletes a URL from the history DB for a specific sync profile.
void DeleteUrlFromHistory(int index, const GURL& url);
// Returns true if all clients match the verifier profile.
void AssertAllProfilesHaveSameURLsAsVerifier();
// Checks that the two vectors contain the same set of URLRows (possibly in
// a different order).
void AssertURLRowVectorsAreEqual(const std::vector<history::URLRow>& left,
const std::vector<history::URLRow>& right);
// Checks that the passed URLRows are equivalent.
void AssertURLRowsAreEqual(const history::URLRow& left,
const history::URLRow& right);
// Returns a unique timestamp to use when generating page visits
// (HistoryService does not like having identical timestamps and will modify
// the timestamps behind the scenes if it encounters them, which leads to
// spurious test failures when the resulting timestamps aren't what we
// expect).
base::Time GetTimestamp();
private:
// Waits for the history DB thread to finish executing its current set of
// tasks.
void WaitForHistoryDBThread(int index);
// Creates a URLRow in the specified HistoryService.
void AddToHistory(HistoryService* service,
const GURL& url,
const base::Time& timestamp);
std::vector<history::URLRow> GetTypedUrlsFromHistoryService(
HistoryService* service);
base::Time timestamp_;
DISALLOW_COPY_AND_ASSIGN(LiveTypedUrlsSyncTest);
};
class SingleClientLiveTypedUrlsSyncTest : public LiveTypedUrlsSyncTest {
public:
SingleClientLiveTypedUrlsSyncTest()
: LiveTypedUrlsSyncTest(SINGLE_CLIENT) {}
virtual ~SingleClientLiveTypedUrlsSyncTest() {}
private:
DISALLOW_COPY_AND_ASSIGN(SingleClientLiveTypedUrlsSyncTest);
};
class TwoClientLiveTypedUrlsSyncTest : public LiveTypedUrlsSyncTest {
public:
TwoClientLiveTypedUrlsSyncTest() : LiveTypedUrlsSyncTest(TWO_CLIENT) {}
virtual ~TwoClientLiveTypedUrlsSyncTest() {}
private:
DISALLOW_COPY_AND_ASSIGN(TwoClientLiveTypedUrlsSyncTest);
};
class MultipleClientLiveTypedUrlsSyncTest : public LiveTypedUrlsSyncTest {
public:
MultipleClientLiveTypedUrlsSyncTest()
: LiveTypedUrlsSyncTest(MULTIPLE_CLIENT) {}
virtual ~MultipleClientLiveTypedUrlsSyncTest() {}
private:
DISALLOW_COPY_AND_ASSIGN(MultipleClientLiveTypedUrlsSyncTest);
};
#endif // CHROME_TEST_LIVE_SYNC_LIVE_TYPED_URLS_SYNC_TEST_H_
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
#include "chrome/test/live_sync/bookmarks_helper.h" #include "chrome/test/live_sync/bookmarks_helper.h"
#include "chrome/test/live_sync/live_sync_test.h" #include "chrome/test/live_sync/live_sync_test.h"
using bookmarks_helper::AddURL;
using bookmarks_helper::AllModelsMatch;
class ManyClientBookmarksSyncTest : public LiveSyncTest { class ManyClientBookmarksSyncTest : public LiveSyncTest {
public: public:
ManyClientBookmarksSyncTest() : LiveSyncTest(MANY_CLIENT) {} ManyClientBookmarksSyncTest() : LiveSyncTest(MANY_CLIENT) {}
...@@ -19,8 +22,7 @@ class ManyClientBookmarksSyncTest : public LiveSyncTest { ...@@ -19,8 +22,7 @@ class ManyClientBookmarksSyncTest : public LiveSyncTest {
// TODO(rsimha): Enable once http://crbug.com/69604 is fixed. // TODO(rsimha): Enable once http://crbug.com/69604 is fixed.
IN_PROC_BROWSER_TEST_F(ManyClientBookmarksSyncTest, DISABLED_Sanity) { IN_PROC_BROWSER_TEST_F(ManyClientBookmarksSyncTest, DISABLED_Sanity) {
ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
ASSERT_TRUE(BookmarksHelper::AddURL( ASSERT_TRUE(AddURL(0, L"Google URL", GURL("http://www.google.com/")) != NULL);
0, L"Google URL", GURL("http://www.google.com/")) != NULL);
ASSERT_TRUE(GetClient(0)->AwaitGroupSyncCycleCompletion(clients())); ASSERT_TRUE(GetClient(0)->AwaitGroupSyncCycleCompletion(clients()));
ASSERT_TRUE(BookmarksHelper::AllModelsMatch()); ASSERT_TRUE(AllModelsMatch());
} }
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
#include "chrome/test/live_sync/live_sync_test.h" #include "chrome/test/live_sync/live_sync_test.h"
#include "chrome/test/live_sync/preferences_helper.h" #include "chrome/test/live_sync/preferences_helper.h"
using preferences_helper::BooleanPrefMatches;
using preferences_helper::ChangeBooleanPref;
class ManyClientPreferencesSyncTest : public LiveSyncTest { class ManyClientPreferencesSyncTest : public LiveSyncTest {
public: public:
ManyClientPreferencesSyncTest() : LiveSyncTest(MANY_CLIENT) {} ManyClientPreferencesSyncTest() : LiveSyncTest(MANY_CLIENT) {}
...@@ -19,10 +22,8 @@ class ManyClientPreferencesSyncTest : public LiveSyncTest { ...@@ -19,10 +22,8 @@ class ManyClientPreferencesSyncTest : public LiveSyncTest {
// TODO(rsimha): Enable once http://crbug.com/69604 is fixed. // TODO(rsimha): Enable once http://crbug.com/69604 is fixed.
IN_PROC_BROWSER_TEST_F(ManyClientPreferencesSyncTest, DISABLED_Sanity) { IN_PROC_BROWSER_TEST_F(ManyClientPreferencesSyncTest, DISABLED_Sanity) {
ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
ASSERT_TRUE(PreferencesHelper::BooleanPrefMatches( ASSERT_TRUE(BooleanPrefMatches(prefs::kHomePageIsNewTabPage));
prefs::kHomePageIsNewTabPage)); ChangeBooleanPref(0, prefs::kHomePageIsNewTabPage);
PreferencesHelper::ChangeBooleanPref(0, prefs::kHomePageIsNewTabPage);
ASSERT_TRUE(GetClient(0)->AwaitGroupSyncCycleCompletion(clients())); ASSERT_TRUE(GetClient(0)->AwaitGroupSyncCycleCompletion(clients()));
ASSERT_TRUE(PreferencesHelper::BooleanPrefMatches( ASSERT_TRUE(BooleanPrefMatches(prefs::kHomePageIsNewTabPage));
prefs::kHomePageIsNewTabPage));
} }
...@@ -12,6 +12,13 @@ ...@@ -12,6 +12,13 @@
#include "chrome/test/live_sync/bookmarks_helper.h" #include "chrome/test/live_sync/bookmarks_helper.h"
#include "chrome/test/live_sync/preferences_helper.h" #include "chrome/test/live_sync/preferences_helper.h"
using bookmarks_helper::AddURL;
using bookmarks_helper::IndexedURL;
using bookmarks_helper::IndexedURLTitle;
using preferences_helper::BooleanPrefMatches;
using preferences_helper::ChangeBooleanPref;
class MigrationErrorsTest : public LiveSyncTest { class MigrationErrorsTest : public LiveSyncTest {
public: public:
MigrationErrorsTest() : LiveSyncTest(TWO_CLIENT) {} MigrationErrorsTest() : LiveSyncTest(TWO_CLIENT) {}
...@@ -32,10 +39,10 @@ IN_PROC_BROWSER_TEST_F(MigrationErrorsTest, MigratePrefsThenModifyBookmark) { ...@@ -32,10 +39,10 @@ IN_PROC_BROWSER_TEST_F(MigrationErrorsTest, MigratePrefsThenModifyBookmark) {
ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
// Phase 1: Before migrating anything, create & sync a preference. // Phase 1: Before migrating anything, create & sync a preference.
ASSERT_TRUE(PreferencesHelper::BooleanPrefMatches(prefs::kShowHomeButton)); ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton));
PreferencesHelper::ChangeBooleanPref(0, prefs::kShowHomeButton); ChangeBooleanPref(0, prefs::kShowHomeButton);
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
ASSERT_TRUE(PreferencesHelper::BooleanPrefMatches(prefs::kShowHomeButton)); ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton));
// Phase 2: Trigger a preference migration on the server. // Phase 2: Trigger a preference migration on the server.
syncable::ModelTypeSet migrate_types; syncable::ModelTypeSet migrate_types;
...@@ -43,15 +50,14 @@ IN_PROC_BROWSER_TEST_F(MigrationErrorsTest, MigratePrefsThenModifyBookmark) { ...@@ -43,15 +50,14 @@ IN_PROC_BROWSER_TEST_F(MigrationErrorsTest, MigratePrefsThenModifyBookmark) {
TriggerMigrationDoneError(migrate_types); TriggerMigrationDoneError(migrate_types);
// Phase 3: Modify a bookmark and wait for it to sync. // Phase 3: Modify a bookmark and wait for it to sync.
ASSERT_TRUE(BookmarksHelper::AddURL(0, BookmarksHelper::IndexedURLTitle(0), ASSERT_TRUE(AddURL(0, IndexedURLTitle(0), GURL(IndexedURL(0))) != NULL);
GURL(BookmarksHelper::IndexedURL(0))) != NULL);
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
// Phase 4: Verify that preferences can still be synchronized. // Phase 4: Verify that preferences can still be synchronized.
ASSERT_TRUE(PreferencesHelper::BooleanPrefMatches(prefs::kShowHomeButton)); ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton));
PreferencesHelper::ChangeBooleanPref(0, prefs::kShowHomeButton); ChangeBooleanPref(0, prefs::kShowHomeButton);
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
ASSERT_TRUE(PreferencesHelper::BooleanPrefMatches(prefs::kShowHomeButton)); ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton));
} }
// Triggers a server migration on two datatypes, then makes a local // Triggers a server migration on two datatypes, then makes a local
...@@ -66,10 +72,10 @@ IN_PROC_BROWSER_TEST_F(MigrationErrorsTest, ...@@ -66,10 +72,10 @@ IN_PROC_BROWSER_TEST_F(MigrationErrorsTest,
ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
// Phase 1: Before migrating anything, create & sync a preference. // Phase 1: Before migrating anything, create & sync a preference.
ASSERT_TRUE(PreferencesHelper::BooleanPrefMatches(prefs::kShowHomeButton)); ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton));
PreferencesHelper::ChangeBooleanPref(0, prefs::kShowHomeButton); ChangeBooleanPref(0, prefs::kShowHomeButton);
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
ASSERT_TRUE(PreferencesHelper::BooleanPrefMatches(prefs::kShowHomeButton)); ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton));
// Phase 2: Trigger a migration on the server. // Phase 2: Trigger a migration on the server.
syncable::ModelTypeSet migrate_types; syncable::ModelTypeSet migrate_types;
...@@ -78,15 +84,14 @@ IN_PROC_BROWSER_TEST_F(MigrationErrorsTest, ...@@ -78,15 +84,14 @@ IN_PROC_BROWSER_TEST_F(MigrationErrorsTest,
TriggerMigrationDoneError(migrate_types); TriggerMigrationDoneError(migrate_types);
// Phase 3: Modify a bookmark and wait for it to sync. // Phase 3: Modify a bookmark and wait for it to sync.
ASSERT_TRUE(BookmarksHelper::AddURL(0, BookmarksHelper::IndexedURLTitle(0), ASSERT_TRUE(AddURL(0, IndexedURLTitle(0), GURL(IndexedURL(0))) != NULL);
GURL(BookmarksHelper::IndexedURL(0))) != NULL);
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
// Phase 4: Verify that preferences can still be synchronized. // Phase 4: Verify that preferences can still be synchronized.
ASSERT_TRUE(PreferencesHelper::BooleanPrefMatches(prefs::kShowHomeButton)); ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton));
PreferencesHelper::ChangeBooleanPref(0, prefs::kShowHomeButton); ChangeBooleanPref(0, prefs::kShowHomeButton);
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
ASSERT_TRUE(PreferencesHelper::BooleanPrefMatches(prefs::kShowHomeButton)); ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton));
} }
// Migrate every datatype in sequence; the catch being that the server // Migrate every datatype in sequence; the catch being that the server
...@@ -100,10 +105,10 @@ IN_PROC_BROWSER_TEST_F(MigrationErrorsTest, MigrationHellWithoutNigori) { ...@@ -100,10 +105,10 @@ IN_PROC_BROWSER_TEST_F(MigrationErrorsTest, MigrationHellWithoutNigori) {
ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
// Phase 1: Before migrating anything, create & sync a preference. // Phase 1: Before migrating anything, create & sync a preference.
ASSERT_TRUE(PreferencesHelper::BooleanPrefMatches(prefs::kShowHomeButton)); ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton));
PreferencesHelper::ChangeBooleanPref(0, prefs::kShowHomeButton); ChangeBooleanPref(0, prefs::kShowHomeButton);
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
ASSERT_TRUE(PreferencesHelper::BooleanPrefMatches(prefs::kShowHomeButton)); ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton));
// Phase 2: Queue up a horrendous number of migrations on the server. // Phase 2: Queue up a horrendous number of migrations on the server.
// Let the first nudge be a datatype that's neither prefs nor bookmarks. // Let the first nudge be a datatype that's neither prefs nor bookmarks.
...@@ -121,15 +126,14 @@ IN_PROC_BROWSER_TEST_F(MigrationErrorsTest, MigrationHellWithoutNigori) { ...@@ -121,15 +126,14 @@ IN_PROC_BROWSER_TEST_F(MigrationErrorsTest, MigrationHellWithoutNigori) {
} }
// Phase 3: Modify a bookmark and wait for it to sync. // Phase 3: Modify a bookmark and wait for it to sync.
ASSERT_TRUE(BookmarksHelper::AddURL(0, BookmarksHelper::IndexedURLTitle(0), ASSERT_TRUE(AddURL(0, IndexedURLTitle(0), GURL(IndexedURL(0))) != NULL);
GURL(BookmarksHelper::IndexedURL(0))) != NULL);
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
// Phase 4: Verify that preferences can still be synchronized. // Phase 4: Verify that preferences can still be synchronized.
ASSERT_TRUE(PreferencesHelper::BooleanPrefMatches(prefs::kShowHomeButton)); ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton));
PreferencesHelper::ChangeBooleanPref(0, prefs::kShowHomeButton); ChangeBooleanPref(0, prefs::kShowHomeButton);
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
ASSERT_TRUE(PreferencesHelper::BooleanPrefMatches(prefs::kShowHomeButton)); ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton));
} }
IN_PROC_BROWSER_TEST_F(MigrationErrorsTest, MigrationHellWithNigori) { IN_PROC_BROWSER_TEST_F(MigrationErrorsTest, MigrationHellWithNigori) {
...@@ -141,10 +145,10 @@ IN_PROC_BROWSER_TEST_F(MigrationErrorsTest, MigrationHellWithNigori) { ...@@ -141,10 +145,10 @@ IN_PROC_BROWSER_TEST_F(MigrationErrorsTest, MigrationHellWithNigori) {
ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
// Phase 1: Before migrating anything, create & sync a preference. // Phase 1: Before migrating anything, create & sync a preference.
ASSERT_TRUE(PreferencesHelper::BooleanPrefMatches(prefs::kShowHomeButton)); ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton));
PreferencesHelper::ChangeBooleanPref(0, prefs::kShowHomeButton); ChangeBooleanPref(0, prefs::kShowHomeButton);
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
ASSERT_TRUE(PreferencesHelper::BooleanPrefMatches(prefs::kShowHomeButton)); ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton));
// Phase 2: Queue up a horrendous number of migrations on the server. // Phase 2: Queue up a horrendous number of migrations on the server.
// Let the first nudge be a datatype that's neither prefs nor bookmarks. // Let the first nudge be a datatype that's neither prefs nor bookmarks.
...@@ -163,13 +167,12 @@ IN_PROC_BROWSER_TEST_F(MigrationErrorsTest, MigrationHellWithNigori) { ...@@ -163,13 +167,12 @@ IN_PROC_BROWSER_TEST_F(MigrationErrorsTest, MigrationHellWithNigori) {
} }
// Phase 3: Modify a bookmark and wait for it to sync. // Phase 3: Modify a bookmark and wait for it to sync.
ASSERT_TRUE(BookmarksHelper::AddURL(0, BookmarksHelper::IndexedURLTitle(0), ASSERT_TRUE(AddURL(0, IndexedURLTitle(0), GURL(IndexedURL(0))) != NULL);
GURL(BookmarksHelper::IndexedURL(0))) != NULL);
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
// Phase 4: Verify that preferences can still be synchronized. // Phase 4: Verify that preferences can still be synchronized.
ASSERT_TRUE(PreferencesHelper::BooleanPrefMatches(prefs::kShowHomeButton)); ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton));
PreferencesHelper::ChangeBooleanPref(0, prefs::kShowHomeButton); ChangeBooleanPref(0, prefs::kShowHomeButton);
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
ASSERT_TRUE(PreferencesHelper::BooleanPrefMatches(prefs::kShowHomeButton)); ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton));
} }
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
#include "chrome/test/live_sync/bookmarks_helper.h" #include "chrome/test/live_sync/bookmarks_helper.h"
#include "chrome/test/live_sync/live_sync_test.h" #include "chrome/test/live_sync/live_sync_test.h"
using bookmarks_helper::AddURL;
using bookmarks_helper::AllModelsMatch;
class MultipleClientBookmarksSyncTest : public LiveSyncTest { class MultipleClientBookmarksSyncTest : public LiveSyncTest {
public: public:
MultipleClientBookmarksSyncTest() : LiveSyncTest(MULTIPLE_CLIENT) {} MultipleClientBookmarksSyncTest() : LiveSyncTest(MULTIPLE_CLIENT) {}
...@@ -20,10 +23,9 @@ IN_PROC_BROWSER_TEST_F(MultipleClientBookmarksSyncTest, Sanity) { ...@@ -20,10 +23,9 @@ IN_PROC_BROWSER_TEST_F(MultipleClientBookmarksSyncTest, Sanity) {
ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
DisableVerifier(); DisableVerifier();
for (int i = 0; i < num_clients(); ++i) { for (int i = 0; i < num_clients(); ++i) {
ASSERT_TRUE(BookmarksHelper::AddURL( ASSERT_TRUE(AddURL(i, base::StringPrintf(L"Google URL %d", i),
i, base::StringPrintf(L"Google URL %d", i), GURL(StringPrintf("http://www.google.com/%d", i))) != NULL);
GURL(StringPrintf("http://www.google.com/%d", i))) != NULL);
} }
ASSERT_TRUE(AwaitQuiescence()); ASSERT_TRUE(AwaitQuiescence());
ASSERT_TRUE(BookmarksHelper::AllModelsMatch()); ASSERT_TRUE(AllModelsMatch());
} }
...@@ -8,6 +8,9 @@ ...@@ -8,6 +8,9 @@
#include "chrome/test/live_sync/live_sync_test.h" #include "chrome/test/live_sync/live_sync_test.h"
#include "chrome/test/live_sync/preferences_helper.h" #include "chrome/test/live_sync/preferences_helper.h"
using preferences_helper::ChangeListPref;
using preferences_helper::ListPrefMatches;
class MultipleClientPreferencesSyncTest : public LiveSyncTest { class MultipleClientPreferencesSyncTest : public LiveSyncTest {
public: public:
MultipleClientPreferencesSyncTest() : LiveSyncTest(MULTIPLE_CLIENT) {} MultipleClientPreferencesSyncTest() : LiveSyncTest(MULTIPLE_CLIENT) {}
...@@ -25,10 +28,9 @@ IN_PROC_BROWSER_TEST_F(MultipleClientPreferencesSyncTest, Sanity) { ...@@ -25,10 +28,9 @@ IN_PROC_BROWSER_TEST_F(MultipleClientPreferencesSyncTest, Sanity) {
ListValue urls; ListValue urls;
urls.Append(Value::CreateStringValue( urls.Append(Value::CreateStringValue(
base::StringPrintf("http://www.google.com/%d", i))); base::StringPrintf("http://www.google.com/%d", i)));
PreferencesHelper::ChangeListPref(i, prefs::kURLsToRestoreOnStartup, urls); ChangeListPref(i, prefs::kURLsToRestoreOnStartup, urls);
} }
ASSERT_TRUE(AwaitQuiescence()); ASSERT_TRUE(AwaitQuiescence());
ASSERT_TRUE(PreferencesHelper::ListPrefMatches( ASSERT_TRUE(ListPrefMatches(prefs::kURLsToRestoreOnStartup));
prefs::kURLsToRestoreOnStartup));
} }
...@@ -8,10 +8,24 @@ ...@@ -8,10 +8,24 @@
#include "chrome/browser/history/history_types.h" #include "chrome/browser/history/history_types.h"
#include "chrome/browser/sessions/session_service.h" #include "chrome/browser/sessions/session_service.h"
#include "chrome/browser/sync/profile_sync_service_harness.h" #include "chrome/browser/sync/profile_sync_service_harness.h"
#include "chrome/test/live_sync/live_typed_urls_sync_test.h" #include "chrome/test/live_sync/live_sync_test.h"
#include "chrome/test/live_sync/typed_urls_helper.h"
using typed_urls_helper::AddUrlToHistory;
using typed_urls_helper::AssertAllProfilesHaveSameURLsAsVerifier;
using typed_urls_helper::GetTypedUrlsFromClient;
class MultipleClientTypedUrlsSyncTest : public LiveSyncTest {
public:
MultipleClientTypedUrlsSyncTest() : LiveSyncTest(MULTIPLE_CLIENT) {}
virtual ~MultipleClientTypedUrlsSyncTest() {}
private:
DISALLOW_COPY_AND_ASSIGN(MultipleClientTypedUrlsSyncTest);
};
// TCM: 3728323 // TCM: 3728323
IN_PROC_BROWSER_TEST_F(MultipleClientLiveTypedUrlsSyncTest, AddToOne) { IN_PROC_BROWSER_TEST_F(MultipleClientTypedUrlsSyncTest, AddToOne) {
const string16 kHistoryUrl( const string16 kHistoryUrl(
ASCIIToUTF16("http://www.add-one-history.google.com/")); ASCIIToUTF16("http://www.add-one-history.google.com/"));
ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
...@@ -30,7 +44,7 @@ IN_PROC_BROWSER_TEST_F(MultipleClientLiveTypedUrlsSyncTest, AddToOne) { ...@@ -30,7 +44,7 @@ IN_PROC_BROWSER_TEST_F(MultipleClientLiveTypedUrlsSyncTest, AddToOne) {
AssertAllProfilesHaveSameURLsAsVerifier(); AssertAllProfilesHaveSameURLsAsVerifier();
} }
IN_PROC_BROWSER_TEST_F(MultipleClientLiveTypedUrlsSyncTest, AddToAll) { IN_PROC_BROWSER_TEST_F(MultipleClientTypedUrlsSyncTest, AddToAll) {
const string16 kHistoryUrl( const string16 kHistoryUrl(
ASCIIToUTF16("http://www.add-all-history.google.com/")); ASCIIToUTF16("http://www.add-all-history.google.com/"));
ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
......
...@@ -10,6 +10,11 @@ ...@@ -10,6 +10,11 @@
#include "chrome/test/live_sync/live_sync_test.h" #include "chrome/test/live_sync/live_sync_test.h"
#include "chrome/test/live_sync/performance/sync_timing_helper.h" #include "chrome/test/live_sync/performance/sync_timing_helper.h"
using autofill_helper::AllProfilesMatch;
using autofill_helper::GetAllProfiles;
using autofill_helper::GetProfileCount;
using autofill_helper::SetProfiles;
// TODO(braffert): Move kNumBenchmarkPoints and kBenchmarkPoints for all // TODO(braffert): Move kNumBenchmarkPoints and kBenchmarkPoints for all
// datatypes into a performance test base class, once it is possible to do so. // datatypes into a performance test base class, once it is possible to do so.
static const int kNumProfiles = 150; static const int kNumProfiles = 150;
...@@ -61,7 +66,7 @@ class AutofillSyncPerfTest : public LiveSyncTest { ...@@ -61,7 +66,7 @@ class AutofillSyncPerfTest : public LiveSyncTest {
void AutofillSyncPerfTest::AddProfiles(int profile, int num_profiles) { void AutofillSyncPerfTest::AddProfiles(int profile, int num_profiles) {
const std::vector<AutofillProfile*>& all_profiles = const std::vector<AutofillProfile*>& all_profiles =
AutofillHelper::GetAllProfiles(profile); GetAllProfiles(profile);
std::vector<AutofillProfile> autofill_profiles; std::vector<AutofillProfile> autofill_profiles;
for (size_t i = 0; i < all_profiles.size(); ++i) { for (size_t i = 0; i < all_profiles.size(); ++i) {
autofill_profiles.push_back(*all_profiles[i]); autofill_profiles.push_back(*all_profiles[i]);
...@@ -69,24 +74,24 @@ void AutofillSyncPerfTest::AddProfiles(int profile, int num_profiles) { ...@@ -69,24 +74,24 @@ void AutofillSyncPerfTest::AddProfiles(int profile, int num_profiles) {
for (int i = 0; i < num_profiles; ++i) { for (int i = 0; i < num_profiles; ++i) {
autofill_profiles.push_back(NextAutofillProfile()); autofill_profiles.push_back(NextAutofillProfile());
} }
AutofillHelper::SetProfiles(profile, &autofill_profiles); SetProfiles(profile, &autofill_profiles);
} }
void AutofillSyncPerfTest::UpdateProfiles(int profile) { void AutofillSyncPerfTest::UpdateProfiles(int profile) {
const std::vector<AutofillProfile*>& all_profiles = const std::vector<AutofillProfile*>& all_profiles =
AutofillHelper::GetAllProfiles(profile); GetAllProfiles(profile);
std::vector<AutofillProfile> autofill_profiles; std::vector<AutofillProfile> autofill_profiles;
for (size_t i = 0; i < all_profiles.size(); ++i) { for (size_t i = 0; i < all_profiles.size(); ++i) {
autofill_profiles.push_back(*all_profiles[i]); autofill_profiles.push_back(*all_profiles[i]);
autofill_profiles.back().SetInfo(AutofillFieldType(NAME_FIRST), autofill_profiles.back().SetInfo(AutofillFieldType(NAME_FIRST),
UTF8ToUTF16(NextName())); UTF8ToUTF16(NextName()));
} }
AutofillHelper::SetProfiles(profile, &autofill_profiles); SetProfiles(profile, &autofill_profiles);
} }
void AutofillSyncPerfTest::RemoveProfiles(int profile) { void AutofillSyncPerfTest::RemoveProfiles(int profile) {
std::vector<AutofillProfile> empty; std::vector<AutofillProfile> empty;
AutofillHelper::SetProfiles(profile, &empty); SetProfiles(profile, &empty);
} }
void AutofillSyncPerfTest::Cleanup() { void AutofillSyncPerfTest::Cleanup() {
...@@ -127,19 +132,19 @@ IN_PROC_BROWSER_TEST_F(AutofillSyncPerfTest, P0) { ...@@ -127,19 +132,19 @@ IN_PROC_BROWSER_TEST_F(AutofillSyncPerfTest, P0) {
AddProfiles(0, kNumProfiles); AddProfiles(0, kNumProfiles);
base::TimeDelta dt = base::TimeDelta dt =
SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1));
ASSERT_EQ(kNumProfiles, AutofillHelper::GetProfileCount(1)); ASSERT_EQ(kNumProfiles, GetProfileCount(1));
SyncTimingHelper::PrintResult("autofill", "add", dt); SyncTimingHelper::PrintResult("autofill", "add", dt);
// TCM ID - 7549835. // TCM ID - 7549835.
UpdateProfiles(0); UpdateProfiles(0);
dt = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); dt = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1));
ASSERT_EQ(kNumProfiles, AutofillHelper::GetProfileCount(1)); ASSERT_EQ(kNumProfiles, GetProfileCount(1));
SyncTimingHelper::PrintResult("autofill", "update", dt); SyncTimingHelper::PrintResult("autofill", "update", dt);
// TCM ID - 7553678. // TCM ID - 7553678.
RemoveProfiles(0); RemoveProfiles(0);
dt = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); dt = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1));
ASSERT_EQ(0, AutofillHelper::GetProfileCount(1)); ASSERT_EQ(0, GetProfileCount(1));
SyncTimingHelper::PrintResult("autofill", "delete", dt); SyncTimingHelper::PrintResult("autofill", "delete", dt);
} }
...@@ -151,24 +156,24 @@ IN_PROC_BROWSER_TEST_F(AutofillSyncPerfTest, DISABLED_Benchmark) { ...@@ -151,24 +156,24 @@ IN_PROC_BROWSER_TEST_F(AutofillSyncPerfTest, DISABLED_Benchmark) {
AddProfiles(0, num_profiles); AddProfiles(0, num_profiles);
base::TimeDelta dt_add = base::TimeDelta dt_add =
SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1));
ASSERT_EQ(num_profiles, AutofillHelper::GetProfileCount(0)); ASSERT_EQ(num_profiles, GetProfileCount(0));
ASSERT_TRUE(AutofillHelper::AllProfilesMatch()); ASSERT_TRUE(AllProfilesMatch());
VLOG(0) << std::endl << "Add: " << num_profiles << " " VLOG(0) << std::endl << "Add: " << num_profiles << " "
<< dt_add.InSecondsF(); << dt_add.InSecondsF();
UpdateProfiles(0); UpdateProfiles(0);
base::TimeDelta dt_update = base::TimeDelta dt_update =
SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1));
ASSERT_EQ(num_profiles, AutofillHelper::GetProfileCount(0)); ASSERT_EQ(num_profiles, GetProfileCount(0));
ASSERT_TRUE(AutofillHelper::AllProfilesMatch()); ASSERT_TRUE(AllProfilesMatch());
VLOG(0) << std::endl << "Update: " << num_profiles << " " VLOG(0) << std::endl << "Update: " << num_profiles << " "
<< dt_update.InSecondsF(); << dt_update.InSecondsF();
RemoveProfiles(0); RemoveProfiles(0);
base::TimeDelta dt_delete = base::TimeDelta dt_delete =
SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1));
ASSERT_EQ(0, AutofillHelper::GetProfileCount(0)); ASSERT_EQ(0, GetProfileCount(0));
ASSERT_TRUE(AutofillHelper::AllProfilesMatch()); ASSERT_TRUE(AllProfilesMatch());
VLOG(0) << std::endl << "Delete: " << num_profiles << " " VLOG(0) << std::endl << "Delete: " << num_profiles << " "
<< dt_delete.InSecondsF(); << dt_delete.InSecondsF();
......
...@@ -7,6 +7,14 @@ ...@@ -7,6 +7,14 @@
#include "chrome/test/live_sync/live_sync_test.h" #include "chrome/test/live_sync/live_sync_test.h"
#include "chrome/test/live_sync/performance/sync_timing_helper.h" #include "chrome/test/live_sync/performance/sync_timing_helper.h"
using bookmarks_helper::AddURL;
using bookmarks_helper::AllModelsMatch;
using bookmarks_helper::GetBookmarkBarNode;
using bookmarks_helper::IndexedURL;
using bookmarks_helper::IndexedURLTitle;
using bookmarks_helper::Remove;
using bookmarks_helper::SetURL;
// TODO(braffert): Move kNumBenchmarkPoints and kBenchmarkPoints for all // TODO(braffert): Move kNumBenchmarkPoints and kBenchmarkPoints for all
// datatypes into a performance test base class, once it is possible to do so. // datatypes into a performance test base class, once it is possible to do so.
static const int kNumBookmarks = 150; static const int kNumBookmarks = 150;
...@@ -52,30 +60,29 @@ class BookmarksSyncPerfTest : public LiveSyncTest { ...@@ -52,30 +60,29 @@ class BookmarksSyncPerfTest : public LiveSyncTest {
void BookmarksSyncPerfTest::AddURLs(int profile, int num_urls) { void BookmarksSyncPerfTest::AddURLs(int profile, int num_urls) {
for (int i = 0; i < num_urls; ++i) { for (int i = 0; i < num_urls; ++i) {
ASSERT_TRUE(BookmarksHelper::AddURL( ASSERT_TRUE(AddURL(
profile, 0, NextIndexedURLTitle(), GURL(NextIndexedURL())) != NULL); profile, 0, NextIndexedURLTitle(), GURL(NextIndexedURL())) != NULL);
} }
} }
void BookmarksSyncPerfTest::UpdateURLs(int profile) { void BookmarksSyncPerfTest::UpdateURLs(int profile) {
for (int i = 0; for (int i = 0;
i < BookmarksHelper::GetBookmarkBarNode(profile)->child_count(); i < GetBookmarkBarNode(profile)->child_count();
++i) { ++i) {
ASSERT_TRUE(BookmarksHelper::SetURL( ASSERT_TRUE(SetURL(profile,
profile, BookmarksHelper::GetBookmarkBarNode(profile)->GetChild(i), GetBookmarkBarNode(profile)->GetChild(i),
GURL(NextIndexedURL()))); GURL(NextIndexedURL())));
} }
} }
void BookmarksSyncPerfTest::RemoveURLs(int profile) { void BookmarksSyncPerfTest::RemoveURLs(int profile) {
while (!BookmarksHelper::GetBookmarkBarNode(profile)->empty()) { while (!GetBookmarkBarNode(profile)->empty()) {
BookmarksHelper::Remove( Remove(profile, GetBookmarkBarNode(profile), 0);
profile, BookmarksHelper::GetBookmarkBarNode(profile), 0);
} }
} }
int BookmarksSyncPerfTest::GetURLCount(int profile) { int BookmarksSyncPerfTest::GetURLCount(int profile) {
return BookmarksHelper::GetBookmarkBarNode(profile)->child_count(); return GetBookmarkBarNode(profile)->child_count();
} }
void BookmarksSyncPerfTest::Cleanup() { void BookmarksSyncPerfTest::Cleanup() {
...@@ -83,16 +90,16 @@ void BookmarksSyncPerfTest::Cleanup() { ...@@ -83,16 +90,16 @@ void BookmarksSyncPerfTest::Cleanup() {
RemoveURLs(i); RemoveURLs(i);
} }
ASSERT_TRUE(AwaitQuiescence()); ASSERT_TRUE(AwaitQuiescence());
ASSERT_EQ(0, BookmarksHelper::GetBookmarkBarNode(0)->child_count()); ASSERT_EQ(0, GetBookmarkBarNode(0)->child_count());
ASSERT_TRUE(BookmarksHelper::AllModelsMatch()); ASSERT_TRUE(AllModelsMatch());
} }
std::string BookmarksSyncPerfTest::NextIndexedURL() { std::string BookmarksSyncPerfTest::NextIndexedURL() {
return BookmarksHelper::IndexedURL(url_number_++); return IndexedURL(url_number_++);
} }
std::wstring BookmarksSyncPerfTest::NextIndexedURLTitle() { std::wstring BookmarksSyncPerfTest::NextIndexedURLTitle() {
return BookmarksHelper::IndexedURLTitle(url_title_number_++); return IndexedURLTitle(url_title_number_++);
} }
IN_PROC_BROWSER_TEST_F(BookmarksSyncPerfTest, P0) { IN_PROC_BROWSER_TEST_F(BookmarksSyncPerfTest, P0) {
...@@ -127,26 +134,24 @@ IN_PROC_BROWSER_TEST_F(BookmarksSyncPerfTest, DISABLED_Benchmark) { ...@@ -127,26 +134,24 @@ IN_PROC_BROWSER_TEST_F(BookmarksSyncPerfTest, DISABLED_Benchmark) {
AddURLs(0, num_bookmarks); AddURLs(0, num_bookmarks);
base::TimeDelta dt_add = base::TimeDelta dt_add =
SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1));
ASSERT_EQ(num_bookmarks, ASSERT_EQ(num_bookmarks, GetBookmarkBarNode(0)->child_count());
BookmarksHelper::GetBookmarkBarNode(0)->child_count()); ASSERT_TRUE(AllModelsMatch());
ASSERT_TRUE(BookmarksHelper::AllModelsMatch());
VLOG(0) << std::endl << "Add: " << num_bookmarks << " " VLOG(0) << std::endl << "Add: " << num_bookmarks << " "
<< dt_add.InSecondsF(); << dt_add.InSecondsF();
UpdateURLs(0); UpdateURLs(0);
base::TimeDelta dt_update = base::TimeDelta dt_update =
SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1));
ASSERT_EQ(num_bookmarks, ASSERT_EQ(num_bookmarks, GetBookmarkBarNode(0)->child_count());
BookmarksHelper::GetBookmarkBarNode(0)->child_count()); ASSERT_TRUE(AllModelsMatch());
ASSERT_TRUE(BookmarksHelper::AllModelsMatch());
VLOG(0) << std::endl << "Update: " << num_bookmarks << " " VLOG(0) << std::endl << "Update: " << num_bookmarks << " "
<< dt_update.InSecondsF(); << dt_update.InSecondsF();
RemoveURLs(0); RemoveURLs(0);
base::TimeDelta dt_delete = base::TimeDelta dt_delete =
SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1));
ASSERT_EQ(0, BookmarksHelper::GetBookmarkBarNode(0)->child_count()); ASSERT_EQ(0, GetBookmarkBarNode(0)->child_count());
ASSERT_TRUE(BookmarksHelper::AllModelsMatch()); ASSERT_TRUE(AllModelsMatch());
VLOG(0) << std::endl << "Delete: " << num_bookmarks << " " VLOG(0) << std::endl << "Delete: " << num_bookmarks << " "
<< dt_delete.InSecondsF(); << dt_delete.InSecondsF();
......
...@@ -4,8 +4,14 @@ ...@@ -4,8 +4,14 @@
#include "base/stringprintf.h" #include "base/stringprintf.h"
#include "chrome/browser/sync/profile_sync_service_harness.h" #include "chrome/browser/sync/profile_sync_service_harness.h"
#include "chrome/test/live_sync/live_sync_test.h"
#include "chrome/test/live_sync/performance/sync_timing_helper.h" #include "chrome/test/live_sync/performance/sync_timing_helper.h"
#include "chrome/test/live_sync/live_typed_urls_sync_test.h" #include "chrome/test/live_sync/typed_urls_helper.h"
using typed_urls_helper::AddUrlToHistory;
using typed_urls_helper::AssertAllProfilesHaveSameURLsAsVerifier;
using typed_urls_helper::DeleteUrlFromHistory;
using typed_urls_helper::GetTypedUrlsFromClient;
// TODO(braffert): Move kNumBenchmarkPoints and kBenchmarkPoints for all // TODO(braffert): Move kNumBenchmarkPoints and kBenchmarkPoints for all
// datatypes into a performance test base class, once it is possible to do so. // datatypes into a performance test base class, once it is possible to do so.
...@@ -15,9 +21,11 @@ static const size_t kBenchmarkPoints[] = {1, 10, 20, 30, 40, 50, 75, 100, 125, ...@@ -15,9 +21,11 @@ static const size_t kBenchmarkPoints[] = {1, 10, 20, 30, 40, 50, 75, 100, 125,
150, 175, 200, 225, 250, 300, 350, 150, 175, 200, 225, 250, 300, 350,
400, 500}; 400, 500};
class TypedUrlsSyncPerfTest: public TwoClientLiveTypedUrlsSyncTest { class TypedUrlsSyncPerfTest : public LiveSyncTest {
public: public:
TypedUrlsSyncPerfTest() : url_number_(0) {} TypedUrlsSyncPerfTest()
: LiveSyncTest(TWO_CLIENT),
url_number_(0) {}
// Adds |num_urls| new unique typed urls to |profile|. // Adds |num_urls| new unique typed urls to |profile|.
void AddURLs(int profile, int num_urls); void AddURLs(int profile, int num_urls);
...@@ -31,7 +39,7 @@ class TypedUrlsSyncPerfTest: public TwoClientLiveTypedUrlsSyncTest { ...@@ -31,7 +39,7 @@ class TypedUrlsSyncPerfTest: public TwoClientLiveTypedUrlsSyncTest {
// Returns the number of typed urls stored in |profile|. // Returns the number of typed urls stored in |profile|.
int GetURLCount(int profile); int GetURLCount(int profile);
// Remvoes all typed urls for all profiles. Called between benchmark // Removes all typed urls for all profiles. Called between benchmark
// iterations. // iterations.
void Cleanup(); void Cleanup();
......
...@@ -10,78 +10,66 @@ ...@@ -10,78 +10,66 @@
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/profile_sync_service_harness.h" #include "chrome/browser/sync/profile_sync_service_harness.h"
#include "chrome/test/live_sync/live_sync_test.h" #include "chrome/test/live_sync/live_sync_test.h"
#include "chrome/test/live_sync/sync_datatype_helper.h"
PreferencesHelper::PreferencesHelper() {} using sync_datatype_helper::test;
PreferencesHelper::~PreferencesHelper() {} namespace preferences_helper {
// static PrefService* GetPrefs(int index) {
PrefService* PreferencesHelper::GetPrefs(int index) {
return test()->GetProfile(index)->GetPrefs(); return test()->GetProfile(index)->GetPrefs();
} }
// static PrefService* GetVerifierPrefs() {
PrefService* PreferencesHelper::GetVerifierPrefs() {
return test()->verifier()->GetPrefs(); return test()->verifier()->GetPrefs();
} }
// static void ChangeBooleanPref(int index, const char* pref_name) {
void PreferencesHelper::ChangeBooleanPref(int index, const char* pref_name) {
bool new_value = !GetPrefs(index)->GetBoolean(pref_name); bool new_value = !GetPrefs(index)->GetBoolean(pref_name);
GetPrefs(index)->SetBoolean(pref_name, new_value); GetPrefs(index)->SetBoolean(pref_name, new_value);
if (test()->use_verifier()) if (test()->use_verifier())
GetVerifierPrefs()->SetBoolean(pref_name, new_value); GetVerifierPrefs()->SetBoolean(pref_name, new_value);
} }
// static void ChangeIntegerPref(int index, const char* pref_name, int new_value) {
void PreferencesHelper::ChangeIntegerPref(int index,
const char* pref_name,
int new_value) {
GetPrefs(index)->SetInteger(pref_name, new_value); GetPrefs(index)->SetInteger(pref_name, new_value);
if (test()->use_verifier()) if (test()->use_verifier())
GetVerifierPrefs()->SetInteger(pref_name, new_value); GetVerifierPrefs()->SetInteger(pref_name, new_value);
} }
// static void ChangeDoublePref(int index, const char* pref_name, double new_value) {
void PreferencesHelper::ChangeDoublePref(int index,
const char* pref_name,
double new_value) {
GetPrefs(index)->SetDouble(pref_name, new_value); GetPrefs(index)->SetDouble(pref_name, new_value);
if (test()->use_verifier()) if (test()->use_verifier())
GetVerifierPrefs()->SetDouble(pref_name, new_value); GetVerifierPrefs()->SetDouble(pref_name, new_value);
} }
// static void ChangeStringPref(int index,
void PreferencesHelper::ChangeStringPref(int index, const char* pref_name,
const char* pref_name, const std::string& new_value) {
const std::string& new_value) {
GetPrefs(index)->SetString(pref_name, new_value); GetPrefs(index)->SetString(pref_name, new_value);
if (test()->use_verifier()) if (test()->use_verifier())
GetVerifierPrefs()->SetString(pref_name, new_value); GetVerifierPrefs()->SetString(pref_name, new_value);
} }
// static void AppendStringPref(int index,
void PreferencesHelper::AppendStringPref(int index, const char* pref_name,
const char* pref_name, const std::string& append_value) {
const std::string& append_value) {
ChangeStringPref(index, ChangeStringPref(index,
pref_name, pref_name,
GetPrefs(index)->GetString(pref_name) + append_value); GetPrefs(index)->GetString(pref_name) + append_value);
} }
// static void ChangeFilePathPref(int index,
void PreferencesHelper::ChangeFilePathPref(int index, const char* pref_name,
const char* pref_name, const FilePath& new_value) {
const FilePath& new_value) {
GetPrefs(index)->SetFilePath(pref_name, new_value); GetPrefs(index)->SetFilePath(pref_name, new_value);
if (test()->use_verifier()) if (test()->use_verifier())
GetVerifierPrefs()->SetFilePath(pref_name, new_value); GetVerifierPrefs()->SetFilePath(pref_name, new_value);
} }
// static void ChangeListPref(int index,
void PreferencesHelper::ChangeListPref(int index, const char* pref_name,
const char* pref_name, const ListValue& new_value) {
const ListValue& new_value) {
{ {
ListPrefUpdate update(GetPrefs(index), pref_name); ListPrefUpdate update(GetPrefs(index), pref_name);
ListValue* list = update.Get(); ListValue* list = update.Get();
...@@ -103,8 +91,7 @@ void PreferencesHelper::ChangeListPref(int index, ...@@ -103,8 +91,7 @@ void PreferencesHelper::ChangeListPref(int index,
} }
} }
// static bool BooleanPrefMatches(const char* pref_name) {
bool PreferencesHelper::BooleanPrefMatches(const char* pref_name) {
bool reference_value; bool reference_value;
if (test()->use_verifier()) { if (test()->use_verifier()) {
reference_value = GetVerifierPrefs()->GetBoolean(pref_name); reference_value = GetVerifierPrefs()->GetBoolean(pref_name);
...@@ -121,8 +108,7 @@ bool PreferencesHelper::BooleanPrefMatches(const char* pref_name) { ...@@ -121,8 +108,7 @@ bool PreferencesHelper::BooleanPrefMatches(const char* pref_name) {
return true; return true;
} }
// static bool IntegerPrefMatches(const char* pref_name) {
bool PreferencesHelper::IntegerPrefMatches(const char* pref_name) {
int reference_value; int reference_value;
if (test()->use_verifier()) { if (test()->use_verifier()) {
reference_value = GetVerifierPrefs()->GetInteger(pref_name); reference_value = GetVerifierPrefs()->GetInteger(pref_name);
...@@ -139,8 +125,7 @@ bool PreferencesHelper::IntegerPrefMatches(const char* pref_name) { ...@@ -139,8 +125,7 @@ bool PreferencesHelper::IntegerPrefMatches(const char* pref_name) {
return true; return true;
} }
// static bool DoublePrefMatches(const char* pref_name) {
bool PreferencesHelper::DoublePrefMatches(const char* pref_name) {
double reference_value; double reference_value;
if (test()->use_verifier()) { if (test()->use_verifier()) {
reference_value = GetVerifierPrefs()->GetDouble(pref_name); reference_value = GetVerifierPrefs()->GetDouble(pref_name);
...@@ -157,8 +142,7 @@ bool PreferencesHelper::DoublePrefMatches(const char* pref_name) { ...@@ -157,8 +142,7 @@ bool PreferencesHelper::DoublePrefMatches(const char* pref_name) {
return true; return true;
} }
// static bool StringPrefMatches(const char* pref_name) {
bool PreferencesHelper::StringPrefMatches(const char* pref_name) {
std::string reference_value; std::string reference_value;
if (test()->use_verifier()) { if (test()->use_verifier()) {
reference_value = GetVerifierPrefs()->GetString(pref_name); reference_value = GetVerifierPrefs()->GetString(pref_name);
...@@ -175,8 +159,7 @@ bool PreferencesHelper::StringPrefMatches(const char* pref_name) { ...@@ -175,8 +159,7 @@ bool PreferencesHelper::StringPrefMatches(const char* pref_name) {
return true; return true;
} }
// static bool FilePathPrefMatches(const char* pref_name) {
bool PreferencesHelper::FilePathPrefMatches(const char* pref_name) {
FilePath reference_value; FilePath reference_value;
if (test()->use_verifier()) { if (test()->use_verifier()) {
reference_value = GetVerifierPrefs()->GetFilePath(pref_name); reference_value = GetVerifierPrefs()->GetFilePath(pref_name);
...@@ -193,8 +176,7 @@ bool PreferencesHelper::FilePathPrefMatches(const char* pref_name) { ...@@ -193,8 +176,7 @@ bool PreferencesHelper::FilePathPrefMatches(const char* pref_name) {
return true; return true;
} }
// static bool ListPrefMatches(const char* pref_name) {
bool PreferencesHelper::ListPrefMatches(const char* pref_name) {
const ListValue* reference_value; const ListValue* reference_value;
if (test()->use_verifier()) { if (test()->use_verifier()) {
reference_value = GetVerifierPrefs()->GetList(pref_name); reference_value = GetVerifierPrefs()->GetList(pref_name);
...@@ -211,13 +193,13 @@ bool PreferencesHelper::ListPrefMatches(const char* pref_name) { ...@@ -211,13 +193,13 @@ bool PreferencesHelper::ListPrefMatches(const char* pref_name) {
return true; return true;
} }
// static bool EnableEncryption(int index) {
bool PreferencesHelper::EnableEncryption(int index) {
return test()->GetClient(index)->EnableEncryptionForType( return test()->GetClient(index)->EnableEncryptionForType(
syncable::PREFERENCES); syncable::PREFERENCES);
} }
// static bool IsEncrypted(int index) {
bool PreferencesHelper::IsEncrypted(int index) {
return test()->GetClient(index)->IsTypeEncrypted(syncable::PREFERENCES); return test()->GetClient(index)->IsTypeEncrypted(syncable::PREFERENCES);
} }
} // namespace preferences_helper
...@@ -8,110 +8,99 @@ ...@@ -8,110 +8,99 @@
#include "base/file_path.h" #include "base/file_path.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/test/live_sync/sync_datatype_helper.h"
#include <string> #include <string>
class PrefService; class PrefService;
class PreferencesHelper : public SyncDatatypeHelper { namespace preferences_helper {
public:
// Used to access the preferences within a particular sync profile. // Used to access the preferences within a particular sync profile.
static PrefService* GetPrefs(int index); PrefService* GetPrefs(int index);
// Used to access the preferences within the verifier sync profile. // Used to access the preferences within the verifier sync profile.
static PrefService* GetVerifierPrefs(); PrefService* GetVerifierPrefs();
// Inverts the value of the boolean preference with name |pref_name| in the // Inverts the value of the boolean preference with name |pref_name| in the
// profile with index |index|. Also inverts its value in |verifier| if // profile with index |index|. Also inverts its value in |verifier| if
// DisableVerifier() hasn't been called. // DisableVerifier() hasn't been called.
static void ChangeBooleanPref(int index, const char* pref_name); void ChangeBooleanPref(int index, const char* pref_name);
// Changes the value of the integer preference with name |pref_name| in the // Changes the value of the integer preference with name |pref_name| in the
// profile with index |index| to |new_value|. Also changes its value in // profile with index |index| to |new_value|. Also changes its value in
// |verifier| if DisableVerifier() hasn't been called. // |verifier| if DisableVerifier() hasn't been called.
static void ChangeIntegerPref(int index, void ChangeIntegerPref(int index, const char* pref_name, int new_value);
const char* pref_name,
int new_value); // Changes the value of the double preference with name |pref_name| in the
// profile with index |index| to |new_value|. Also changes its value in
// Changes the value of the double preference with name |pref_name| in the // |verifier| if DisableVerifier() hasn't been called.
// profile with index |index| to |new_value|. Also changes its value in void ChangeDoublePref(int index, const char* pref_name, double new_value);
// |verifier| if DisableVerifier() hasn't been called.
static void ChangeDoublePref(int index, // Changes the value of the string preference with name |pref_name| in the
const char* pref_name, // profile with index |index| to |new_value|. Also changes its value in
double new_value); // |verifier| if DisableVerifier() hasn't been called.
void ChangeStringPref(int index,
// Changes the value of the string preference with name |pref_name| in the const char* pref_name,
// profile with index |index| to |new_value|. Also changes its value in const std::string& new_value);
// |verifier| if DisableVerifier() hasn't been called.
static void ChangeStringPref(int index, // Modifies the value of the string preference with name |pref_name| in the
const char* pref_name, // profile with index |index| by appending |append_value| to its current
const std::string& new_value); // value. Also changes its value in |verifier| if DisableVerifier() hasn't
// been called.
// Modifies the value of the string preference with name |pref_name| in the void AppendStringPref(int index,
// profile with index |index| by appending |append_value| to its current const char* pref_name,
// value. Also changes its value in |verifier| if DisableVerifier() hasn't const std::string& append_value);
// been called.
static void AppendStringPref(int index, // Changes the value of the file path preference with name |pref_name| in the
const char* pref_name, // profile with index |index| to |new_value|. Also changes its value in
const std::string& append_value); // |verifier| if DisableVerifier() hasn't been called.
void ChangeFilePathPref(int index,
// Changes the value of the file path preference with name |pref_name| in the const char* pref_name,
// profile with index |index| to |new_value|. Also changes its value in const FilePath& new_value);
// |verifier| if DisableVerifier() hasn't been called.
static void ChangeFilePathPref(int index, // Changes the value of the list preference with name |pref_name| in the
const char* pref_name, // profile with index |index| to |new_value|. Also changes its value in
const FilePath& new_value); // |verifier| if DisableVerifier() hasn't been called.
void ChangeListPref(int index,
// Changes the value of the list preference with name |pref_name| in the const char* pref_name,
// profile with index |index| to |new_value|. Also changes its value in const ListValue& new_value);
// |verifier| if DisableVerifier() hasn't been called.
static void ChangeListPref(int index, // Used to verify that the boolean preference with name |pref_name| has the
const char* pref_name, // same value across all profiles. Also checks |verifier| if DisableVerifier()
const ListValue& new_value); // hasn't been called.
bool BooleanPrefMatches(const char* pref_name) WARN_UNUSED_RESULT;
// Used to verify that the boolean preference with name |pref_name| has the
// same value across all profiles. Also checks |verifier| if DisableVerifier() // Used to verify that the integer preference with name |pref_name| has the
// hasn't been called. // same value across all profiles. Also checks |verifier| if DisableVerifier()
static bool BooleanPrefMatches(const char* pref_name) WARN_UNUSED_RESULT; // hasn't been called.
bool IntegerPrefMatches(const char* pref_name) WARN_UNUSED_RESULT;
// Used to verify that the integer preference with name |pref_name| has the
// same value across all profiles. Also checks |verifier| if DisableVerifier() // Used to verify that the double preference with name |pref_name| has the
// hasn't been called. // same value across all profiles. Also checks |verifier| if DisableVerifier()
static bool IntegerPrefMatches(const char* pref_name) WARN_UNUSED_RESULT; // hasn't been called.
bool DoublePrefMatches(const char* pref_name) WARN_UNUSED_RESULT;
// Used to verify that the double preference with name |pref_name| has the
// same value across all profiles. Also checks |verifier| if DisableVerifier() // Used to verify that the string preference with name |pref_name| has the
// hasn't been called. // same value across all profiles. Also checks |verifier| if DisableVerifier()
static bool DoublePrefMatches(const char* pref_name) WARN_UNUSED_RESULT; // hasn't been called.
bool StringPrefMatches(const char* pref_name) WARN_UNUSED_RESULT;
// Used to verify that the string preference with name |pref_name| has the
// same value across all profiles. Also checks |verifier| if DisableVerifier() // Used to verify that the file path preference with name |pref_name| has the
// hasn't been called. // same value across all profiles. Also checks |verifier| if DisableVerifier()
static bool StringPrefMatches(const char* pref_name) WARN_UNUSED_RESULT; // hasn't been called.
bool FilePathPrefMatches(const char* pref_name) WARN_UNUSED_RESULT;
// Used to verify that the file path preference with name |pref_name| has the
// same value across all profiles. Also checks |verifier| if DisableVerifier() // Used to verify that the list preference with name |pref_name| has the
// hasn't been called. // same value across all profiles. Also checks |verifier| if DisableVerifier()
static bool FilePathPrefMatches(const char* pref_name) WARN_UNUSED_RESULT; // hasn't been called.
bool ListPrefMatches(const char* pref_name) WARN_UNUSED_RESULT;
// Used to verify that the list preference with name |pref_name| has the
// same value across all profiles. Also checks |verifier| if DisableVerifier() // Encrypts the Preferences datatype.
// hasn't been called. bool EnableEncryption(int index);
static bool ListPrefMatches(const char* pref_name) WARN_UNUSED_RESULT;
// Checks if Preferences are encrypted.
// Encrypts the Preferences datatype. bool IsEncrypted(int index);
static bool EnableEncryption(int index);
} // namespace preferences_helper
// Checks if Preferences are encrypted.
static bool IsEncrypted(int index);
protected:
PreferencesHelper();
virtual ~PreferencesHelper();
private:
DISALLOW_COPY_AND_ASSIGN(PreferencesHelper);
};
#endif // CHROME_TEST_LIVE_SYNC_PREFERENCES_HELPER_H_ #endif // CHROME_TEST_LIVE_SYNC_PREFERENCES_HELPER_H_
...@@ -7,6 +7,15 @@ ...@@ -7,6 +7,15 @@
#include "chrome/test/live_sync/bookmarks_helper.h" #include "chrome/test/live_sync/bookmarks_helper.h"
#include "chrome/test/live_sync/live_sync_test.h" #include "chrome/test/live_sync/live_sync_test.h"
using bookmarks_helper::AddFolder;
using bookmarks_helper::AddURL;
using bookmarks_helper::GetBookmarkBarNode;
using bookmarks_helper::GetOtherNode;
using bookmarks_helper::ModelMatchesVerifier;
using bookmarks_helper::Move;
using bookmarks_helper::Remove;
using bookmarks_helper::SetTitle;
class SingleClientBookmarksSyncTest : public LiveSyncTest { class SingleClientBookmarksSyncTest : public LiveSyncTest {
public: public:
SingleClientBookmarksSyncTest() : LiveSyncTest(SINGLE_CLIENT) {} SingleClientBookmarksSyncTest() : LiveSyncTest(SINGLE_CLIENT) {}
...@@ -20,8 +29,8 @@ IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest, OfflineToOnline) { ...@@ -20,8 +29,8 @@ IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest, OfflineToOnline) {
ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
DisableNetwork(GetProfile(0)); DisableNetwork(GetProfile(0));
const BookmarkNode* node = BookmarksHelper::AddFolder(0, L"title"); const BookmarkNode* node = AddFolder(0, L"title");
BookmarksHelper::SetTitle(0, node, L"new_title"); SetTitle(0, node, L"new_title");
ASSERT_FALSE(GetClient(0)->AwaitSyncCycleCompletion("Offline state change.")); ASSERT_FALSE(GetClient(0)->AwaitSyncCycleCompletion("Offline state change."));
ASSERT_EQ(ProfileSyncService::Status::OFFLINE_UNSYNCED, ASSERT_EQ(ProfileSyncService::Status::OFFLINE_UNSYNCED,
GetClient(0)->GetStatus().summary); GetClient(0)->GetStatus().summary);
...@@ -30,7 +39,7 @@ IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest, OfflineToOnline) { ...@@ -30,7 +39,7 @@ IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest, OfflineToOnline) {
ASSERT_TRUE(GetClient(0)->AwaitSyncCycleCompletion("Commit changes.")); ASSERT_TRUE(GetClient(0)->AwaitSyncCycleCompletion("Commit changes."));
ASSERT_EQ(ProfileSyncService::Status::READY, ASSERT_EQ(ProfileSyncService::Status::READY,
GetClient(0)->GetStatus().summary); GetClient(0)->GetStatus().summary);
ASSERT_TRUE(BookmarksHelper::ModelMatchesVerifier(0)); ASSERT_TRUE(ModelMatchesVerifier(0));
} }
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest, Sanity) { IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest, Sanity) {
...@@ -45,25 +54,22 @@ IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest, Sanity) { ...@@ -45,25 +54,22 @@ IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest, Sanity) {
// -> http://www.facebook.com "tier1_a_url2" // -> http://www.facebook.com "tier1_a_url2"
// -> tier1_b // -> tier1_b
// -> http://www.nhl.com "tier1_b_url0" // -> http://www.nhl.com "tier1_b_url0"
const BookmarkNode* top = BookmarksHelper::AddFolder( const BookmarkNode* top = AddFolder(0, GetOtherNode(0), 0, L"top");
0, BookmarksHelper::GetOtherNode(0), 0, L"top"); const BookmarkNode* tier1_a = AddFolder(0, top, 0, L"tier1_a");
const BookmarkNode* tier1_a = BookmarksHelper::AddFolder( const BookmarkNode* tier1_b = AddFolder(0, top, 1, L"tier1_b");
0, top, 0, L"tier1_a"); const BookmarkNode* tier1_a_url0 = AddURL(
const BookmarkNode* tier1_b = BookmarksHelper::AddFolder(
0, top, 1, L"tier1_b");
const BookmarkNode* tier1_a_url0 = BookmarksHelper::AddURL(
0, tier1_a, 0, L"tier1_a_url0", GURL("http://mail.google.com")); 0, tier1_a, 0, L"tier1_a_url0", GURL("http://mail.google.com"));
const BookmarkNode* tier1_a_url1 = BookmarksHelper::AddURL( const BookmarkNode* tier1_a_url1 = AddURL(
0, tier1_a, 1, L"tier1_a_url1", GURL("http://www.pandora.com")); 0, tier1_a, 1, L"tier1_a_url1", GURL("http://www.pandora.com"));
const BookmarkNode* tier1_a_url2 = BookmarksHelper::AddURL( const BookmarkNode* tier1_a_url2 = AddURL(
0, tier1_a, 2, L"tier1_a_url2", GURL("http://www.facebook.com")); 0, tier1_a, 2, L"tier1_a_url2", GURL("http://www.facebook.com"));
const BookmarkNode* tier1_b_url0 = BookmarksHelper::AddURL( const BookmarkNode* tier1_b_url0 = AddURL(
0, tier1_b, 0, L"tier1_b_url0", GURL("http://www.nhl.com")); 0, tier1_b, 0, L"tier1_b_url0", GURL("http://www.nhl.com"));
ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
ASSERT_TRUE(GetClient(0)->AwaitSyncCycleCompletion( ASSERT_TRUE(GetClient(0)->AwaitSyncCycleCompletion(
"Waiting for initial sync completed.")); "Waiting for initial sync completed."));
ASSERT_TRUE(BookmarksHelper::ModelMatchesVerifier(0)); ASSERT_TRUE(ModelMatchesVerifier(0));
// Ultimately we want to end up with the following model; but this test is // Ultimately we want to end up with the following model; but this test is
// more about the journey than the destination. // more about the journey than the destination.
...@@ -86,60 +92,59 @@ IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest, Sanity) { ...@@ -86,60 +92,59 @@ IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest, Sanity) {
// -> Toronto Maple Leafs (mapleleafs.nhl.com) // -> Toronto Maple Leafs (mapleleafs.nhl.com)
// -> Wynn (www.wynnlasvegas.com) // -> Wynn (www.wynnlasvegas.com)
// -> tier1_a_url0 // -> tier1_a_url0
const BookmarkNode* bar = BookmarksHelper::GetBookmarkBarNode(0); const BookmarkNode* bar = GetBookmarkBarNode(0);
const BookmarkNode* cnn = BookmarksHelper::AddURL(0, bar, 0, L"CNN", const BookmarkNode* cnn = AddURL(0, bar, 0, L"CNN",
GURL("http://www.cnn.com")); GURL("http://www.cnn.com"));
ASSERT_TRUE(cnn != NULL); ASSERT_TRUE(cnn != NULL);
BookmarksHelper::Move(0, tier1_a, bar, 1); Move(0, tier1_a, bar, 1);
ASSERT_TRUE(GetClient(0)->AwaitSyncCycleCompletion("Bookmark moved.")); ASSERT_TRUE(GetClient(0)->AwaitSyncCycleCompletion("Bookmark moved."));
ASSERT_TRUE(BookmarksHelper::ModelMatchesVerifier(0)); ASSERT_TRUE(ModelMatchesVerifier(0));
const BookmarkNode* porsche = BookmarksHelper::AddURL(0, bar, 2, L"Porsche", const BookmarkNode* porsche = AddURL(0, bar, 2, L"Porsche",
GURL("http://www.porsche.com")); GURL("http://www.porsche.com"));
// Rearrange stuff in tier1_a. // Rearrange stuff in tier1_a.
ASSERT_EQ(tier1_a, tier1_a_url2->parent()); ASSERT_EQ(tier1_a, tier1_a_url2->parent());
ASSERT_EQ(tier1_a, tier1_a_url1->parent()); ASSERT_EQ(tier1_a, tier1_a_url1->parent());
BookmarksHelper::Move(0, tier1_a_url2, tier1_a, 0); Move(0, tier1_a_url2, tier1_a, 0);
BookmarksHelper::Move(0, tier1_a_url1, tier1_a, 2); Move(0, tier1_a_url1, tier1_a, 2);
ASSERT_TRUE(GetClient(0)->AwaitSyncCycleCompletion( ASSERT_TRUE(GetClient(0)->AwaitSyncCycleCompletion(
"Rearrange stuff in tier1_a")); "Rearrange stuff in tier1_a"));
ASSERT_TRUE(BookmarksHelper::ModelMatchesVerifier(0)); ASSERT_TRUE(ModelMatchesVerifier(0));
ASSERT_EQ(1, tier1_a_url0->parent()->GetIndexOf(tier1_a_url0)); ASSERT_EQ(1, tier1_a_url0->parent()->GetIndexOf(tier1_a_url0));
BookmarksHelper::Move(0, tier1_a_url0, bar, bar->child_count()); Move(0, tier1_a_url0, bar, bar->child_count());
const BookmarkNode* boa = BookmarksHelper::AddURL(0, bar, bar->child_count(), const BookmarkNode* boa = AddURL(0, bar, bar->child_count(),
L"Bank of America", GURL("https://www.bankofamerica.com")); L"Bank of America", GURL("https://www.bankofamerica.com"));
ASSERT_TRUE(boa != NULL); ASSERT_TRUE(boa != NULL);
BookmarksHelper::Move(0, tier1_a_url0, top, top->child_count()); Move(0, tier1_a_url0, top, top->child_count());
const BookmarkNode* bubble = BookmarksHelper::AddURL( const BookmarkNode* bubble = AddURL(
0, bar, bar->child_count(), L"Seattle Bubble", 0, bar, bar->child_count(), L"Seattle Bubble",
GURL("http://seattlebubble.com")); GURL("http://seattlebubble.com"));
ASSERT_TRUE(bubble != NULL); ASSERT_TRUE(bubble != NULL);
const BookmarkNode* wired = BookmarksHelper::AddURL(0, bar, 2, L"Wired News", const BookmarkNode* wired = AddURL(0, bar, 2, L"Wired News",
GURL("http://www.wired.com")); GURL("http://www.wired.com"));
const BookmarkNode* tier2_b = BookmarksHelper::AddFolder( const BookmarkNode* tier2_b = AddFolder(
0, tier1_b, 0, L"tier2_b"); 0, tier1_b, 0, L"tier2_b");
BookmarksHelper::Move(0, tier1_b_url0, tier2_b, 0); Move(0, tier1_b_url0, tier2_b, 0);
BookmarksHelper::Move(0, porsche, bar, 0); Move(0, porsche, bar, 0);
BookmarksHelper::SetTitle(0, wired, L"News Wired"); SetTitle(0, wired, L"News Wired");
BookmarksHelper::SetTitle(0, porsche, L"ICanHazPorsche?"); SetTitle(0, porsche, L"ICanHazPorsche?");
ASSERT_TRUE(GetClient(0)->AwaitSyncCycleCompletion("Change title.")); ASSERT_TRUE(GetClient(0)->AwaitSyncCycleCompletion("Change title."));
ASSERT_TRUE(BookmarksHelper::ModelMatchesVerifier(0)); ASSERT_TRUE(ModelMatchesVerifier(0));
ASSERT_EQ(tier1_a_url0->id(), top->GetChild(top->child_count() - 1)->id()); ASSERT_EQ(tier1_a_url0->id(), top->GetChild(top->child_count() - 1)->id());
BookmarksHelper::Remove(0, top, top->child_count() - 1); Remove(0, top, top->child_count() - 1);
BookmarksHelper::Move(0, wired, tier1_b, 0); Move(0, wired, tier1_b, 0);
BookmarksHelper::Move(0, porsche, bar, 3); Move(0, porsche, bar, 3);
const BookmarkNode* tier3_b = BookmarksHelper::AddFolder( const BookmarkNode* tier3_b = AddFolder(0, tier2_b, 1, L"tier3_b");
0, tier2_b, 1, L"tier3_b"); const BookmarkNode* leafs = AddURL(
const BookmarkNode* leafs = BookmarksHelper::AddURL(
0, tier1_a, 0, L"Toronto Maple Leafs", GURL("http://mapleleafs.nhl.com")); 0, tier1_a, 0, L"Toronto Maple Leafs", GURL("http://mapleleafs.nhl.com"));
const BookmarkNode* wynn = BookmarksHelper::AddURL(0, bar, 1, L"Wynn", const BookmarkNode* wynn = AddURL(0, bar, 1, L"Wynn",
GURL("http://www.wynnlasvegas.com")); GURL("http://www.wynnlasvegas.com"));
BookmarksHelper::Move(0, wynn, tier3_b, 0); Move(0, wynn, tier3_b, 0);
BookmarksHelper::Move(0, leafs, tier3_b, 0); Move(0, leafs, tier3_b, 0);
ASSERT_TRUE(GetClient(0)->AwaitSyncCycleCompletion( ASSERT_TRUE(GetClient(0)->AwaitSyncCycleCompletion(
"Move after addition of bookmarks.")); "Move after addition of bookmarks."));
ASSERT_TRUE(BookmarksHelper::ModelMatchesVerifier(0)); ASSERT_TRUE(ModelMatchesVerifier(0));
} }
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
#include "chrome/test/live_sync/preferences_helper.h" #include "chrome/test/live_sync/preferences_helper.h"
#include "chrome/test/live_sync/live_sync_test.h" #include "chrome/test/live_sync/live_sync_test.h"
using preferences_helper::BooleanPrefMatches;
using preferences_helper::ChangeBooleanPref;
class SingleClientPreferencesSyncTest : public LiveSyncTest { class SingleClientPreferencesSyncTest : public LiveSyncTest {
public: public:
SingleClientPreferencesSyncTest() : LiveSyncTest(SINGLE_CLIENT) {} SingleClientPreferencesSyncTest() : LiveSyncTest(SINGLE_CLIENT) {}
...@@ -18,11 +21,9 @@ class SingleClientPreferencesSyncTest : public LiveSyncTest { ...@@ -18,11 +21,9 @@ class SingleClientPreferencesSyncTest : public LiveSyncTest {
IN_PROC_BROWSER_TEST_F(SingleClientPreferencesSyncTest, Sanity) { IN_PROC_BROWSER_TEST_F(SingleClientPreferencesSyncTest, Sanity) {
ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
ASSERT_TRUE(PreferencesHelper::BooleanPrefMatches( ASSERT_TRUE(BooleanPrefMatches(prefs::kHomePageIsNewTabPage));
prefs::kHomePageIsNewTabPage)); ChangeBooleanPref(0, prefs::kHomePageIsNewTabPage);
PreferencesHelper::ChangeBooleanPref(0, prefs::kHomePageIsNewTabPage);
ASSERT_TRUE(GetClient(0)->AwaitSyncCycleCompletion( ASSERT_TRUE(GetClient(0)->AwaitSyncCycleCompletion(
"Waiting for prefs change.")); "Waiting for prefs change."));
ASSERT_TRUE(PreferencesHelper::BooleanPrefMatches( ASSERT_TRUE(BooleanPrefMatches(prefs::kHomePageIsNewTabPage));
prefs::kHomePageIsNewTabPage));
} }
...@@ -6,11 +6,25 @@ ...@@ -6,11 +6,25 @@
#include "chrome/browser/history/history_types.h" #include "chrome/browser/history/history_types.h"
#include "chrome/browser/sessions/session_service.h" #include "chrome/browser/sessions/session_service.h"
#include "chrome/browser/sync/profile_sync_service_harness.h" #include "chrome/browser/sync/profile_sync_service_harness.h"
#include "chrome/test/live_sync/live_typed_urls_sync_test.h" #include "chrome/test/live_sync/live_sync_test.h"
#include "chrome/test/live_sync/typed_urls_helper.h"
using typed_urls_helper::AddUrlToHistory;
using typed_urls_helper::AssertAllProfilesHaveSameURLsAsVerifier;
using typed_urls_helper::GetTypedUrlsFromClient;
const std::string kSanityHistoryUrl = "http://www.sanity-history.google.com"; const std::string kSanityHistoryUrl = "http://www.sanity-history.google.com";
IN_PROC_BROWSER_TEST_F(SingleClientLiveTypedUrlsSyncTest, Sanity) { class SingleClientTypedUrlsSyncTest : public LiveSyncTest {
public:
SingleClientTypedUrlsSyncTest() : LiveSyncTest(SINGLE_CLIENT) {}
virtual ~SingleClientTypedUrlsSyncTest() {}
private:
DISALLOW_COPY_AND_ASSIGN(SingleClientTypedUrlsSyncTest);
};
IN_PROC_BROWSER_TEST_F(SingleClientTypedUrlsSyncTest, Sanity) {
ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
std::vector<history::URLRow> urls = GetTypedUrlsFromClient(0); std::vector<history::URLRow> urls = GetTypedUrlsFromClient(0);
ASSERT_EQ(0U, urls.size()); ASSERT_EQ(0U, urls.size());
......
...@@ -6,22 +6,24 @@ ...@@ -6,22 +6,24 @@
#include "chrome/test/live_sync/live_sync_test.h" #include "chrome/test/live_sync/live_sync_test.h"
SyncDatatypeHelper::SyncDatatypeHelper() {} namespace {
SyncDatatypeHelper::~SyncDatatypeHelper() {} // The LiveSyncTest instance associated with sync_datatype_helper.
static LiveSyncTest* test = NULL;
// static } // namespace
void SyncDatatypeHelper::AssociateWithTest(LiveSyncTest* test) {
namespace sync_datatype_helper {
void AssociateWithTest(LiveSyncTest* test) {
ASSERT_TRUE(test != NULL) << "Cannot associate with null test."; ASSERT_TRUE(test != NULL) << "Cannot associate with null test.";
ASSERT_TRUE(test_ == NULL) << "Already associated with a test."; ASSERT_TRUE(::test == NULL) << "Already associated with a test.";
test_ = test; ::test = test;
} }
// static LiveSyncTest* test() {
LiveSyncTest* SyncDatatypeHelper::test() { EXPECT_TRUE(::test != NULL) << "Must call AssociateWithTest first.";
EXPECT_TRUE(test_ != NULL) << "Must call AssociateWithTest first."; return ::test;
return test_;
} }
// static } // namespace sync_datatype_helper
LiveSyncTest* SyncDatatypeHelper::test_ = NULL;
...@@ -10,25 +10,17 @@ ...@@ -10,25 +10,17 @@
class LiveSyncTest; class LiveSyncTest;
class SyncDatatypeHelper { namespace sync_datatype_helper {
public:
// Associates an instance of LiveSyncTest with a SyncDatatypeHelper. Must be
// called before any of the methods in the helper subclasses can be used.
static void AssociateWithTest(LiveSyncTest* test);
// Returns |test_| after making sure it is a valid pointer. // Associates an instance of LiveSyncTest with sync_datatype_helper. Must be
static LiveSyncTest* test(); // called before any of the methods in the per-datatype helper namespaces can be
// used.
void AssociateWithTest(LiveSyncTest* test);
protected: // Returns a pointer to the instance of LiveSyncTest associated with the
SyncDatatypeHelper(); // per-datatype helpers after making sure it is valid.
virtual ~SyncDatatypeHelper(); LiveSyncTest* test();
private:
// The LiveSyncTest instance associated with this helper object.
static LiveSyncTest* test_;
DISALLOW_COPY_AND_ASSIGN(SyncDatatypeHelper);
};
} // namespace sync_datatype_helper
#endif // CHROME_TEST_LIVE_SYNC_SYNC_DATATYPE_HELPER_H_ #endif // CHROME_TEST_LIVE_SYNC_SYNC_DATATYPE_HELPER_H_
...@@ -3,32 +3,31 @@ ...@@ -3,32 +3,31 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/sync/profile_sync_service_harness.h" #include "chrome/browser/sync/profile_sync_service_harness.h"
#include "chrome/test/live_sync/bookmarks_helper.h"
#include "chrome/test/live_sync/live_sync_test.h" #include "chrome/test/live_sync/live_sync_test.h"
#include "chrome/test/live_sync/bookmarks_helper.h" using bookmarks_helper::AddFolder;
using bookmarks_helper::SetTitle;
class SyncErrorTest : public LiveSyncTest{ class SyncErrorTest : public LiveSyncTest{
public: public:
SyncErrorTest() : LiveSyncTest(SINGLE_CLIENT) { SyncErrorTest() : LiveSyncTest(SINGLE_CLIENT) {}
} virtual ~SyncErrorTest() {}
~SyncErrorTest() {}
private: private:
DISALLOW_COPY_AND_ASSIGN(SyncErrorTest); DISALLOW_COPY_AND_ASSIGN(SyncErrorTest);
}; };
IN_PROC_BROWSER_TEST_F(SyncErrorTest, BirthdayErrorTest) { IN_PROC_BROWSER_TEST_F(SyncErrorTest, BirthdayErrorTest) {
ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
const BookmarkNode* node1 = BookmarksHelper::AddFolder(0, 0, L"title1"); const BookmarkNode* node1 = AddFolder(0, 0, L"title1");
BookmarksHelper::SetTitle(0, node1, L"new_title1"); SetTitle(0, node1, L"new_title1");
ASSERT_TRUE(GetClient(0)->AwaitSyncCycleCompletion("Offline state change.")); ASSERT_TRUE(GetClient(0)->AwaitSyncCycleCompletion("Offline state change."));
TriggerBirthdayError(); TriggerBirthdayError();
// Now make one more change so we will do another sync. // Now make one more change so we will do another sync.
const BookmarkNode* node2 = BookmarksHelper::AddFolder(0, 0, L"title2"); const BookmarkNode* node2 = AddFolder(0, 0, L"title2");
BookmarksHelper::SetTitle(0, node2, L"new_title2"); SetTitle(0, node2, L"new_title2");
ASSERT_TRUE(GetClient(0)->AwaitSyncDisabled("Birthday error.")); ASSERT_TRUE(GetClient(0)->AwaitSyncDisabled("Birthday error."));
} }
...@@ -8,10 +8,25 @@ ...@@ -8,10 +8,25 @@
#include "chrome/browser/history/history_types.h" #include "chrome/browser/history/history_types.h"
#include "chrome/browser/sessions/session_service.h" #include "chrome/browser/sessions/session_service.h"
#include "chrome/browser/sync/profile_sync_service_harness.h" #include "chrome/browser/sync/profile_sync_service_harness.h"
#include "chrome/test/live_sync/live_typed_urls_sync_test.h" #include "chrome/test/live_sync/live_sync_test.h"
#include "chrome/test/live_sync/typed_urls_helper.h"
using typed_urls_helper::AddUrlToHistory;
using typed_urls_helper::AssertAllProfilesHaveSameURLsAsVerifier;
using typed_urls_helper::DeleteUrlFromHistory;
using typed_urls_helper::GetTypedUrlsFromClient;
class TwoClientTypedUrlsSyncTest : public LiveSyncTest {
public:
TwoClientTypedUrlsSyncTest() : LiveSyncTest(TWO_CLIENT) {}
virtual ~TwoClientTypedUrlsSyncTest() {}
private:
DISALLOW_COPY_AND_ASSIGN(TwoClientTypedUrlsSyncTest);
};
// TCM: 3728323 // TCM: 3728323
IN_PROC_BROWSER_TEST_F(TwoClientLiveTypedUrlsSyncTest, Add) { IN_PROC_BROWSER_TEST_F(TwoClientTypedUrlsSyncTest, Add) {
const string16 kHistoryUrl( const string16 kHistoryUrl(
ASCIIToUTF16("http://www.add-one-history.google.com/")); ASCIIToUTF16("http://www.add-one-history.google.com/"));
ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
...@@ -31,7 +46,7 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveTypedUrlsSyncTest, Add) { ...@@ -31,7 +46,7 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveTypedUrlsSyncTest, Add) {
} }
// TCM: 3705291 // TCM: 3705291
IN_PROC_BROWSER_TEST_F(TwoClientLiveTypedUrlsSyncTest, AddThenDelete) { IN_PROC_BROWSER_TEST_F(TwoClientTypedUrlsSyncTest, AddThenDelete) {
const string16 kHistoryUrl( const string16 kHistoryUrl(
ASCIIToUTF16("http://www.add-one-history.google.com/")); ASCIIToUTF16("http://www.add-one-history.google.com/"));
ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
...@@ -60,7 +75,7 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveTypedUrlsSyncTest, AddThenDelete) { ...@@ -60,7 +75,7 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveTypedUrlsSyncTest, AddThenDelete) {
} }
// TCM: 3643277 // TCM: 3643277
IN_PROC_BROWSER_TEST_F(TwoClientLiveTypedUrlsSyncTest, DisableEnableSync) { IN_PROC_BROWSER_TEST_F(TwoClientTypedUrlsSyncTest, DisableEnableSync) {
const string16 kUrl1(ASCIIToUTF16("http://history1.google.com/")); const string16 kUrl1(ASCIIToUTF16("http://history1.google.com/"));
const string16 kUrl2(ASCIIToUTF16("http://history2.google.com/")); const string16 kUrl2(ASCIIToUTF16("http://history2.google.com/"));
ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
...@@ -91,7 +106,7 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveTypedUrlsSyncTest, DisableEnableSync) { ...@@ -91,7 +106,7 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveTypedUrlsSyncTest, DisableEnableSync) {
AssertAllProfilesHaveSameURLsAsVerifier(); AssertAllProfilesHaveSameURLsAsVerifier();
} }
IN_PROC_BROWSER_TEST_F(TwoClientLiveTypedUrlsSyncTest, AddOneDeleteOther) { IN_PROC_BROWSER_TEST_F(TwoClientTypedUrlsSyncTest, AddOneDeleteOther) {
const string16 kHistoryUrl( const string16 kHistoryUrl(
ASCIIToUTF16("http://www.add-one-delete-history.google.com/")); ASCIIToUTF16("http://www.add-one-delete-history.google.com/"));
ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
...@@ -121,7 +136,7 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveTypedUrlsSyncTest, AddOneDeleteOther) { ...@@ -121,7 +136,7 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveTypedUrlsSyncTest, AddOneDeleteOther) {
AssertAllProfilesHaveSameURLsAsVerifier(); AssertAllProfilesHaveSameURLsAsVerifier();
} }
IN_PROC_BROWSER_TEST_F(TwoClientLiveTypedUrlsSyncTest, IN_PROC_BROWSER_TEST_F(TwoClientTypedUrlsSyncTest,
AddOneDeleteOtherAddAgain) { AddOneDeleteOtherAddAgain) {
const string16 kHistoryUrl( const string16 kHistoryUrl(
ASCIIToUTF16("http://www.add-delete-add-history.google.com/")); ASCIIToUTF16("http://www.add-delete-add-history.google.com/"));
...@@ -161,6 +176,3 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveTypedUrlsSyncTest, ...@@ -161,6 +176,3 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveTypedUrlsSyncTest,
// Both clients should have this URL added again. // Both clients should have this URL added again.
AssertAllProfilesHaveSameURLsAsVerifier(); AssertAllProfilesHaveSameURLsAsVerifier();
} }
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/test/live_sync/live_typed_urls_sync_test.h" #include "chrome/test/live_sync/typed_urls_helper.h"
#include "base/synchronization/waitable_event.h" #include "base/synchronization/waitable_event.h"
#include "base/time.h" #include "base/time.h"
...@@ -11,8 +11,12 @@ ...@@ -11,8 +11,12 @@
#include "chrome/browser/history/history_backend.h" #include "chrome/browser/history/history_backend.h"
#include "chrome/browser/history/history_types.h" #include "chrome/browser/history/history_types.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/test/live_sync/live_sync_test.h"
#include "chrome/test/live_sync/sync_datatype_helper.h"
#include "content/browser/cancelable_request.h" #include "content/browser/cancelable_request.h"
using sync_datatype_helper::test;
namespace { namespace {
class FlushHistoryDBQueueTask : public HistoryDBTask { class FlushHistoryDBQueueTask : public HistoryDBTask {
...@@ -50,23 +54,35 @@ class GetTypedUrlsTask : public HistoryDBTask { ...@@ -50,23 +54,35 @@ class GetTypedUrlsTask : public HistoryDBTask {
base::WaitableEvent* wait_event_; base::WaitableEvent* wait_event_;
}; };
} // namespace // Waits for the history DB thread to finish executing its current set of
// tasks.
LiveTypedUrlsSyncTest::LiveTypedUrlsSyncTest(TestType test_type) void WaitForHistoryDBThread(int index) {
: LiveSyncTest(test_type), CancelableRequestConsumer cancelable_consumer;
timestamp_(base::Time::Now()) {}
LiveTypedUrlsSyncTest::~LiveTypedUrlsSyncTest() {}
std::vector<history::URLRow>
LiveTypedUrlsSyncTest::GetTypedUrlsFromClient(int index) {
HistoryService* service = HistoryService* service =
GetProfile(index)->GetHistoryServiceWithoutCreating(); test()->GetProfile(index)->GetHistoryServiceWithoutCreating();
return GetTypedUrlsFromHistoryService(service); base::WaitableEvent wait_event(true, false);
service->ScheduleDBTask(new FlushHistoryDBQueueTask(&wait_event),
&cancelable_consumer);
wait_event.Wait();
}
// Creates a URLRow in the specified HistoryService.
void AddToHistory(HistoryService* service,
const GURL& url,
const base::Time& timestamp) {
service->AddPage(url,
timestamp,
NULL, // scope
1234, // page_id
GURL(), // referrer
PageTransition::TYPED,
history::RedirectList(),
history::SOURCE_BROWSED,
false);
} }
std::vector<history::URLRow> std::vector<history::URLRow> GetTypedUrlsFromHistoryService(
LiveTypedUrlsSyncTest::GetTypedUrlsFromHistoryService(HistoryService *service) { HistoryService* service) {
CancelableRequestConsumer cancelable_consumer; CancelableRequestConsumer cancelable_consumer;
std::vector<history::URLRow> rows; std::vector<history::URLRow> rows;
base::WaitableEvent wait_event(true, false); base::WaitableEvent wait_event(true, false);
...@@ -76,24 +92,40 @@ LiveTypedUrlsSyncTest::GetTypedUrlsFromHistoryService(HistoryService *service) { ...@@ -76,24 +92,40 @@ LiveTypedUrlsSyncTest::GetTypedUrlsFromHistoryService(HistoryService *service) {
return rows; return rows;
} }
base::Time LiveTypedUrlsSyncTest::GetTimestamp() { static base::Time* timestamp = NULL;
} // namespace
namespace typed_urls_helper {
std::vector<history::URLRow> GetTypedUrlsFromClient(int index) {
HistoryService* service =
test()->GetProfile(index)->GetHistoryServiceWithoutCreating();
return GetTypedUrlsFromHistoryService(service);
}
base::Time GetTimestamp() {
// The history subsystem doesn't like identical timestamps for page visits, // The history subsystem doesn't like identical timestamps for page visits,
// and it will massage the visit timestamps if we try to use identical // and it will massage the visit timestamps if we try to use identical
// values, which can lead to spurious errors. So make sure all timestamps // values, which can lead to spurious errors. So make sure all timestamps
// are unique. // are unique.
base::Time original = timestamp_; if (!::timestamp)
timestamp_ += base::TimeDelta::FromMilliseconds(1); ::timestamp = new base::Time(base::Time::Now());
base::Time original = *::timestamp;
*::timestamp += base::TimeDelta::FromMilliseconds(1);
return original; return original;
} }
void LiveTypedUrlsSyncTest::AddUrlToHistory(int index, const GURL& url) { void AddUrlToHistory(int index, const GURL& url) {
base::Time timestamp = GetTimestamp(); base::Time timestamp = GetTimestamp();
AddToHistory(GetProfile(index)->GetHistoryServiceWithoutCreating(), AddToHistory(test()->GetProfile(index)->GetHistoryServiceWithoutCreating(),
url,
timestamp);
AddToHistory(verifier()->GetHistoryService(Profile::IMPLICIT_ACCESS),
url, url,
timestamp); timestamp);
if (test()->use_verifier())
AddToHistory(
test()->verifier()->GetHistoryService(Profile::IMPLICIT_ACCESS),
url,
timestamp);
// Wait until the AddPage() request has completed so we know the change has // Wait until the AddPage() request has completed so we know the change has
// filtered down to the sync observers (don't need to wait for the // filtered down to the sync observers (don't need to wait for the
...@@ -101,37 +133,15 @@ void LiveTypedUrlsSyncTest::AddUrlToHistory(int index, const GURL& url) { ...@@ -101,37 +133,15 @@ void LiveTypedUrlsSyncTest::AddUrlToHistory(int index, const GURL& url) {
WaitForHistoryDBThread(index); WaitForHistoryDBThread(index);
} }
void LiveTypedUrlsSyncTest::AddToHistory(HistoryService* service, void DeleteUrlFromHistory(int index, const GURL& url) {
const GURL& url, test()->GetProfile(index)->GetHistoryServiceWithoutCreating()->DeleteURL(url);
const base::Time& timestamp) { if (test()->use_verifier())
service->AddPage(url, test()->verifier()->GetHistoryService(Profile::IMPLICIT_ACCESS)->
timestamp, DeleteURL(url);
NULL, // scope
1234, // page_id
GURL(), // referrer
PageTransition::TYPED,
history::RedirectList(),
history::SOURCE_BROWSED,
false);
}
void LiveTypedUrlsSyncTest::DeleteUrlFromHistory(int index, const GURL& url) {
GetProfile(index)->GetHistoryServiceWithoutCreating()->DeleteURL(url);
verifier()->GetHistoryService(Profile::IMPLICIT_ACCESS)->DeleteURL(url);
WaitForHistoryDBThread(index); WaitForHistoryDBThread(index);
} }
void LiveTypedUrlsSyncTest::WaitForHistoryDBThread(int index) { void AssertURLRowVectorsAreEqual(
CancelableRequestConsumer cancelable_consumer;
HistoryService* service =
GetProfile(index)->GetHistoryServiceWithoutCreating();
base::WaitableEvent wait_event(true, false);
service->ScheduleDBTask(new FlushHistoryDBQueueTask(&wait_event),
&cancelable_consumer);
wait_event.Wait();
}
void LiveTypedUrlsSyncTest::AssertURLRowVectorsAreEqual(
const std::vector<history::URLRow>& left, const std::vector<history::URLRow>& left,
const std::vector<history::URLRow>& right) { const std::vector<history::URLRow>& right) {
ASSERT_EQ(left.size(), right.size()); ASSERT_EQ(left.size(), right.size());
...@@ -150,7 +160,7 @@ void LiveTypedUrlsSyncTest::AssertURLRowVectorsAreEqual( ...@@ -150,7 +160,7 @@ void LiveTypedUrlsSyncTest::AssertURLRowVectorsAreEqual(
} }
} }
void LiveTypedUrlsSyncTest::AssertURLRowsAreEqual( void AssertURLRowsAreEqual(
const history::URLRow& left, const history::URLRow& right) { const history::URLRow& left, const history::URLRow& right) {
ASSERT_EQ(left.url(), right.url()); ASSERT_EQ(left.url(), right.url());
ASSERT_EQ(left.title(), right.title()); ASSERT_EQ(left.title(), right.title());
...@@ -160,13 +170,15 @@ void LiveTypedUrlsSyncTest::AssertURLRowsAreEqual( ...@@ -160,13 +170,15 @@ void LiveTypedUrlsSyncTest::AssertURLRowsAreEqual(
ASSERT_EQ(left.hidden(), right.hidden()); ASSERT_EQ(left.hidden(), right.hidden());
} }
void LiveTypedUrlsSyncTest::AssertAllProfilesHaveSameURLsAsVerifier() { void AssertAllProfilesHaveSameURLsAsVerifier() {
HistoryService* verifier_service = HistoryService* verifier_service =
verifier()->GetHistoryService(Profile::IMPLICIT_ACCESS); test()->verifier()->GetHistoryService(Profile::IMPLICIT_ACCESS);
std::vector<history::URLRow> verifier_urls = std::vector<history::URLRow> verifier_urls =
GetTypedUrlsFromHistoryService(verifier_service); GetTypedUrlsFromHistoryService(verifier_service);
for (int i = 0; i < num_clients(); ++i) { for (int i = 0; i < test()->num_clients(); ++i) {
std::vector<history::URLRow> urls = GetTypedUrlsFromClient(i); std::vector<history::URLRow> urls = GetTypedUrlsFromClient(i);
AssertURLRowVectorsAreEqual(verifier_urls, urls); AssertURLRowVectorsAreEqual(verifier_urls, urls);
} }
} }
} // namespace typed_urls_helper
// Copyright (c) 2011 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.
#ifndef CHROME_TEST_LIVE_SYNC_TYPED_URLS_HELPER_H_
#define CHROME_TEST_LIVE_SYNC_TYPED_URLS_HELPER_H_
#pragma once
#include <vector>
#include "chrome/browser/history/history_types.h"
namespace base {
class Time;
}
namespace typed_urls_helper {
// Gets the typed URLs from a specific sync profile.
std::vector<history::URLRow> GetTypedUrlsFromClient(int index);
// Adds a URL to the history DB for a specific sync profile (just registers a
// new visit if the URL already exists).
void AddUrlToHistory(int index, const GURL& url);
// Deletes a URL from the history DB for a specific sync profile.
void DeleteUrlFromHistory(int index, const GURL& url);
// Returns true if all clients match the verifier profile.
void AssertAllProfilesHaveSameURLsAsVerifier();
// Checks that the two vectors contain the same set of URLRows (possibly in
// a different order).
void AssertURLRowVectorsAreEqual(
const std::vector<history::URLRow>& left,
const std::vector<history::URLRow>& right);
// Checks that the passed URLRows are equivalent.
void AssertURLRowsAreEqual(const history::URLRow& left,
const history::URLRow& right);
// Returns a unique timestamp to use when generating page visits
// (HistoryService does not like having identical timestamps and will modify
// the timestamps behind the scenes if it encounters them, which leads to
// spurious test failures when the resulting timestamps aren't what we
// expect).
base::Time GetTimestamp();
} // namespace typed_urls_helper
#endif // CHROME_TEST_LIVE_SYNC_TYPED_URLS_HELPER_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment