| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 } | 55 } |
| 56 | 56 |
| 57 scoped_ptr<TemplateURL> DefaultSearchPrefMigrationTest::CreateKeyword( | 57 scoped_ptr<TemplateURL> DefaultSearchPrefMigrationTest::CreateKeyword( |
| 58 const std::string& short_name, | 58 const std::string& short_name, |
| 59 const std::string& keyword, | 59 const std::string& keyword, |
| 60 const std::string& url) { | 60 const std::string& url) { |
| 61 TemplateURLData data; | 61 TemplateURLData data; |
| 62 data.short_name = base::ASCIIToUTF16(short_name); | 62 data.short_name = base::ASCIIToUTF16(short_name); |
| 63 data.SetKeyword(base::ASCIIToUTF16(keyword)); | 63 data.SetKeyword(base::ASCIIToUTF16(keyword)); |
| 64 data.SetURL(url); | 64 data.SetURL(url); |
| 65 scoped_ptr<TemplateURL> t_url(new TemplateURL(profile(), data)); | 65 scoped_ptr<TemplateURL> t_url(new TemplateURL(data)); |
| 66 return t_url.Pass(); | 66 return t_url.Pass(); |
| 67 } | 67 } |
| 68 | 68 |
| 69 TEST_F(DefaultSearchPrefMigrationTest, MigrateUserSelectedValue) { | 69 TEST_F(DefaultSearchPrefMigrationTest, MigrateUserSelectedValue) { |
| 70 scoped_ptr<TemplateURL> t_url( | 70 scoped_ptr<TemplateURL> t_url( |
| 71 CreateKeyword("name1", "key1", "http://foo1/{searchTerms}")); | 71 CreateKeyword("name1", "key1", "http://foo1/{searchTerms}")); |
| 72 // Store a value in the legacy location. | 72 // Store a value in the legacy location. |
| 73 TemplateURLService::SaveDefaultSearchProviderToPrefs(t_url.get(), | 73 TemplateURLService::SaveDefaultSearchProviderToPrefs(t_url.get(), |
| 74 profile()->GetPrefs()); | 74 profile()->GetPrefs()); |
| 75 | 75 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 EXPECT_EQ(t_url2->url(), modern_default->url()); | 143 EXPECT_EQ(t_url2->url(), modern_default->url()); |
| 144 } | 144 } |
| 145 | 145 |
| 146 TEST_F(DefaultSearchPrefMigrationTest, | 146 TEST_F(DefaultSearchPrefMigrationTest, |
| 147 AutomaticallySelectedValueIsNotMigrated) { | 147 AutomaticallySelectedValueIsNotMigrated) { |
| 148 DefaultSearchManager::Source source; | 148 DefaultSearchManager::Source source; |
| 149 TemplateURLData prepopulated_default( | 149 TemplateURLData prepopulated_default( |
| 150 *default_search_manager()->GetDefaultSearchEngine(&source)); | 150 *default_search_manager()->GetDefaultSearchEngine(&source)); |
| 151 EXPECT_EQ(DefaultSearchManager::FROM_FALLBACK, source); | 151 EXPECT_EQ(DefaultSearchManager::FROM_FALLBACK, source); |
| 152 | 152 |
| 153 TemplateURL prepopulated_turl(profile(), prepopulated_default); | 153 TemplateURL prepopulated_turl(prepopulated_default); |
| 154 | 154 |
| 155 // Store a value in the legacy location. | 155 // Store a value in the legacy location. |
| 156 TemplateURLService::SaveDefaultSearchProviderToPrefs(&prepopulated_turl, | 156 TemplateURLService::SaveDefaultSearchProviderToPrefs(&prepopulated_turl, |
| 157 profile()->GetPrefs()); | 157 profile()->GetPrefs()); |
| 158 | 158 |
| 159 // Run the migration. | 159 // Run the migration. |
| 160 ConfigureDefaultSearchPrefMigrationToDictionaryValue(profile()->GetPrefs()); | 160 ConfigureDefaultSearchPrefMigrationToDictionaryValue(profile()->GetPrefs()); |
| 161 | 161 |
| 162 // Test that the legacy value is not migrated, as it is not user-selected. | 162 // Test that the legacy value is not migrated, as it is not user-selected. |
| 163 default_search_manager()->GetDefaultSearchEngine(&source); | 163 default_search_manager()->GetDefaultSearchEngine(&source); |
| 164 EXPECT_EQ(DefaultSearchManager::FROM_FALLBACK, source); | 164 EXPECT_EQ(DefaultSearchManager::FROM_FALLBACK, source); |
| 165 } | 165 } |
| OLD | NEW |