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