| OLD | NEW |
| (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/browser/sync/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/browser/sync/test/live_sync/live_sync_test.h" | |
| 13 #include "chrome/browser/sync/test/live_sync/sync_datatype_helper.h" | |
| 14 | |
| 15 using sync_datatype_helper::test; | |
| 16 | |
| 17 namespace preferences_helper { | |
| 18 | |
| 19 PrefService* GetPrefs(int index) { | |
| 20 return test()->GetProfile(index)->GetPrefs(); | |
| 21 } | |
| 22 | |
| 23 PrefService* GetVerifierPrefs() { | |
| 24 return test()->verifier()->GetPrefs(); | |
| 25 } | |
| 26 | |
| 27 void ChangeBooleanPref(int index, const char* pref_name) { | |
| 28 bool new_value = !GetPrefs(index)->GetBoolean(pref_name); | |
| 29 GetPrefs(index)->SetBoolean(pref_name, new_value); | |
| 30 if (test()->use_verifier()) | |
| 31 GetVerifierPrefs()->SetBoolean(pref_name, new_value); | |
| 32 } | |
| 33 | |
| 34 void ChangeIntegerPref(int index, const char* pref_name, int new_value) { | |
| 35 GetPrefs(index)->SetInteger(pref_name, new_value); | |
| 36 if (test()->use_verifier()) | |
| 37 GetVerifierPrefs()->SetInteger(pref_name, new_value); | |
| 38 } | |
| 39 | |
| 40 void ChangeDoublePref(int index, const char* pref_name, double new_value) { | |
| 41 GetPrefs(index)->SetDouble(pref_name, new_value); | |
| 42 if (test()->use_verifier()) | |
| 43 GetVerifierPrefs()->SetDouble(pref_name, new_value); | |
| 44 } | |
| 45 | |
| 46 void ChangeStringPref(int index, | |
| 47 const char* pref_name, | |
| 48 const std::string& new_value) { | |
| 49 GetPrefs(index)->SetString(pref_name, new_value); | |
| 50 if (test()->use_verifier()) | |
| 51 GetVerifierPrefs()->SetString(pref_name, new_value); | |
| 52 } | |
| 53 | |
| 54 void AppendStringPref(int index, | |
| 55 const char* pref_name, | |
| 56 const std::string& append_value) { | |
| 57 ChangeStringPref(index, | |
| 58 pref_name, | |
| 59 GetPrefs(index)->GetString(pref_name) + append_value); | |
| 60 } | |
| 61 | |
| 62 void ChangeFilePathPref(int index, | |
| 63 const char* pref_name, | |
| 64 const FilePath& new_value) { | |
| 65 GetPrefs(index)->SetFilePath(pref_name, new_value); | |
| 66 if (test()->use_verifier()) | |
| 67 GetVerifierPrefs()->SetFilePath(pref_name, new_value); | |
| 68 } | |
| 69 | |
| 70 void ChangeListPref(int index, | |
| 71 const char* pref_name, | |
| 72 const ListValue& new_value) { | |
| 73 { | |
| 74 ListPrefUpdate update(GetPrefs(index), pref_name); | |
| 75 ListValue* list = update.Get(); | |
| 76 for (ListValue::const_iterator it = new_value.begin(); | |
| 77 it != new_value.end(); | |
| 78 ++it) { | |
| 79 list->Append((*it)->DeepCopy()); | |
| 80 } | |
| 81 } | |
| 82 | |
| 83 if (test()->use_verifier()) { | |
| 84 ListPrefUpdate update_verifier(GetVerifierPrefs(), pref_name); | |
| 85 ListValue* list_verifier = update_verifier.Get(); | |
| 86 for (ListValue::const_iterator it = new_value.begin(); | |
| 87 it != new_value.end(); | |
| 88 ++it) { | |
| 89 list_verifier->Append((*it)->DeepCopy()); | |
| 90 } | |
| 91 } | |
| 92 } | |
| 93 | |
| 94 bool BooleanPrefMatches(const char* pref_name) { | |
| 95 bool reference_value; | |
| 96 if (test()->use_verifier()) { | |
| 97 reference_value = GetVerifierPrefs()->GetBoolean(pref_name); | |
| 98 } else { | |
| 99 reference_value = GetPrefs(0)->GetBoolean(pref_name); | |
| 100 } | |
| 101 for (int i = 0; i < test()->num_clients(); ++i) { | |
| 102 if (reference_value != GetPrefs(i)->GetBoolean(pref_name)) { | |
| 103 LOG(ERROR) << "Boolean preference " << pref_name << " mismatched in" | |
| 104 << " profile " << i << "."; | |
| 105 return false; | |
| 106 } | |
| 107 } | |
| 108 return true; | |
| 109 } | |
| 110 | |
| 111 bool IntegerPrefMatches(const char* pref_name) { | |
| 112 int reference_value; | |
| 113 if (test()->use_verifier()) { | |
| 114 reference_value = GetVerifierPrefs()->GetInteger(pref_name); | |
| 115 } else { | |
| 116 reference_value = GetPrefs(0)->GetInteger(pref_name); | |
| 117 } | |
| 118 for (int i = 0; i < test()->num_clients(); ++i) { | |
| 119 if (reference_value != GetPrefs(i)->GetInteger(pref_name)) { | |
| 120 LOG(ERROR) << "Integer preference " << pref_name << " mismatched in" | |
| 121 << " profile " << i << "."; | |
| 122 return false; | |
| 123 } | |
| 124 } | |
| 125 return true; | |
| 126 } | |
| 127 | |
| 128 bool DoublePrefMatches(const char* pref_name) { | |
| 129 double reference_value; | |
| 130 if (test()->use_verifier()) { | |
| 131 reference_value = GetVerifierPrefs()->GetDouble(pref_name); | |
| 132 } else { | |
| 133 reference_value = GetPrefs(0)->GetDouble(pref_name); | |
| 134 } | |
| 135 for (int i = 0; i < test()->num_clients(); ++i) { | |
| 136 if (reference_value != GetPrefs(i)->GetDouble(pref_name)) { | |
| 137 LOG(ERROR) << "Double preference " << pref_name << " mismatched in" | |
| 138 << " profile " << i << "."; | |
| 139 return false; | |
| 140 } | |
| 141 } | |
| 142 return true; | |
| 143 } | |
| 144 | |
| 145 bool StringPrefMatches(const char* pref_name) { | |
| 146 std::string reference_value; | |
| 147 if (test()->use_verifier()) { | |
| 148 reference_value = GetVerifierPrefs()->GetString(pref_name); | |
| 149 } else { | |
| 150 reference_value = GetPrefs(0)->GetString(pref_name); | |
| 151 } | |
| 152 for (int i = 0; i < test()->num_clients(); ++i) { | |
| 153 if (reference_value != GetPrefs(i)->GetString(pref_name)) { | |
| 154 LOG(ERROR) << "String preference " << pref_name << " mismatched in" | |
| 155 << " profile " << i << "."; | |
| 156 return false; | |
| 157 } | |
| 158 } | |
| 159 return true; | |
| 160 } | |
| 161 | |
| 162 bool FilePathPrefMatches(const char* pref_name) { | |
| 163 FilePath reference_value; | |
| 164 if (test()->use_verifier()) { | |
| 165 reference_value = GetVerifierPrefs()->GetFilePath(pref_name); | |
| 166 } else { | |
| 167 reference_value = GetPrefs(0)->GetFilePath(pref_name); | |
| 168 } | |
| 169 for (int i = 0; i < test()->num_clients(); ++i) { | |
| 170 if (reference_value != GetPrefs(i)->GetFilePath(pref_name)) { | |
| 171 LOG(ERROR) << "FilePath preference " << pref_name << " mismatched in" | |
| 172 << " profile " << i << "."; | |
| 173 return false; | |
| 174 } | |
| 175 } | |
| 176 return true; | |
| 177 } | |
| 178 | |
| 179 bool ListPrefMatches(const char* pref_name) { | |
| 180 const ListValue* reference_value; | |
| 181 if (test()->use_verifier()) { | |
| 182 reference_value = GetVerifierPrefs()->GetList(pref_name); | |
| 183 } else { | |
| 184 reference_value = GetPrefs(0)->GetList(pref_name); | |
| 185 } | |
| 186 for (int i = 0; i < test()->num_clients(); ++i) { | |
| 187 if (!reference_value->Equals(GetPrefs(i)->GetList(pref_name))) { | |
| 188 LOG(ERROR) << "List preference " << pref_name << " mismatched in" | |
| 189 << " profile " << i << "."; | |
| 190 return false; | |
| 191 } | |
| 192 } | |
| 193 return true; | |
| 194 } | |
| 195 | |
| 196 } // namespace preferences_helper | |
| OLD | NEW |