| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser/search_engines/template_url_service_test_util.h" | 5 #include "chrome/browser/search_engines/template_url_service_test_util.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/strings/string_split.h" |
| 9 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
| 10 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
| 11 #include "chrome/browser/google/google_url_tracker.h" | 12 #include "chrome/browser/google/google_url_tracker.h" |
| 13 #include "chrome/browser/search_engines/default_search_manager.h" |
| 12 #include "chrome/browser/search_engines/search_terms_data.h" | 14 #include "chrome/browser/search_engines/search_terms_data.h" |
| 13 #include "chrome/browser/search_engines/template_url_service.h" | 15 #include "chrome/browser/search_engines/template_url_service.h" |
| 14 #include "chrome/browser/search_engines/template_url_service_factory.h" | 16 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 15 #include "chrome/browser/webdata/web_data_service_factory.h" | 17 #include "chrome/browser/webdata/web_data_service_factory.h" |
| 16 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 17 #include "chrome/test/base/testing_pref_service_syncable.h" | 19 #include "chrome/test/base/testing_pref_service_syncable.h" |
| 18 #include "chrome/test/base/testing_profile.h" | 20 #include "chrome/test/base/testing_profile.h" |
| 19 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 23 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 void TemplateURLServiceTestUtilBase::SetManagedDefaultSearchPreferences( | 139 void TemplateURLServiceTestUtilBase::SetManagedDefaultSearchPreferences( |
| 138 bool enabled, | 140 bool enabled, |
| 139 const std::string& name, | 141 const std::string& name, |
| 140 const std::string& keyword, | 142 const std::string& keyword, |
| 141 const std::string& search_url, | 143 const std::string& search_url, |
| 142 const std::string& suggest_url, | 144 const std::string& suggest_url, |
| 143 const std::string& icon_url, | 145 const std::string& icon_url, |
| 144 const std::string& encodings, | 146 const std::string& encodings, |
| 145 const std::string& alternate_url, | 147 const std::string& alternate_url, |
| 146 const std::string& search_terms_replacement_key) { | 148 const std::string& search_terms_replacement_key) { |
| 147 if (enabled) { | 149 TestingPrefServiceSyncable* pref_service = profile()->GetTestingPrefService(); |
| 148 EXPECT_FALSE(keyword.empty()); | 150 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue); |
| 149 EXPECT_FALSE(search_url.empty()); | 151 if (!enabled) { |
| 152 value->SetBoolean(DefaultSearchManager::kDisabledByPolicy, true); |
| 153 pref_service->SetManagedPref( |
| 154 DefaultSearchManager::kDefaultSearchProviderDataPrefName, |
| 155 value.release()); |
| 156 return; |
| 150 } | 157 } |
| 151 TestingPrefServiceSyncable* pref_service = profile()->GetTestingPrefService(); | 158 |
| 152 pref_service->SetManagedPref(prefs::kDefaultSearchProviderEnabled, | 159 EXPECT_FALSE(keyword.empty()); |
| 153 base::Value::CreateBooleanValue(enabled)); | 160 EXPECT_FALSE(search_url.empty()); |
| 154 pref_service->SetManagedPref(prefs::kDefaultSearchProviderName, | 161 value->Set(DefaultSearchManager::kShortName, |
| 155 base::Value::CreateStringValue(name)); | 162 base::Value::CreateStringValue(name)); |
| 156 pref_service->SetManagedPref(prefs::kDefaultSearchProviderKeyword, | 163 value->Set(DefaultSearchManager::kKeyword, |
| 157 base::Value::CreateStringValue(keyword)); | 164 base::Value::CreateStringValue(keyword)); |
| 158 pref_service->SetManagedPref(prefs::kDefaultSearchProviderSearchURL, | 165 value->Set(DefaultSearchManager::kURL, |
| 159 base::Value::CreateStringValue(search_url)); | 166 base::Value::CreateStringValue(search_url)); |
| 160 pref_service->SetManagedPref(prefs::kDefaultSearchProviderSuggestURL, | 167 value->Set(DefaultSearchManager::kSuggestionsURL, |
| 161 base::Value::CreateStringValue(suggest_url)); | 168 base::Value::CreateStringValue(suggest_url)); |
| 162 pref_service->SetManagedPref(prefs::kDefaultSearchProviderIconURL, | 169 value->Set(DefaultSearchManager::kFaviconURL, |
| 163 base::Value::CreateStringValue(icon_url)); | 170 base::Value::CreateStringValue(icon_url)); |
| 164 pref_service->SetManagedPref(prefs::kDefaultSearchProviderEncodings, | 171 value->Set(DefaultSearchManager::kSearchTermsReplacementKey, |
| 165 base::Value::CreateStringValue(encodings)); | 172 base::Value::CreateStringValue(search_terms_replacement_key)); |
| 173 |
| 174 std::vector<std::string> encodings_items; |
| 175 base::SplitString(encodings, ';', &encodings_items); |
| 176 scoped_ptr<base::ListValue> encodings_list(new base::ListValue); |
| 177 for (std::vector<std::string>::const_iterator it = encodings_items.begin(); |
| 178 it != encodings_items.end(); |
| 179 ++it) { |
| 180 encodings_list->AppendString(*it); |
| 181 } |
| 182 value->Set(DefaultSearchManager::kInputEncodings, encodings_list.release()); |
| 183 |
| 166 scoped_ptr<base::ListValue> alternate_url_list(new base::ListValue()); | 184 scoped_ptr<base::ListValue> alternate_url_list(new base::ListValue()); |
| 167 if (!alternate_url.empty()) | 185 if (!alternate_url.empty()) |
| 168 alternate_url_list->Append(base::Value::CreateStringValue(alternate_url)); | 186 alternate_url_list->Append(base::Value::CreateStringValue(alternate_url)); |
| 169 pref_service->SetManagedPref(prefs::kDefaultSearchProviderAlternateURLs, | 187 value->Set(DefaultSearchManager::kAlternateURLs, |
| 170 alternate_url_list.release()); | 188 alternate_url_list.release()); |
| 189 |
| 171 pref_service->SetManagedPref( | 190 pref_service->SetManagedPref( |
| 172 prefs::kDefaultSearchProviderSearchTermsReplacementKey, | 191 DefaultSearchManager::kDefaultSearchProviderDataPrefName, |
| 173 base::Value::CreateStringValue(search_terms_replacement_key)); | 192 value.release()); |
| 174 model()->Observe(chrome::NOTIFICATION_DEFAULT_SEARCH_POLICY_CHANGED, | |
| 175 content::NotificationService::AllSources(), | |
| 176 content::NotificationService::NoDetails()); | |
| 177 } | 193 } |
| 178 | 194 |
| 179 void TemplateURLServiceTestUtilBase::RemoveManagedDefaultSearchPreferences() { | 195 void TemplateURLServiceTestUtilBase::RemoveManagedDefaultSearchPreferences() { |
| 180 TestingPrefServiceSyncable* pref_service = profile()->GetTestingPrefService(); | 196 TestingPrefServiceSyncable* pref_service = profile()->GetTestingPrefService(); |
| 181 pref_service->RemoveManagedPref(prefs::kDefaultSearchProviderEnabled); | |
| 182 pref_service->RemoveManagedPref(prefs::kDefaultSearchProviderName); | |
| 183 pref_service->RemoveManagedPref(prefs::kDefaultSearchProviderKeyword); | |
| 184 pref_service->RemoveManagedPref(prefs::kDefaultSearchProviderSearchURL); | |
| 185 pref_service->RemoveManagedPref(prefs::kDefaultSearchProviderSuggestURL); | |
| 186 pref_service->RemoveManagedPref(prefs::kDefaultSearchProviderIconURL); | |
| 187 pref_service->RemoveManagedPref(prefs::kDefaultSearchProviderEncodings); | |
| 188 pref_service->RemoveManagedPref(prefs::kDefaultSearchProviderAlternateURLs); | |
| 189 pref_service->RemoveManagedPref( | 197 pref_service->RemoveManagedPref( |
| 190 prefs::kDefaultSearchProviderSearchTermsReplacementKey); | 198 DefaultSearchManager::kDefaultSearchProviderDataPrefName); |
| 191 pref_service->RemoveManagedPref(prefs::kDefaultSearchProviderID); | |
| 192 pref_service->RemoveManagedPref(prefs::kDefaultSearchProviderPrepopulateID); | |
| 193 model()->Observe(chrome::NOTIFICATION_DEFAULT_SEARCH_POLICY_CHANGED, | |
| 194 content::NotificationService::AllSources(), | |
| 195 content::NotificationService::NoDetails()); | |
| 196 } | 199 } |
| 197 | 200 |
| 198 TemplateURLService* TemplateURLServiceTestUtilBase::model() const { | 201 TemplateURLService* TemplateURLServiceTestUtilBase::model() const { |
| 199 return TemplateURLServiceFactory::GetForProfile(profile()); | 202 return TemplateURLServiceFactory::GetForProfile(profile()); |
| 200 } | 203 } |
| 201 | 204 |
| 202 | 205 |
| 203 // TemplateURLServiceTestUtil ------------------------------------------------- | 206 // TemplateURLServiceTestUtil ------------------------------------------------- |
| 204 | 207 |
| 205 TemplateURLServiceTestUtil::TemplateURLServiceTestUtil() | 208 TemplateURLServiceTestUtil::TemplateURLServiceTestUtil() |
| (...skipping 20 matching lines...) Expand all Loading... |
| 226 | 229 |
| 227 UIThreadSearchTermsData::SetGoogleBaseURL(std::string()); | 230 UIThreadSearchTermsData::SetGoogleBaseURL(std::string()); |
| 228 | 231 |
| 229 // Flush the message loop to make application verifiers happy. | 232 // Flush the message loop to make application verifiers happy. |
| 230 base::RunLoop().RunUntilIdle(); | 233 base::RunLoop().RunUntilIdle(); |
| 231 } | 234 } |
| 232 | 235 |
| 233 TestingProfile* TemplateURLServiceTestUtil::profile() const { | 236 TestingProfile* TemplateURLServiceTestUtil::profile() const { |
| 234 return profile_.get(); | 237 return profile_.get(); |
| 235 } | 238 } |
| OLD | NEW |