diff options
3 files changed, 69 insertions, 56 deletions
diff --git a/chrome/browser/sync/test/integration/search_engines_helper.cc b/chrome/browser/sync/test/integration/search_engines_helper.cc index 12e2404..4ea7670 100644 --- a/chrome/browser/sync/test/integration/search_engines_helper.cc +++ b/chrome/browser/sync/test/integration/search_engines_helper.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -34,8 +34,8 @@ GUIDToTURLMap CreateGUIDToTURLMap(TemplateURLService* service) { CHECK(service); GUIDToTURLMap map; - std::vector<const TemplateURL*> turls = service->GetTemplateURLs(); - for (std::vector<const TemplateURL*>::iterator it = turls.begin(); + TemplateURLService::TemplateURLVector turls = service->GetTemplateURLs(); + for (TemplateURLService::TemplateURLVector::iterator it = turls.begin(); it != turls.end(); ++it) { CHECK(*it); CHECK(map.find((*it)->sync_guid()) == map.end()); @@ -84,7 +84,8 @@ bool ServiceMatchesVerifier(int profile) { CHECK(verifier); CHECK(other); - std::vector<const TemplateURL*> verifier_turls = verifier->GetTemplateURLs(); + TemplateURLService::TemplateURLVector verifier_turls = + verifier->GetTemplateURLs(); if (verifier_turls.size() != other->GetTemplateURLs().size()) { LOG(ERROR) << "Verifier and other service have a different count of TURLs: " << verifier_turls.size() << " vs " @@ -178,17 +179,31 @@ string16 CreateKeyword(int seed) { } TemplateURL* CreateTestTemplateURL(int seed) { + return CreateTestTemplateURL(seed, CreateKeyword(seed), + base::StringPrintf("0000-0000-0000-%04d", seed)); +} + +TemplateURL* CreateTestTemplateURL(int seed, + const string16& keyword, + const std::string& sync_guid) { + return CreateTestTemplateURL(seed, + base::StringPrintf("http://www.test%d.com/", seed), keyword, sync_guid); +} + +TemplateURL* CreateTestTemplateURL(int seed, + const std::string& url, + const string16& keyword, + const std::string& sync_guid) { TemplateURL* turl = new TemplateURL(); - turl->SetURL(base::StringPrintf("http://www.test%d.com/", seed), 0, 0); - turl->set_keyword(CreateKeyword(seed)); - turl->set_short_name(ASCIIToUTF16(base::StringPrintf("test%d", seed))); + turl->set_short_name(CreateKeyword(seed)); + turl->set_keyword(keyword); turl->set_safe_for_autoreplace(true); - GURL favicon_url("http://favicon.url"); - turl->SetFaviconURL(favicon_url); turl->set_date_created(base::Time::FromTimeT(100)); turl->set_last_modified(base::Time::FromTimeT(100)); turl->SetPrepopulateId(999999); - turl->set_sync_guid(base::StringPrintf("0000-0000-0000-%04d", seed)); + turl->set_sync_guid(sync_guid); + turl->SetURL(url, 0, 0); + turl->SetFaviconURL(GURL("http://favicon.url")); return turl; } @@ -199,32 +214,30 @@ void AddSearchEngine(int profile, int seed) { } void EditSearchEngine(int profile, - const std::string& keyword, - const std::string& short_name, - const std::string& new_keyword, + const string16& keyword, + const string16& short_name, + const string16& new_keyword, const std::string& url) { - const TemplateURL* turl = GetServiceForProfile(profile)-> - GetTemplateURLForKeyword(ASCIIToUTF16(keyword)); + DCHECK(!url.empty()); + const TemplateURL* turl = + GetServiceForProfile(profile)->GetTemplateURLForKeyword(keyword); EXPECT_TRUE(turl); - GetServiceForProfile(profile)->ResetTemplateURL(turl, - ASCIIToUTF16(short_name), - ASCIIToUTF16(new_keyword), + ASSERT_FALSE(new_keyword.empty()); + GetServiceForProfile(profile)->ResetTemplateURL(turl, short_name, new_keyword, url); // Make sure we do the same on the verifier. if (test()->use_verifier()) { const TemplateURL* verifier_turl = - GetVerifierService()->GetTemplateURLForKeyword(ASCIIToUTF16(keyword)); + GetVerifierService()->GetTemplateURLForKeyword(keyword); EXPECT_TRUE(verifier_turl); - GetVerifierService()->ResetTemplateURL(verifier_turl, - ASCIIToUTF16(short_name), - ASCIIToUTF16(new_keyword), - url); + GetVerifierService()->ResetTemplateURL(verifier_turl, short_name, + new_keyword, url); } } -void DeleteSearchEngineByKeyword(int profile, const string16 keyword) { - const TemplateURL* turl = GetServiceForProfile(profile)-> - GetTemplateURLForKeyword(keyword); +void DeleteSearchEngineByKeyword(int profile, const string16& keyword) { + const TemplateURL* turl = + GetServiceForProfile(profile)->GetTemplateURLForKeyword(keyword); EXPECT_TRUE(turl); GetServiceForProfile(profile)->Remove(turl); // Make sure we do the same on the verifier. @@ -243,8 +256,8 @@ void DeleteSearchEngineBySeed(int profile, int seed) { void ChangeDefaultSearchProvider(int profile, int seed) { TemplateURLService* service = GetServiceForProfile(profile); ASSERT_TRUE(service); - const TemplateURL* turl = service->GetTemplateURLForKeyword( - CreateKeyword(seed)); + const TemplateURL* turl = + service->GetTemplateURLForKeyword(CreateKeyword(seed)); ASSERT_TRUE(turl); service->SetDefaultSearchProvider(turl); if (test()->use_verifier()) { diff --git a/chrome/browser/sync/test/integration/search_engines_helper.h b/chrome/browser/sync/test/integration/search_engines_helper.h index 4858280..8e4ca3e 100644 --- a/chrome/browser/sync/test/integration/search_engines_helper.h +++ b/chrome/browser/sync/test/integration/search_engines_helper.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -45,6 +45,13 @@ bool AllServicesMatch(); // Create a TemplateURL with some test values based on |seed|. The caller owns // the returned TemplateURL*. TemplateURL* CreateTestTemplateURL(int seed); +TemplateURL* CreateTestTemplateURL(int seed, + const string16& keyword, + const std::string& sync_guid); +TemplateURL* CreateTestTemplateURL(int seed, + const std::string& url, + const string16& keyword, + const std::string& sync_guid); // Add a search engine based on a seed to the service at index |profile| and the // verifier if it is used. @@ -54,14 +61,14 @@ void AddSearchEngine(int profile, int seed); // keyword |keyword| and changes its user-visible fields. Does the same to the // verifier, if it is used. void EditSearchEngine(int profile, - const std::string& keyword, - const std::string& short_name, - const std::string& new_keyword, + const string16& keyword, + const string16& short_name, + const string16& new_keyword, const std::string& url); // Deletes a search engine from the service at index |profile| with original // keyword |keyword|. Does the same to the verifier, if it is used. -void DeleteSearchEngineByKeyword(int profile, const string16 keyword); +void DeleteSearchEngineByKeyword(int profile, const string16& keyword); // Deletes a search engine from the service at index |profile| which was // generated by seed |seed|. diff --git a/chrome/browser/sync/test/integration/two_client_search_engines_sync_test.cc b/chrome/browser/sync/test/integration/two_client_search_engines_sync_test.cc index 5fb09f0..892f067 100644 --- a/chrome/browser/sync/test/integration/two_client_search_engines_sync_test.cc +++ b/chrome/browser/sync/test/integration/two_client_search_engines_sync_test.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -62,17 +62,10 @@ IN_PROC_BROWSER_TEST_F(TwoClientSearchEnginesSyncTest, Duplicates) { // Add two entries with the same Name and URL (but different keywords). // Note that we have to change the GUID of the duplicate. AddSearchEngine(0, 0); - - TemplateURL* dupe = CreateTestTemplateURL(0); - dupe->set_keyword(ASCIIToUTF16("somethingelse")); - dupe->set_sync_guid("newguid"); - GetServiceForProfile(0)->Add(dupe); - - TemplateURL* verifier_dupe = CreateTestTemplateURL(0); - verifier_dupe->set_keyword(ASCIIToUTF16("somethingelse")); - verifier_dupe->set_sync_guid("newguid"); - GetVerifierService()->Add(verifier_dupe); - + GetServiceForProfile(0)->Add(CreateTestTemplateURL(0, + ASCIIToUTF16("somethingelse"), "newguid")); + GetVerifierService()->Add(CreateTestTemplateURL(0, + ASCIIToUTF16("somethingelse"), "newguid")); ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); ASSERT_TRUE(AllServicesMatch()); } @@ -88,7 +81,8 @@ IN_PROC_BROWSER_TEST_F(TwoClientSearchEnginesSyncTest, UpdateKeyword) { ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); ASSERT_TRUE(AllServicesMatch()); - EditSearchEngine(0, "test0", "test0", "newkeyword", "http://www.test0.com/"); + EditSearchEngine(0, ASCIIToUTF16("test0"), ASCIIToUTF16("test0"), + ASCIIToUTF16("newkeyword"), "http://www.test0.com/"); ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); ASSERT_TRUE(AllServicesMatch()); @@ -105,8 +99,8 @@ IN_PROC_BROWSER_TEST_F(TwoClientSearchEnginesSyncTest, UpdateUrl) { ASSERT_TRUE(AllServicesMatch()); // Change the URL. - EditSearchEngine(0, "test0", "test0", "test0", - "http://www.wikipedia.org/q=%s"); + EditSearchEngine(0, ASCIIToUTF16("test0"), ASCIIToUTF16("test0"), + ASCIIToUTF16("test0"), "http://www.wikipedia.org/q=%s"); ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); ASSERT_TRUE(AllServicesMatch()); @@ -123,7 +117,8 @@ IN_PROC_BROWSER_TEST_F(TwoClientSearchEnginesSyncTest, UpdateName) { ASSERT_TRUE(AllServicesMatch()); // Change the short name. - EditSearchEngine(0, "test0", "New Name", "test0", "http://www.test0.com/"); + EditSearchEngine(0, ASCIIToUTF16("test0"), ASCIIToUTF16("New Name"), + ASCIIToUTF16("test0"), "http://www.test0.com/"); ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); ASSERT_TRUE(AllServicesMatch()); @@ -155,8 +150,8 @@ IN_PROC_BROWSER_TEST_F(TwoClientSearchEnginesSyncTest, ConflictKeyword) { // conflict. AddSearchEngine(0, 0); AddSearchEngine(1, 1); - const TemplateURL* turl = GetServiceForProfile(1)-> - GetTemplateURLForKeyword(ASCIIToUTF16("test1")); + const TemplateURL* turl = GetServiceForProfile(1)->GetTemplateURLForKeyword( + ASCIIToUTF16("test1")); EXPECT_TRUE(turl); GetServiceForProfile(1)->ResetTemplateURL(turl, turl->short_name(), @@ -184,11 +179,9 @@ IN_PROC_BROWSER_TEST_F(TwoClientSearchEnginesSyncTest, MergeMultiple) { AddSearchEngine(1, 0); AddSearchEngine(1, 2); AddSearchEngine(1, 3); - TemplateURL* turl = CreateTestTemplateURL(0); - turl->SetURL("http://www.somethingelse.com/", 0, 0); - turl->set_keyword(ASCIIToUTF16("somethingelse.com")); - turl->set_sync_guid("somethingelse"); - GetServiceForProfile(1)->Add(turl); + GetServiceForProfile(1)->Add(CreateTestTemplateURL(0, + "http://www.somethingelse.com/", ASCIIToUTF16("somethingelse.com"), + "somethingelse")); ASSERT_TRUE(AwaitQuiescence()); ASSERT_TRUE(AllServicesMatch()); |