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/macros.h" | 10 #include "base/macros.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 data.SetKeyword(base::ASCIIToUTF16(keyword)); | 57 data.SetKeyword(base::ASCIIToUTF16(keyword)); |
58 data.SetURL(url); | 58 data.SetURL(url); |
59 scoped_ptr<TemplateURL> t_url(new TemplateURL(test_util_.profile(), data)); | 59 scoped_ptr<TemplateURL> t_url(new TemplateURL(test_util_.profile(), data)); |
60 return t_url.Pass(); | 60 return t_url.Pass(); |
61 } | 61 } |
62 | 62 |
63 TEST_F(DefaultSearchPrefMigrationTest, MigrateUserSelectedValue) { | 63 TEST_F(DefaultSearchPrefMigrationTest, MigrateUserSelectedValue) { |
64 scoped_ptr<TemplateURL> t_url( | 64 scoped_ptr<TemplateURL> t_url( |
65 CreateKeyword("name1", "key1", "http://foo1/{searchTerms}")); | 65 CreateKeyword("name1", "key1", "http://foo1/{searchTerms}")); |
66 // Store a value in the legacy location. | 66 // Store a value in the legacy location. |
67 TemplateURLService::SaveDefaultSearchProviderToPrefs( | 67 test_util()->model()->SaveDefaultSearchProviderToPrefs( |
68 t_url.get(), test_util()->profile()->GetPrefs()); | 68 t_url.get(), test_util()->profile()->GetPrefs()); |
69 | 69 |
70 // Run the migration. | 70 // Run the migration. |
71 ConfigureDefaultSearchPrefMigrationToDictionaryValue( | 71 ConfigureDefaultSearchPrefMigrationToDictionaryValue( |
72 test_util()->profile()->GetPrefs()); | 72 test_util()->profile()->GetPrefs()); |
73 | 73 |
74 // Test that it was migrated. | 74 // Test that it was migrated. |
75 DefaultSearchManager manager(test_util()->profile()->GetPrefs(), | 75 DefaultSearchManager manager(test_util()->profile()->GetPrefs(), |
76 DefaultSearchManager::ObserverCallback()); | 76 DefaultSearchManager::ObserverCallback()); |
77 TemplateURLData* modern_default = manager.GetDefaultSearchEngine(NULL); | 77 TemplateURLData* modern_default = manager.GetDefaultSearchEngine(NULL); |
78 ASSERT_TRUE(modern_default); | 78 ASSERT_TRUE(modern_default); |
79 EXPECT_EQ(t_url->short_name(), modern_default->short_name); | 79 EXPECT_EQ(t_url->short_name(), modern_default->short_name); |
80 EXPECT_EQ(t_url->keyword(), modern_default->keyword()); | 80 EXPECT_EQ(t_url->keyword(), modern_default->keyword()); |
81 EXPECT_EQ(t_url->url(), modern_default->url()); | 81 EXPECT_EQ(t_url->url(), modern_default->url()); |
82 } | 82 } |
83 | 83 |
84 TEST_F(DefaultSearchPrefMigrationTest, ModernValuePresent) { | 84 TEST_F(DefaultSearchPrefMigrationTest, ModernValuePresent) { |
85 scoped_ptr<TemplateURL> t_url( | 85 scoped_ptr<TemplateURL> t_url( |
86 CreateKeyword("name1", "key1", "http://foo1/{searchTerms}")); | 86 CreateKeyword("name1", "key1", "http://foo1/{searchTerms}")); |
87 scoped_ptr<TemplateURL> t_url2( | 87 scoped_ptr<TemplateURL> t_url2( |
88 CreateKeyword("name2", "key2", "http://foo2/{searchTerms}")); | 88 CreateKeyword("name2", "key2", "http://foo2/{searchTerms}")); |
89 // Store a value in the legacy location. | 89 // Store a value in the legacy location. |
90 TemplateURLService::SaveDefaultSearchProviderToPrefs( | 90 test_util()->model()->SaveDefaultSearchProviderToPrefs( |
91 t_url.get(), test_util()->profile()->GetPrefs()); | 91 t_url.get(), test_util()->profile()->GetPrefs()); |
92 | 92 |
93 // Store another value in the modern location. | 93 // Store another value in the modern location. |
94 DefaultSearchManager(test_util()->profile()->GetPrefs(), | 94 DefaultSearchManager(test_util()->profile()->GetPrefs(), |
95 DefaultSearchManager::ObserverCallback()) | 95 DefaultSearchManager::ObserverCallback()) |
96 .SetUserSelectedDefaultSearchEngine(t_url2->data()); | 96 .SetUserSelectedDefaultSearchEngine(t_url2->data()); |
97 | 97 |
98 // Run the migration. | 98 // Run the migration. |
99 ConfigureDefaultSearchPrefMigrationToDictionaryValue( | 99 ConfigureDefaultSearchPrefMigrationToDictionaryValue( |
100 test_util()->profile()->GetPrefs()); | 100 test_util()->profile()->GetPrefs()); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 // TODO(caitkp/erikwright): Look into loading policy values in tests. In | 171 // TODO(caitkp/erikwright): Look into loading policy values in tests. In |
172 // practice, the DefaultSearchEngineSource() would be FROM_POLICY in this | 172 // practice, the DefaultSearchEngineSource() would be FROM_POLICY in this |
173 // case, but since we are not loading the policy here, it will be | 173 // case, but since we are not loading the policy here, it will be |
174 // FROM_FALLBACK instead. | 174 // FROM_FALLBACK instead. |
175 // Test that the policy-defined value is not migrated. | 175 // Test that the policy-defined value is not migrated. |
176 ASSERT_EQ(DefaultSearchManager::FROM_FALLBACK, | 176 ASSERT_EQ(DefaultSearchManager::FROM_FALLBACK, |
177 DefaultSearchManager(test_util()->profile()->GetPrefs(), | 177 DefaultSearchManager(test_util()->profile()->GetPrefs(), |
178 DefaultSearchManager::ObserverCallback()) | 178 DefaultSearchManager::ObserverCallback()) |
179 .GetDefaultSearchEngineSource()); | 179 .GetDefaultSearchEngineSource()); |
180 } | 180 } |
OLD | NEW |