Commit 3113536e authored by hashimoto's avatar hashimoto Committed by Commit bot

Move TemplateURLService related tests to components/search_engines

Put tests next to the code being tested.

Move tests to components/ without actually removing dependencies with temporary DEPS rules added.
This results in these tests still built as parts of unit_tests, not components_unittests.

Fix TemplateURLServiceTestUtil to simplify the code and reduce chrome dependencies:
- Create KeywordWebDataService instead of depending on WebDataServiceFactory.
- Remove TemplateURLService::SetKeywordSearchTermsForURL() and TestingTemplateURLService.  Instead, TestingTemplateURLServiceClient is responsible to implement SetKeywordSearchTermsForURL().
- Remove content::TestBrowserThreadBundle from test util.  Tests are responsible to set up one.  This enables TemplateURLServiceTestSyncTest to use multiple test util instances.

BUG=387985
TEST=unit_tests

Review URL: https://codereview.chromium.org/513133002

Cr-Commit-Position: refs/heads/master@{#292597}
parent eefc52bd
...@@ -19,8 +19,9 @@ ...@@ -19,8 +19,9 @@
#include "components/search_engines/template_url.h" #include "components/search_engines/template_url.h"
#include "components/search_engines/template_url_prepopulate_data.h" #include "components/search_engines/template_url_prepopulate_data.h"
#include "components/search_engines/template_url_service.h" #include "components/search_engines/template_url_service.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/test/mock_render_process_host.h" #include "content/public/test/mock_render_process_host.h"
#include "content/public/test/test_browser_thread.h" #include "content/public/test/test_browser_thread_bundle.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
using content::BrowserThread; using content::BrowserThread;
...@@ -122,7 +123,6 @@ class SearchProviderInstallDataTest : public testing::Test { ...@@ -122,7 +123,6 @@ class SearchProviderInstallDataTest : public testing::Test {
virtual void SetUp() OVERRIDE; virtual void SetUp() OVERRIDE;
virtual void TearDown() OVERRIDE; virtual void TearDown() OVERRIDE;
protected:
TemplateURL* AddNewTemplateURL(const std::string& url, TemplateURL* AddNewTemplateURL(const std::string& url,
const base::string16& keyword); const base::string16& keyword);
...@@ -130,6 +130,11 @@ class SearchProviderInstallDataTest : public testing::Test { ...@@ -130,6 +130,11 @@ class SearchProviderInstallDataTest : public testing::Test {
// |SearchProviderInstallData| to process the update. // |SearchProviderInstallData| to process the update.
void SetGoogleBaseURLAndProcessOnIOThread(GURL base_url); void SetGoogleBaseURLAndProcessOnIOThread(GURL base_url);
TemplateURLServiceTestUtil* util() { return &util_; }
SearchProviderInstallData* install_data() { return install_data_; }
private:
content::TestBrowserThreadBundle thread_bundle_; // To set up BrowserThreads.
TemplateURLServiceTestUtil util_; TemplateURLServiceTestUtil util_;
// Provides the search provider install state on the I/O thread. It must be // Provides the search provider install state on the I/O thread. It must be
...@@ -200,7 +205,7 @@ void SearchProviderInstallDataTest::SetGoogleBaseURLAndProcessOnIOThread( ...@@ -200,7 +205,7 @@ void SearchProviderInstallDataTest::SetGoogleBaseURLAndProcessOnIOThread(
TEST_F(SearchProviderInstallDataTest, GetInstallState) { TEST_F(SearchProviderInstallDataTest, GetInstallState) {
// Set up the database. // Set up the database.
util_.ChangeModelToLoadState(); util()->ChangeModelToLoadState();
std::string host = "www.unittest.com"; std::string host = "www.unittest.com";
AddNewTemplateURL("http://" + host + "/path", base::ASCIIToUTF16("unittest")); AddNewTemplateURL("http://" + host + "/path", base::ASCIIToUTF16("unittest"));
...@@ -208,7 +213,7 @@ TEST_F(SearchProviderInstallDataTest, GetInstallState) { ...@@ -208,7 +213,7 @@ TEST_F(SearchProviderInstallDataTest, GetInstallState) {
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
// Verify the search providers install state (with no default set). // Verify the search providers install state (with no default set).
TestGetInstallState test_get_install_state(install_data_); TestGetInstallState test_get_install_state(install_data());
test_get_install_state.RunTests(host, std::string()); test_get_install_state.RunTests(host, std::string());
// Set-up a default and try it all one more time. // Set-up a default and try it all one more time.
...@@ -216,19 +221,19 @@ TEST_F(SearchProviderInstallDataTest, GetInstallState) { ...@@ -216,19 +221,19 @@ TEST_F(SearchProviderInstallDataTest, GetInstallState) {
TemplateURL* default_url = TemplateURL* default_url =
AddNewTemplateURL("http://" + default_host + "/", AddNewTemplateURL("http://" + default_host + "/",
base::ASCIIToUTF16("mmm")); base::ASCIIToUTF16("mmm"));
util_.model()->SetUserSelectedDefaultSearchProvider(default_url); util()->model()->SetUserSelectedDefaultSearchProvider(default_url);
test_get_install_state.RunTests(host, default_host); test_get_install_state.RunTests(host, default_host);
} }
TEST_F(SearchProviderInstallDataTest, ManagedDefaultSearch) { TEST_F(SearchProviderInstallDataTest, ManagedDefaultSearch) {
// Set up the database. // Set up the database.
util_.ChangeModelToLoadState(); util()->ChangeModelToLoadState();
std::string host = "www.unittest.com"; std::string host = "www.unittest.com";
AddNewTemplateURL("http://" + host + "/path", base::ASCIIToUTF16("unittest")); AddNewTemplateURL("http://" + host + "/path", base::ASCIIToUTF16("unittest"));
// Set a managed preference that establishes a default search provider. // Set a managed preference that establishes a default search provider.
std::string host2 = "www.managedtest.com"; std::string host2 = "www.managedtest.com";
util_.SetManagedDefaultSearchPreferences( util()->SetManagedDefaultSearchPreferences(
true, true,
"managed", "managed",
"managed", "managed",
...@@ -239,22 +244,22 @@ TEST_F(SearchProviderInstallDataTest, ManagedDefaultSearch) { ...@@ -239,22 +244,22 @@ TEST_F(SearchProviderInstallDataTest, ManagedDefaultSearch) {
std::string(), std::string(),
std::string()); std::string());
EXPECT_TRUE(util_.model()->is_default_search_managed()); EXPECT_TRUE(util()->model()->is_default_search_managed());
// Wait for the changes to be saved. // Wait for the changes to be saved.
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
// Verify the search providers install state. The default search should be // Verify the search providers install state. The default search should be
// the managed one we previously set. // the managed one we previously set.
TestGetInstallState test_get_install_state(install_data_); TestGetInstallState test_get_install_state(install_data());
test_get_install_state.RunTests(host, host2); test_get_install_state.RunTests(host, host2);
} }
TEST_F(SearchProviderInstallDataTest, GoogleBaseUrlChange) { TEST_F(SearchProviderInstallDataTest, GoogleBaseUrlChange) {
TestGetInstallState test_get_install_state(install_data_); TestGetInstallState test_get_install_state(install_data());
// Set up the database. // Set up the database.
util_.ChangeModelToLoadState(); util()->ChangeModelToLoadState();
std::string google_host = "w.com"; std::string google_host = "w.com";
SetGoogleBaseURLAndProcessOnIOThread(GURL("http://" + google_host + "/")); SetGoogleBaseURLAndProcessOnIOThread(GURL("http://" + google_host + "/"));
...@@ -262,7 +267,7 @@ TEST_F(SearchProviderInstallDataTest, GoogleBaseUrlChange) { ...@@ -262,7 +267,7 @@ TEST_F(SearchProviderInstallDataTest, GoogleBaseUrlChange) {
base::ASCIIToUTF16("t")); base::ASCIIToUTF16("t"));
TemplateURL* default_url = TemplateURL* default_url =
AddNewTemplateURL("http://d.com/", base::ASCIIToUTF16("d")); AddNewTemplateURL("http://d.com/", base::ASCIIToUTF16("d"));
util_.model()->SetUserSelectedDefaultSearchProvider(default_url); util()->model()->SetUserSelectedDefaultSearchProvider(default_url);
// Wait for the changes to be saved. // Wait for the changes to be saved.
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
......
...@@ -4,72 +4,64 @@ ...@@ -4,72 +4,64 @@
#include "chrome/browser/search_engines/template_url_service_test_util.h" #include "chrome/browser/search_engines/template_url_service_test_util.h"
#include "base/bind.h" #include "base/message_loop/message_loop_proxy.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/strings/string_split.h"
#include "base/threading/thread.h"
#include "chrome/browser/search_engines/chrome_template_url_service_client.h" #include "chrome/browser/search_engines/chrome_template_url_service_client.h"
#include "chrome/browser/webdata/web_data_service_factory.h"
#include "chrome/test/base/testing_pref_service_syncable.h" #include "chrome/test/base/testing_pref_service_syncable.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "components/google/core/browser/google_url_tracker.h"
#include "components/search_engines/default_search_manager.h"
#include "components/search_engines/default_search_pref_test_util.h" #include "components/search_engines/default_search_pref_test_util.h"
#include "components/search_engines/keyword_table.h"
#include "components/search_engines/keyword_web_data_service.h"
#include "components/search_engines/template_url_service.h" #include "components/search_engines/template_url_service.h"
#include "components/search_engines/testing_search_terms_data.h" #include "components/search_engines/testing_search_terms_data.h"
#include "components/webdata/common/web_database_service.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
// Trivial subclass of TemplateURLService that records the last invocation of namespace {
// SetKeywordSearchTermsForURL.
class TestingTemplateURLService : public TemplateURLService {
public:
TestingTemplateURLService(Profile* profile,
scoped_ptr<SearchTermsData> search_terms_data)
: TemplateURLService(
profile->GetPrefs(),
search_terms_data.Pass(),
WebDataServiceFactory::GetKeywordWebDataForProfile(
profile, Profile::EXPLICIT_ACCESS),
scoped_ptr<TemplateURLServiceClient>(
new ChromeTemplateURLServiceClient(profile)), NULL, NULL,
base::Closure()) {
}
base::string16 GetAndClearSearchTerm() { class TestingTemplateURLServiceClient : public ChromeTemplateURLServiceClient {
base::string16 search_term; public:
search_term.swap(search_term_); TestingTemplateURLServiceClient(Profile* profile,
return search_term; base::string16* search_term)
} : ChromeTemplateURLServiceClient(profile),
search_term_(search_term) {}
protected:
virtual void SetKeywordSearchTermsForURL( virtual void SetKeywordSearchTermsForURL(
const TemplateURL* t_url,
const GURL& url, const GURL& url,
TemplateURLID id,
const base::string16& term) OVERRIDE { const base::string16& term) OVERRIDE {
search_term_ = term; *search_term_ = term;
} }
private: private:
base::string16 search_term_; base::string16* search_term_;
DISALLOW_COPY_AND_ASSIGN(TestingTemplateURLService); DISALLOW_COPY_AND_ASSIGN(TestingTemplateURLServiceClient);
}; };
} // namespace
TemplateURLServiceTestUtil::TemplateURLServiceTestUtil() TemplateURLServiceTestUtil::TemplateURLServiceTestUtil()
: thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), : changed_count_(0),
changed_count_(0),
search_terms_data_(NULL) { search_terms_data_(NULL) {
// Make unique temp directory. // Make unique temp directory.
EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); EXPECT_TRUE(temp_dir_.CreateUniqueTempDir());
profile_.reset(new TestingProfile(temp_dir_.path())); profile_.reset(new TestingProfile(temp_dir_.path()));
profile()->CreateWebDataService(); scoped_refptr<WebDatabaseService> web_database_service =
new WebDatabaseService(temp_dir_.path().AppendASCII("webdata"),
base::MessageLoopProxy::current(),
base::MessageLoopProxy::current());
web_database_service->AddTable(
scoped_ptr<WebDatabaseTable>(new KeywordTable()));
web_database_service->LoadDatabase();
search_terms_data_ = new TestingSearchTermsData("http://www.google.com/"); web_data_service_ = new KeywordWebDataService(
model_.reset(new TestingTemplateURLService( web_database_service.get(), base::MessageLoopProxy::current(),
profile(), scoped_ptr<SearchTermsData>(search_terms_data_))); KeywordWebDataService::ProfileErrorCallback());
model_->AddObserver(this); web_data_service_->Init();
ResetModel(false);
} }
TemplateURLServiceTestUtil::~TemplateURLServiceTestUtil() { TemplateURLServiceTestUtil::~TemplateURLServiceTestUtil() {
...@@ -105,9 +97,7 @@ void TemplateURLServiceTestUtil::ChangeModelToLoadState() { ...@@ -105,9 +97,7 @@ void TemplateURLServiceTestUtil::ChangeModelToLoadState() {
// Initialize the web data service so that the database gets updated with // Initialize the web data service so that the database gets updated with
// any changes made. // any changes made.
model()->web_data_service_ = model()->web_data_service_ = web_data_service_;
WebDataServiceFactory::GetKeywordWebDataForProfile(
profile(), Profile::EXPLICIT_ACCESS);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
} }
...@@ -121,8 +111,12 @@ void TemplateURLServiceTestUtil::ResetModel(bool verify_load) { ...@@ -121,8 +111,12 @@ void TemplateURLServiceTestUtil::ResetModel(bool verify_load) {
if (model_) if (model_)
ClearModel(); ClearModel();
search_terms_data_ = new TestingSearchTermsData("http://www.google.com/"); search_terms_data_ = new TestingSearchTermsData("http://www.google.com/");
model_.reset(new TestingTemplateURLService( model_.reset(new TemplateURLService(
profile(), scoped_ptr<SearchTermsData>(search_terms_data_))); profile()->GetPrefs(), scoped_ptr<SearchTermsData>(search_terms_data_),
web_data_service_.get(),
scoped_ptr<TemplateURLServiceClient>(
new TestingTemplateURLServiceClient(profile(), &search_term_)),
NULL, NULL, base::Closure()));
model()->AddObserver(this); model()->AddObserver(this);
changed_count_ = 0; changed_count_ = 0;
if (verify_load) if (verify_load)
...@@ -130,7 +124,9 @@ void TemplateURLServiceTestUtil::ResetModel(bool verify_load) { ...@@ -130,7 +124,9 @@ void TemplateURLServiceTestUtil::ResetModel(bool verify_load) {
} }
base::string16 TemplateURLServiceTestUtil::GetAndClearSearchTerm() { base::string16 TemplateURLServiceTestUtil::GetAndClearSearchTerm() {
return model_->GetAndClearSearchTerm(); base::string16 search_term;
search_term.swap(search_term_);
return search_term;
} }
void TemplateURLServiceTestUtil::SetGoogleBaseURL(const GURL& base_url) { void TemplateURLServiceTestUtil::SetGoogleBaseURL(const GURL& base_url) {
...@@ -159,7 +155,3 @@ void TemplateURLServiceTestUtil::RemoveManagedDefaultSearchPreferences() { ...@@ -159,7 +155,3 @@ void TemplateURLServiceTestUtil::RemoveManagedDefaultSearchPreferences() {
DefaultSearchPrefTestUtil::RemoveManagedPref( DefaultSearchPrefTestUtil::RemoveManagedPref(
profile()->GetTestingPrefService()); profile()->GetTestingPrefService());
} }
TemplateURLService* TemplateURLServiceTestUtil::model() {
return model_.get();
}
...@@ -9,16 +9,16 @@ ...@@ -9,16 +9,16 @@
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/files/scoped_temp_dir.h" #include "base/files/scoped_temp_dir.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "components/search_engines/template_url_service_observer.h" #include "components/search_engines/template_url_service_observer.h"
#include "content/public/test/test_browser_thread_bundle.h"
class GURL; class GURL;
class KeywordWebDataService;
class TemplateURLService; class TemplateURLService;
class TestingProfile; class TestingProfile;
class TestingSearchTermsData; class TestingSearchTermsData;
class TestingTemplateURLService;
class TemplateURLServiceTestUtil : public TemplateURLServiceObserver { class TemplateURLServiceTestUtil : public TemplateURLServiceObserver {
public: public:
...@@ -52,12 +52,12 @@ class TemplateURLServiceTestUtil : public TemplateURLServiceObserver { ...@@ -52,12 +52,12 @@ class TemplateURLServiceTestUtil : public TemplateURLServiceObserver {
// TemplateURLService::SetKeywordSearchTermsForURL and clears the search term. // TemplateURLService::SetKeywordSearchTermsForURL and clears the search term.
base::string16 GetAndClearSearchTerm(); base::string16 GetAndClearSearchTerm();
// Set the google base url. |base_url| must be valid. // Sets the google base url. |base_url| must be valid.
void SetGoogleBaseURL(const GURL& base_url); void SetGoogleBaseURL(const GURL& base_url);
// Set the managed preferences for the default search provider and trigger // Sets the managed preferences for the default search provider and trigger
// notification. If |alternate_url| is empty, uses an empty list of alternate // notification. If |alternate_url| is empty, uses an empty list of alternate
// URLs, otherwise use a list containing a single entry. // URLs, otherwise uses a list containing a single entry.
void SetManagedDefaultSearchPreferences( void SetManagedDefaultSearchPreferences(
bool enabled, bool enabled,
const std::string& name, const std::string& name,
...@@ -69,23 +69,22 @@ class TemplateURLServiceTestUtil : public TemplateURLServiceObserver { ...@@ -69,23 +69,22 @@ class TemplateURLServiceTestUtil : public TemplateURLServiceObserver {
const std::string& alternate_url, const std::string& alternate_url,
const std::string& search_terms_replacement_key); const std::string& search_terms_replacement_key);
// Remove all the managed preferences for the default search provider and // Removes all the managed preferences for the default search provider and
// trigger notification. // triggers notification.
void RemoveManagedDefaultSearchPreferences(); void RemoveManagedDefaultSearchPreferences();
// Returns the TemplateURLService. KeywordWebDataService* web_data_service() { return web_data_service_.get(); }
TemplateURLService* model(); TemplateURLService* model() { return model_.get(); }
// Returns the TestingProfile.
TestingProfile* profile() { return profile_.get(); } TestingProfile* profile() { return profile_.get(); }
private: private:
content::TestBrowserThreadBundle thread_bundle_;
scoped_ptr<TestingProfile> profile_; scoped_ptr<TestingProfile> profile_;
base::ScopedTempDir temp_dir_; base::ScopedTempDir temp_dir_;
int changed_count_; int changed_count_;
base::string16 search_term_;
scoped_refptr<KeywordWebDataService> web_data_service_;
TestingSearchTermsData* search_terms_data_; TestingSearchTermsData* search_terms_data_;
scoped_ptr<TestingTemplateURLService> model_; scoped_ptr<TemplateURLService> model_;
DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceTestUtil); DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceTestUtil);
}; };
......
...@@ -1240,10 +1240,6 @@ ...@@ -1240,10 +1240,6 @@
'browser/search/suggestions/image_manager_impl_unittest.cc', 'browser/search/suggestions/image_manager_impl_unittest.cc',
'browser/search_engines/default_search_pref_migration_unittest.cc', 'browser/search_engines/default_search_pref_migration_unittest.cc',
'browser/search_engines/search_provider_install_data_unittest.cc', 'browser/search_engines/search_provider_install_data_unittest.cc',
'browser/search_engines/template_url_fetcher_unittest.cc',
'browser/search_engines/template_url_parser_unittest.cc',
'browser/search_engines/template_url_service_sync_unittest.cc',
'browser/search_engines/template_url_service_unittest.cc',
'browser/search_engines/template_url_scraper_unittest.cc', 'browser/search_engines/template_url_scraper_unittest.cc',
'browser/services/gcm/fake_signin_manager.cc', 'browser/services/gcm/fake_signin_manager.cc',
'browser/services/gcm/fake_signin_manager.h', 'browser/services/gcm/fake_signin_manager.h',
...@@ -1949,6 +1945,11 @@ ...@@ -1949,6 +1945,11 @@
'../components/nacl/loader/nacl_ipc_adapter_unittest.cc', '../components/nacl/loader/nacl_ipc_adapter_unittest.cc',
'../components/nacl/loader/nacl_validation_query_unittest.cc', '../components/nacl/loader/nacl_validation_query_unittest.cc',
'../components/search_engines/template_url_fetcher_unittest.cc',
'../components/search_engines/template_url_parser_unittest.cc',
'../components/search_engines/template_url_service_sync_unittest.cc',
'../components/search_engines/template_url_service_unittest.cc',
'../components/webdata/common/web_data_service_test_util.cc', '../components/webdata/common/web_data_service_test_util.cc',
'../components/webdata/common/web_data_service_test_util.h', '../components/webdata/common/web_data_service_test_util.h',
......
...@@ -17,3 +17,15 @@ include_rules = [ ...@@ -17,3 +17,15 @@ include_rules = [
"+sync", "+sync",
"+ui/gfx", "+ui/gfx",
] ]
specific_include_rules = {
".*_unittest\.cc$": [
"!chrome/browser/history/history_service.h",
"!chrome/browser/history/history_service_factory.h",
"!chrome/browser/search_engines/template_url_service_test_util.h",
"!chrome/common/chrome_paths.h",
"!chrome/test/base/testing_pref_service_syncable.h",
"!chrome/test/base/testing_profile.h",
"!content/public/test/test_browser_thread_bundle.h",
],
}
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "components/search_engines/template_url.h" #include "components/search_engines/template_url.h"
#include "components/search_engines/template_url_fetcher.h" #include "components/search_engines/template_url_fetcher.h"
#include "components/search_engines/template_url_service.h" #include "components/search_engines/template_url_service.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "net/test/embedded_test_server/embedded_test_server.h" #include "net/test/embedded_test_server/embedded_test_server.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -47,7 +48,6 @@ class TemplateURLFetcherTest : public testing::Test { ...@@ -47,7 +48,6 @@ class TemplateURLFetcherTest : public testing::Test {
base::ScopedClosureRunner* callback_destruction_notifier, base::ScopedClosureRunner* callback_destruction_notifier,
scoped_ptr<TemplateURL> template_url); scoped_ptr<TemplateURL> template_url);
protected:
// Schedules the download of the url. // Schedules the download of the url.
void StartDownload(const base::string16& keyword, void StartDownload(const base::string16& keyword,
const std::string& osdd_file_name, const std::string& osdd_file_name,
...@@ -57,6 +57,18 @@ class TemplateURLFetcherTest : public testing::Test { ...@@ -57,6 +57,18 @@ class TemplateURLFetcherTest : public testing::Test {
// Waits for any downloads to finish. // Waits for any downloads to finish.
void WaitForDownloadToFinish(); void WaitForDownloadToFinish();
TemplateURLServiceTestUtil* test_util() { return &test_util_; }
TemplateURLFetcher* template_url_fetcher() {
return template_url_fetcher_.get();
}
const TemplateURL* last_callback_template_url() const {
return last_callback_template_url_.get();
}
int callbacks_destroyed() const { return callbacks_destroyed_; }
int add_provider_called() const { return add_provider_called_; }
private:
content::TestBrowserThreadBundle thread_bundle_; // To set up BrowserThreads.
TemplateURLServiceTestUtil test_util_; TemplateURLServiceTestUtil test_util_;
scoped_ptr<TemplateURLFetcher> template_url_fetcher_; scoped_ptr<TemplateURLFetcher> template_url_fetcher_;
net::test_server::EmbeddedTestServer test_server_; net::test_server::EmbeddedTestServer test_server_;
...@@ -79,7 +91,8 @@ class TemplateURLFetcherTest : public testing::Test { ...@@ -79,7 +91,8 @@ class TemplateURLFetcherTest : public testing::Test {
}; };
TemplateURLFetcherTest::TemplateURLFetcherTest() TemplateURLFetcherTest::TemplateURLFetcherTest()
: callbacks_destroyed_(0), : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
callbacks_destroyed_(0),
add_provider_called_(0), add_provider_called_(0),
waiting_for_download_(false) { waiting_for_download_(false) {
base::FilePath src_dir; base::FilePath src_dir;
...@@ -142,39 +155,39 @@ void TemplateURLFetcherTest::WaitForDownloadToFinish() { ...@@ -142,39 +155,39 @@ void TemplateURLFetcherTest::WaitForDownloadToFinish() {
TEST_F(TemplateURLFetcherTest, BasicAutodetectedTest) { TEST_F(TemplateURLFetcherTest, BasicAutodetectedTest) {
base::string16 keyword(ASCIIToUTF16("test")); base::string16 keyword(ASCIIToUTF16("test"));
test_util_.ChangeModelToLoadState(); test_util()->ChangeModelToLoadState();
ASSERT_FALSE(test_util_.model()->GetTemplateURLForKeyword(keyword)); ASSERT_FALSE(test_util()->model()->GetTemplateURLForKeyword(keyword));
std::string osdd_file_name("simple_open_search.xml"); std::string osdd_file_name("simple_open_search.xml");
StartDownload(keyword, osdd_file_name, StartDownload(keyword, osdd_file_name,
TemplateURLFetcher::AUTODETECTED_PROVIDER, true); TemplateURLFetcher::AUTODETECTED_PROVIDER, true);
ASSERT_EQ(0, add_provider_called_); ASSERT_EQ(0, add_provider_called());
ASSERT_EQ(0, callbacks_destroyed_); ASSERT_EQ(0, callbacks_destroyed());
WaitForDownloadToFinish(); WaitForDownloadToFinish();
ASSERT_EQ(0, add_provider_called_); ASSERT_EQ(0, add_provider_called());
ASSERT_EQ(1, callbacks_destroyed_); ASSERT_EQ(1, callbacks_destroyed());
const TemplateURL* t_url = test_util_.model()->GetTemplateURLForKeyword( const TemplateURL* t_url = test_util()->model()->GetTemplateURLForKeyword(
keyword); keyword);
ASSERT_TRUE(t_url); ASSERT_TRUE(t_url);
EXPECT_EQ(ASCIIToUTF16("http://example.com/%s/other_stuff"), EXPECT_EQ(ASCIIToUTF16("http://example.com/%s/other_stuff"),
t_url->url_ref().DisplayURL( t_url->url_ref().DisplayURL(
test_util_.model()->search_terms_data())); test_util()->model()->search_terms_data()));
EXPECT_TRUE(t_url->safe_for_autoreplace()); EXPECT_TRUE(t_url->safe_for_autoreplace());
} }
TEST_F(TemplateURLFetcherTest, DuplicatesThrownAway) { TEST_F(TemplateURLFetcherTest, DuplicatesThrownAway) {
base::string16 keyword(ASCIIToUTF16("test")); base::string16 keyword(ASCIIToUTF16("test"));
test_util_.ChangeModelToLoadState(); test_util()->ChangeModelToLoadState();
ASSERT_FALSE(test_util_.model()->GetTemplateURLForKeyword(keyword)); ASSERT_FALSE(test_util()->model()->GetTemplateURLForKeyword(keyword));
std::string osdd_file_name("simple_open_search.xml"); std::string osdd_file_name("simple_open_search.xml");
StartDownload(keyword, osdd_file_name, StartDownload(keyword, osdd_file_name,
TemplateURLFetcher::AUTODETECTED_PROVIDER, true); TemplateURLFetcher::AUTODETECTED_PROVIDER, true);
ASSERT_EQ(0, add_provider_called_); ASSERT_EQ(0, add_provider_called());
ASSERT_EQ(0, callbacks_destroyed_); ASSERT_EQ(0, callbacks_destroyed());
struct { struct {
std::string description; std::string description;
...@@ -194,74 +207,74 @@ TEST_F(TemplateURLFetcherTest, DuplicatesThrownAway) { ...@@ -194,74 +207,74 @@ TEST_F(TemplateURLFetcherTest, DuplicatesThrownAway) {
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) {
StartDownload(test_cases[i].keyword, test_cases[i].osdd_file_name, StartDownload(test_cases[i].keyword, test_cases[i].osdd_file_name,
test_cases[i].provider_type, false); test_cases[i].provider_type, false);
ASSERT_EQ(1, template_url_fetcher_->requests_count()) ASSERT_EQ(1, template_url_fetcher()->requests_count())
<< test_cases[i].description; << test_cases[i].description;
ASSERT_EQ(i + 1, static_cast<size_t>(callbacks_destroyed_)); ASSERT_EQ(i + 1, static_cast<size_t>(callbacks_destroyed()));
} }
WaitForDownloadToFinish(); WaitForDownloadToFinish();
ASSERT_EQ(1 + ARRAYSIZE_UNSAFE(test_cases), ASSERT_EQ(1 + ARRAYSIZE_UNSAFE(test_cases),
static_cast<size_t>(callbacks_destroyed_)); static_cast<size_t>(callbacks_destroyed()));
ASSERT_EQ(0, add_provider_called_); ASSERT_EQ(0, add_provider_called());
} }
TEST_F(TemplateURLFetcherTest, BasicExplicitTest) { TEST_F(TemplateURLFetcherTest, BasicExplicitTest) {
base::string16 keyword(ASCIIToUTF16("test")); base::string16 keyword(ASCIIToUTF16("test"));
test_util_.ChangeModelToLoadState(); test_util()->ChangeModelToLoadState();
ASSERT_FALSE(test_util_.model()->GetTemplateURLForKeyword(keyword)); ASSERT_FALSE(test_util()->model()->GetTemplateURLForKeyword(keyword));
std::string osdd_file_name("simple_open_search.xml"); std::string osdd_file_name("simple_open_search.xml");
StartDownload(keyword, osdd_file_name, StartDownload(keyword, osdd_file_name,
TemplateURLFetcher::EXPLICIT_PROVIDER, true); TemplateURLFetcher::EXPLICIT_PROVIDER, true);
ASSERT_EQ(0, add_provider_called_); ASSERT_EQ(0, add_provider_called());
ASSERT_EQ(0, callbacks_destroyed_); ASSERT_EQ(0, callbacks_destroyed());
WaitForDownloadToFinish(); WaitForDownloadToFinish();
ASSERT_EQ(1, add_provider_called_); ASSERT_EQ(1, add_provider_called());
ASSERT_EQ(1, callbacks_destroyed_); ASSERT_EQ(1, callbacks_destroyed());
ASSERT_TRUE(last_callback_template_url_.get()); ASSERT_TRUE(last_callback_template_url());
EXPECT_EQ(ASCIIToUTF16("http://example.com/%s/other_stuff"), EXPECT_EQ(ASCIIToUTF16("http://example.com/%s/other_stuff"),
last_callback_template_url_->url_ref().DisplayURL( last_callback_template_url()->url_ref().DisplayURL(
test_util_.model()->search_terms_data())); test_util()->model()->search_terms_data()));
EXPECT_EQ(ASCIIToUTF16("example.com"), EXPECT_EQ(ASCIIToUTF16("example.com"),
last_callback_template_url_->keyword()); last_callback_template_url()->keyword());
EXPECT_FALSE(last_callback_template_url_->safe_for_autoreplace()); EXPECT_FALSE(last_callback_template_url()->safe_for_autoreplace());
} }
TEST_F(TemplateURLFetcherTest, AutodetectedBeforeLoadTest) { TEST_F(TemplateURLFetcherTest, AutodetectedBeforeLoadTest) {
base::string16 keyword(ASCIIToUTF16("test")); base::string16 keyword(ASCIIToUTF16("test"));
ASSERT_FALSE(test_util_.model()->GetTemplateURLForKeyword(keyword)); ASSERT_FALSE(test_util()->model()->GetTemplateURLForKeyword(keyword));
std::string osdd_file_name("simple_open_search.xml"); std::string osdd_file_name("simple_open_search.xml");
StartDownload(keyword, osdd_file_name, StartDownload(keyword, osdd_file_name,
TemplateURLFetcher::AUTODETECTED_PROVIDER, true); TemplateURLFetcher::AUTODETECTED_PROVIDER, true);
ASSERT_EQ(0, add_provider_called_); ASSERT_EQ(0, add_provider_called());
ASSERT_EQ(1, callbacks_destroyed_); ASSERT_EQ(1, callbacks_destroyed());
} }
TEST_F(TemplateURLFetcherTest, ExplicitBeforeLoadTest) { TEST_F(TemplateURLFetcherTest, ExplicitBeforeLoadTest) {
base::string16 keyword(ASCIIToUTF16("test")); base::string16 keyword(ASCIIToUTF16("test"));
ASSERT_FALSE(test_util_.model()->GetTemplateURLForKeyword(keyword)); ASSERT_FALSE(test_util()->model()->GetTemplateURLForKeyword(keyword));
std::string osdd_file_name("simple_open_search.xml"); std::string osdd_file_name("simple_open_search.xml");
StartDownload(keyword, osdd_file_name, StartDownload(keyword, osdd_file_name,
TemplateURLFetcher::EXPLICIT_PROVIDER, true); TemplateURLFetcher::EXPLICIT_PROVIDER, true);
ASSERT_EQ(0, add_provider_called_); ASSERT_EQ(0, add_provider_called());
ASSERT_EQ(0, callbacks_destroyed_); ASSERT_EQ(0, callbacks_destroyed());
WaitForDownloadToFinish(); WaitForDownloadToFinish();
ASSERT_EQ(1, add_provider_called_); ASSERT_EQ(1, add_provider_called());
ASSERT_EQ(1, callbacks_destroyed_); ASSERT_EQ(1, callbacks_destroyed());
ASSERT_TRUE(last_callback_template_url_.get()); ASSERT_TRUE(last_callback_template_url());
EXPECT_EQ(ASCIIToUTF16("http://example.com/%s/other_stuff"), EXPECT_EQ(ASCIIToUTF16("http://example.com/%s/other_stuff"),
last_callback_template_url_->url_ref().DisplayURL( last_callback_template_url()->url_ref().DisplayURL(
test_util_.model()->search_terms_data())); test_util()->model()->search_terms_data()));
EXPECT_EQ(ASCIIToUTF16("example.com"), EXPECT_EQ(ASCIIToUTF16("example.com"),
last_callback_template_url_->keyword()); last_callback_template_url()->keyword());
EXPECT_FALSE(last_callback_template_url_->safe_for_autoreplace()); EXPECT_FALSE(last_callback_template_url()->safe_for_autoreplace());
} }
TEST_F(TemplateURLFetcherTest, DuplicateKeywordsTest) { TEST_F(TemplateURLFetcherTest, DuplicateKeywordsTest) {
...@@ -270,18 +283,18 @@ TEST_F(TemplateURLFetcherTest, DuplicateKeywordsTest) { ...@@ -270,18 +283,18 @@ TEST_F(TemplateURLFetcherTest, DuplicateKeywordsTest) {
data.short_name = keyword; data.short_name = keyword;
data.SetKeyword(keyword); data.SetKeyword(keyword);
data.SetURL("http://example.com/"); data.SetURL("http://example.com/");
test_util_.model()->Add(new TemplateURL(data)); test_util()->model()->Add(new TemplateURL(data));
test_util_.ChangeModelToLoadState(); test_util()->ChangeModelToLoadState();
ASSERT_TRUE(test_util_.model()->GetTemplateURLForKeyword(keyword)); ASSERT_TRUE(test_util()->model()->GetTemplateURLForKeyword(keyword));
// This should bail because the keyword already exists. // This should bail because the keyword already exists.
std::string osdd_file_name("simple_open_search.xml"); std::string osdd_file_name("simple_open_search.xml");
StartDownload(keyword, osdd_file_name, StartDownload(keyword, osdd_file_name,
TemplateURLFetcher::AUTODETECTED_PROVIDER, true); TemplateURLFetcher::AUTODETECTED_PROVIDER, true);
ASSERT_EQ(0, add_provider_called_); ASSERT_EQ(0, add_provider_called());
ASSERT_EQ(1, callbacks_destroyed_); ASSERT_EQ(1, callbacks_destroyed());
ASSERT_FALSE(last_callback_template_url_.get()); ASSERT_FALSE(last_callback_template_url());
} }
TEST_F(TemplateURLFetcherTest, DuplicateDownloadTest) { TEST_F(TemplateURLFetcherTest, DuplicateDownloadTest) {
...@@ -289,17 +302,17 @@ TEST_F(TemplateURLFetcherTest, DuplicateDownloadTest) { ...@@ -289,17 +302,17 @@ TEST_F(TemplateURLFetcherTest, DuplicateDownloadTest) {
std::string osdd_file_name("simple_open_search.xml"); std::string osdd_file_name("simple_open_search.xml");
StartDownload(keyword, osdd_file_name, StartDownload(keyword, osdd_file_name,
TemplateURLFetcher::EXPLICIT_PROVIDER, true); TemplateURLFetcher::EXPLICIT_PROVIDER, true);
ASSERT_EQ(0, add_provider_called_); ASSERT_EQ(0, add_provider_called());
ASSERT_EQ(0, callbacks_destroyed_); ASSERT_EQ(0, callbacks_destroyed());
// This should bail because the keyword already has a pending download. // This should bail because the keyword already has a pending download.
StartDownload(keyword, osdd_file_name, StartDownload(keyword, osdd_file_name,
TemplateURLFetcher::EXPLICIT_PROVIDER, true); TemplateURLFetcher::EXPLICIT_PROVIDER, true);
ASSERT_EQ(0, add_provider_called_); ASSERT_EQ(0, add_provider_called());
ASSERT_EQ(1, callbacks_destroyed_); ASSERT_EQ(1, callbacks_destroyed());
WaitForDownloadToFinish(); WaitForDownloadToFinish();
ASSERT_EQ(1, add_provider_called_); ASSERT_EQ(1, add_provider_called());
ASSERT_EQ(2, callbacks_destroyed_); ASSERT_EQ(2, callbacks_destroyed());
ASSERT_TRUE(last_callback_template_url_.get()); ASSERT_TRUE(last_callback_template_url());
} }
...@@ -1408,14 +1408,6 @@ SyncDataMap TemplateURLService::CreateGUIDToSyncDataMap( ...@@ -1408,14 +1408,6 @@ SyncDataMap TemplateURLService::CreateGUIDToSyncDataMap(
return data_map; return data_map;
} }
void TemplateURLService::SetKeywordSearchTermsForURL(
const TemplateURL* t_url,
const GURL& url,
const base::string16& term) {
if (client_)
client_->SetKeywordSearchTermsForURL(url, t_url->id(), term);
}
void TemplateURLService::Init(const Initializer* initializers, void TemplateURLService::Init(const Initializer* initializers,
int num_initializers) { int num_initializers) {
if (client_) if (client_)
...@@ -1747,7 +1739,10 @@ void TemplateURLService::UpdateKeywordSearchTermsForURL( ...@@ -1747,7 +1739,10 @@ void TemplateURLService::UpdateKeywordSearchTermsForURL(
// count is boosted. // count is boosted.
AddTabToSearchVisit(**i); AddTabToSearchVisit(**i);
} }
SetKeywordSearchTermsForURL(*i, details.url, search_terms); if (client_) {
client_->SetKeywordSearchTermsForURL(
details.url, (*i)->id(), search_terms);
}
} }
} }
} }
......
...@@ -374,15 +374,6 @@ class TemplateURLService : public WebDataServiceConsumer, ...@@ -374,15 +374,6 @@ class TemplateURLService : public WebDataServiceConsumer,
} }
#endif #endif
protected:
// Cover method for the method of the same name on the HistoryService.
// url is the one that was visited with the given search terms.
//
// This exists and is virtual for testing.
virtual void SetKeywordSearchTermsForURL(const TemplateURL* t_url,
const GURL& url,
const base::string16& term);
private: private:
FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest, TestManagedDefaultSearch); FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest, TestManagedDefaultSearch);
FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest, FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest,
......
...@@ -4,11 +4,11 @@ ...@@ -4,11 +4,11 @@
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h" #include "base/memory/scoped_vector.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/search_engines/template_url_service_test_util.h" #include "chrome/browser/search_engines/template_url_service_test_util.h"
#include "chrome/test/base/testing_pref_service_syncable.h" #include "chrome/test/base/testing_pref_service_syncable.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
...@@ -161,7 +161,7 @@ class TemplateURLServiceSyncTest : public testing::Test { ...@@ -161,7 +161,7 @@ class TemplateURLServiceSyncTest : public testing::Test {
// For readability, we redefine an accessor for Model A for use in tests that // For readability, we redefine an accessor for Model A for use in tests that
// involve syncing two models. // involve syncing two models.
TemplateURLService* model_a() { return test_util_a_->model(); } TemplateURLService* model_a() { return test_util_a_->model(); }
TemplateURLService* model_b() { return model_b_.get(); } TemplateURLService* model_b() { return test_util_b_->model(); }
TestingProfile* profile_a() { return test_util_a_->profile(); } TestingProfile* profile_a() { return test_util_a_->profile(); }
TestChangeProcessor* processor() { return sync_processor_.get(); } TestChangeProcessor* processor() { return sync_processor_.get(); }
scoped_ptr<syncer::SyncChangeProcessor> PassProcessor(); scoped_ptr<syncer::SyncChangeProcessor> PassProcessor();
...@@ -209,10 +209,10 @@ class TemplateURLServiceSyncTest : public testing::Test { ...@@ -209,10 +209,10 @@ class TemplateURLServiceSyncTest : public testing::Test {
const std::string& guid); const std::string& guid);
protected: protected:
base::MessageLoop message_loop_;
// We keep two TemplateURLServices to test syncing between them. // We keep two TemplateURLServices to test syncing between them.
scoped_ptr<TemplateURLServiceTestUtil> test_util_a_; scoped_ptr<TemplateURLServiceTestUtil> test_util_a_;
scoped_ptr<TestingProfile> profile_b_; scoped_ptr<TemplateURLServiceTestUtil> test_util_b_;
scoped_ptr<TemplateURLService> model_b_;
// Our dummy ChangeProcessor used to inspect changes pushed to Sync. // Our dummy ChangeProcessor used to inspect changes pushed to Sync.
scoped_ptr<TestChangeProcessor> sync_processor_; scoped_ptr<TestChangeProcessor> sync_processor_;
...@@ -233,13 +233,9 @@ void TemplateURLServiceSyncTest::SetUp() { ...@@ -233,13 +233,9 @@ void TemplateURLServiceSyncTest::SetUp() {
// in the prepopulate data, which the sync tests don't care about (and would // in the prepopulate data, which the sync tests don't care about (and would
// just foul them up). // just foul them up).
test_util_a_->ChangeModelToLoadState(); test_util_a_->ChangeModelToLoadState();
profile_b_.reset(new TestingProfile);
TemplateURLServiceFactory::GetInstance()-> test_util_b_.reset(new TemplateURLServiceTestUtil);
RegisterUserPrefsOnBrowserContextForTest(profile_b_.get()); test_util_b_->VerifyLoad();
model_b_.reset(new TemplateURLService(
profile_b_->GetPrefs(), make_scoped_ptr(new SearchTermsData), NULL,
scoped_ptr<TemplateURLServiceClient>(), NULL, NULL, base::Closure()));
model_b_->Load();
} }
void TemplateURLServiceSyncTest::TearDown() { void TemplateURLServiceSyncTest::TearDown() {
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
#include "chrome/browser/history/history_service.h" #include "chrome/browser/history/history_service.h"
#include "chrome/browser/history/history_service_factory.h" #include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/search_engines/template_url_service_test_util.h" #include "chrome/browser/search_engines/template_url_service_test_util.h"
#include "chrome/browser/webdata/web_data_service_factory.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "components/search_engines/keyword_web_data_service.h" #include "components/search_engines/keyword_web_data_service.h"
#include "components/search_engines/search_host_to_urls_map.h" #include "components/search_engines/search_host_to_urls_map.h"
...@@ -26,7 +25,7 @@ ...@@ -26,7 +25,7 @@
#include "components/search_engines/template_url.h" #include "components/search_engines/template_url.h"
#include "components/search_engines/template_url_prepopulate_data.h" #include "components/search_engines/template_url_prepopulate_data.h"
#include "components/search_engines/template_url_service.h" #include "components/search_engines/template_url_service.h"
#include "components/webdata/common/web_database.h" #include "content/public/test/test_browser_thread_bundle.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
using base::ASCIIToUTF16; using base::ASCIIToUTF16;
...@@ -160,12 +159,14 @@ class TemplateURLServiceTest : public testing::Test { ...@@ -160,12 +159,14 @@ class TemplateURLServiceTest : public testing::Test {
// visually noisy in the test code. // visually noisy in the test code.
void VerifyObserverCount(int expected_changed_count); void VerifyObserverCount(int expected_changed_count);
void VerifyObserverFired(); void VerifyObserverFired();
TemplateURLServiceTestUtil* test_util() { return test_util_.get(); }
TemplateURLService* model() { return test_util_->model(); } TemplateURLService* model() { return test_util_->model(); }
const SearchTermsData& search_terms_data() { const SearchTermsData& search_terms_data() {
return model()->search_terms_data(); return model()->search_terms_data();
} }
protected: private:
content::TestBrowserThreadBundle thread_bundle_; // To set up BrowserThreads.
scoped_ptr<TemplateURLServiceTestUtil> test_util_; scoped_ptr<TemplateURLServiceTestUtil> test_util_;
DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceTest); DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceTest);
...@@ -263,12 +264,12 @@ void TemplateURLServiceTest::VerifyObserverFired() { ...@@ -263,12 +264,12 @@ void TemplateURLServiceTest::VerifyObserverFired() {
// Actual tests --------------------------------------------------------------- // Actual tests ---------------------------------------------------------------
TEST_F(TemplateURLServiceTest, Load) { TEST_F(TemplateURLServiceTest, Load) {
test_util_->VerifyLoad(); test_util()->VerifyLoad();
} }
TEST_F(TemplateURLServiceTest, AddUpdateRemove) { TEST_F(TemplateURLServiceTest, AddUpdateRemove) {
// Add a new TemplateURL. // Add a new TemplateURL.
test_util_->VerifyLoad(); test_util()->VerifyLoad();
const size_t initial_count = model()->GetTemplateURLs().size(); const size_t initial_count = model()->GetTemplateURLs().size();
TemplateURLData data; TemplateURLData data;
...@@ -294,7 +295,7 @@ TEST_F(TemplateURLServiceTest, AddUpdateRemove) { ...@@ -294,7 +295,7 @@ TEST_F(TemplateURLServiceTest, AddUpdateRemove) {
scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->data())); scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->data()));
// Reload the model to verify it was actually saved to the database. // Reload the model to verify it was actually saved to the database.
test_util_->ResetModel(true); test_util()->ResetModel(true);
ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size());
TemplateURL* loaded_url = TemplateURL* loaded_url =
model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"));
...@@ -322,7 +323,7 @@ TEST_F(TemplateURLServiceTest, AddUpdateRemove) { ...@@ -322,7 +323,7 @@ TEST_F(TemplateURLServiceTest, AddUpdateRemove) {
ASSERT_FALSE(model()->CanReplaceKeyword(ASCIIToUTF16("b"), GURL(), NULL)); ASSERT_FALSE(model()->CanReplaceKeyword(ASCIIToUTF16("b"), GURL(), NULL));
cloned_url.reset(new TemplateURL(loaded_url->data())); cloned_url.reset(new TemplateURL(loaded_url->data()));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
test_util_->ResetModel(true); test_util()->ResetModel(true);
ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size());
loaded_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("b")); loaded_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("b"));
ASSERT_TRUE(loaded_url != NULL); ASSERT_TRUE(loaded_url != NULL);
...@@ -334,13 +335,13 @@ TEST_F(TemplateURLServiceTest, AddUpdateRemove) { ...@@ -334,13 +335,13 @@ TEST_F(TemplateURLServiceTest, AddUpdateRemove) {
// Remove an element and verify it succeeded. // Remove an element and verify it succeeded.
model()->Remove(loaded_url); model()->Remove(loaded_url);
VerifyObserverCount(1); VerifyObserverCount(1);
test_util_->ResetModel(true); test_util()->ResetModel(true);
ASSERT_EQ(initial_count, model()->GetTemplateURLs().size()); ASSERT_EQ(initial_count, model()->GetTemplateURLs().size());
EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("b")) == NULL); EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("b")) == NULL);
} }
TEST_F(TemplateURLServiceTest, AddSameKeyword) { TEST_F(TemplateURLServiceTest, AddSameKeyword) {
test_util_->VerifyLoad(); test_util()->VerifyLoad();
AddKeywordWithDate( AddKeywordWithDate(
"first", "keyword", "http://test1", std::string(), std::string(), "first", "keyword", "http://test1", std::string(), std::string(),
...@@ -393,7 +394,7 @@ TEST_F(TemplateURLServiceTest, AddSameKeyword) { ...@@ -393,7 +394,7 @@ TEST_F(TemplateURLServiceTest, AddSameKeyword) {
} }
TEST_F(TemplateURLServiceTest, AddExtensionKeyword) { TEST_F(TemplateURLServiceTest, AddExtensionKeyword) {
test_util_->VerifyLoad(); test_util()->VerifyLoad();
TemplateURL* original1 = AddKeywordWithDate( TemplateURL* original1 = AddKeywordWithDate(
"replaceable", "keyword1", "http://test1", std::string(), std::string(), "replaceable", "keyword1", "http://test1", std::string(), std::string(),
...@@ -434,7 +435,7 @@ TEST_F(TemplateURLServiceTest, AddExtensionKeyword) { ...@@ -434,7 +435,7 @@ TEST_F(TemplateURLServiceTest, AddExtensionKeyword) {
} }
TEST_F(TemplateURLServiceTest, AddSameKeywordWithExtensionPresent) { TEST_F(TemplateURLServiceTest, AddSameKeywordWithExtensionPresent) {
test_util_->VerifyLoad(); test_util()->VerifyLoad();
// Similar to the AddSameKeyword test, but with an extension keyword masking a // Similar to the AddSameKeyword test, but with an extension keyword masking a
// replaceable TemplateURL. We should still do correct conflict resolution // replaceable TemplateURL. We should still do correct conflict resolution
...@@ -479,7 +480,7 @@ TEST_F(TemplateURLServiceTest, AddSameKeywordWithExtensionPresent) { ...@@ -479,7 +480,7 @@ TEST_F(TemplateURLServiceTest, AddSameKeywordWithExtensionPresent) {
} }
TEST_F(TemplateURLServiceTest, RestoreOmniboxExtensionKeyword) { TEST_F(TemplateURLServiceTest, RestoreOmniboxExtensionKeyword) {
test_util_->VerifyLoad(); test_util()->VerifyLoad();
// Register an omnibox keyword. // Register an omnibox keyword.
model()->RegisterOmniboxKeyword("test", "extension", "keyword", model()->RegisterOmniboxKeyword("test", "extension", "keyword",
...@@ -487,7 +488,7 @@ TEST_F(TemplateURLServiceTest, RestoreOmniboxExtensionKeyword) { ...@@ -487,7 +488,7 @@ TEST_F(TemplateURLServiceTest, RestoreOmniboxExtensionKeyword) {
ASSERT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); ASSERT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")));
// Reload the data. // Reload the data.
test_util_->ResetModel(true); test_util()->ResetModel(true);
// Ensure the omnibox keyword is restored correctly. // Ensure the omnibox keyword is restored correctly.
TemplateURL* t_url = TemplateURL* t_url =
...@@ -613,7 +614,7 @@ TEST_F(TemplateURLServiceTest, ClearBrowsingData_KeywordsForOrigin) { ...@@ -613,7 +614,7 @@ TEST_F(TemplateURLServiceTest, ClearBrowsingData_KeywordsForOrigin) {
TEST_F(TemplateURLServiceTest, Reset) { TEST_F(TemplateURLServiceTest, Reset) {
// Add a new TemplateURL. // Add a new TemplateURL.
test_util_->VerifyLoad(); test_util()->VerifyLoad();
const size_t initial_count = model()->GetTemplateURLs().size(); const size_t initial_count = model()->GetTemplateURLs().size();
TemplateURLData data; TemplateURLData data;
data.short_name = ASCIIToUTF16("google"); data.short_name = ASCIIToUTF16("google");
...@@ -649,7 +650,7 @@ TEST_F(TemplateURLServiceTest, Reset) { ...@@ -649,7 +650,7 @@ TEST_F(TemplateURLServiceTest, Reset) {
scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->data())); scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->data()));
// Reload the model from the database and make sure the change took. // Reload the model from the database and make sure the change took.
test_util_->ResetModel(true); test_util()->ResetModel(true);
EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size());
const TemplateURL* read_url = model()->GetTemplateURLForKeyword(new_keyword); const TemplateURL* read_url = model()->GetTemplateURLForKeyword(new_keyword);
ASSERT_TRUE(read_url); ASSERT_TRUE(read_url);
...@@ -659,12 +660,12 @@ TEST_F(TemplateURLServiceTest, Reset) { ...@@ -659,12 +660,12 @@ TEST_F(TemplateURLServiceTest, Reset) {
TEST_F(TemplateURLServiceTest, DefaultSearchProvider) { TEST_F(TemplateURLServiceTest, DefaultSearchProvider) {
// Add a new TemplateURL. // Add a new TemplateURL.
test_util_->VerifyLoad(); test_util()->VerifyLoad();
const size_t initial_count = model()->GetTemplateURLs().size(); const size_t initial_count = model()->GetTemplateURLs().size();
TemplateURL* t_url = AddKeywordWithDate( TemplateURL* t_url = AddKeywordWithDate(
"name1", "key1", "http://foo1/{searchTerms}", "http://sugg1", "name1", "key1", "http://foo1/{searchTerms}", "http://sugg1",
std::string(), "http://icon1", true, "UTF-8;UTF-16", Time(), Time()); std::string(), "http://icon1", true, "UTF-8;UTF-16", Time(), Time());
test_util_->ResetObserverCount(); test_util()->ResetObserverCount();
model()->SetUserSelectedDefaultSearchProvider(t_url); model()->SetUserSelectedDefaultSearchProvider(t_url);
ASSERT_EQ(t_url, model()->GetDefaultSearchProvider()); ASSERT_EQ(t_url, model()->GetDefaultSearchProvider());
...@@ -678,14 +679,14 @@ TEST_F(TemplateURLServiceTest, DefaultSearchProvider) { ...@@ -678,14 +679,14 @@ TEST_F(TemplateURLServiceTest, DefaultSearchProvider) {
scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->data())); scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->data()));
// Make sure when we reload we get a default search provider. // Make sure when we reload we get a default search provider.
test_util_->ResetModel(true); test_util()->ResetModel(true);
EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size());
ASSERT_TRUE(model()->GetDefaultSearchProvider()); ASSERT_TRUE(model()->GetDefaultSearchProvider());
AssertEquals(*cloned_url, *model()->GetDefaultSearchProvider()); AssertEquals(*cloned_url, *model()->GetDefaultSearchProvider());
} }
TEST_F(TemplateURLServiceTest, CantReplaceWithSameKeyword) { TEST_F(TemplateURLServiceTest, CantReplaceWithSameKeyword) {
test_util_->ChangeModelToLoadState(); test_util()->ChangeModelToLoadState();
ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("foo"), GURL(), NULL)); ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("foo"), GURL(), NULL));
TemplateURL* t_url = AddKeywordWithDate( TemplateURL* t_url = AddKeywordWithDate(
"name1", "foo", "http://foo1", "http://sugg1", std::string(), "name1", "foo", "http://foo1", "http://sugg1", std::string(),
...@@ -705,7 +706,7 @@ TEST_F(TemplateURLServiceTest, CantReplaceWithSameKeyword) { ...@@ -705,7 +706,7 @@ TEST_F(TemplateURLServiceTest, CantReplaceWithSameKeyword) {
} }
TEST_F(TemplateURLServiceTest, CantReplaceWithSameHosts) { TEST_F(TemplateURLServiceTest, CantReplaceWithSameHosts) {
test_util_->ChangeModelToLoadState(); test_util()->ChangeModelToLoadState();
ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("foo"), ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("foo"),
GURL("http://foo.com"), NULL)); GURL("http://foo.com"), NULL));
TemplateURL* t_url = AddKeywordWithDate( TemplateURL* t_url = AddKeywordWithDate(
...@@ -730,13 +731,13 @@ TEST_F(TemplateURLServiceTest, HasDefaultSearchProvider) { ...@@ -730,13 +731,13 @@ TEST_F(TemplateURLServiceTest, HasDefaultSearchProvider) {
ASSERT_TRUE(model()->GetDefaultSearchProvider()); ASSERT_TRUE(model()->GetDefaultSearchProvider());
// Now force the model to load and make sure we still have a default. // Now force the model to load and make sure we still have a default.
test_util_->VerifyLoad(); test_util()->VerifyLoad();
ASSERT_TRUE(model()->GetDefaultSearchProvider()); ASSERT_TRUE(model()->GetDefaultSearchProvider());
} }
TEST_F(TemplateURLServiceTest, DefaultSearchProviderLoadedFromPrefs) { TEST_F(TemplateURLServiceTest, DefaultSearchProviderLoadedFromPrefs) {
test_util_->VerifyLoad(); test_util()->VerifyLoad();
TemplateURLData data; TemplateURLData data;
data.short_name = ASCIIToUTF16("a"); data.short_name = ASCIIToUTF16("a");
...@@ -756,7 +757,7 @@ TEST_F(TemplateURLServiceTest, DefaultSearchProviderLoadedFromPrefs) { ...@@ -756,7 +757,7 @@ TEST_F(TemplateURLServiceTest, DefaultSearchProviderLoadedFromPrefs) {
// Reset the model and don't load it. The template url we set as the default // Reset the model and don't load it. The template url we set as the default
// should be pulled from prefs now. // should be pulled from prefs now.
test_util_->ResetModel(false); test_util()->ResetModel(false);
// NOTE: This doesn't use AssertEquals as only a subset of the TemplateURLs // NOTE: This doesn't use AssertEquals as only a subset of the TemplateURLs
// value are persisted to prefs. // value are persisted to prefs.
...@@ -769,14 +770,14 @@ TEST_F(TemplateURLServiceTest, DefaultSearchProviderLoadedFromPrefs) { ...@@ -769,14 +770,14 @@ TEST_F(TemplateURLServiceTest, DefaultSearchProviderLoadedFromPrefs) {
EXPECT_EQ(id, default_turl->id()); EXPECT_EQ(id, default_turl->id());
// Now do a load and make sure the default search provider really takes. // Now do a load and make sure the default search provider really takes.
test_util_->VerifyLoad(); test_util()->VerifyLoad();
ASSERT_TRUE(model()->GetDefaultSearchProvider()); ASSERT_TRUE(model()->GetDefaultSearchProvider());
AssertEquals(*cloned_url, *model()->GetDefaultSearchProvider()); AssertEquals(*cloned_url, *model()->GetDefaultSearchProvider());
} }
TEST_F(TemplateURLServiceTest, RepairPrepopulatedSearchEngines) { TEST_F(TemplateURLServiceTest, RepairPrepopulatedSearchEngines) {
test_util_->VerifyLoad(); test_util()->VerifyLoad();
// Edit Google search engine. // Edit Google search engine.
TemplateURL* google = model()->GetTemplateURLForKeyword( TemplateURL* google = model()->GetTemplateURLForKeyword(
...@@ -835,12 +836,12 @@ TEST_F(TemplateURLServiceTest, RepairSearchEnginesWithManagedDefault) { ...@@ -835,12 +836,12 @@ TEST_F(TemplateURLServiceTest, RepairSearchEnginesWithManagedDefault) {
const char kEncodings[] = "UTF-16;UTF-32"; const char kEncodings[] = "UTF-16;UTF-32";
const char kAlternateURL[] = "http://test.com/search#t={searchTerms}"; const char kAlternateURL[] = "http://test.com/search#t={searchTerms}";
const char kSearchTermsReplacementKey[] = "espv"; const char kSearchTermsReplacementKey[] = "espv";
test_util_->SetManagedDefaultSearchPreferences(true, kName, kKeyword, test_util()->SetManagedDefaultSearchPreferences(true, kName, kKeyword,
kSearchURL, std::string(), kSearchURL, std::string(),
kIconURL, kEncodings, kIconURL, kEncodings,
kAlternateURL, kAlternateURL,
kSearchTermsReplacementKey); kSearchTermsReplacementKey);
test_util_->VerifyLoad(); test_util()->VerifyLoad();
// Verify that the default manager we are getting is the managed one. // Verify that the default manager we are getting is the managed one.
TemplateURLData data; TemplateURLData data;
data.short_name = ASCIIToUTF16(kName); data.short_name = ASCIIToUTF16(kName);
...@@ -883,7 +884,7 @@ TEST_F(TemplateURLServiceTest, UpdateKeywordSearchTermsForURL) { ...@@ -883,7 +884,7 @@ TEST_F(TemplateURLServiceTest, UpdateKeywordSearchTermsForURL) {
{ "http://x/foo?query=b#q=xx", base::string16() }, { "http://x/foo?query=b#q=xx", base::string16() },
}; };
test_util_->ChangeModelToLoadState(); test_util()->ChangeModelToLoadState();
AddKeywordWithDate("name", "x", "http://x/foo?q={searchTerms}", AddKeywordWithDate("name", "x", "http://x/foo?q={searchTerms}",
"http://sugg1", "http://x/foo#query={searchTerms}", "http://sugg1", "http://x/foo#query={searchTerms}",
"http://icon1", false, "UTF-8;UTF-16", Time(), Time()); "http://icon1", false, "UTF-8;UTF-16", Time(), Time());
...@@ -893,7 +894,7 @@ TEST_F(TemplateURLServiceTest, UpdateKeywordSearchTermsForURL) { ...@@ -893,7 +894,7 @@ TEST_F(TemplateURLServiceTest, UpdateKeywordSearchTermsForURL) {
GURL(data[i].url), false GURL(data[i].url), false
}; };
model()->UpdateKeywordSearchTermsForURL(details); model()->UpdateKeywordSearchTermsForURL(details);
EXPECT_EQ(data[i].term, test_util_->GetAndClearSearchTerm()); EXPECT_EQ(data[i].term, test_util()->GetAndClearSearchTerm());
} }
} }
...@@ -906,7 +907,7 @@ TEST_F(TemplateURLServiceTest, DontUpdateKeywordSearchForNonReplaceable) { ...@@ -906,7 +907,7 @@ TEST_F(TemplateURLServiceTest, DontUpdateKeywordSearchForNonReplaceable) {
{ "http://x/foo?y=xx" }, { "http://x/foo?y=xx" },
}; };
test_util_->ChangeModelToLoadState(); test_util()->ChangeModelToLoadState();
AddKeywordWithDate("name", "x", "http://x/foo", "http://sugg1", std::string(), AddKeywordWithDate("name", "x", "http://x/foo", "http://sugg1", std::string(),
"http://icon1", false, "UTF-8;UTF-16", Time(), Time()); "http://icon1", false, "UTF-8;UTF-16", Time(), Time());
...@@ -915,16 +916,16 @@ TEST_F(TemplateURLServiceTest, DontUpdateKeywordSearchForNonReplaceable) { ...@@ -915,16 +916,16 @@ TEST_F(TemplateURLServiceTest, DontUpdateKeywordSearchForNonReplaceable) {
GURL(data[i].url), false GURL(data[i].url), false
}; };
model()->UpdateKeywordSearchTermsForURL(details); model()->UpdateKeywordSearchTermsForURL(details);
ASSERT_EQ(base::string16(), test_util_->GetAndClearSearchTerm()); ASSERT_EQ(base::string16(), test_util()->GetAndClearSearchTerm());
} }
} }
TEST_F(TemplateURLServiceWithoutFallbackTest, ChangeGoogleBaseValue) { TEST_F(TemplateURLServiceWithoutFallbackTest, ChangeGoogleBaseValue) {
// NOTE: Do not load the prepopulate data, which also has a {google:baseURL} // NOTE: Do not load the prepopulate data, which also has a {google:baseURL}
// keyword in it and would confuse this test. // keyword in it and would confuse this test.
test_util_->ChangeModelToLoadState(); test_util()->ChangeModelToLoadState();
test_util_->SetGoogleBaseURL(GURL("http://google.com/")); test_util()->SetGoogleBaseURL(GURL("http://google.com/"));
const TemplateURL* t_url = AddKeywordWithDate( const TemplateURL* t_url = AddKeywordWithDate(
"name", "google.com", "{google:baseURL}?q={searchTerms}", "http://sugg1", "name", "google.com", "{google:baseURL}?q={searchTerms}", "http://sugg1",
std::string(), "http://icon1", false, "UTF-8;UTF-16", Time(), Time()); std::string(), "http://icon1", false, "UTF-8;UTF-16", Time(), Time());
...@@ -933,8 +934,8 @@ TEST_F(TemplateURLServiceWithoutFallbackTest, ChangeGoogleBaseValue) { ...@@ -933,8 +934,8 @@ TEST_F(TemplateURLServiceWithoutFallbackTest, ChangeGoogleBaseValue) {
EXPECT_EQ(ASCIIToUTF16("google.com"), t_url->keyword()); EXPECT_EQ(ASCIIToUTF16("google.com"), t_url->keyword());
// Change the Google base url. // Change the Google base url.
test_util_->ResetObserverCount(); test_util()->ResetObserverCount();
test_util_->SetGoogleBaseURL(GURL("http://google.co.uk/")); test_util()->SetGoogleBaseURL(GURL("http://google.co.uk/"));
VerifyObserverCount(1); VerifyObserverCount(1);
// Make sure the host->TemplateURL map was updated appropriately. // Make sure the host->TemplateURL map was updated appropriately.
...@@ -951,7 +952,7 @@ TEST_F(TemplateURLServiceWithoutFallbackTest, ChangeGoogleBaseValue) { ...@@ -951,7 +952,7 @@ TEST_F(TemplateURLServiceWithoutFallbackTest, ChangeGoogleBaseValue) {
"manual", "google.de", "http://google.de/search?q={searchTerms}", "manual", "google.de", "http://google.de/search?q={searchTerms}",
std::string(), std::string(), std::string(), false, "UTF-8", Time(), std::string(), std::string(), std::string(), false, "UTF-8", Time(),
Time()); Time());
test_util_->SetGoogleBaseURL(GURL("http://google.de")); test_util()->SetGoogleBaseURL(GURL("http://google.de"));
// Verify that the manual entry is untouched, and the autogenerated keyword // Verify that the manual entry is untouched, and the autogenerated keyword
// has not changed. // has not changed.
...@@ -966,7 +967,7 @@ TEST_F(TemplateURLServiceWithoutFallbackTest, ChangeGoogleBaseValue) { ...@@ -966,7 +967,7 @@ TEST_F(TemplateURLServiceWithoutFallbackTest, ChangeGoogleBaseValue) {
// Change the base URL again and verify that the autogenerated keyword follows // Change the base URL again and verify that the autogenerated keyword follows
// even though it didn't match the base URL, while the manual entry is still // even though it didn't match the base URL, while the manual entry is still
// untouched. // untouched.
test_util_->SetGoogleBaseURL(GURL("http://google.fr/")); test_util()->SetGoogleBaseURL(GURL("http://google.fr/"));
ASSERT_EQ(manual, model()->GetTemplateURLForHost("google.de")); ASSERT_EQ(manual, model()->GetTemplateURLForHost("google.de"));
EXPECT_EQ("google.de", manual->url_ref().GetHost(search_terms_data())); EXPECT_EQ("google.de", manual->url_ref().GetHost(search_terms_data()));
EXPECT_EQ(ASCIIToUTF16("google.de"), manual->keyword()); EXPECT_EQ(ASCIIToUTF16("google.de"), manual->keyword());
...@@ -979,8 +980,8 @@ TEST_F(TemplateURLServiceWithoutFallbackTest, ChangeGoogleBaseValue) { ...@@ -979,8 +980,8 @@ TEST_F(TemplateURLServiceWithoutFallbackTest, ChangeGoogleBaseValue) {
// Make sure TemplateURLService generates a KEYWORD_GENERATED visit for // Make sure TemplateURLService generates a KEYWORD_GENERATED visit for
// KEYWORD visits. // KEYWORD visits.
TEST_F(TemplateURLServiceTest, GenerateVisitOnKeyword) { TEST_F(TemplateURLServiceTest, GenerateVisitOnKeyword) {
test_util_->VerifyLoad(); test_util()->VerifyLoad();
ASSERT_TRUE(test_util_->profile()->CreateHistoryService(true, false)); ASSERT_TRUE(test_util()->profile()->CreateHistoryService(true, false));
// Create a keyword. // Create a keyword.
TemplateURL* t_url = AddKeywordWithDate( TemplateURL* t_url = AddKeywordWithDate(
...@@ -990,7 +991,7 @@ TEST_F(TemplateURLServiceTest, GenerateVisitOnKeyword) { ...@@ -990,7 +991,7 @@ TEST_F(TemplateURLServiceTest, GenerateVisitOnKeyword) {
// Add a visit that matches the url of the keyword. // Add a visit that matches the url of the keyword.
HistoryService* history = HistoryService* history =
HistoryServiceFactory::GetForProfile(test_util_->profile(), HistoryServiceFactory::GetForProfile(test_util()->profile(),
Profile::EXPLICIT_ACCESS); Profile::EXPLICIT_ACCESS);
history->AddPage( history->AddPage(
GURL(t_url->url_ref().ReplaceSearchTerms( GURL(t_url->url_ref().ReplaceSearchTerms(
...@@ -1000,7 +1001,7 @@ TEST_F(TemplateURLServiceTest, GenerateVisitOnKeyword) { ...@@ -1000,7 +1001,7 @@ TEST_F(TemplateURLServiceTest, GenerateVisitOnKeyword) {
content::PAGE_TRANSITION_KEYWORD, history::SOURCE_BROWSED, false); content::PAGE_TRANSITION_KEYWORD, history::SOURCE_BROWSED, false);
// Wait for history to finish processing the request. // Wait for history to finish processing the request.
test_util_->profile()->BlockUntilHistoryProcessesPendingRequests(); test_util()->profile()->BlockUntilHistoryProcessesPendingRequests();
// Query history for the generated url. // Query history for the generated url.
base::CancelableTaskTracker tracker; base::CancelableTaskTracker tracker;
...@@ -1012,7 +1013,7 @@ TEST_F(TemplateURLServiceTest, GenerateVisitOnKeyword) { ...@@ -1012,7 +1013,7 @@ TEST_F(TemplateURLServiceTest, GenerateVisitOnKeyword) {
&tracker); &tracker);
// Wait for the request to be processed. // Wait for the request to be processed.
test_util_->profile()->BlockUntilHistoryProcessesPendingRequests(); test_util()->profile()->BlockUntilHistoryProcessesPendingRequests();
// And make sure the url and visit were added. // And make sure the url and visit were added.
EXPECT_TRUE(callback.success); EXPECT_TRUE(callback.success);
...@@ -1028,14 +1029,14 @@ TEST_F(TemplateURLServiceTest, LoadDeletesUnusedProvider) { ...@@ -1028,14 +1029,14 @@ TEST_F(TemplateURLServiceTest, LoadDeletesUnusedProvider) {
// Create a preloaded template url. Add it to a loaded model and wait for the // Create a preloaded template url. Add it to a loaded model and wait for the
// saves to finish. // saves to finish.
TemplateURL* t_url = CreatePreloadedTemplateURL(true, 999999); TemplateURL* t_url = CreatePreloadedTemplateURL(true, 999999);
test_util_->ChangeModelToLoadState(); test_util()->ChangeModelToLoadState();
model()->Add(t_url); model()->Add(t_url);
ASSERT_TRUE( ASSERT_TRUE(
model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) != NULL); model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) != NULL);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
// Ensure that merging clears this engine. // Ensure that merging clears this engine.
test_util_->ResetModel(true); test_util()->ResetModel(true);
ASSERT_TRUE( ASSERT_TRUE(
model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) == NULL); model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) == NULL);
...@@ -1044,7 +1045,7 @@ TEST_F(TemplateURLServiceTest, LoadDeletesUnusedProvider) { ...@@ -1044,7 +1045,7 @@ TEST_F(TemplateURLServiceTest, LoadDeletesUnusedProvider) {
// Reload the model to verify that the database was updated as a result of the // Reload the model to verify that the database was updated as a result of the
// merge. // merge.
test_util_->ResetModel(true); test_util()->ResetModel(true);
ASSERT_TRUE( ASSERT_TRUE(
model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) == NULL); model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) == NULL);
} }
...@@ -1054,7 +1055,7 @@ TEST_F(TemplateURLServiceTest, LoadDeletesUnusedProvider) { ...@@ -1054,7 +1055,7 @@ TEST_F(TemplateURLServiceTest, LoadDeletesUnusedProvider) {
TEST_F(TemplateURLServiceTest, LoadRetainsModifiedProvider) { TEST_F(TemplateURLServiceTest, LoadRetainsModifiedProvider) {
// Create a preloaded template url and add it to a loaded model. // Create a preloaded template url and add it to a loaded model.
TemplateURL* t_url = CreatePreloadedTemplateURL(false, 999999); TemplateURL* t_url = CreatePreloadedTemplateURL(false, 999999);
test_util_->ChangeModelToLoadState(); test_util()->ChangeModelToLoadState();
model()->Add(t_url); model()->Add(t_url);
// Do the copy after t_url is added so that the id is set. // Do the copy after t_url is added so that the id is set.
...@@ -1065,7 +1066,7 @@ TEST_F(TemplateURLServiceTest, LoadRetainsModifiedProvider) { ...@@ -1065,7 +1066,7 @@ TEST_F(TemplateURLServiceTest, LoadRetainsModifiedProvider) {
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
// Ensure that merging won't clear it if the user has edited it. // Ensure that merging won't clear it if the user has edited it.
test_util_->ResetModel(true); test_util()->ResetModel(true);
const TemplateURL* url_for_unittest = const TemplateURL* url_for_unittest =
model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest"));
ASSERT_TRUE(url_for_unittest != NULL); ASSERT_TRUE(url_for_unittest != NULL);
...@@ -1075,7 +1076,7 @@ TEST_F(TemplateURLServiceTest, LoadRetainsModifiedProvider) { ...@@ -1075,7 +1076,7 @@ TEST_F(TemplateURLServiceTest, LoadRetainsModifiedProvider) {
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
// Reload the model to verify that save/reload retains the item. // Reload the model to verify that save/reload retains the item.
test_util_->ResetModel(true); test_util()->ResetModel(true);
ASSERT_TRUE( ASSERT_TRUE(
model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) != NULL); model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) != NULL);
} }
...@@ -1084,7 +1085,7 @@ TEST_F(TemplateURLServiceTest, LoadRetainsModifiedProvider) { ...@@ -1084,7 +1085,7 @@ TEST_F(TemplateURLServiceTest, LoadRetainsModifiedProvider) {
// prepopulated engines that no longer exist in the prepopulate data if // prepopulated engines that no longer exist in the prepopulate data if
// it has been modified by the user. // it has been modified by the user.
TEST_F(TemplateURLServiceTest, LoadSavesPrepopulatedDefaultSearchProvider) { TEST_F(TemplateURLServiceTest, LoadSavesPrepopulatedDefaultSearchProvider) {
test_util_->VerifyLoad(); test_util()->VerifyLoad();
// Verify that the default search provider is set to something. // Verify that the default search provider is set to something.
TemplateURL* default_search = model()->GetDefaultSearchProvider(); TemplateURL* default_search = model()->GetDefaultSearchProvider();
ASSERT_TRUE(default_search != NULL); ASSERT_TRUE(default_search != NULL);
...@@ -1095,7 +1096,7 @@ TEST_F(TemplateURLServiceTest, LoadSavesPrepopulatedDefaultSearchProvider) { ...@@ -1095,7 +1096,7 @@ TEST_F(TemplateURLServiceTest, LoadSavesPrepopulatedDefaultSearchProvider) {
// Reload the model and check that the default search provider // Reload the model and check that the default search provider
// was properly saved. // was properly saved.
test_util_->ResetModel(true); test_util()->ResetModel(true);
default_search = model()->GetDefaultSearchProvider(); default_search = model()->GetDefaultSearchProvider();
ASSERT_TRUE(default_search != NULL); ASSERT_TRUE(default_search != NULL);
AssertEquals(*cloned_url, *default_search); AssertEquals(*cloned_url, *default_search);
...@@ -1109,7 +1110,7 @@ TEST_F(TemplateURLServiceTest, LoadRetainsDefaultProvider) { ...@@ -1109,7 +1110,7 @@ TEST_F(TemplateURLServiceTest, LoadRetainsDefaultProvider) {
// is not in the current set of preloaded template urls and save // is not in the current set of preloaded template urls and save
// the result. // the result.
TemplateURL* t_url = CreatePreloadedTemplateURL(true, 999999); TemplateURL* t_url = CreatePreloadedTemplateURL(true, 999999);
test_util_->ChangeModelToLoadState(); test_util()->ChangeModelToLoadState();
model()->Add(t_url); model()->Add(t_url);
model()->SetUserSelectedDefaultSearchProvider(t_url); model()->SetUserSelectedDefaultSearchProvider(t_url);
// Do the copy after t_url is added and set as default so that its // Do the copy after t_url is added and set as default so that its
...@@ -1122,7 +1123,7 @@ TEST_F(TemplateURLServiceTest, LoadRetainsDefaultProvider) { ...@@ -1122,7 +1123,7 @@ TEST_F(TemplateURLServiceTest, LoadRetainsDefaultProvider) {
// Ensure that merging won't clear the prepopulated template url // Ensure that merging won't clear the prepopulated template url
// which is no longer present if it's the default engine. // which is no longer present if it's the default engine.
test_util_->ResetModel(true); test_util()->ResetModel(true);
{ {
const TemplateURL* keyword_url = const TemplateURL* keyword_url =
model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest"));
...@@ -1135,7 +1136,7 @@ TEST_F(TemplateURLServiceTest, LoadRetainsDefaultProvider) { ...@@ -1135,7 +1136,7 @@ TEST_F(TemplateURLServiceTest, LoadRetainsDefaultProvider) {
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
// Reload the model to verify that the update was saved. // Reload the model to verify that the update was saved.
test_util_->ResetModel(true); test_util()->ResetModel(true);
{ {
const TemplateURL* keyword_url = const TemplateURL* keyword_url =
model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest"));
...@@ -1149,7 +1150,7 @@ TEST_F(TemplateURLServiceTest, LoadRetainsDefaultProvider) { ...@@ -1149,7 +1150,7 @@ TEST_F(TemplateURLServiceTest, LoadRetainsDefaultProvider) {
// missing and not managed. // missing and not managed.
TEST_F(TemplateURLServiceTest, LoadEnsuresDefaultSearchProviderExists) { TEST_F(TemplateURLServiceTest, LoadEnsuresDefaultSearchProviderExists) {
// Force the model to load and make sure we have a default search provider. // Force the model to load and make sure we have a default search provider.
test_util_->VerifyLoad(); test_util()->VerifyLoad();
EXPECT_TRUE(model()->GetDefaultSearchProvider()); EXPECT_TRUE(model()->GetDefaultSearchProvider());
EXPECT_TRUE(model()->GetDefaultSearchProvider()->SupportsReplacement( EXPECT_TRUE(model()->GetDefaultSearchProvider()->SupportsReplacement(
...@@ -1163,7 +1164,7 @@ TEST_F(TemplateURLServiceTest, LoadEnsuresDefaultSearchProviderExists) { ...@@ -1163,7 +1164,7 @@ TEST_F(TemplateURLServiceTest, LoadEnsuresDefaultSearchProviderExists) {
// Reset the model and load it. There should be a usable default search // Reset the model and load it. There should be a usable default search
// provider. // provider.
test_util_->ResetModel(true); test_util()->ResetModel(true);
ASSERT_TRUE(model()->GetDefaultSearchProvider()); ASSERT_TRUE(model()->GetDefaultSearchProvider());
EXPECT_TRUE(model()->GetDefaultSearchProvider()->SupportsReplacement( EXPECT_TRUE(model()->GetDefaultSearchProvider()->SupportsReplacement(
...@@ -1173,13 +1174,12 @@ TEST_F(TemplateURLServiceTest, LoadEnsuresDefaultSearchProviderExists) { ...@@ -1173,13 +1174,12 @@ TEST_F(TemplateURLServiceTest, LoadEnsuresDefaultSearchProviderExists) {
// Simulates failing to load the webdb and makes sure the default search // Simulates failing to load the webdb and makes sure the default search
// provider is valid. // provider is valid.
TEST_F(TemplateURLServiceTest, FailedInit) { TEST_F(TemplateURLServiceTest, FailedInit) {
test_util_->VerifyLoad(); test_util()->VerifyLoad();
test_util_->ClearModel(); test_util()->ClearModel();
WebDataServiceFactory::GetKeywordWebDataForProfile( test_util()->web_data_service()->ShutdownDatabase();
test_util_->profile(), Profile::EXPLICIT_ACCESS)->ShutdownDatabase();
test_util_->ResetModel(false); test_util()->ResetModel(false);
model()->Load(); model()->Load();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
...@@ -1190,9 +1190,9 @@ TEST_F(TemplateURLServiceTest, FailedInit) { ...@@ -1190,9 +1190,9 @@ TEST_F(TemplateURLServiceTest, FailedInit) {
// the default search as managed. Also check that we are getting the right // the default search as managed. Also check that we are getting the right
// values. // values.
TEST_F(TemplateURLServiceTest, TestManagedDefaultSearch) { TEST_F(TemplateURLServiceTest, TestManagedDefaultSearch) {
test_util_->VerifyLoad(); test_util()->VerifyLoad();
const size_t initial_count = model()->GetTemplateURLs().size(); const size_t initial_count = model()->GetTemplateURLs().size();
test_util_->ResetObserverCount(); test_util()->ResetObserverCount();
// Set a regular default search provider. // Set a regular default search provider.
TemplateURL* regular_default = AddKeywordWithDate( TemplateURL* regular_default = AddKeywordWithDate(
...@@ -1214,7 +1214,7 @@ TEST_F(TemplateURLServiceTest, TestManagedDefaultSearch) { ...@@ -1214,7 +1214,7 @@ TEST_F(TemplateURLServiceTest, TestManagedDefaultSearch) {
const char kEncodings[] = "UTF-16;UTF-32"; const char kEncodings[] = "UTF-16;UTF-32";
const char kAlternateURL[] = "http://test.com/search#t={searchTerms}"; const char kAlternateURL[] = "http://test.com/search#t={searchTerms}";
const char kSearchTermsReplacementKey[] = "espv"; const char kSearchTermsReplacementKey[] = "espv";
test_util_->SetManagedDefaultSearchPreferences(true, kName, kKeyword, test_util()->SetManagedDefaultSearchPreferences(true, kName, kKeyword,
kSearchURL, std::string(), kIconURL, kEncodings, kAlternateURL, kSearchURL, std::string(), kIconURL, kEncodings, kAlternateURL,
kSearchTermsReplacementKey); kSearchTermsReplacementKey);
VerifyObserverFired(); VerifyObserverFired();
...@@ -1242,7 +1242,7 @@ TEST_F(TemplateURLServiceTest, TestManagedDefaultSearch) { ...@@ -1242,7 +1242,7 @@ TEST_F(TemplateURLServiceTest, TestManagedDefaultSearch) {
const char kNewKeyword[] = "other.com"; const char kNewKeyword[] = "other.com";
const char kNewSearchURL[] = "http://other.com/search?t={searchTerms}"; const char kNewSearchURL[] = "http://other.com/search?t={searchTerms}";
const char kNewSuggestURL[] = "http://other.com/suggest?t={searchTerms}"; const char kNewSuggestURL[] = "http://other.com/suggest?t={searchTerms}";
test_util_->SetManagedDefaultSearchPreferences(true, kNewName, kNewKeyword, test_util()->SetManagedDefaultSearchPreferences(true, kNewName, kNewKeyword,
kNewSearchURL, kNewSuggestURL, std::string(), std::string(), kNewSearchURL, kNewSuggestURL, std::string(), std::string(),
std::string(), std::string()); std::string(), std::string());
VerifyObserverFired(); VerifyObserverFired();
...@@ -1262,7 +1262,7 @@ TEST_F(TemplateURLServiceTest, TestManagedDefaultSearch) { ...@@ -1262,7 +1262,7 @@ TEST_F(TemplateURLServiceTest, TestManagedDefaultSearch) {
EXPECT_EQ(actual_managed_default->show_in_default_list(), true); EXPECT_EQ(actual_managed_default->show_in_default_list(), true);
// Remove all the managed prefs and check that we are no longer managed. // Remove all the managed prefs and check that we are no longer managed.
test_util_->RemoveManagedDefaultSearchPreferences(); test_util()->RemoveManagedDefaultSearchPreferences();
VerifyObserverFired(); VerifyObserverFired();
EXPECT_FALSE(model()->is_default_search_managed()); EXPECT_FALSE(model()->is_default_search_managed());
EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size());
...@@ -1274,7 +1274,7 @@ TEST_F(TemplateURLServiceTest, TestManagedDefaultSearch) { ...@@ -1274,7 +1274,7 @@ TEST_F(TemplateURLServiceTest, TestManagedDefaultSearch) {
EXPECT_EQ(actual_final_managed_default->show_in_default_list(), true); EXPECT_EQ(actual_final_managed_default->show_in_default_list(), true);
// Disable the default search provider through policy. // Disable the default search provider through policy.
test_util_->SetManagedDefaultSearchPreferences(false, std::string(), test_util()->SetManagedDefaultSearchPreferences(false, std::string(),
std::string(), std::string(), std::string(), std::string(), std::string(), std::string(), std::string(), std::string(),
std::string(), std::string(), std::string()); std::string(), std::string(), std::string());
VerifyObserverFired(); VerifyObserverFired();
...@@ -1283,7 +1283,7 @@ TEST_F(TemplateURLServiceTest, TestManagedDefaultSearch) { ...@@ -1283,7 +1283,7 @@ TEST_F(TemplateURLServiceTest, TestManagedDefaultSearch) {
EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size());
// Re-enable it. // Re-enable it.
test_util_->SetManagedDefaultSearchPreferences(true, kName, kKeyword, test_util()->SetManagedDefaultSearchPreferences(true, kName, kKeyword,
kSearchURL, std::string(), kIconURL, kEncodings, kAlternateURL, kSearchURL, std::string(), kIconURL, kEncodings, kAlternateURL,
kSearchTermsReplacementKey); kSearchTermsReplacementKey);
VerifyObserverFired(); VerifyObserverFired();
...@@ -1300,8 +1300,8 @@ TEST_F(TemplateURLServiceTest, TestManagedDefaultSearch) { ...@@ -1300,8 +1300,8 @@ TEST_F(TemplateURLServiceTest, TestManagedDefaultSearch) {
// This checks against regressions of http://crbug.com/67180 // This checks against regressions of http://crbug.com/67180
// First, remove the preferences, reset the model, and set a default. // First, remove the preferences, reset the model, and set a default.
test_util_->RemoveManagedDefaultSearchPreferences(); test_util()->RemoveManagedDefaultSearchPreferences();
test_util_->ResetModel(true); test_util()->ResetModel(true);
TemplateURL* new_default = TemplateURL* new_default =
model()->GetTemplateURLForKeyword(ASCIIToUTF16("key1")); model()->GetTemplateURLForKeyword(ASCIIToUTF16("key1"));
ASSERT_FALSE(new_default == NULL); ASSERT_FALSE(new_default == NULL);
...@@ -1309,11 +1309,11 @@ TEST_F(TemplateURLServiceTest, TestManagedDefaultSearch) { ...@@ -1309,11 +1309,11 @@ TEST_F(TemplateURLServiceTest, TestManagedDefaultSearch) {
EXPECT_EQ(new_default, model()->GetDefaultSearchProvider()); EXPECT_EQ(new_default, model()->GetDefaultSearchProvider());
// Now reset the model again but load it after setting the preferences. // Now reset the model again but load it after setting the preferences.
test_util_->ResetModel(false); test_util()->ResetModel(false);
test_util_->SetManagedDefaultSearchPreferences(false, std::string(), test_util()->SetManagedDefaultSearchPreferences(false, std::string(),
std::string(), std::string(), std::string(), std::string(), std::string(), std::string(), std::string(), std::string(),
std::string(), std::string(), std::string()); std::string(), std::string(), std::string());
test_util_->VerifyLoad(); test_util()->VerifyLoad();
EXPECT_TRUE(model()->is_default_search_managed()); EXPECT_TRUE(model()->is_default_search_managed());
EXPECT_TRUE(model()->GetDefaultSearchProvider() == NULL); EXPECT_TRUE(model()->GetDefaultSearchProvider() == NULL);
} }
...@@ -1322,7 +1322,7 @@ TEST_F(TemplateURLServiceTest, TestManagedDefaultSearch) { ...@@ -1322,7 +1322,7 @@ TEST_F(TemplateURLServiceTest, TestManagedDefaultSearch) {
// assigns it a newly generated GUID. // assigns it a newly generated GUID.
TEST_F(TemplateURLServiceTest, PatchEmptySyncGUID) { TEST_F(TemplateURLServiceTest, PatchEmptySyncGUID) {
// Add a new TemplateURL. // Add a new TemplateURL.
test_util_->VerifyLoad(); test_util()->VerifyLoad();
const size_t initial_count = model()->GetTemplateURLs().size(); const size_t initial_count = model()->GetTemplateURLs().size();
TemplateURLData data; TemplateURLData data;
...@@ -1339,7 +1339,7 @@ TEST_F(TemplateURLServiceTest, PatchEmptySyncGUID) { ...@@ -1339,7 +1339,7 @@ TEST_F(TemplateURLServiceTest, PatchEmptySyncGUID) {
// Reload the model to verify it was actually saved to the database and // Reload the model to verify it was actually saved to the database and
// assigned a new GUID when brought back. // assigned a new GUID when brought back.
test_util_->ResetModel(true); test_util()->ResetModel(true);
ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size());
const TemplateURL* loaded_url = const TemplateURL* loaded_url =
model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"));
...@@ -1351,7 +1351,7 @@ TEST_F(TemplateURLServiceTest, PatchEmptySyncGUID) { ...@@ -1351,7 +1351,7 @@ TEST_F(TemplateURLServiceTest, PatchEmptySyncGUID) {
// process de-dupes them. // process de-dupes them.
TEST_F(TemplateURLServiceTest, DuplicateInputEncodings) { TEST_F(TemplateURLServiceTest, DuplicateInputEncodings) {
// Add a new TemplateURL. // Add a new TemplateURL.
test_util_->VerifyLoad(); test_util()->VerifyLoad();
const size_t initial_count = model()->GetTemplateURLs().size(); const size_t initial_count = model()->GetTemplateURLs().size();
TemplateURLData data; TemplateURLData data;
...@@ -1380,7 +1380,7 @@ TEST_F(TemplateURLServiceTest, DuplicateInputEncodings) { ...@@ -1380,7 +1380,7 @@ TEST_F(TemplateURLServiceTest, DuplicateInputEncodings) {
// Reload the model to verify it was actually saved to the database and the // Reload the model to verify it was actually saved to the database and the
// duplicate encodings were removed. // duplicate encodings were removed.
test_util_->ResetModel(true); test_util()->ResetModel(true);
ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size());
loaded_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); loaded_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"));
ASSERT_FALSE(loaded_url == NULL); ASSERT_FALSE(loaded_url == NULL);
...@@ -1388,7 +1388,7 @@ TEST_F(TemplateURLServiceTest, DuplicateInputEncodings) { ...@@ -1388,7 +1388,7 @@ TEST_F(TemplateURLServiceTest, DuplicateInputEncodings) {
} }
TEST_F(TemplateURLServiceTest, DefaultExtensionEngine) { TEST_F(TemplateURLServiceTest, DefaultExtensionEngine) {
test_util_->VerifyLoad(); test_util()->VerifyLoad();
// Add third-party default search engine. // Add third-party default search engine.
TemplateURL* user_dse = AddKeywordWithDate( TemplateURL* user_dse = AddKeywordWithDate(
"user", "user", "http://www.goo.com/s?q={searchTerms}", "user", "user", "http://www.goo.com/s?q={searchTerms}",
...@@ -1414,7 +1414,7 @@ TEST_F(TemplateURLServiceTest, DefaultExtensionEngine) { ...@@ -1414,7 +1414,7 @@ TEST_F(TemplateURLServiceTest, DefaultExtensionEngine) {
} }
TEST_F(TemplateURLServiceTest, ExtensionEnginesNotPersist) { TEST_F(TemplateURLServiceTest, ExtensionEnginesNotPersist) {
test_util_->VerifyLoad(); test_util()->VerifyLoad();
// Add third-party default search engine. // Add third-party default search engine.
TemplateURL* user_dse = AddKeywordWithDate( TemplateURL* user_dse = AddKeywordWithDate(
"user", "user", "http://www.goo.com/s?q={searchTerms}", "user", "user", "http://www.goo.com/s?q={searchTerms}",
...@@ -1444,7 +1444,7 @@ TEST_F(TemplateURLServiceTest, ExtensionEnginesNotPersist) { ...@@ -1444,7 +1444,7 @@ TEST_F(TemplateURLServiceTest, ExtensionEnginesNotPersist) {
model()->AddExtensionControlledTURL(ext_dse, extension_info.Pass()); model()->AddExtensionControlledTURL(ext_dse, extension_info.Pass());
EXPECT_EQ(ext_dse, model()->GetDefaultSearchProvider()); EXPECT_EQ(ext_dse, model()->GetDefaultSearchProvider());
test_util_->ResetModel(true); test_util()->ResetModel(true);
user_dse = model()->GetTemplateURLForKeyword(ASCIIToUTF16("user")); user_dse = model()->GetTemplateURLForKeyword(ASCIIToUTF16("user"));
ExpectSimilar(user_dse, model()->GetDefaultSearchProvider()); ExpectSimilar(user_dse, model()->GetDefaultSearchProvider());
EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1")));
...@@ -1460,10 +1460,10 @@ TEST_F(TemplateURLServiceTest, ExtensionEngineVsPolicy) { ...@@ -1460,10 +1460,10 @@ TEST_F(TemplateURLServiceTest, ExtensionEngineVsPolicy) {
const char kEncodings[] = "UTF-16;UTF-32"; const char kEncodings[] = "UTF-16;UTF-32";
const char kAlternateURL[] = "http://test.com/search#t={searchTerms}"; const char kAlternateURL[] = "http://test.com/search#t={searchTerms}";
const char kSearchTermsReplacementKey[] = "espv"; const char kSearchTermsReplacementKey[] = "espv";
test_util_->SetManagedDefaultSearchPreferences( test_util()->SetManagedDefaultSearchPreferences(
true, kName, kKeyword, kSearchURL, std::string(), kIconURL, kEncodings, true, kName, kKeyword, kSearchURL, std::string(), kIconURL, kEncodings,
kAlternateURL, kSearchTermsReplacementKey); kAlternateURL, kSearchTermsReplacementKey);
test_util_->VerifyLoad(); test_util()->VerifyLoad();
// Verify that the default manager we are getting is the managed one. // Verify that the default manager we are getting is the managed one.
TemplateURLData data; TemplateURLData data;
data.short_name = ASCIIToUTF16(kName); data.short_name = ASCIIToUTF16(kName);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment