| 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 "chrome/browser/search_engines/default_search_pref_migration.h" | 5 #include "chrome/browser/search_engines/default_search_pref_migration.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 prefs->Set(prefs::kDefaultSearchProviderAlternateURLs, alternate_urls); | 132 prefs->Set(prefs::kDefaultSearchProviderAlternateURLs, alternate_urls); |
| 133 prefs->SetString(prefs::kDefaultSearchProviderSearchTermsReplacementKey, | 133 prefs->SetString(prefs::kDefaultSearchProviderSearchTermsReplacementKey, |
| 134 search_terms_replacement_key); | 134 search_terms_replacement_key); |
| 135 } | 135 } |
| 136 | 136 |
| 137 scoped_ptr<TemplateURL> DefaultSearchPrefMigrationTest::CreateKeyword( | 137 scoped_ptr<TemplateURL> DefaultSearchPrefMigrationTest::CreateKeyword( |
| 138 const std::string& short_name, | 138 const std::string& short_name, |
| 139 const std::string& keyword, | 139 const std::string& keyword, |
| 140 const std::string& url) { | 140 const std::string& url) { |
| 141 TemplateURLData data; | 141 TemplateURLData data; |
| 142 data.short_name = base::ASCIIToUTF16(short_name); | 142 data.SetShortName(base::ASCIIToUTF16(short_name)); |
| 143 data.SetKeyword(base::ASCIIToUTF16(keyword)); | 143 data.SetKeyword(base::ASCIIToUTF16(keyword)); |
| 144 data.SetURL(url); | 144 data.SetURL(url); |
| 145 scoped_ptr<TemplateURL> t_url(new TemplateURL(data)); | 145 scoped_ptr<TemplateURL> t_url(new TemplateURL(data)); |
| 146 return t_url.Pass(); | 146 return t_url.Pass(); |
| 147 } | 147 } |
| 148 | 148 |
| 149 TEST_F(DefaultSearchPrefMigrationTest, MigrateUserSelectedValue) { | 149 TEST_F(DefaultSearchPrefMigrationTest, MigrateUserSelectedValue) { |
| 150 scoped_ptr<TemplateURL> t_url( | 150 scoped_ptr<TemplateURL> t_url( |
| 151 CreateKeyword("name1", "key1", "http://foo1/{searchTerms}")); | 151 CreateKeyword("name1", "key1", "http://foo1/{searchTerms}")); |
| 152 // Store a value in the legacy location. | 152 // Store a value in the legacy location. |
| 153 SaveDefaultSearchProviderToLegacyPrefs(t_url.get()); | 153 SaveDefaultSearchProviderToLegacyPrefs(t_url.get()); |
| 154 | 154 |
| 155 // Run the migration. | 155 // Run the migration. |
| 156 ConfigureDefaultSearchPrefMigrationToDictionaryValue(profile()->GetPrefs()); | 156 ConfigureDefaultSearchPrefMigrationToDictionaryValue(profile()->GetPrefs()); |
| 157 | 157 |
| 158 // Test that it was migrated. | 158 // Test that it was migrated. |
| 159 DefaultSearchManager::Source source; | 159 DefaultSearchManager::Source source; |
| 160 const TemplateURLData* modern_default = | 160 const TemplateURLData* modern_default = |
| 161 default_search_manager()->GetDefaultSearchEngine(&source); | 161 default_search_manager()->GetDefaultSearchEngine(&source); |
| 162 ASSERT_TRUE(modern_default); | 162 ASSERT_TRUE(modern_default); |
| 163 EXPECT_EQ(DefaultSearchManager::FROM_USER, source); | 163 EXPECT_EQ(DefaultSearchManager::FROM_USER, source); |
| 164 EXPECT_EQ(t_url->short_name(), modern_default->short_name); | 164 EXPECT_EQ(t_url->short_name(), modern_default->short_name()); |
| 165 EXPECT_EQ(t_url->keyword(), modern_default->keyword()); | 165 EXPECT_EQ(t_url->keyword(), modern_default->keyword()); |
| 166 EXPECT_EQ(t_url->url(), modern_default->url()); | 166 EXPECT_EQ(t_url->url(), modern_default->url()); |
| 167 } | 167 } |
| 168 | 168 |
| 169 TEST_F(DefaultSearchPrefMigrationTest, MigrateOnlyOnce) { | 169 TEST_F(DefaultSearchPrefMigrationTest, MigrateOnlyOnce) { |
| 170 scoped_ptr<TemplateURL> t_url( | 170 scoped_ptr<TemplateURL> t_url( |
| 171 CreateKeyword("name1", "key1", "http://foo1/{searchTerms}")); | 171 CreateKeyword("name1", "key1", "http://foo1/{searchTerms}")); |
| 172 // Store a value in the legacy location. | 172 // Store a value in the legacy location. |
| 173 SaveDefaultSearchProviderToLegacyPrefs(t_url.get()); | 173 SaveDefaultSearchProviderToLegacyPrefs(t_url.get()); |
| 174 | 174 |
| 175 // Run the migration. | 175 // Run the migration. |
| 176 ConfigureDefaultSearchPrefMigrationToDictionaryValue(profile()->GetPrefs()); | 176 ConfigureDefaultSearchPrefMigrationToDictionaryValue(profile()->GetPrefs()); |
| 177 | 177 |
| 178 // Test that it was migrated. | 178 // Test that it was migrated. |
| 179 DefaultSearchManager::Source source; | 179 DefaultSearchManager::Source source; |
| 180 const TemplateURLData* modern_default = | 180 const TemplateURLData* modern_default = |
| 181 default_search_manager()->GetDefaultSearchEngine(&source); | 181 default_search_manager()->GetDefaultSearchEngine(&source); |
| 182 ASSERT_TRUE(modern_default); | 182 ASSERT_TRUE(modern_default); |
| 183 EXPECT_EQ(DefaultSearchManager::FROM_USER, source); | 183 EXPECT_EQ(DefaultSearchManager::FROM_USER, source); |
| 184 EXPECT_EQ(t_url->short_name(), modern_default->short_name); | 184 EXPECT_EQ(t_url->short_name(), modern_default->short_name()); |
| 185 EXPECT_EQ(t_url->keyword(), modern_default->keyword()); | 185 EXPECT_EQ(t_url->keyword(), modern_default->keyword()); |
| 186 EXPECT_EQ(t_url->url(), modern_default->url()); | 186 EXPECT_EQ(t_url->url(), modern_default->url()); |
| 187 default_search_manager()->ClearUserSelectedDefaultSearchEngine(); | 187 default_search_manager()->ClearUserSelectedDefaultSearchEngine(); |
| 188 | 188 |
| 189 // Run the migration. | 189 // Run the migration. |
| 190 ConfigureDefaultSearchPrefMigrationToDictionaryValue(profile()->GetPrefs()); | 190 ConfigureDefaultSearchPrefMigrationToDictionaryValue(profile()->GetPrefs()); |
| 191 | 191 |
| 192 // Test that it was NOT migrated. | 192 // Test that it was NOT migrated. |
| 193 modern_default = default_search_manager()->GetDefaultSearchEngine(&source); | 193 modern_default = default_search_manager()->GetDefaultSearchEngine(&source); |
| 194 ASSERT_TRUE(modern_default); | 194 ASSERT_TRUE(modern_default); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 208 | 208 |
| 209 // Run the migration. | 209 // Run the migration. |
| 210 ConfigureDefaultSearchPrefMigrationToDictionaryValue(profile()->GetPrefs()); | 210 ConfigureDefaultSearchPrefMigrationToDictionaryValue(profile()->GetPrefs()); |
| 211 | 211 |
| 212 // Test that no migration occurred. The modern value is left intact. | 212 // Test that no migration occurred. The modern value is left intact. |
| 213 DefaultSearchManager::Source source; | 213 DefaultSearchManager::Source source; |
| 214 const TemplateURLData* modern_default = | 214 const TemplateURLData* modern_default = |
| 215 default_search_manager()->GetDefaultSearchEngine(&source); | 215 default_search_manager()->GetDefaultSearchEngine(&source); |
| 216 ASSERT_TRUE(modern_default); | 216 ASSERT_TRUE(modern_default); |
| 217 EXPECT_EQ(DefaultSearchManager::FROM_USER, source); | 217 EXPECT_EQ(DefaultSearchManager::FROM_USER, source); |
| 218 EXPECT_EQ(t_url2->short_name(), modern_default->short_name); | 218 EXPECT_EQ(t_url2->short_name(), modern_default->short_name()); |
| 219 EXPECT_EQ(t_url2->keyword(), modern_default->keyword()); | 219 EXPECT_EQ(t_url2->keyword(), modern_default->keyword()); |
| 220 EXPECT_EQ(t_url2->url(), modern_default->url()); | 220 EXPECT_EQ(t_url2->url(), modern_default->url()); |
| 221 } | 221 } |
| 222 | 222 |
| 223 TEST_F(DefaultSearchPrefMigrationTest, | 223 TEST_F(DefaultSearchPrefMigrationTest, |
| 224 AutomaticallySelectedValueIsNotMigrated) { | 224 AutomaticallySelectedValueIsNotMigrated) { |
| 225 DefaultSearchManager::Source source; | 225 DefaultSearchManager::Source source; |
| 226 TemplateURLData prepopulated_default( | 226 TemplateURLData prepopulated_default( |
| 227 *default_search_manager()->GetDefaultSearchEngine(&source)); | 227 *default_search_manager()->GetDefaultSearchEngine(&source)); |
| 228 EXPECT_EQ(DefaultSearchManager::FROM_FALLBACK, source); | 228 EXPECT_EQ(DefaultSearchManager::FROM_FALLBACK, source); |
| 229 | 229 |
| 230 TemplateURL prepopulated_turl(prepopulated_default); | 230 TemplateURL prepopulated_turl(prepopulated_default); |
| 231 | 231 |
| 232 // Store a value in the legacy location. | 232 // Store a value in the legacy location. |
| 233 SaveDefaultSearchProviderToLegacyPrefs(&prepopulated_turl); | 233 SaveDefaultSearchProviderToLegacyPrefs(&prepopulated_turl); |
| 234 | 234 |
| 235 // Run the migration. | 235 // Run the migration. |
| 236 ConfigureDefaultSearchPrefMigrationToDictionaryValue(profile()->GetPrefs()); | 236 ConfigureDefaultSearchPrefMigrationToDictionaryValue(profile()->GetPrefs()); |
| 237 | 237 |
| 238 // Test that the legacy value is not migrated, as it is not user-selected. | 238 // Test that the legacy value is not migrated, as it is not user-selected. |
| 239 default_search_manager()->GetDefaultSearchEngine(&source); | 239 default_search_manager()->GetDefaultSearchEngine(&source); |
| 240 EXPECT_EQ(DefaultSearchManager::FROM_FALLBACK, source); | 240 EXPECT_EQ(DefaultSearchManager::FROM_FALLBACK, source); |
| 241 } | 241 } |
| OLD | NEW |