Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(982)

Side by Side Diff: chrome/browser/search_engines/default_search_pref_migration_unittest.cc

Issue 263823007: Handle TemplateURLService load failure better (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: RemoveObserver Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 TemplateURLData modern_default; 75 TemplateURLData modern_default;
76 ASSERT_TRUE(DefaultSearchManager(test_util()->profile()->GetPrefs()) 76 ASSERT_TRUE(DefaultSearchManager(test_util()->profile()->GetPrefs())
77 .GetDefaultSearchEngine(&modern_default)); 77 .GetDefaultSearchEngine(&modern_default));
78 EXPECT_EQ(t_url->short_name(), modern_default.short_name); 78 EXPECT_EQ(t_url->short_name(), modern_default.short_name);
79 EXPECT_EQ(t_url->keyword(), modern_default.keyword()); 79 EXPECT_EQ(t_url->keyword(), modern_default.keyword());
80 EXPECT_EQ(t_url->url(), modern_default.url()); 80 EXPECT_EQ(t_url->url(), modern_default.url());
81 } 81 }
82 82
83 TEST_F(DefaultSearchPrefMigrationTest, ModernValuePresent) { 83 TEST_F(DefaultSearchPrefMigrationTest, ModernValuePresent) {
84 scoped_ptr<TemplateURL> t_url( 84 scoped_ptr<TemplateURL> t_url(
85 CreateKeyword("name1", "key1", "http://foo1/{searchTerms}")); 85 CreateKeyword("name1", "key1", "http://foo1/{searchTerms}"));
86 scoped_ptr<TemplateURL> t_url2( 86 scoped_ptr<TemplateURL> t_url2(
87 CreateKeyword("name2", "key2", "http://foo2/{searchTerms}")); 87 CreateKeyword("name2", "key2", "http://foo2/{searchTerms}"));
88 // Store a value in the legacy location. 88 // Store a value in the legacy location.
89 TemplateURLService::SaveDefaultSearchProviderToPrefs( 89 test_util()->model()->SaveDefaultSearchProviderToPrefs(
90 t_url.get(), test_util()->profile()->GetPrefs()); 90 t_url.get(), test_util()->profile()->GetPrefs());
91 91
92 // Store another value in the modern location. 92 // Store another value in the modern location.
93 DefaultSearchManager(test_util()->profile()->GetPrefs()) 93 DefaultSearchManager(test_util()->profile()->GetPrefs())
94 .SetUserSelectedDefaultSearchEngine(t_url2->data()); 94 .SetUserSelectedDefaultSearchEngine(t_url2->data());
95 95
96 // Run the migration. 96 // Run the migration.
97 ConfigureDefaultSearchPrefMigrationToDictionaryValue( 97 ConfigureDefaultSearchPrefMigrationToDictionaryValue(
98 test_util()->profile()->GetPrefs()); 98 test_util()->profile()->GetPrefs());
99 99
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 162
163 // Run the migration. 163 // Run the migration.
164 ConfigureDefaultSearchPrefMigrationToDictionaryValue( 164 ConfigureDefaultSearchPrefMigrationToDictionaryValue(
165 test_util()->profile()->GetPrefs()); 165 test_util()->profile()->GetPrefs());
166 166
167 // Test that the policy-defined value is not migrated. 167 // Test that the policy-defined value is not migrated.
168 TemplateURLData modern_default; 168 TemplateURLData modern_default;
169 ASSERT_FALSE(DefaultSearchManager(test_util()->profile()->GetPrefs()) 169 ASSERT_FALSE(DefaultSearchManager(test_util()->profile()->GetPrefs())
170 .GetDefaultSearchEngine(&modern_default)); 170 .GetDefaultSearchEngine(&modern_default));
171 } 171 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698