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

Side by Side 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 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/preferences_helper.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 #include "chrome/test/live_sync/live_sync_test.h"
13
14 PreferencesHelper::PreferencesHelper() {}
15
16 PreferencesHelper::~PreferencesHelper() {}
17
18 // static
19 void PreferencesHelper::AssociateWithTest(LiveSyncTest* test) {
20 ASSERT_TRUE(test != NULL) << "Cannot associate with null test.";
21 ASSERT_TRUE(test_ == NULL) << "Already associated with a test.";
22 test_ = test;
23 }
24
25 // static
26 LiveSyncTest* PreferencesHelper::test() {
27 EXPECT_TRUE(test_ != NULL) << "Must call AssociateWithTest first.";
28 return test_;
29 }
30
31 // static
32 PrefService* PreferencesHelper::GetPrefs(int index) {
33 return test()->GetProfile(index)->GetPrefs();
34 }
35
36 // static
37 PrefService* PreferencesHelper::GetVerifierPrefs() {
38 return test()->verifier()->GetPrefs();
39 }
40
41 // static
42 void PreferencesHelper::ChangeBooleanPref(int index, const char* pref_name) {
43 bool new_value = !GetPrefs(index)->GetBoolean(pref_name);
44 GetPrefs(index)->SetBoolean(pref_name, new_value);
45 if (test()->use_verifier_prefs())
46 GetVerifierPrefs()->SetBoolean(pref_name, new_value);
47 }
48
49 // static
50 void PreferencesHelper::ChangeIntegerPref(int index,
51 const char* pref_name,
52 int new_value) {
53 GetPrefs(index)->SetInteger(pref_name, new_value);
54 if (test()->use_verifier_prefs())
55 GetVerifierPrefs()->SetInteger(pref_name, new_value);
56 }
57
58 // static
59 void PreferencesHelper::ChangeDoublePref(int index,
60 const char* pref_name,
61 double new_value) {
62 GetPrefs(index)->SetDouble(pref_name, new_value);
63 if (test()->use_verifier_prefs())
64 GetVerifierPrefs()->SetDouble(pref_name, new_value);
65 }
66
67 // static
68 void PreferencesHelper::ChangeStringPref(int index,
69 const char* pref_name,
70 const std::string& new_value) {
71 GetPrefs(index)->SetString(pref_name, new_value);
72 if (test()->use_verifier_prefs())
73 GetVerifierPrefs()->SetString(pref_name, new_value);
74 }
75
76 // static
77 void PreferencesHelper::AppendStringPref(int index,
78 const char* pref_name,
79 const std::string& append_value) {
80 ChangeStringPref(index,
81 pref_name,
82 GetPrefs(index)->GetString(pref_name) + append_value);
83 }
84
85 // static
86 void PreferencesHelper::ChangeFilePathPref(int index,
87 const char* pref_name,
88 const FilePath& new_value) {
89 GetPrefs(index)->SetFilePath(pref_name, new_value);
90 if (test()->use_verifier_prefs())
91 GetVerifierPrefs()->SetFilePath(pref_name, new_value);
92 }
93
94 // static
95 void PreferencesHelper::ChangeListPref(int index,
96 const char* pref_name,
97 const ListValue& new_value) {
98 {
99 ListPrefUpdate update(GetPrefs(index), pref_name);
100 ListValue* list = update.Get();
101 for (ListValue::const_iterator it = new_value.begin();
102 it != new_value.end();
103 ++it) {
104 list->Append((*it)->DeepCopy());
105 }
106 }
107
108 if (test()->use_verifier_prefs()) {
109 ListPrefUpdate update_verifier(GetVerifierPrefs(), pref_name);
110 ListValue* list_verifier = update_verifier.Get();
111 for (ListValue::const_iterator it = new_value.begin();
112 it != new_value.end();
113 ++it) {
114 list_verifier->Append((*it)->DeepCopy());
115 }
116 }
117 }
118
119 // static
120 bool PreferencesHelper::BooleanPrefMatches(const char* pref_name) {
121 bool reference_value;
122 if (test()->use_verifier_prefs()) {
123 reference_value = GetVerifierPrefs()->GetBoolean(pref_name);
124 } else {
125 reference_value = GetPrefs(0)->GetBoolean(pref_name);
126 }
127 for (int i = 0; i < test()->num_clients(); ++i) {
128 if (reference_value != GetPrefs(i)->GetBoolean(pref_name)) {
129 LOG(ERROR) << "Boolean preference " << pref_name << " mismatched in"
130 << " profile " << i << ".";
131 return false;
132 }
133 }
134 return true;
135 }
136
137 // static
138 bool PreferencesHelper::IntegerPrefMatches(const char* pref_name) {
139 int reference_value;
140 if (test()->use_verifier_prefs()) {
141 reference_value = GetVerifierPrefs()->GetInteger(pref_name);
142 } else {
143 reference_value = GetPrefs(0)->GetInteger(pref_name);
144 }
145 for (int i = 0; i < test()->num_clients(); ++i) {
146 if (reference_value != GetPrefs(i)->GetInteger(pref_name)) {
147 LOG(ERROR) << "Integer preference " << pref_name << " mismatched in"
148 << " profile " << i << ".";
149 return false;
150 }
151 }
152 return true;
153 }
154
155 // static
156 bool PreferencesHelper::DoublePrefMatches(const char* pref_name) {
157 double reference_value;
158 if (test()->use_verifier_prefs()) {
159 reference_value = GetVerifierPrefs()->GetDouble(pref_name);
160 } else {
161 reference_value = GetPrefs(0)->GetDouble(pref_name);
162 }
163 for (int i = 0; i < test()->num_clients(); ++i) {
164 if (reference_value != GetPrefs(i)->GetDouble(pref_name)) {
165 LOG(ERROR) << "Double preference " << pref_name << " mismatched in"
166 << " profile " << i << ".";
167 return false;
168 }
169 }
170 return true;
171 }
172
173 // static
174 bool PreferencesHelper::StringPrefMatches(const char* pref_name) {
175 std::string reference_value;
176 if (test()->use_verifier_prefs()) {
177 reference_value = GetVerifierPrefs()->GetString(pref_name);
178 } else {
179 reference_value = GetPrefs(0)->GetString(pref_name);
180 }
181 for (int i = 0; i < test()->num_clients(); ++i) {
182 if (reference_value != GetPrefs(i)->GetString(pref_name)) {
183 LOG(ERROR) << "String preference " << pref_name << " mismatched in"
184 << " profile " << i << ".";
185 return false;
186 }
187 }
188 return true;
189 }
190
191 // static
192 bool PreferencesHelper::FilePathPrefMatches(const char* pref_name) {
193 FilePath reference_value;
194 if (test()->use_verifier_prefs()) {
195 reference_value = GetVerifierPrefs()->GetFilePath(pref_name);
196 } else {
197 reference_value = GetPrefs(0)->GetFilePath(pref_name);
198 }
199 for (int i = 0; i < test()->num_clients(); ++i) {
200 if (reference_value != GetPrefs(i)->GetFilePath(pref_name)) {
201 LOG(ERROR) << "FilePath preference " << pref_name << " mismatched in"
202 << " profile " << i << ".";
203 return false;
204 }
205 }
206 return true;
207 }
208
209 // static
210 bool PreferencesHelper::ListPrefMatches(const char* pref_name) {
211 const ListValue* reference_value;
212 if (test()->use_verifier_prefs()) {
213 reference_value = GetVerifierPrefs()->GetList(pref_name);
214 } else {
215 reference_value = GetPrefs(0)->GetList(pref_name);
216 }
217 for (int i = 0; i < test()->num_clients(); ++i) {
218 if (!reference_value->Equals(GetPrefs(i)->GetList(pref_name))) {
219 LOG(ERROR) << "List preference " << pref_name << " mismatched in"
220 << " profile " << i << ".";
221 return false;
222 }
223 }
224 return true;
225 }
226
227 // static
228 bool PreferencesHelper::EnableEncryption(int index) {
229 return test()->GetClient(index)->EnableEncryptionForType(
230 syncable::PREFERENCES);
231 }
232
233 // static
234 bool PreferencesHelper::IsEncrypted(int index) {
235 return test()->GetClient(index)->IsTypeEncrypted(syncable::PREFERENCES);
236 }
237
238 // static
239 LiveSyncTest* PreferencesHelper::test_ = NULL;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698