OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/search_engines/default_search_manager.h" | 5 #include "components/search_engines/default_search_manager.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> |
10 | 11 |
11 #include "base/files/scoped_temp_dir.h" | 12 #include "base/files/scoped_temp_dir.h" |
12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ptr_util.h" |
13 #include "base/strings/string_split.h" | 15 #include "base/strings/string_split.h" |
14 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
15 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
16 #include "base/time/time.h" | 18 #include "base/time/time.h" |
17 #include "components/pref_registry/pref_registry_syncable.h" | 19 #include "components/pref_registry/pref_registry_syncable.h" |
18 #include "components/search_engines/default_search_manager.h" | 20 #include "components/search_engines/default_search_manager.h" |
19 #include "components/search_engines/search_engines_pref_names.h" | 21 #include "components/search_engines/search_engines_pref_names.h" |
20 #include "components/search_engines/search_engines_test_util.h" | 22 #include "components/search_engines/search_engines_test_util.h" |
21 #include "components/search_engines/template_url_data.h" | 23 #include "components/search_engines/template_url_data.h" |
22 #include "components/search_engines/template_url_data_util.h" | 24 #include "components/search_engines/template_url_data_util.h" |
23 #include "components/search_engines/template_url_prepopulate_data.h" | 25 #include "components/search_engines/template_url_prepopulate_data.h" |
24 #include "components/sync_preferences/testing_pref_service_syncable.h" | 26 #include "components/sync_preferences/testing_pref_service_syncable.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
26 | 28 |
27 namespace { | 29 namespace { |
28 | 30 |
29 // TODO(caitkp): TemplateURLData-ify this. | 31 // TODO(caitkp): TemplateURLData-ify this. |
30 void SetOverrides(sync_preferences::TestingPrefServiceSyncable* prefs, | 32 void SetOverrides(sync_preferences::TestingPrefServiceSyncable* prefs, |
31 bool update) { | 33 bool update) { |
32 prefs->SetUserPref(prefs::kSearchProviderOverridesVersion, | 34 prefs->SetUserPref(prefs::kSearchProviderOverridesVersion, |
33 new base::Value(1)); | 35 base::MakeUnique<base::Value>(1)); |
34 base::ListValue* overrides = new base::ListValue; | 36 auto overrides = base::MakeUnique<base::ListValue>(); |
35 std::unique_ptr<base::DictionaryValue> entry(new base::DictionaryValue); | 37 std::unique_ptr<base::DictionaryValue> entry(new base::DictionaryValue); |
36 | 38 |
37 entry->SetString("name", update ? "new_foo" : "foo"); | 39 entry->SetString("name", update ? "new_foo" : "foo"); |
38 entry->SetString("keyword", update ? "new_fook" : "fook"); | 40 entry->SetString("keyword", update ? "new_fook" : "fook"); |
39 entry->SetString("search_url", "http://foo.com/s?q={searchTerms}"); | 41 entry->SetString("search_url", "http://foo.com/s?q={searchTerms}"); |
40 entry->SetString("favicon_url", "http://foi.com/favicon.ico"); | 42 entry->SetString("favicon_url", "http://foi.com/favicon.ico"); |
41 entry->SetString("encoding", "UTF-8"); | 43 entry->SetString("encoding", "UTF-8"); |
42 entry->SetInteger("id", 1001); | 44 entry->SetInteger("id", 1001); |
43 entry->SetString("suggest_url", "http://foo.com/suggest?q={searchTerms}"); | 45 entry->SetString("suggest_url", "http://foo.com/suggest?q={searchTerms}"); |
44 entry->SetString("instant_url", "http://foo.com/instant?q={searchTerms}"); | 46 entry->SetString("instant_url", "http://foo.com/instant?q={searchTerms}"); |
45 base::ListValue* alternate_urls = new base::ListValue; | 47 base::ListValue* alternate_urls = new base::ListValue; |
46 alternate_urls->AppendString("http://foo.com/alternate?q={searchTerms}"); | 48 alternate_urls->AppendString("http://foo.com/alternate?q={searchTerms}"); |
47 entry->Set("alternate_urls", alternate_urls); | 49 entry->Set("alternate_urls", alternate_urls); |
48 entry->SetString("search_terms_replacement_key", "espv"); | 50 entry->SetString("search_terms_replacement_key", "espv"); |
49 overrides->Append(entry->CreateDeepCopy()); | 51 overrides->Append(entry->CreateDeepCopy()); |
50 | 52 |
51 entry.reset(new base::DictionaryValue); | 53 entry.reset(new base::DictionaryValue); |
52 entry->SetInteger("id", 1002); | 54 entry->SetInteger("id", 1002); |
53 entry->SetString("name", update ? "new_bar" : "bar"); | 55 entry->SetString("name", update ? "new_bar" : "bar"); |
54 entry->SetString("keyword", update ? "new_bark" : "bark"); | 56 entry->SetString("keyword", update ? "new_bark" : "bark"); |
55 entry->SetString("encoding", std::string()); | 57 entry->SetString("encoding", std::string()); |
56 overrides->Append(entry->CreateDeepCopy()); | 58 overrides->Append(entry->CreateDeepCopy()); |
57 entry->SetInteger("id", 1003); | 59 entry->SetInteger("id", 1003); |
58 entry->SetString("name", "baz"); | 60 entry->SetString("name", "baz"); |
59 entry->SetString("keyword", "bazk"); | 61 entry->SetString("keyword", "bazk"); |
60 entry->SetString("encoding", "UTF-8"); | 62 entry->SetString("encoding", "UTF-8"); |
61 overrides->Append(entry->CreateDeepCopy()); | 63 overrides->Append(entry->CreateDeepCopy()); |
62 prefs->SetUserPref(prefs::kSearchProviderOverrides, overrides); | 64 prefs->SetUserPref(prefs::kSearchProviderOverrides, std::move(overrides)); |
63 } | 65 } |
64 | 66 |
65 void SetPolicy(sync_preferences::TestingPrefServiceSyncable* prefs, | 67 void SetPolicy(sync_preferences::TestingPrefServiceSyncable* prefs, |
66 bool enabled, | 68 bool enabled, |
67 TemplateURLData* data) { | 69 TemplateURLData* data) { |
68 if (enabled) { | 70 if (enabled) { |
69 EXPECT_FALSE(data->keyword().empty()); | 71 EXPECT_FALSE(data->keyword().empty()); |
70 EXPECT_FALSE(data->url().empty()); | 72 EXPECT_FALSE(data->url().empty()); |
71 } | 73 } |
72 std::unique_ptr<base::DictionaryValue> entry( | 74 std::unique_ptr<base::DictionaryValue> entry( |
73 TemplateURLDataToDictionary(*data)); | 75 TemplateURLDataToDictionary(*data)); |
74 entry->SetBoolean(DefaultSearchManager::kDisabledByPolicy, !enabled); | 76 entry->SetBoolean(DefaultSearchManager::kDisabledByPolicy, !enabled); |
75 prefs->SetManagedPref( | 77 prefs->SetManagedPref( |
76 DefaultSearchManager::kDefaultSearchProviderDataPrefName, | 78 DefaultSearchManager::kDefaultSearchProviderDataPrefName, |
77 entry.release()); | 79 std::move(entry)); |
78 } | 80 } |
79 | 81 |
80 } // namespace | 82 } // namespace |
81 | 83 |
82 class DefaultSearchManagerTest : public testing::Test { | 84 class DefaultSearchManagerTest : public testing::Test { |
83 public: | 85 public: |
84 DefaultSearchManagerTest() {}; | 86 DefaultSearchManagerTest() {}; |
85 | 87 |
86 void SetUp() override { | 88 void SetUp() override { |
87 pref_service_.reset(new sync_preferences::TestingPrefServiceSyncable); | 89 pref_service_.reset(new sync_preferences::TestingPrefServiceSyncable); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 SetExtensionDefaultSearchInPrefs(pref_service(), *extension_data_2); | 261 SetExtensionDefaultSearchInPrefs(pref_service(), *extension_data_2); |
260 SetExtensionDefaultSearchInPrefs(pref_service(), *extension_data_3); | 262 SetExtensionDefaultSearchInPrefs(pref_service(), *extension_data_3); |
261 ExpectSimilar(extension_data_3.get(), | 263 ExpectSimilar(extension_data_3.get(), |
262 manager.GetDefaultSearchEngine(&source)); | 264 manager.GetDefaultSearchEngine(&source)); |
263 EXPECT_EQ(DefaultSearchManager::FROM_EXTENSION, source); | 265 EXPECT_EQ(DefaultSearchManager::FROM_EXTENSION, source); |
264 | 266 |
265 RemoveExtensionDefaultSearchFromPrefs(pref_service()); | 267 RemoveExtensionDefaultSearchFromPrefs(pref_service()); |
266 ExpectSimilar(data.get(), manager.GetDefaultSearchEngine(&source)); | 268 ExpectSimilar(data.get(), manager.GetDefaultSearchEngine(&source)); |
267 EXPECT_EQ(DefaultSearchManager::FROM_USER, source); | 269 EXPECT_EQ(DefaultSearchManager::FROM_USER, source); |
268 } | 270 } |
OLD | NEW |