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

Unified Diff: chrome/test/live_sync/preferences_helper.cc

Issue 7259005: Allow sync integration tests to operate on multiple datatypes: Preferences + Bookmarks (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Actual patch set. (Moves show up as adds / deletes. Hard to review) Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/test/live_sync/preferences_helper.cc
diff --git a/chrome/test/live_sync/preferences_helper.cc b/chrome/test/live_sync/preferences_helper.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4f5f779becd17ae10f105549f17fa6704327bccc
--- /dev/null
+++ b/chrome/test/live_sync/preferences_helper.cc
@@ -0,0 +1,239 @@
+// 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.
+
+#include "chrome/test/live_sync/preferences_helper.h"
+
+#include "base/values.h"
+#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/browser/prefs/scoped_user_pref_update.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/sync/profile_sync_service_harness.h"
+#include "chrome/test/live_sync/live_sync_test.h"
+
+PreferencesHelper::PreferencesHelper() {}
+
+PreferencesHelper::~PreferencesHelper() {}
+
+// static
+void PreferencesHelper::AssociateWithTest(LiveSyncTest* test) {
+ ASSERT_TRUE(test != NULL) << "Cannot associate with null test.";
+ ASSERT_TRUE(test_ == NULL) << "Already associated with a test.";
+ test_ = test;
+}
+
+// static
+LiveSyncTest* PreferencesHelper::test() {
+ EXPECT_TRUE(test_ != NULL) << "Must call AssociateWithTest first.";
+ return test_;
+}
+
+// static
+PrefService* PreferencesHelper::GetPrefs(int index) {
+ return test()->GetProfile(index)->GetPrefs();
+}
+
+// static
+PrefService* PreferencesHelper::GetVerifierPrefs() {
+ return test()->verifier()->GetPrefs();
+}
+
+// static
+void PreferencesHelper::ChangeBooleanPref(int index, const char* pref_name) {
+ bool new_value = !GetPrefs(index)->GetBoolean(pref_name);
+ GetPrefs(index)->SetBoolean(pref_name, new_value);
+ if (test()->use_verifier_prefs())
+ GetVerifierPrefs()->SetBoolean(pref_name, new_value);
+}
+
+// static
+void PreferencesHelper::ChangeIntegerPref(int index,
+ const char* pref_name,
+ int new_value) {
+ GetPrefs(index)->SetInteger(pref_name, new_value);
+ if (test()->use_verifier_prefs())
+ GetVerifierPrefs()->SetInteger(pref_name, new_value);
+}
+
+// static
+void PreferencesHelper::ChangeDoublePref(int index,
+ const char* pref_name,
+ double new_value) {
+ GetPrefs(index)->SetDouble(pref_name, new_value);
+ if (test()->use_verifier_prefs())
+ GetVerifierPrefs()->SetDouble(pref_name, new_value);
+}
+
+// static
+void PreferencesHelper::ChangeStringPref(int index,
+ const char* pref_name,
+ const std::string& new_value) {
+ GetPrefs(index)->SetString(pref_name, new_value);
+ if (test()->use_verifier_prefs())
+ GetVerifierPrefs()->SetString(pref_name, new_value);
+}
+
+// static
+void PreferencesHelper::AppendStringPref(int index,
+ const char* pref_name,
+ const std::string& append_value) {
+ ChangeStringPref(index,
+ pref_name,
+ GetPrefs(index)->GetString(pref_name) + append_value);
+}
+
+// static
+void PreferencesHelper::ChangeFilePathPref(int index,
+ const char* pref_name,
+ const FilePath& new_value) {
+ GetPrefs(index)->SetFilePath(pref_name, new_value);
+ if (test()->use_verifier_prefs())
+ GetVerifierPrefs()->SetFilePath(pref_name, new_value);
+}
+
+// static
+void PreferencesHelper::ChangeListPref(int index,
+ const char* pref_name,
+ const ListValue& new_value) {
+ {
+ ListPrefUpdate update(GetPrefs(index), pref_name);
+ ListValue* list = update.Get();
+ for (ListValue::const_iterator it = new_value.begin();
+ it != new_value.end();
+ ++it) {
+ list->Append((*it)->DeepCopy());
+ }
+ }
+
+ if (test()->use_verifier_prefs()) {
+ ListPrefUpdate update_verifier(GetVerifierPrefs(), pref_name);
+ ListValue* list_verifier = update_verifier.Get();
+ for (ListValue::const_iterator it = new_value.begin();
+ it != new_value.end();
+ ++it) {
+ list_verifier->Append((*it)->DeepCopy());
+ }
+ }
+}
+
+// static
+bool PreferencesHelper::BooleanPrefMatches(const char* pref_name) {
+ bool reference_value;
+ if (test()->use_verifier_prefs()) {
+ reference_value = GetVerifierPrefs()->GetBoolean(pref_name);
+ } else {
+ reference_value = GetPrefs(0)->GetBoolean(pref_name);
+ }
+ for (int i = 0; i < test()->num_clients(); ++i) {
+ if (reference_value != GetPrefs(i)->GetBoolean(pref_name)) {
+ LOG(ERROR) << "Boolean preference " << pref_name << " mismatched in"
+ << " profile " << i << ".";
+ return false;
+ }
+ }
+ return true;
+}
+
+// static
+bool PreferencesHelper::IntegerPrefMatches(const char* pref_name) {
+ int reference_value;
+ if (test()->use_verifier_prefs()) {
+ reference_value = GetVerifierPrefs()->GetInteger(pref_name);
+ } else {
+ reference_value = GetPrefs(0)->GetInteger(pref_name);
+ }
+ for (int i = 0; i < test()->num_clients(); ++i) {
+ if (reference_value != GetPrefs(i)->GetInteger(pref_name)) {
+ LOG(ERROR) << "Integer preference " << pref_name << " mismatched in"
+ << " profile " << i << ".";
+ return false;
+ }
+ }
+ return true;
+}
+
+// static
+bool PreferencesHelper::DoublePrefMatches(const char* pref_name) {
+ double reference_value;
+ if (test()->use_verifier_prefs()) {
+ reference_value = GetVerifierPrefs()->GetDouble(pref_name);
+ } else {
+ reference_value = GetPrefs(0)->GetDouble(pref_name);
+ }
+ for (int i = 0; i < test()->num_clients(); ++i) {
+ if (reference_value != GetPrefs(i)->GetDouble(pref_name)) {
+ LOG(ERROR) << "Double preference " << pref_name << " mismatched in"
+ << " profile " << i << ".";
+ return false;
+ }
+ }
+ return true;
+}
+
+// static
+bool PreferencesHelper::StringPrefMatches(const char* pref_name) {
+ std::string reference_value;
+ if (test()->use_verifier_prefs()) {
+ reference_value = GetVerifierPrefs()->GetString(pref_name);
+ } else {
+ reference_value = GetPrefs(0)->GetString(pref_name);
+ }
+ for (int i = 0; i < test()->num_clients(); ++i) {
+ if (reference_value != GetPrefs(i)->GetString(pref_name)) {
+ LOG(ERROR) << "String preference " << pref_name << " mismatched in"
+ << " profile " << i << ".";
+ return false;
+ }
+ }
+ return true;
+}
+
+// static
+bool PreferencesHelper::FilePathPrefMatches(const char* pref_name) {
+ FilePath reference_value;
+ if (test()->use_verifier_prefs()) {
+ reference_value = GetVerifierPrefs()->GetFilePath(pref_name);
+ } else {
+ reference_value = GetPrefs(0)->GetFilePath(pref_name);
+ }
+ for (int i = 0; i < test()->num_clients(); ++i) {
+ if (reference_value != GetPrefs(i)->GetFilePath(pref_name)) {
+ LOG(ERROR) << "FilePath preference " << pref_name << " mismatched in"
+ << " profile " << i << ".";
+ return false;
+ }
+ }
+ return true;
+}
+
+// static
+bool PreferencesHelper::ListPrefMatches(const char* pref_name) {
+ const ListValue* reference_value;
+ if (test()->use_verifier_prefs()) {
+ reference_value = GetVerifierPrefs()->GetList(pref_name);
+ } else {
+ reference_value = GetPrefs(0)->GetList(pref_name);
+ }
+ for (int i = 0; i < test()->num_clients(); ++i) {
+ if (!reference_value->Equals(GetPrefs(i)->GetList(pref_name))) {
+ LOG(ERROR) << "List preference " << pref_name << " mismatched in"
+ << " profile " << i << ".";
+ return false;
+ }
+ }
+ return true;
+}
+
+// static
+bool PreferencesHelper::EnableEncryption(int index) {
+ return test()->GetClient(index)->EnableEncryptionForType(
+ syncable::PREFERENCES);
+}
+
+// static
+bool PreferencesHelper::IsEncrypted(int index) {
+ return test()->GetClient(index)->IsTypeEncrypted(syncable::PREFERENCES);
+}
+
+// static
+LiveSyncTest* PreferencesHelper::test_ = NULL;

Powered by Google App Engine
This is Rietveld 408576698