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