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_pref_migration.h" | 5 #include "components/search_engines/default_search_pref_migration.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/files/scoped_temp_dir.h" | 12 #include "base/files/scoped_temp_dir.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
19 #include "components/pref_registry/testing_pref_service_syncable.h" | |
20 #include "components/search_engines/default_search_manager.h" | 19 #include "components/search_engines/default_search_manager.h" |
21 #include "components/search_engines/search_engines_pref_names.h" | 20 #include "components/search_engines/search_engines_pref_names.h" |
22 #include "components/search_engines/template_url.h" | 21 #include "components/search_engines/template_url.h" |
23 #include "components/search_engines/template_url_prepopulate_data.h" | 22 #include "components/search_engines/template_url_prepopulate_data.h" |
24 #include "components/search_engines/template_url_service.h" | 23 #include "components/search_engines/template_url_service.h" |
| 24 #include "components/sync_preferences/testing_pref_service_syncable.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
26 #include "url/gurl.h" | 26 #include "url/gurl.h" |
27 | 27 |
28 class DefaultSearchPrefMigrationTest : public testing::Test { | 28 class DefaultSearchPrefMigrationTest : public testing::Test { |
29 public: | 29 public: |
30 DefaultSearchPrefMigrationTest(); | 30 DefaultSearchPrefMigrationTest(); |
31 | 31 |
32 void SaveDefaultSearchProviderToLegacyPrefs(const TemplateURL* t_url); | 32 void SaveDefaultSearchProviderToLegacyPrefs(const TemplateURL* t_url); |
33 | 33 |
34 std::unique_ptr<TemplateURL> CreateKeyword(const std::string& short_name, | 34 std::unique_ptr<TemplateURL> CreateKeyword(const std::string& short_name, |
35 const std::string& keyword, | 35 const std::string& keyword, |
36 const std::string& url); | 36 const std::string& url); |
37 | 37 |
38 DefaultSearchManager* default_search_manager() { | 38 DefaultSearchManager* default_search_manager() { |
39 return default_search_manager_.get(); | 39 return default_search_manager_.get(); |
40 } | 40 } |
41 | 41 |
42 PrefService* pref_service() { return &prefs_; } | 42 PrefService* pref_service() { return &prefs_; } |
43 | 43 |
44 private: | 44 private: |
45 user_prefs::TestingPrefServiceSyncable prefs_; | 45 sync_preferences::TestingPrefServiceSyncable prefs_; |
46 std::unique_ptr<DefaultSearchManager> default_search_manager_; | 46 std::unique_ptr<DefaultSearchManager> default_search_manager_; |
47 | 47 |
48 DISALLOW_COPY_AND_ASSIGN(DefaultSearchPrefMigrationTest); | 48 DISALLOW_COPY_AND_ASSIGN(DefaultSearchPrefMigrationTest); |
49 }; | 49 }; |
50 | 50 |
51 DefaultSearchPrefMigrationTest::DefaultSearchPrefMigrationTest() { | 51 DefaultSearchPrefMigrationTest::DefaultSearchPrefMigrationTest() { |
52 DefaultSearchManager::RegisterProfilePrefs(prefs_.registry()); | 52 DefaultSearchManager::RegisterProfilePrefs(prefs_.registry()); |
53 TemplateURLPrepopulateData::RegisterProfilePrefs(prefs_.registry()); | 53 TemplateURLPrepopulateData::RegisterProfilePrefs(prefs_.registry()); |
54 TemplateURLService::RegisterProfilePrefs(prefs_.registry()); | 54 TemplateURLService::RegisterProfilePrefs(prefs_.registry()); |
55 default_search_manager_.reset(new DefaultSearchManager( | 55 default_search_manager_.reset(new DefaultSearchManager( |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 // Store a value in the legacy location. | 225 // Store a value in the legacy location. |
226 SaveDefaultSearchProviderToLegacyPrefs(&prepopulated_turl); | 226 SaveDefaultSearchProviderToLegacyPrefs(&prepopulated_turl); |
227 | 227 |
228 // Run the migration. | 228 // Run the migration. |
229 ConfigureDefaultSearchPrefMigrationToDictionaryValue(pref_service()); | 229 ConfigureDefaultSearchPrefMigrationToDictionaryValue(pref_service()); |
230 | 230 |
231 // Test that the legacy value is not migrated, as it is not user-selected. | 231 // Test that the legacy value is not migrated, as it is not user-selected. |
232 default_search_manager()->GetDefaultSearchEngine(&source); | 232 default_search_manager()->GetDefaultSearchEngine(&source); |
233 EXPECT_EQ(DefaultSearchManager::FROM_FALLBACK, source); | 233 EXPECT_EQ(DefaultSearchManager::FROM_FALLBACK, source); |
234 } | 234 } |
OLD | NEW |