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

Side by Side Diff: chrome/test/live_sync/live_preferences_sync_test.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: Rebase Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/test/live_sync/live_preferences_sync_test.h"
6
7 #include "base/values.h"
8 #include "chrome/browser/prefs/pref_service.h"
9 #include "chrome/browser/prefs/scoped_user_pref_update.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/sync/profile_sync_service_harness.h"
12
13 LivePreferencesSyncTest::LivePreferencesSyncTest(TestType test_type)
14 : LiveSyncTest(test_type),
15 use_verifier_prefs_(true) {}
16
17 LivePreferencesSyncTest::~LivePreferencesSyncTest() {}
18
19 PrefService* LivePreferencesSyncTest::GetPrefs(int index) {
20 return GetProfile(index)->GetPrefs();
21 }
22
23 PrefService* LivePreferencesSyncTest::GetVerifierPrefs() {
24 return verifier()->GetPrefs();
25 }
26
27 void LivePreferencesSyncTest::ChangeBooleanPref(int index,
28 const char* pref_name) {
29 bool new_value = !GetPrefs(index)->GetBoolean(pref_name);
30 GetPrefs(index)->SetBoolean(pref_name, new_value);
31 if (use_verifier_prefs_)
32 GetVerifierPrefs()->SetBoolean(pref_name, new_value);
33 }
34
35 void LivePreferencesSyncTest::ChangeIntegerPref(int index,
36 const char* pref_name,
37 int new_value) {
38 GetPrefs(index)->SetInteger(pref_name, new_value);
39 if (use_verifier_prefs_)
40 GetVerifierPrefs()->SetInteger(pref_name, new_value);
41 }
42
43 void LivePreferencesSyncTest::ChangeDoublePref(int index,
44 const char* pref_name,
45 double new_value) {
46 GetPrefs(index)->SetDouble(pref_name, new_value);
47 if (use_verifier_prefs_)
48 GetVerifierPrefs()->SetDouble(pref_name, new_value);
49 }
50
51 void LivePreferencesSyncTest::ChangeStringPref(int index,
52 const char* pref_name,
53 const std::string& new_value) {
54 GetPrefs(index)->SetString(pref_name, new_value);
55 if (use_verifier_prefs_)
56 GetVerifierPrefs()->SetString(pref_name, new_value);
57 }
58
59 void LivePreferencesSyncTest::AppendStringPref(
60 int index,
61 const char* pref_name,
62 const std::string& append_value) {
63 ChangeStringPref(index, pref_name,
64 GetPrefs(index)->GetString(pref_name) + append_value);
65 }
66
67 void LivePreferencesSyncTest::ChangeFilePathPref(int index,
68 const char* pref_name,
69 const FilePath& new_value) {
70 GetPrefs(index)->SetFilePath(pref_name, new_value);
71 if (use_verifier_prefs_)
72 GetVerifierPrefs()->SetFilePath(pref_name, new_value);
73 }
74
75 void LivePreferencesSyncTest::ChangeListPref(int index,
76 const char* pref_name,
77 const ListValue& new_value) {
78 {
79 ListPrefUpdate update(GetPrefs(index), pref_name);
80 ListValue* list = update.Get();
81 for (ListValue::const_iterator it = new_value.begin();
82 it != new_value.end();
83 ++it) {
84 list->Append((*it)->DeepCopy());
85 }
86 }
87
88 if (use_verifier_prefs_) {
89 ListPrefUpdate update_verifier(GetVerifierPrefs(), pref_name);
90 ListValue* list_verifier = update_verifier.Get();
91 for (ListValue::const_iterator it = new_value.begin();
92 it != new_value.end();
93 ++it) {
94 list_verifier->Append((*it)->DeepCopy());
95 }
96 }
97 }
98
99 bool LivePreferencesSyncTest::BooleanPrefMatches(const char* pref_name) {
100 bool reference_value;
101 if (use_verifier_prefs_) {
102 reference_value = GetVerifierPrefs()->GetBoolean(pref_name);
103 } else {
104 reference_value = GetPrefs(0)->GetBoolean(pref_name);
105 }
106 for (int i = 0; i < num_clients(); ++i) {
107 if (reference_value != GetPrefs(i)->GetBoolean(pref_name)) {
108 LOG(ERROR) << "Boolean preference " << pref_name << " mismatched in"
109 << "profile " << i << ".";
110 return false;
111 }
112 }
113 return true;
114 }
115
116 bool LivePreferencesSyncTest::IntegerPrefMatches(const char* pref_name) {
117 int reference_value;
118 if (use_verifier_prefs_) {
119 reference_value = GetVerifierPrefs()->GetInteger(pref_name);
120 } else {
121 reference_value = GetPrefs(0)->GetInteger(pref_name);
122 }
123 for (int i = 0; i < num_clients(); ++i) {
124 if (reference_value != GetPrefs(i)->GetInteger(pref_name)) {
125 LOG(ERROR) << "Integer preference " << pref_name << " mismatched in"
126 << "profile " << i << ".";
127 return false;
128 }
129 }
130 return true;
131 }
132
133 bool LivePreferencesSyncTest::DoublePrefMatches(const char* pref_name) {
134 double reference_value;
135 if (use_verifier_prefs_) {
136 reference_value = GetVerifierPrefs()->GetDouble(pref_name);
137 } else {
138 reference_value = GetPrefs(0)->GetDouble(pref_name);
139 }
140 for (int i = 0; i < num_clients(); ++i) {
141 if (reference_value != GetPrefs(i)->GetDouble(pref_name)) {
142 LOG(ERROR) << "Double preference " << pref_name << " mismatched in"
143 << "profile " << i << ".";
144 return false;
145 }
146 }
147 return true;
148 }
149
150 bool LivePreferencesSyncTest::StringPrefMatches(const char* pref_name) {
151 std::string reference_value;
152 if (use_verifier_prefs_) {
153 reference_value = GetVerifierPrefs()->GetString(pref_name);
154 } else {
155 reference_value = GetPrefs(0)->GetString(pref_name);
156 }
157 for (int i = 0; i < num_clients(); ++i) {
158 if (reference_value != GetPrefs(i)->GetString(pref_name)) {
159 LOG(ERROR) << "String preference " << pref_name << " mismatched in"
160 << "profile " << i << ".";
161 return false;
162 }
163 }
164 return true;
165 }
166
167 bool LivePreferencesSyncTest::FilePathPrefMatches(const char* pref_name) {
168 FilePath reference_value;
169 if (use_verifier_prefs_) {
170 reference_value = GetVerifierPrefs()->GetFilePath(pref_name);
171 } else {
172 reference_value = GetPrefs(0)->GetFilePath(pref_name);
173 }
174 for (int i = 0; i < num_clients(); ++i) {
175 if (reference_value != GetPrefs(i)->GetFilePath(pref_name)) {
176 LOG(ERROR) << "FilePath preference " << pref_name << " mismatched in"
177 << "profile " << i << ".";
178 return false;
179 }
180 }
181 return true;
182 }
183
184 bool LivePreferencesSyncTest::ListPrefMatches(const char* pref_name) {
185 const ListValue* reference_value;
186 if (use_verifier_prefs_) {
187 reference_value = GetVerifierPrefs()->GetList(pref_name);
188 } else {
189 reference_value = GetPrefs(0)->GetList(pref_name);
190 }
191 for (int i = 0; i < num_clients(); ++i) {
192 if (!reference_value->Equals(GetPrefs(i)->GetList(pref_name))) {
193 LOG(ERROR) << "List preference " << pref_name << " mismatched in"
194 << "profile " << i << ".";
195 return false;
196 }
197 }
198 return true;
199 }
200
201 void LivePreferencesSyncTest::DisableVerifier() {
202 use_verifier_prefs_ = false;
203 }
204
205 bool LivePreferencesSyncTest::EnableEncryption(int index) {
206 return GetClient(index)->EnableEncryptionForType(syncable::PREFERENCES);
207 }
208
209 bool LivePreferencesSyncTest::IsEncrypted(int index) {
210 return GetClient(index)->IsTypeEncrypted(syncable::PREFERENCES);
211 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698