1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
// 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/browser/sync/test/integration/preferences_helper.h"
#include "base/prefs/pref_service.h"
#include "base/prefs/scoped_user_pref_update.h"
#include "base/values.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
#include "chrome/browser/sync/test/integration/sync_datatype_helper.h"
#include "chrome/browser/sync/test/integration/sync_test.h"
using sync_datatype_helper::test;
namespace preferences_helper {
PrefService* GetPrefs(int index) {
return test()->GetProfile(index)->GetPrefs();
}
PrefService* GetVerifierPrefs() {
return test()->verifier()->GetPrefs();
}
void 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())
GetVerifierPrefs()->SetBoolean(pref_name, new_value);
}
void ChangeIntegerPref(int index, const char* pref_name, int new_value) {
GetPrefs(index)->SetInteger(pref_name, new_value);
if (test()->use_verifier())
GetVerifierPrefs()->SetInteger(pref_name, new_value);
}
void ChangeInt64Pref(int index, const char* pref_name, int64 new_value) {
GetPrefs(index)->SetInt64(pref_name, new_value);
if (test()->use_verifier())
GetVerifierPrefs()->SetInt64(pref_name, new_value);
}
void ChangeDoublePref(int index, const char* pref_name, double new_value) {
GetPrefs(index)->SetDouble(pref_name, new_value);
if (test()->use_verifier())
GetVerifierPrefs()->SetDouble(pref_name, new_value);
}
void ChangeStringPref(int index,
const char* pref_name,
const std::string& new_value) {
GetPrefs(index)->SetString(pref_name, new_value);
if (test()->use_verifier())
GetVerifierPrefs()->SetString(pref_name, new_value);
}
void AppendStringPref(int index,
const char* pref_name,
const std::string& append_value) {
ChangeStringPref(index,
pref_name,
GetPrefs(index)->GetString(pref_name) + append_value);
}
void ChangeFilePathPref(int index,
const char* pref_name,
const base::FilePath& new_value) {
GetPrefs(index)->SetFilePath(pref_name, new_value);
if (test()->use_verifier())
GetVerifierPrefs()->SetFilePath(pref_name, new_value);
}
void 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()) {
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());
}
}
}
bool BooleanPrefMatches(const char* pref_name) {
bool reference_value;
if (test()->use_verifier()) {
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;
}
bool IntegerPrefMatches(const char* pref_name) {
int reference_value;
if (test()->use_verifier()) {
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;
}
bool Int64PrefMatches(const char* pref_name) {
int64 reference_value;
if (test()->use_verifier()) {
reference_value = GetVerifierPrefs()->GetInt64(pref_name);
} else {
reference_value = GetPrefs(0)->GetInt64(pref_name);
}
for (int i = 0; i < test()->num_clients(); ++i) {
if (reference_value != GetPrefs(i)->GetInt64(pref_name)) {
LOG(ERROR) << "Integer preference " << pref_name << " mismatched in"
<< " profile " << i << ".";
return false;
}
}
return true;
}
bool DoublePrefMatches(const char* pref_name) {
double reference_value;
if (test()->use_verifier()) {
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;
}
bool StringPrefMatches(const char* pref_name) {
std::string reference_value;
if (test()->use_verifier()) {
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;
}
bool FilePathPrefMatches(const char* pref_name) {
base::FilePath reference_value;
if (test()->use_verifier()) {
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) << "base::FilePath preference " << pref_name
<< " mismatched in" << " profile " << i << ".";
return false;
}
}
return true;
}
bool ListPrefMatches(const char* pref_name) {
const ListValue* reference_value;
if (test()->use_verifier()) {
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;
}
} // namespace preferences_helper
|