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

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: Use make_scoped_ptr Created 6 years, 3 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(), make_scoped_ptr(new SearchTermsData), NULL,
241 new UIThreadSearchTermsData(profile_b_.get())), NULL,
242 scoped_ptr<TemplateURLServiceClient>(), NULL, NULL, base::Closure())); 241 scoped_ptr<TemplateURLServiceClient>(), NULL, NULL, base::Closure()));
243 model_b_->Load(); 242 model_b_->Load();
244 } 243 }
245 244
246 void TemplateURLServiceSyncTest::TearDown() { 245 void TemplateURLServiceSyncTest::TearDown() {
247 test_util_a_.reset(); 246 test_util_a_.reset();
248 DefaultSearchManager::SetFallbackSearchEnginesDisabledForTesting(false); 247 DefaultSearchManager::SetFallbackSearchEnginesDisabledForTesting(false);
249 } 248 }
250 249
251 scoped_ptr<syncer::SyncChangeProcessor> 250 scoped_ptr<syncer::SyncChangeProcessor>
(...skipping 863 matching lines...) Expand 10 before | Expand all | Expand 10 after
1115 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); 1114 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid()));
1116 1115
1117 // Now try to sync the data locally. 1116 // Now try to sync the data locally.
1118 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, 1117 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data,
1119 PassProcessor(), CreateAndPassSyncErrorFactory()); 1118 PassProcessor(), CreateAndPassSyncErrorFactory());
1120 1119
1121 // Both entries should have been added, with explicit keywords. 1120 // Both entries should have been added, with explicit keywords.
1122 TemplateURL* key1 = model()->GetTemplateURLForHost("key1.com"); 1121 TemplateURL* key1 = model()->GetTemplateURLForHost("key1.com");
1123 ASSERT_FALSE(key1 == NULL); 1122 ASSERT_FALSE(key1 == NULL);
1124 EXPECT_EQ(ASCIIToUTF16("key1.com"), key1->keyword()); 1123 EXPECT_EQ(ASCIIToUTF16("key1.com"), key1->keyword());
1125 GURL google_url(UIThreadSearchTermsData(profile_a()).GoogleBaseURLValue()); 1124 GURL google_url(model()->search_terms_data().GoogleBaseURLValue());
1126 TemplateURL* key2 = model()->GetTemplateURLForHost(google_url.host()); 1125 TemplateURL* key2 = model()->GetTemplateURLForHost(google_url.host());
1127 ASSERT_FALSE(key2 == NULL); 1126 ASSERT_FALSE(key2 == NULL);
1128 base::string16 google_keyword(net::StripWWWFromHost(google_url)); 1127 base::string16 google_keyword(net::StripWWWFromHost(google_url));
1129 EXPECT_EQ(google_keyword, key2->keyword()); 1128 EXPECT_EQ(google_keyword, key2->keyword());
1130 1129
1131 // We should also have gotten some corresponding UPDATEs pushed upstream. 1130 // We should also have gotten some corresponding UPDATEs pushed upstream.
1132 EXPECT_GE(processor()->change_list_size(), 2U); 1131 EXPECT_GE(processor()->change_list_size(), 2U);
1133 ASSERT_TRUE(processor()->contains_guid("key1")); 1132 ASSERT_TRUE(processor()->contains_guid("key1"));
1134 syncer::SyncChange key1_change = processor()->change_for_guid("key1"); 1133 syncer::SyncChange key1_change = processor()->change_for_guid("key1");
1135 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key1_change.change_type()); 1134 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key1_change.change_type());
1136 EXPECT_EQ("key1.com", GetKeyword(key1_change.sync_data())); 1135 EXPECT_EQ("key1.com", GetKeyword(key1_change.sync_data()));
1137 ASSERT_TRUE(processor()->contains_guid("key2")); 1136 ASSERT_TRUE(processor()->contains_guid("key2"));
1138 syncer::SyncChange key2_change = processor()->change_for_guid("key2"); 1137 syncer::SyncChange key2_change = processor()->change_for_guid("key2");
1139 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key2_change.change_type()); 1138 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key2_change.change_type());
1140 EXPECT_EQ(google_keyword, UTF8ToUTF16(GetKeyword(key2_change.sync_data()))); 1139 EXPECT_EQ(google_keyword, UTF8ToUTF16(GetKeyword(key2_change.sync_data())));
1141 } 1140 }
1142 1141
1143 TEST_F(TemplateURLServiceSyncTest, AutogeneratedKeywordConflicts) { 1142 TEST_F(TemplateURLServiceSyncTest, AutogeneratedKeywordConflicts) {
1144 // Sync brings in some autogenerated keywords, but the generated keywords we 1143 // Sync brings in some autogenerated keywords, but the generated keywords we
1145 // try to create conflict with ones in the model. 1144 // try to create conflict with ones in the model.
1146 base::string16 google_keyword(net::StripWWWFromHost(GURL( 1145 base::string16 google_keyword(net::StripWWWFromHost(GURL(
1147 UIThreadSearchTermsData(profile_a()).GoogleBaseURLValue()))); 1146 model()->search_terms_data().GoogleBaseURLValue())));
1148 const std::string local_google_url = 1147 const std::string local_google_url =
1149 "{google:baseURL}1/search?q={searchTerms}"; 1148 "{google:baseURL}1/search?q={searchTerms}";
1150 TemplateURL* google = CreateTestTemplateURL(google_keyword, local_google_url); 1149 TemplateURL* google = CreateTestTemplateURL(google_keyword, local_google_url);
1151 model()->Add(google); 1150 model()->Add(google);
1152 TemplateURL* other = 1151 TemplateURL* other =
1153 CreateTestTemplateURL(ASCIIToUTF16("other.com"), "http://other.com/foo"); 1152 CreateTestTemplateURL(ASCIIToUTF16("other.com"), "http://other.com/foo");
1154 model()->Add(other); 1153 model()->Add(other);
1155 syncer::SyncDataList initial_data; 1154 syncer::SyncDataList initial_data;
1156 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("sync1"), 1155 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("sync1"),
1157 "{google:baseURL}2/search?q={searchTerms}", "sync1", 50)); 1156 "{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())); 1209 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid()));
1211 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key2"), 1210 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key2"),
1212 "{google:baseURL}2/search?q={searchTerms}", "key2")); 1211 "{google:baseURL}2/search?q={searchTerms}", "key2"));
1213 initial_data.push_back( 1212 initial_data.push_back(
1214 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); 1213 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid()));
1215 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, 1214 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data,
1216 PassProcessor(), CreateAndPassSyncErrorFactory()); 1215 PassProcessor(), CreateAndPassSyncErrorFactory());
1217 1216
1218 // We should still have coalesced the updates to one each. 1217 // We should still have coalesced the updates to one each.
1219 base::string16 google_keyword(net::StripWWWFromHost(GURL( 1218 base::string16 google_keyword(net::StripWWWFromHost(GURL(
1220 UIThreadSearchTermsData(profile_a()).GoogleBaseURLValue()))); 1219 model()->search_terms_data().GoogleBaseURLValue())));
1221 TemplateURL* keyword1 = 1220 TemplateURL* keyword1 =
1222 model()->GetTemplateURLForKeyword(google_keyword + ASCIIToUTF16("_")); 1221 model()->GetTemplateURLForKeyword(google_keyword + ASCIIToUTF16("_"));
1223 ASSERT_FALSE(keyword1 == NULL); 1222 ASSERT_FALSE(keyword1 == NULL);
1224 EXPECT_EQ("key1", keyword1->sync_guid()); 1223 EXPECT_EQ("key1", keyword1->sync_guid());
1225 TemplateURL* keyword2 = model()->GetTemplateURLForKeyword(google_keyword); 1224 TemplateURL* keyword2 = model()->GetTemplateURLForKeyword(google_keyword);
1226 ASSERT_FALSE(keyword2 == NULL); 1225 ASSERT_FALSE(keyword2 == NULL);
1227 EXPECT_EQ("key2", keyword2->sync_guid()); 1226 EXPECT_EQ("key2", keyword2->sync_guid());
1228 1227
1229 EXPECT_GE(processor()->change_list_size(), 2U); 1228 EXPECT_GE(processor()->change_list_size(), 2U);
1230 ASSERT_TRUE(processor()->contains_guid("key1")); 1229 ASSERT_TRUE(processor()->contains_guid("key1"));
(...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after
2235 const char kNewGUID[] = "newdefault"; 2234 const char kNewGUID[] = "newdefault";
2236 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("what"), 2235 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("what"),
2237 "http://thewhat.com/{searchTerms}", 2236 "http://thewhat.com/{searchTerms}",
2238 kNewGUID)); 2237 kNewGUID));
2239 model()->SetUserSelectedDefaultSearchProvider( 2238 model()->SetUserSelectedDefaultSearchProvider(
2240 model()->GetTemplateURLForGUID(kNewGUID)); 2239 model()->GetTemplateURLForGUID(kNewGUID));
2241 2240
2242 EXPECT_EQ(kNewGUID, profile_a()->GetTestingPrefService()->GetString( 2241 EXPECT_EQ(kNewGUID, profile_a()->GetTestingPrefService()->GetString(
2243 prefs::kSyncedDefaultSearchProviderGUID)); 2242 prefs::kSyncedDefaultSearchProviderGUID));
2244 } 2243 }
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