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

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

Issue 492963005: Stop using UIThreadSearchTermsData for search_engines related tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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
« no previous file with comments | « no previous file | chrome/browser/search_engines/template_url_service_test_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/memory/scoped_vector.h" 6 #include "base/memory/scoped_vector.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
11 #include "chrome/browser/search_engines/template_url_service_factory.h" 11 #include "chrome/browser/search_engines/template_url_service_factory.h"
12 #include "chrome/browser/search_engines/template_url_service_test_util.h" 12 #include "chrome/browser/search_engines/template_url_service_test_util.h"
13 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h"
14 #include "chrome/test/base/testing_pref_service_syncable.h" 13 #include "chrome/test/base/testing_pref_service_syncable.h"
15 #include "chrome/test/base/testing_profile.h" 14 #include "chrome/test/base/testing_profile.h"
16 #include "components/search_engines/search_engines_pref_names.h" 15 #include "components/search_engines/search_engines_pref_names.h"
16 #include "components/search_engines/search_terms_data.h"
17 #include "components/search_engines/template_url.h" 17 #include "components/search_engines/template_url.h"
18 #include "components/search_engines/template_url_prepopulate_data.h" 18 #include "components/search_engines/template_url_prepopulate_data.h"
19 #include "components/search_engines/template_url_service.h" 19 #include "components/search_engines/template_url_service.h"
20 #include "components/search_engines/template_url_service_client.h" 20 #include "components/search_engines/template_url_service_client.h"
21 #include "net/base/net_util.h" 21 #include "net/base/net_util.h"
22 #include "sync/api/sync_change_processor_wrapper_for_test.h" 22 #include "sync/api/sync_change_processor_wrapper_for_test.h"
23 #include "sync/api/sync_error_factory.h" 23 #include "sync/api/sync_error_factory.h"
24 #include "sync/api/sync_error_factory_mock.h" 24 #include "sync/api/sync_error_factory_mock.h"
25 #include "sync/protocol/search_engine_specifics.pb.h" 25 #include "sync/protocol/search_engine_specifics.pb.h"
26 #include "sync/protocol/sync.pb.h" 26 #include "sync/protocol/sync.pb.h"
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 DefaultSearchManager::SetFallbackSearchEnginesDisabledForTesting(true); 230 DefaultSearchManager::SetFallbackSearchEnginesDisabledForTesting(true);
231 test_util_a_.reset(new TemplateURLServiceTestUtil); 231 test_util_a_.reset(new TemplateURLServiceTestUtil);
232 // Use ChangeToLoadState() instead of VerifyLoad() so we don't actually pull 232 // Use ChangeToLoadState() instead of VerifyLoad() so we don't actually pull
233 // in the prepopulate data, which the sync tests don't care about (and would 233 // in the prepopulate data, which the sync tests don't care about (and would
234 // just foul them up). 234 // just foul them up).
235 test_util_a_->ChangeModelToLoadState(); 235 test_util_a_->ChangeModelToLoadState();
236 profile_b_.reset(new TestingProfile); 236 profile_b_.reset(new TestingProfile);
237 TemplateURLServiceFactory::GetInstance()-> 237 TemplateURLServiceFactory::GetInstance()->
238 RegisterUserPrefsOnBrowserContextForTest(profile_b_.get()); 238 RegisterUserPrefsOnBrowserContextForTest(profile_b_.get());
239 model_b_.reset(new TemplateURLService( 239 model_b_.reset(new TemplateURLService(
240 profile_b_->GetPrefs(), scoped_ptr<SearchTermsData>( 240 profile_b_->GetPrefs(), scoped_ptr<SearchTermsData>(new SearchTermsData),
Peter Kasting 2014/08/22 18:57:26 Nit: make_scoped_ptr() would be slightly shorter
hashimoto 2014/08/25 05:45:21 Done.
241 new UIThreadSearchTermsData(profile_b_.get())), NULL, 241 NULL, scoped_ptr<TemplateURLServiceClient>(), NULL, NULL,
242 scoped_ptr<TemplateURLServiceClient>(), NULL, NULL, base::Closure())); 242 base::Closure()));
243 model_b_->Load(); 243 model_b_->Load();
244 } 244 }
245 245
246 void TemplateURLServiceSyncTest::TearDown() { 246 void TemplateURLServiceSyncTest::TearDown() {
247 test_util_a_.reset(); 247 test_util_a_.reset();
248 DefaultSearchManager::SetFallbackSearchEnginesDisabledForTesting(false); 248 DefaultSearchManager::SetFallbackSearchEnginesDisabledForTesting(false);
249 } 249 }
250 250
251 scoped_ptr<syncer::SyncChangeProcessor> 251 scoped_ptr<syncer::SyncChangeProcessor>
252 TemplateURLServiceSyncTest::PassProcessor() { 252 TemplateURLServiceSyncTest::PassProcessor() {
(...skipping 862 matching lines...) Expand 10 before | Expand all | Expand 10 after
1115 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); 1115 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid()));
1116 1116
1117 // Now try to sync the data locally. 1117 // Now try to sync the data locally.
1118 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, 1118 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data,
1119 PassProcessor(), CreateAndPassSyncErrorFactory()); 1119 PassProcessor(), CreateAndPassSyncErrorFactory());
1120 1120
1121 // Both entries should have been added, with explicit keywords. 1121 // Both entries should have been added, with explicit keywords.
1122 TemplateURL* key1 = model()->GetTemplateURLForHost("key1.com"); 1122 TemplateURL* key1 = model()->GetTemplateURLForHost("key1.com");
1123 ASSERT_FALSE(key1 == NULL); 1123 ASSERT_FALSE(key1 == NULL);
1124 EXPECT_EQ(ASCIIToUTF16("key1.com"), key1->keyword()); 1124 EXPECT_EQ(ASCIIToUTF16("key1.com"), key1->keyword());
1125 GURL google_url(UIThreadSearchTermsData(profile_a()).GoogleBaseURLValue()); 1125 GURL google_url(model()->search_terms_data().GoogleBaseURLValue());
1126 TemplateURL* key2 = model()->GetTemplateURLForHost(google_url.host()); 1126 TemplateURL* key2 = model()->GetTemplateURLForHost(google_url.host());
1127 ASSERT_FALSE(key2 == NULL); 1127 ASSERT_FALSE(key2 == NULL);
1128 base::string16 google_keyword(net::StripWWWFromHost(google_url)); 1128 base::string16 google_keyword(net::StripWWWFromHost(google_url));
1129 EXPECT_EQ(google_keyword, key2->keyword()); 1129 EXPECT_EQ(google_keyword, key2->keyword());
1130 1130
1131 // We should also have gotten some corresponding UPDATEs pushed upstream. 1131 // We should also have gotten some corresponding UPDATEs pushed upstream.
1132 EXPECT_GE(processor()->change_list_size(), 2U); 1132 EXPECT_GE(processor()->change_list_size(), 2U);
1133 ASSERT_TRUE(processor()->contains_guid("key1")); 1133 ASSERT_TRUE(processor()->contains_guid("key1"));
1134 syncer::SyncChange key1_change = processor()->change_for_guid("key1"); 1134 syncer::SyncChange key1_change = processor()->change_for_guid("key1");
1135 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key1_change.change_type()); 1135 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key1_change.change_type());
1136 EXPECT_EQ("key1.com", GetKeyword(key1_change.sync_data())); 1136 EXPECT_EQ("key1.com", GetKeyword(key1_change.sync_data()));
1137 ASSERT_TRUE(processor()->contains_guid("key2")); 1137 ASSERT_TRUE(processor()->contains_guid("key2"));
1138 syncer::SyncChange key2_change = processor()->change_for_guid("key2"); 1138 syncer::SyncChange key2_change = processor()->change_for_guid("key2");
1139 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key2_change.change_type()); 1139 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key2_change.change_type());
1140 EXPECT_EQ(google_keyword, UTF8ToUTF16(GetKeyword(key2_change.sync_data()))); 1140 EXPECT_EQ(google_keyword, UTF8ToUTF16(GetKeyword(key2_change.sync_data())));
1141 } 1141 }
1142 1142
1143 TEST_F(TemplateURLServiceSyncTest, AutogeneratedKeywordConflicts) { 1143 TEST_F(TemplateURLServiceSyncTest, AutogeneratedKeywordConflicts) {
1144 // Sync brings in some autogenerated keywords, but the generated keywords we 1144 // Sync brings in some autogenerated keywords, but the generated keywords we
1145 // try to create conflict with ones in the model. 1145 // try to create conflict with ones in the model.
1146 base::string16 google_keyword(net::StripWWWFromHost(GURL( 1146 base::string16 google_keyword(net::StripWWWFromHost(GURL(
1147 UIThreadSearchTermsData(profile_a()).GoogleBaseURLValue()))); 1147 model()->search_terms_data().GoogleBaseURLValue())));
1148 const std::string local_google_url = 1148 const std::string local_google_url =
1149 "{google:baseURL}1/search?q={searchTerms}"; 1149 "{google:baseURL}1/search?q={searchTerms}";
1150 TemplateURL* google = CreateTestTemplateURL(google_keyword, local_google_url); 1150 TemplateURL* google = CreateTestTemplateURL(google_keyword, local_google_url);
1151 model()->Add(google); 1151 model()->Add(google);
1152 TemplateURL* other = 1152 TemplateURL* other =
1153 CreateTestTemplateURL(ASCIIToUTF16("other.com"), "http://other.com/foo"); 1153 CreateTestTemplateURL(ASCIIToUTF16("other.com"), "http://other.com/foo");
1154 model()->Add(other); 1154 model()->Add(other);
1155 syncer::SyncDataList initial_data; 1155 syncer::SyncDataList initial_data;
1156 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("sync1"), 1156 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("sync1"),
1157 "{google:baseURL}2/search?q={searchTerms}", "sync1", 50)); 1157 "{google:baseURL}2/search?q={searchTerms}", "sync1", 50));
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1210 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); 1210 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid()));
1211 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key2"), 1211 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key2"),
1212 "{google:baseURL}2/search?q={searchTerms}", "key2")); 1212 "{google:baseURL}2/search?q={searchTerms}", "key2"));
1213 initial_data.push_back( 1213 initial_data.push_back(
1214 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); 1214 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid()));
1215 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, 1215 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data,
1216 PassProcessor(), CreateAndPassSyncErrorFactory()); 1216 PassProcessor(), CreateAndPassSyncErrorFactory());
1217 1217
1218 // We should still have coalesced the updates to one each. 1218 // We should still have coalesced the updates to one each.
1219 base::string16 google_keyword(net::StripWWWFromHost(GURL( 1219 base::string16 google_keyword(net::StripWWWFromHost(GURL(
1220 UIThreadSearchTermsData(profile_a()).GoogleBaseURLValue()))); 1220 model()->search_terms_data().GoogleBaseURLValue())));
1221 TemplateURL* keyword1 = 1221 TemplateURL* keyword1 =
1222 model()->GetTemplateURLForKeyword(google_keyword + ASCIIToUTF16("_")); 1222 model()->GetTemplateURLForKeyword(google_keyword + ASCIIToUTF16("_"));
1223 ASSERT_FALSE(keyword1 == NULL); 1223 ASSERT_FALSE(keyword1 == NULL);
1224 EXPECT_EQ("key1", keyword1->sync_guid()); 1224 EXPECT_EQ("key1", keyword1->sync_guid());
1225 TemplateURL* keyword2 = model()->GetTemplateURLForKeyword(google_keyword); 1225 TemplateURL* keyword2 = model()->GetTemplateURLForKeyword(google_keyword);
1226 ASSERT_FALSE(keyword2 == NULL); 1226 ASSERT_FALSE(keyword2 == NULL);
1227 EXPECT_EQ("key2", keyword2->sync_guid()); 1227 EXPECT_EQ("key2", keyword2->sync_guid());
1228 1228
1229 EXPECT_GE(processor()->change_list_size(), 2U); 1229 EXPECT_GE(processor()->change_list_size(), 2U);
1230 ASSERT_TRUE(processor()->contains_guid("key1")); 1230 ASSERT_TRUE(processor()->contains_guid("key1"));
(...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after
2235 const char kNewGUID[] = "newdefault"; 2235 const char kNewGUID[] = "newdefault";
2236 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("what"), 2236 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("what"),
2237 "http://thewhat.com/{searchTerms}", 2237 "http://thewhat.com/{searchTerms}",
2238 kNewGUID)); 2238 kNewGUID));
2239 model()->SetUserSelectedDefaultSearchProvider( 2239 model()->SetUserSelectedDefaultSearchProvider(
2240 model()->GetTemplateURLForGUID(kNewGUID)); 2240 model()->GetTemplateURLForGUID(kNewGUID));
2241 2241
2242 EXPECT_EQ(kNewGUID, profile_a()->GetTestingPrefService()->GetString( 2242 EXPECT_EQ(kNewGUID, profile_a()->GetTestingPrefService()->GetString(
2243 prefs::kSyncedDefaultSearchProviderGUID)); 2243 prefs::kSyncedDefaultSearchProviderGUID));
2244 } 2244 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/search_engines/template_url_service_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698