diff options
author | levin@chromium.org <levin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-16 19:29:09 +0000 |
---|---|---|
committer | levin@chromium.org <levin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-16 19:29:09 +0000 |
commit | 65651f25f4409a2003a45e1cb30e1d0a4ec2e9f4 (patch) | |
tree | ba8a35e3bca0d1b0529b5cb8825477e0b06c7b36 /chrome | |
parent | a0e7e3e7b6204e4a83c15371c823b8b12ad69da4 (diff) | |
download | chromium_src-65651f25f4409a2003a45e1cb30e1d0a4ec2e9f4.zip chromium_src-65651f25f4409a2003a45e1cb30e1d0a4ec2e9f4.tar.gz chromium_src-65651f25f4409a2003a45e1cb30e1d0a4ec2e9f4.tar.bz2 |
Make a utility test class that is useful to any code which is trying to create
a TemplateURLModel and persist it.
This only affects test code and should have no functionality change (just code
re-arrangement).
This change prepares the way for an implementation of SearchProviderInstallData
and a unit test for it.
BUG=38475
TEST=unit_tests --gtest_filter=Temp*
Review URL: http://codereview.chromium.org/3422006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@59689 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/search_engines/template_url.h | 2 | ||||
-rw-r--r-- | chrome/browser/search_engines/template_url_model.h | 2 | ||||
-rw-r--r-- | chrome/browser/search_engines/template_url_model_test_util.cc | 210 | ||||
-rw-r--r-- | chrome/browser/search_engines/template_url_model_test_util.h | 97 | ||||
-rw-r--r-- | chrome/browser/search_engines/template_url_model_unittest.cc | 430 | ||||
-rw-r--r-- | chrome/chrome_tests.gypi | 2 |
6 files changed, 455 insertions, 288 deletions
diff --git a/chrome/browser/search_engines/template_url.h b/chrome/browser/search_engines/template_url.h index ceaa0ecd2..7a4f12d 100644 --- a/chrome/browser/search_engines/template_url.h +++ b/chrome/browser/search_engines/template_url.h @@ -130,7 +130,7 @@ class TemplateURLRef { private: friend class SearchHostToURLsMapTest; friend class TemplateURL; - friend class TemplateURLModelTest; + friend class TemplateURLModelTestUtil; friend class TemplateURLTest; FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseParameterKnown); FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseParameterUnknown); diff --git a/chrome/browser/search_engines/template_url_model.h b/chrome/browser/search_engines/template_url_model.h index 44b5029..2ea0feb 100644 --- a/chrome/browser/search_engines/template_url_model.h +++ b/chrome/browser/search_engines/template_url_model.h @@ -240,7 +240,7 @@ class TemplateURLModel : public WebDataServiceConsumer, DontUpdateKeywordSearchForNonReplaceable); FRIEND_TEST_ALL_PREFIXES(TemplateURLModelTest, ChangeGoogleBaseValue); FRIEND_TEST_ALL_PREFIXES(TemplateURLModelTest, MergeDeletesUnusedProviders); - friend class TemplateURLModelTest; + friend class TemplateURLModelTestUtil; typedef std::map<std::wstring, const TemplateURL*> KeywordToTemplateMap; typedef std::vector<const TemplateURL*> TemplateURLVector; diff --git a/chrome/browser/search_engines/template_url_model_test_util.cc b/chrome/browser/search_engines/template_url_model_test_util.cc new file mode 100644 index 0000000..91f0065 --- /dev/null +++ b/chrome/browser/search_engines/template_url_model_test_util.cc @@ -0,0 +1,210 @@ +// Copyright (c) 2010 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. + +#include "chrome/browser/search_engines/template_url_model_test_util.h" + +#include "base/file_util.h" +#include "base/message_loop.h" +#include "base/path_service.h" +#include "chrome/browser/search_engines/template_url.h" +#include "chrome/browser/search_engines/template_url_model.h" +#include "chrome/test/testing_profile.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace { + +// A Task used to coordinate when the database has finished processing +// requests. See note in BlockTillServiceProcessesRequests for details. +// +// When Run() schedules a QuitTask on the message loop it was created with. +class QuitTask2 : public Task { + public: + QuitTask2() : main_loop_(MessageLoop::current()) {} + + virtual void Run() { + main_loop_->PostTask(FROM_HERE, new MessageLoop::QuitTask()); + } + + private: + MessageLoop* main_loop_; +}; + +// Blocks the caller until thread has finished servicing all pending +// requests. +static void WaitForThreadToProcessRequests(ChromeThread::ID identifier) { + // Schedule a task on the thread that is processed after all + // pending requests on the thread. + ChromeThread::PostTask(identifier, FROM_HERE, new QuitTask2()); + // Run the current message loop. QuitTask2, when run, invokes Quit, + // which unblocks this. + MessageLoop::current()->Run(); +} + +} // namespace + +// Subclass the TestingProfile so that it can return a WebDataService. +class TemplateURLModelTestingProfile : public TestingProfile { + public: + TemplateURLModelTestingProfile() : TestingProfile() {} + + void SetUp(); + void TearDown(); + + virtual WebDataService* GetWebDataService(ServiceAccessType access) { + return service_.get(); + } + + private: + scoped_refptr<WebDataService> service_; + FilePath test_dir_; + scoped_ptr<ChromeThread> db_thread_; +}; + +// Trivial subclass of TemplateURLModel that records the last invocation of +// SetKeywordSearchTermsForURL. +class TestingTemplateURLModel : public TemplateURLModel { + public: + explicit TestingTemplateURLModel(Profile* profile) + : TemplateURLModel(profile) { + } + + std::wstring GetAndClearSearchTerm() { + std::wstring search_term; + search_term.swap(search_term_); + return search_term; + } + + protected: + virtual void SetKeywordSearchTermsForURL(const TemplateURL* t_url, + const GURL& url, + const std::wstring& term) { + search_term_ = term; + } + + private: + std::wstring search_term_; + + DISALLOW_COPY_AND_ASSIGN(TestingTemplateURLModel); +}; + +void TemplateURLModelTestingProfile::SetUp() { + db_thread_.reset(new ChromeThread(ChromeThread::DB)); + db_thread_->Start(); + + // Name a subdirectory of the temp directory. + ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &test_dir_)); + test_dir_ = test_dir_.AppendASCII("TemplateURLModelTest"); + + // Create a fresh, empty copy of this directory. + file_util::Delete(test_dir_, true); + file_util::CreateDirectory(test_dir_); + + FilePath path = test_dir_.AppendASCII("TestDataService.db"); + service_ = new WebDataService; + EXPECT_TRUE(service_->InitWithPath(path)); +} + +void TemplateURLModelTestingProfile::TearDown() { + // Clean up the test directory. + service_->Shutdown(); + // Note that we must ensure the DB thread is stopped after WDS + // shutdown (so it can commit pending transactions) but before + // deleting the test profile directory, otherwise we may not be + // able to delete it due to an open transaction. + db_thread_->Stop(); + + ASSERT_TRUE(file_util::Delete(test_dir_, true)); + ASSERT_FALSE(file_util::PathExists(test_dir_)); +} + +TemplateURLModelTestUtil::TemplateURLModelTestUtil() + : ui_thread_(ChromeThread::UI, &message_loop_), + changed_count_(0) { +} + +TemplateURLModelTestUtil::~TemplateURLModelTestUtil() { +} + +void TemplateURLModelTestUtil::SetUp() { + profile_.reset(new TemplateURLModelTestingProfile()); + profile_->SetUp(); + model_.reset(new TestingTemplateURLModel(profile_.get())); + model_->AddObserver(this); +} + +void TemplateURLModelTestUtil::TearDown() { + profile_->TearDown(); + TemplateURLRef::SetGoogleBaseURL(NULL); + + // Flush the message loop to make Purify happy. + message_loop_.RunAllPending(); +} + +void TemplateURLModelTestUtil::OnTemplateURLModelChanged() { + changed_count_++; +} + +void TemplateURLModelTestUtil::VerifyObserverCount(int expected_changed_count) { + ASSERT_EQ(expected_changed_count, changed_count_); + changed_count_ = 0; +} + +void TemplateURLModelTestUtil::ResetObserverCount() { + changed_count_ = 0; +} + +void TemplateURLModelTestUtil::BlockTillServiceProcessesRequests() { + WaitForThreadToProcessRequests(ChromeThread::DB); +} + +void TemplateURLModelTestUtil::BlockTillIOThreadProcessesRequests() { + WaitForThreadToProcessRequests(ChromeThread::IO); +} + +void TemplateURLModelTestUtil::VerifyLoad() { + ASSERT_FALSE(model_->loaded()); + model_->Load(); + BlockTillServiceProcessesRequests(); + VerifyObserverCount(1); +} + +void TemplateURLModelTestUtil::ChangeModelToLoadState() { + model_->ChangeToLoadedState(); + // Initialize the web data service so that the database gets updated with + // any changes made. + model_->service_ = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); +} + +void TemplateURLModelTestUtil::ClearModel() { + model_.reset(NULL); +} + +void TemplateURLModelTestUtil::ResetModel(bool verify_load) { + model_.reset(new TestingTemplateURLModel(profile_.get())); + model_->AddObserver(this); + changed_count_ = 0; + if (verify_load) + VerifyLoad(); +} + +std::wstring TemplateURLModelTestUtil::GetAndClearSearchTerm() { + return model_->GetAndClearSearchTerm(); +} + +void TemplateURLModelTestUtil::SetGoogleBaseURL( + const std::string& base_url) const { + TemplateURLRef::SetGoogleBaseURL(new std::string(base_url)); +} + +WebDataService* TemplateURLModelTestUtil::GetWebDataService() { + return profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); +} + +TemplateURLModel* TemplateURLModelTestUtil::model() const { + return model_.get(); +} + +TestingProfile* TemplateURLModelTestUtil::profile() const { + return profile_.get(); +} diff --git a/chrome/browser/search_engines/template_url_model_test_util.h b/chrome/browser/search_engines/template_url_model_test_util.h new file mode 100644 index 0000000..cdcafa9 --- /dev/null +++ b/chrome/browser/search_engines/template_url_model_test_util.h @@ -0,0 +1,97 @@ +// Copyright (c) 2010 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. + +#ifndef CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_MODEL_TEST_UTIL_H_ +#define CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_MODEL_TEST_UTIL_H_ +#pragma once + +#include "base/basictypes.h" +#include "base/message_loop.h" +#include "base/ref_counted.h" +#include "base/scoped_ptr.h" +#include "chrome/browser/chrome_thread.h" +#include "chrome/browser/search_engines/template_url_model_observer.h" + +#include <string> + +class TemplateURLModel; +class TemplateURLModelTestingProfile; +class TestingTemplateURLModel; +class TestingProfile; +class WebDataService; + +class TemplateURLModelTestUtil : public TemplateURLModelObserver { + public: + TemplateURLModelTestUtil(); + + virtual ~TemplateURLModelTestUtil(); + + // Sets up the data structures for this class (mirroring gtest standard + // methods). + void SetUp(); + + // Cleans up data structures for this class (mirroring gtest standard + // methods). + void TearDown(); + + // TemplateURLModelObserver implemementation. + virtual void OnTemplateURLModelChanged(); + + // Checks that the observer count is what is expected. + void VerifyObserverCount(int expected_changed_count); + + // Sets the observer count to 0. + void ResetObserverCount(); + + // Blocks the caller until the service has finished servicing all pending + // requests. + void BlockTillServiceProcessesRequests(); + + // Blocks the caller until the I/O thread has finished servicing all pending + // requests. + void BlockTillIOThreadProcessesRequests(); + + // Makes sure the load was successful and sent the correct notification. + void VerifyLoad(); + + // Makes the model believe it has been loaded (without actually doing the + // load). Since this avoids setting the built-in keyword version, the next + // load will do a merge from prepopulated data. + void ChangeModelToLoadState(); + + // Deletes the current model (and doesn't create a new one). + void ClearModel(); + + // Creates a new TemplateURLModel. + void ResetModel(bool verify_load); + + // Returns the search term from the last invocation of + // TemplateURLModel::SetKeywordSearchTermsForURL and clears the search term. + std::wstring GetAndClearSearchTerm(); + + // Set the google base url. + void SetGoogleBaseURL(const std::string& base_url) const; + + // Returns the WebDataService. + WebDataService* GetWebDataService(); + + // Returns the TemplateURLModel. + TemplateURLModel* model() const; + + // Returns the TestingProfile. + TestingProfile* profile() const; + + private: + MessageLoopForUI message_loop_; + // Needed to make the DeleteOnUIThread trait of WebDataService work + // properly. + ChromeThread ui_thread_; + scoped_ptr<TemplateURLModelTestingProfile> profile_; + scoped_ptr<TestingTemplateURLModel> model_; + int changed_count_; + + DISALLOW_COPY_AND_ASSIGN(TemplateURLModelTestUtil); +}; + +#endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_MODEL_TEST_UTIL_H_ diff --git a/chrome/browser/search_engines/template_url_model_unittest.cc b/chrome/browser/search_engines/template_url_model_unittest.cc index 32cee09..cf01642 100644 --- a/chrome/browser/search_engines/template_url_model_unittest.cc +++ b/chrome/browser/search_engines/template_url_model_unittest.cc @@ -3,8 +3,6 @@ // found in the LICENSE file. #include "base/callback.h" -#include "base/file_util.h" -#include "base/path_service.h" #include "base/scoped_vector.h" #include "base/string_util.h" #include "base/ref_counted.h" @@ -16,7 +14,7 @@ #include "chrome/browser/search_engines/search_terms_data.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_model.h" -#include "chrome/browser/search_engines/template_url_model_observer.h" +#include "chrome/browser/search_engines/template_url_model_test_util.h" #include "chrome/browser/search_engines/template_url_prepopulate_data.h" #include "chrome/browser/webdata/web_database.h" #include "chrome/common/pref_names.h" @@ -34,22 +32,6 @@ using base::TimeDelta; #define MAYBE_Load Load #endif -// A Task used to coordinate when the database has finished processing -// requests. See note in BlockTillServiceProcessesRequests for details. -// -// When Run() schedules a QuitTask on the message loop it was created with. -class QuitTask2 : public Task { - public: - QuitTask2() : main_loop_(MessageLoop::current()) {} - - virtual void Run() { - main_loop_->PostTask(FROM_HERE, new MessageLoop::QuitTask()); - } - - private: - MessageLoop* main_loop_; -}; - // Test the GenerateSearchURL on a thread or the main thread. class TestGenerateSearchURL : public base::RefCountedThreadSafe<TestGenerateSearchURL> { @@ -118,98 +100,16 @@ static TemplateURL* CreatePreloadedTemplateURL() { return t_url; } -// Subclass the TestingProfile so that it can return a WebDataService. -class TemplateURLModelTestingProfile : public TestingProfile { +class TemplateURLModelTest : public testing::Test { public: - TemplateURLModelTestingProfile() : TestingProfile() {} - - void SetUp() { - db_thread_.reset(new ChromeThread(ChromeThread::DB)); - db_thread_->Start(); - - // Name a subdirectory of the temp directory. - ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &test_dir_)); - test_dir_ = test_dir_.AppendASCII("TemplateURLModelTest"); - - // Create a fresh, empty copy of this directory. - file_util::Delete(test_dir_, true); - file_util::CreateDirectory(test_dir_); - - FilePath path = test_dir_.AppendASCII("TestDataService.db"); - service_ = new WebDataService; - EXPECT_TRUE(service_->InitWithPath(path)); - } - - void TearDown() { - // Clean up the test directory. - service_->Shutdown(); - // Note that we must ensure the DB thread is stopped after WDS - // shutdown (so it can commit pending transactions) but before - // deleting the test profile directory, otherwise we may not be - // able to delete it due to an open transaction. - db_thread_->Stop(); - - ASSERT_TRUE(file_util::Delete(test_dir_, true)); - ASSERT_FALSE(file_util::PathExists(test_dir_)); - } - - virtual WebDataService* GetWebDataService(ServiceAccessType access) { - return service_.get(); - } - - private: - scoped_refptr<WebDataService> service_; - FilePath test_dir_; - scoped_ptr<ChromeThread> db_thread_; -}; - -// Trivial subclass of TemplateURLModel that records the last invocation of -// SetKeywordSearchTermsForURL. -class TestingTemplateURLModel : public TemplateURLModel { - public: - explicit TestingTemplateURLModel(Profile* profile) - : TemplateURLModel(profile) { - } - - std::wstring GetAndClearSearchTerm() { - std::wstring search_term; - search_term.swap(search_term_); - return search_term; - } - - protected: - virtual void SetKeywordSearchTermsForURL(const TemplateURL* t_url, - const GURL& url, - const std::wstring& term) { - search_term_ = term; - } - - private: - std::wstring search_term_; - - DISALLOW_COPY_AND_ASSIGN(TestingTemplateURLModel); -}; - -class TemplateURLModelTest : public testing::Test, - public TemplateURLModelObserver { - public: - TemplateURLModelTest() : ui_thread_(ChromeThread::UI, &message_loop_), - changed_count_(0) { - } + TemplateURLModelTest() {} virtual void SetUp() { - profile_.reset(new TemplateURLModelTestingProfile()); - profile_->SetUp(); - model_.reset(new TestingTemplateURLModel(profile_.get())); - model_->AddObserver(this); + test_util_.SetUp(); } virtual void TearDown() { - profile_->TearDown(); - TemplateURLRef::SetGoogleBaseURL(NULL); - - // Flush the message loop to make Purify happy. - message_loop_.RunAllPending(); + test_util_.TearDown(); } TemplateURL* AddKeywordWithDate(const std::wstring& keyword, @@ -225,64 +125,11 @@ class TemplateURLModelTest : public testing::Test, template_url->set_short_name(short_name); template_url->set_date_created(created_date); template_url->set_safe_for_autoreplace(safe_for_autoreplace); - model_->Add(template_url); + model()->Add(template_url); EXPECT_NE(0, template_url->id()); return template_url; } - virtual void OnTemplateURLModelChanged() { - changed_count_++; - } - - void VerifyObserverCount(int expected_changed_count) { - ASSERT_EQ(expected_changed_count, changed_count_); - changed_count_ = 0; - } - - // Blocks the caller until thread has finished servicing all pending - // requests. - void WaitForThreadToProcessRequests(ChromeThread::ID identifier) { - // Schedule a task on the thread that is processed after all - // pending requests on the thread. - ChromeThread::PostTask(identifier, FROM_HERE, new QuitTask2()); - // Run the current message loop. QuitTask2, when run, invokes Quit, - // which unblocks this. - MessageLoop::current()->Run(); - } - - // Blocks the caller until the service has finished servicing all pending - // requests. - void BlockTillServiceProcessesRequests() { - WaitForThreadToProcessRequests(ChromeThread::DB); - } - - // Makes sure the load was successful and sent the correct notification. - void VerifyLoad() { - ASSERT_FALSE(model_->loaded()); - model_->Load(); - BlockTillServiceProcessesRequests(); - VerifyObserverCount(1); - } - - // Makes the model believe it has been loaded (without actually doing the - // load). Since this avoids setting the built-in keyword version, the next - // load will do a merge from prepopulated data. - void ChangeModelToLoadState() { - model_->ChangeToLoadedState(); - // Initialize the web data service so that the database gets updated with - // any changes made. - model_->service_ = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); - } - - // Creates a new TemplateURLModel. - void ResetModel(bool verify_load) { - model_.reset(new TestingTemplateURLModel(profile_.get())); - model_->AddObserver(this); - changed_count_ = 0; - if (verify_load) - VerifyLoad(); - } - // Verifies the two TemplateURLs are equal. void AssertEquals(const TemplateURL& expected, const TemplateURL& actual) { ASSERT_EQ(expected.url()->url(), actual.url()->url()); @@ -295,14 +142,6 @@ class TemplateURLModelTest : public testing::Test, ASSERT_TRUE(expected.date_created() == actual.date_created()); } - std::wstring GetAndClearSearchTerm() { - return model_->GetAndClearSearchTerm(); - } - - void SetGoogleBaseURL(const std::string& base_url) const { - TemplateURLRef::SetGoogleBaseURL(new std::string(base_url)); - } - // Creates a TemplateURL with the same prepopluated id as a real prepopulated // item. The input number determines which prepopulated item. The caller is // responsible for owning the returned TemplateURL*. @@ -316,13 +155,31 @@ class TemplateURLModelTest : public testing::Test, // happens when a preloaded url that is not the default gets updated. void TestLoadUpdatingPreloadedURL(size_t index_offset_from_default); - MessageLoopForUI message_loop_; - // Needed to make the DeleteOnUIThread trait of WebDataService work - // properly. - ChromeThread ui_thread_; - scoped_ptr<TemplateURLModelTestingProfile> profile_; - scoped_ptr<TestingTemplateURLModel> model_; - int changed_count_; + // Helper methods to make calling TemplateURLModelTestUtil methods less + // visually noisy in the test code. + void VerifyObserverCount(int expected_changed_count) { + test_util_.VerifyObserverCount(expected_changed_count); + } + void BlockTillServiceProcessesRequests() { + test_util_.BlockTillServiceProcessesRequests(); + } + void VerifyLoad() { test_util_.VerifyLoad(); } + void ChangeModelToLoadState() { test_util_.ChangeModelToLoadState(); } + void ResetModel(bool verify_load) { test_util_.ResetModel(verify_load); } + std::wstring GetAndClearSearchTerm() { + return test_util_.GetAndClearSearchTerm(); + } + void SetGoogleBaseURL(const std::string& base_url) const { + test_util_.SetGoogleBaseURL(base_url); + } + WebDataService* GetWebDataService() { return test_util_.GetWebDataService(); } + TemplateURLModel* model() { return test_util_.model(); } + TestingProfile* profile() { return test_util_.profile(); } + + protected: + TemplateURLModelTestUtil test_util_; + + DISALLOW_COPY_AND_ASSIGN(TemplateURLModelTest); }; void TestGenerateSearchURL::RunTest() { @@ -368,7 +225,7 @@ TemplateURL* TemplateURLModelTest::CreateReplaceablePreloadedTemplateURL( ScopedVector<TemplateURL> prepopulated_urls; size_t default_search_provider_index = 0; TemplateURLPrepopulateData::GetPrepopulatedEngines( - profile_->GetPrefs(), + profile()->GetPrefs(), &prepopulated_urls.get(), &default_search_provider_index); EXPECT_LT(index_offset_from_default, prepopulated_urls.size()); @@ -394,16 +251,16 @@ void TemplateURLModelTest::TestLoadUpdatingPreloadedURL( // Then add it to the model and save it all. ChangeModelToLoadState(); - model_->Add(t_url); + model()->Add(t_url); const TemplateURL* keyword_url = - model_->GetTemplateURLForKeyword(L"unittest"); + model()->GetTemplateURLForKeyword(L"unittest"); ASSERT_EQ(t_url, keyword_url); ASSERT_STREQ(original_url.c_str(), keyword_url->url()->DisplayURL().c_str()); BlockTillServiceProcessesRequests(); // Now reload the model and verify that the merge updates the url. ResetModel(true); - keyword_url = model_->GetTemplateURLForKeyword(L"unittest"); + keyword_url = model()->GetTemplateURLForKeyword(L"unittest"); ASSERT_TRUE(keyword_url != NULL); ASSERT_STREQ(prepopulated_url.c_str(), keyword_url->url()->DisplayURL().c_str()); @@ -413,7 +270,7 @@ void TemplateURLModelTest::TestLoadUpdatingPreloadedURL( // Reload the model to verify that change was saved correctly. ResetModel(true); - keyword_url = model_->GetTemplateURLForKeyword(L"unittest"); + keyword_url = model()->GetTemplateURLForKeyword(L"unittest"); ASSERT_TRUE(keyword_url != NULL); ASSERT_STREQ(prepopulated_url.c_str(), keyword_url->url()->DisplayURL().c_str()); @@ -426,7 +283,7 @@ TEST_F(TemplateURLModelTest, MAYBE_Load) { TEST_F(TemplateURLModelTest, AddUpdateRemove) { // Add a new TemplateURL. VerifyLoad(); - const size_t initial_count = model_->GetTemplateURLs().size(); + const size_t initial_count = model()->GetTemplateURLs().size(); TemplateURL* t_url = new TemplateURL(); t_url->SetURL("http://www.google.com/foo/bar", 0, 0); @@ -436,47 +293,47 @@ TEST_F(TemplateURLModelTest, AddUpdateRemove) { t_url->SetFavIconURL(favicon_url); t_url->set_date_created(Time::FromTimeT(100)); t_url->set_safe_for_autoreplace(true); - model_->Add(t_url); - ASSERT_TRUE(model_->CanReplaceKeyword(L"keyword", GURL(), NULL)); + model()->Add(t_url); + ASSERT_TRUE(model()->CanReplaceKeyword(L"keyword", GURL(), NULL)); VerifyObserverCount(1); BlockTillServiceProcessesRequests(); // We need to clone as model takes ownership of TemplateURL and will // delete it. TemplateURL cloned_url(*t_url); - ASSERT_EQ(1 + initial_count, model_->GetTemplateURLs().size()); - ASSERT_TRUE(model_->GetTemplateURLForKeyword(t_url->keyword()) == t_url); + ASSERT_EQ(1 + initial_count, model()->GetTemplateURLs().size()); + ASSERT_TRUE(model()->GetTemplateURLForKeyword(t_url->keyword()) == t_url); ASSERT_TRUE(t_url->date_created() == cloned_url.date_created()); // Reload the model to verify it was actually saved to the database. ResetModel(true); - ASSERT_EQ(1 + initial_count, model_->GetTemplateURLs().size()); - const TemplateURL* loaded_url = model_->GetTemplateURLForKeyword(L"keyword"); + ASSERT_EQ(1 + initial_count, model()->GetTemplateURLs().size()); + const TemplateURL* loaded_url = model()->GetTemplateURLForKeyword(L"keyword"); ASSERT_TRUE(loaded_url != NULL); AssertEquals(cloned_url, *loaded_url); - ASSERT_TRUE(model_->CanReplaceKeyword(L"keyword", GURL(), NULL)); + ASSERT_TRUE(model()->CanReplaceKeyword(L"keyword", GURL(), NULL)); // Mutate an element and verify it succeeded. - model_->ResetTemplateURL(loaded_url, L"a", L"b", "c"); + model()->ResetTemplateURL(loaded_url, L"a", L"b", "c"); ASSERT_EQ(L"a", loaded_url->short_name()); ASSERT_EQ(L"b", loaded_url->keyword()); ASSERT_EQ("c", loaded_url->url()->url()); ASSERT_FALSE(loaded_url->safe_for_autoreplace()); - ASSERT_TRUE(model_->CanReplaceKeyword(L"keyword", GURL(), NULL)); - ASSERT_FALSE(model_->CanReplaceKeyword(L"b", GURL(), NULL)); + ASSERT_TRUE(model()->CanReplaceKeyword(L"keyword", GURL(), NULL)); + ASSERT_FALSE(model()->CanReplaceKeyword(L"b", GURL(), NULL)); cloned_url = *loaded_url; BlockTillServiceProcessesRequests(); ResetModel(true); - ASSERT_EQ(1 + initial_count, model_->GetTemplateURLs().size()); - loaded_url = model_->GetTemplateURLForKeyword(L"b"); + ASSERT_EQ(1 + initial_count, model()->GetTemplateURLs().size()); + loaded_url = model()->GetTemplateURLForKeyword(L"b"); ASSERT_TRUE(loaded_url != NULL); AssertEquals(cloned_url, *loaded_url); // Remove an element and verify it succeeded. - model_->Remove(loaded_url); + model()->Remove(loaded_url); VerifyObserverCount(1); ResetModel(true); - ASSERT_EQ(initial_count, model_->GetTemplateURLs().size()); - EXPECT_TRUE(model_->GetTemplateURLForKeyword(L"b") == NULL); + ASSERT_EQ(initial_count, model()->GetTemplateURLs().size()); + EXPECT_TRUE(model()->GetTemplateURLForKeyword(L"b") == NULL); } TEST_F(TemplateURLModelTest, GenerateKeyword) { @@ -520,7 +377,7 @@ TEST_F(TemplateURLModelTest, GenerateSearchURLUsingTermsData) { FROM_HERE, NewRunnableMethod(test_generate_search_url.get(), &TestGenerateSearchURL::RunTest)); - WaitForThreadToProcessRequests(ChromeThread::IO); + test_util_.BlockTillIOThreadProcessesRequests(); EXPECT_TRUE(test_generate_search_url->passed()); io_thread.Stop(); } @@ -531,7 +388,7 @@ TEST_F(TemplateURLModelTest, ClearBrowsingData_Keywords) { Time month_ago = now - TimeDelta::FromDays(30); // Nothing has been added. - EXPECT_EQ(0U, model_->GetTemplateURLs().size()); + EXPECT_EQ(0U, model()->GetTemplateURLs().size()); // Create one with a 0 time. AddKeywordWithDate(L"key1", false, "http://foo1", L"name1", true, Time()); @@ -547,42 +404,43 @@ TEST_F(TemplateURLModelTest, ClearBrowsingData_Keywords) { month_ago); // We just added a few items, validate them. - EXPECT_EQ(6U, model_->GetTemplateURLs().size()); + EXPECT_EQ(6U, model()->GetTemplateURLs().size()); // Try removing from current timestamp. This should delete the one in the // future and one very recent one. - model_->RemoveAutoGeneratedSince(now); - EXPECT_EQ(4U, model_->GetTemplateURLs().size()); + model()->RemoveAutoGeneratedSince(now); + EXPECT_EQ(4U, model()->GetTemplateURLs().size()); // Try removing from two months ago. This should only delete items that are // auto-generated. - model_->RemoveAutoGeneratedSince(now - TimeDelta::FromDays(60)); - EXPECT_EQ(3U, model_->GetTemplateURLs().size()); + model()->RemoveAutoGeneratedSince(now - TimeDelta::FromDays(60)); + EXPECT_EQ(3U, model()->GetTemplateURLs().size()); // Make sure the right values remain. - EXPECT_EQ(L"key1", model_->GetTemplateURLs()[0]->keyword()); - EXPECT_TRUE(model_->GetTemplateURLs()[0]->safe_for_autoreplace()); - EXPECT_EQ(0U, model_->GetTemplateURLs()[0]->date_created().ToInternalValue()); + EXPECT_EQ(L"key1", model()->GetTemplateURLs()[0]->keyword()); + EXPECT_TRUE(model()->GetTemplateURLs()[0]->safe_for_autoreplace()); + EXPECT_EQ(0U, + model()->GetTemplateURLs()[0]->date_created().ToInternalValue()); - EXPECT_EQ(L"key5", model_->GetTemplateURLs()[1]->keyword()); - EXPECT_FALSE(model_->GetTemplateURLs()[1]->safe_for_autoreplace()); + EXPECT_EQ(L"key5", model()->GetTemplateURLs()[1]->keyword()); + EXPECT_FALSE(model()->GetTemplateURLs()[1]->safe_for_autoreplace()); EXPECT_EQ(now.ToInternalValue(), - model_->GetTemplateURLs()[1]->date_created().ToInternalValue()); + model()->GetTemplateURLs()[1]->date_created().ToInternalValue()); - EXPECT_EQ(L"key6", model_->GetTemplateURLs()[2]->keyword()); - EXPECT_FALSE(model_->GetTemplateURLs()[2]->safe_for_autoreplace()); + EXPECT_EQ(L"key6", model()->GetTemplateURLs()[2]->keyword()); + EXPECT_FALSE(model()->GetTemplateURLs()[2]->safe_for_autoreplace()); EXPECT_EQ(month_ago.ToInternalValue(), - model_->GetTemplateURLs()[2]->date_created().ToInternalValue()); + model()->GetTemplateURLs()[2]->date_created().ToInternalValue()); // Try removing from Time=0. This should delete one more. - model_->RemoveAutoGeneratedSince(Time()); - EXPECT_EQ(2U, model_->GetTemplateURLs().size()); + model()->RemoveAutoGeneratedSince(Time()); + EXPECT_EQ(2U, model()->GetTemplateURLs().size()); } TEST_F(TemplateURLModelTest, Reset) { // Add a new TemplateURL. VerifyLoad(); - const size_t initial_count = model_->GetTemplateURLs().size(); + const size_t initial_count = model()->GetTemplateURLs().size(); TemplateURL* t_url = new TemplateURL(); t_url->SetURL("http://www.google.com/foo/bar", 0, 0); t_url->set_keyword(L"keyword"); @@ -590,7 +448,7 @@ TEST_F(TemplateURLModelTest, Reset) { GURL favicon_url("http://favicon.url"); t_url->SetFavIconURL(favicon_url); t_url->set_date_created(Time::FromTimeT(100)); - model_->Add(t_url); + model()->Add(t_url); VerifyObserverCount(1); BlockTillServiceProcessesRequests(); @@ -599,22 +457,22 @@ TEST_F(TemplateURLModelTest, Reset) { const std::wstring new_short_name(L"a"); const std::wstring new_keyword(L"b"); const std::string new_url("c"); - model_->ResetTemplateURL(t_url, new_short_name, new_keyword, new_url); + model()->ResetTemplateURL(t_url, new_short_name, new_keyword, new_url); ASSERT_EQ(new_short_name, t_url->short_name()); ASSERT_EQ(new_keyword, t_url->keyword()); ASSERT_EQ(new_url, t_url->url()->url()); // Make sure the mappings in the model were updated. - ASSERT_TRUE(model_->GetTemplateURLForKeyword(new_keyword) == t_url); - ASSERT_TRUE(model_->GetTemplateURLForKeyword(L"keyword") == NULL); + ASSERT_TRUE(model()->GetTemplateURLForKeyword(new_keyword) == t_url); + ASSERT_TRUE(model()->GetTemplateURLForKeyword(L"keyword") == NULL); TemplateURL last_url = *t_url; // Reload the model from the database and make sure the change took. ResetModel(true); t_url = NULL; - EXPECT_EQ(initial_count + 1, model_->GetTemplateURLs().size()); - const TemplateURL* read_url = model_->GetTemplateURLForKeyword(new_keyword); + EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); + const TemplateURL* read_url = model()->GetTemplateURLForKeyword(new_keyword); ASSERT_TRUE(read_url); AssertEquals(last_url, *read_url); } @@ -622,14 +480,14 @@ TEST_F(TemplateURLModelTest, Reset) { TEST_F(TemplateURLModelTest, DefaultSearchProvider) { // Add a new TemplateURL. VerifyLoad(); - const size_t initial_count = model_->GetTemplateURLs().size(); + const size_t initial_count = model()->GetTemplateURLs().size(); TemplateURL* t_url = AddKeywordWithDate(L"key1", false, "http://foo1", L"name1", true, Time()); - changed_count_ = 0; - model_->SetDefaultSearchProvider(t_url); + test_util_.ResetObserverCount(); + model()->SetDefaultSearchProvider(t_url); - ASSERT_EQ(t_url, model_->GetDefaultSearchProvider()); + ASSERT_EQ(t_url, model()->GetDefaultSearchProvider()); ASSERT_TRUE(t_url->safe_for_autoreplace()); ASSERT_TRUE(t_url->show_in_default_list()); @@ -645,30 +503,30 @@ TEST_F(TemplateURLModelTest, DefaultSearchProvider) { t_url = NULL; // Make sure when we reload we get a default search provider. - EXPECT_EQ(1 + initial_count, model_->GetTemplateURLs().size()); - ASSERT_TRUE(model_->GetDefaultSearchProvider()); - AssertEquals(cloned_url, *model_->GetDefaultSearchProvider()); + EXPECT_EQ(1 + initial_count, model()->GetTemplateURLs().size()); + ASSERT_TRUE(model()->GetDefaultSearchProvider()); + AssertEquals(cloned_url, *model()->GetDefaultSearchProvider()); } TEST_F(TemplateURLModelTest, TemplateURLWithNoKeyword) { VerifyLoad(); - const size_t initial_count = model_->GetTemplateURLs().size(); + const size_t initial_count = model()->GetTemplateURLs().size(); AddKeywordWithDate(std::wstring(), false, "http://foo1", L"name1", true, Time()); // We just added a few items, validate them. - ASSERT_EQ(initial_count + 1, model_->GetTemplateURLs().size()); + ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); // Reload the model from the database and make sure we get the url back. ResetModel(true); - ASSERT_EQ(1 + initial_count, model_->GetTemplateURLs().size()); + ASSERT_EQ(1 + initial_count, model()->GetTemplateURLs().size()); bool found_keyword = false; for (size_t i = 0; i < initial_count + 1; ++i) { - if (model_->GetTemplateURLs()[i]->keyword().empty()) { + if (model()->GetTemplateURLs()[i]->keyword().empty()) { found_keyword = true; break; } @@ -678,46 +536,47 @@ TEST_F(TemplateURLModelTest, TemplateURLWithNoKeyword) { TEST_F(TemplateURLModelTest, CantReplaceWithSameKeyword) { ChangeModelToLoadState(); - ASSERT_TRUE(model_->CanReplaceKeyword(L"foo", GURL(), NULL)); + ASSERT_TRUE(model()->CanReplaceKeyword(L"foo", GURL(), NULL)); TemplateURL* t_url = AddKeywordWithDate(L"foo", false, "http://foo1", L"name1", true, Time()); // Can still replace, newly added template url is marked safe to replace. - ASSERT_TRUE(model_->CanReplaceKeyword(L"foo", GURL("http://foo2"), NULL)); + ASSERT_TRUE(model()->CanReplaceKeyword(L"foo", GURL("http://foo2"), NULL)); // ResetTemplateURL marks the TemplateURL as unsafe to replace, so it should // no longer be replaceable. - model_->ResetTemplateURL(t_url, t_url->short_name(), t_url->keyword(), + model()->ResetTemplateURL(t_url, t_url->short_name(), t_url->keyword(), t_url->url()->url()); - ASSERT_FALSE(model_->CanReplaceKeyword(L"foo", GURL("http://foo2"), NULL)); + ASSERT_FALSE(model()->CanReplaceKeyword(L"foo", GURL("http://foo2"), NULL)); } TEST_F(TemplateURLModelTest, CantReplaceWithSameHosts) { ChangeModelToLoadState(); - ASSERT_TRUE(model_->CanReplaceKeyword(L"foo", GURL("http://foo.com"), NULL)); + ASSERT_TRUE(model()->CanReplaceKeyword(L"foo", GURL("http://foo.com"), NULL)); TemplateURL* t_url = AddKeywordWithDate(L"foo", false, "http://foo.com", L"name1", true, Time()); // Can still replace, newly added template url is marked safe to replace. - ASSERT_TRUE(model_->CanReplaceKeyword(L"bar", GURL("http://foo.com"), NULL)); + ASSERT_TRUE(model()->CanReplaceKeyword(L"bar", GURL("http://foo.com"), NULL)); // ResetTemplateURL marks the TemplateURL as unsafe to replace, so it should // no longer be replaceable. - model_->ResetTemplateURL(t_url, t_url->short_name(), t_url->keyword(), + model()->ResetTemplateURL(t_url, t_url->short_name(), t_url->keyword(), t_url->url()->url()); - ASSERT_FALSE(model_->CanReplaceKeyword(L"bar", GURL("http://foo.com"), NULL)); + ASSERT_FALSE(model()->CanReplaceKeyword(L"bar", + GURL("http://foo.com"), NULL)); } TEST_F(TemplateURLModelTest, HasDefaultSearchProvider) { // We should have a default search provider even if we haven't loaded. - ASSERT_TRUE(model_->GetDefaultSearchProvider()); + ASSERT_TRUE(model()->GetDefaultSearchProvider()); // Now force the model to load and make sure we still have a default. VerifyLoad(); - ASSERT_TRUE(model_->GetDefaultSearchProvider()); + ASSERT_TRUE(model()->GetDefaultSearchProvider()); } TEST_F(TemplateURLModelTest, DefaultSearchProviderLoadedFromPrefs) { @@ -730,11 +589,11 @@ TEST_F(TemplateURLModelTest, DefaultSearchProviderLoadedFromPrefs) { template_url->set_safe_for_autoreplace(true); template_url->set_date_created(Time::FromTimeT(100)); - model_->Add(template_url); + model()->Add(template_url); const TemplateURLID id = template_url->id(); - model_->SetDefaultSearchProvider(template_url); + model()->SetDefaultSearchProvider(template_url); BlockTillServiceProcessesRequests(); @@ -748,7 +607,7 @@ TEST_F(TemplateURLModelTest, DefaultSearchProviderLoadedFromPrefs) { // NOTE: This doesn't use AssertEquals as only a subset of the TemplateURLs // value are persisted to prefs. - const TemplateURL* default_turl = model_->GetDefaultSearchProvider(); + const TemplateURL* default_turl = model()->GetDefaultSearchProvider(); ASSERT_TRUE(default_turl); ASSERT_TRUE(default_turl->url()); ASSERT_EQ("http://url", default_turl->url()->url()); @@ -760,9 +619,9 @@ TEST_F(TemplateURLModelTest, DefaultSearchProviderLoadedFromPrefs) { // Now do a load and make sure the default search provider really takes. VerifyLoad(); - ASSERT_TRUE(model_->GetDefaultSearchProvider()); + ASSERT_TRUE(model()->GetDefaultSearchProvider()); AssertEquals(first_default_search_provider, - *model_->GetDefaultSearchProvider()); + *model()->GetDefaultSearchProvider()); } TEST_F(TemplateURLModelTest, BuildQueryTerms) { @@ -833,7 +692,7 @@ TEST_F(TemplateURLModelTest, UpdateKeywordSearchTermsForURL) { history::URLVisitedDetails details; details.row = history::URLRow(GURL(data[i].url)); details.transition = 0; - model_->UpdateKeywordSearchTermsForURL(details); + model()->UpdateKeywordSearchTermsForURL(details); EXPECT_EQ(data[i].term, GetAndClearSearchTerm()); } } @@ -854,7 +713,7 @@ TEST_F(TemplateURLModelTest, DontUpdateKeywordSearchForNonReplaceable) { history::URLVisitedDetails details; details.row = history::URLRow(GURL(data[i].url)); details.transition = 0; - model_->UpdateKeywordSearchTermsForURL(details); + model()->UpdateKeywordSearchTermsForURL(details); ASSERT_EQ(std::wstring(), GetAndClearSearchTerm()); } } @@ -867,19 +726,19 @@ TEST_F(TemplateURLModelTest, ChangeGoogleBaseValue) { SetGoogleBaseURL("http://google.com/"); const TemplateURL* t_url = AddKeywordWithDate(std::wstring(), true, "{google:baseURL}?q={searchTerms}", L"name", false, Time()); - ASSERT_EQ(t_url, model_->GetTemplateURLForHost("google.com")); + ASSERT_EQ(t_url, model()->GetTemplateURLForHost("google.com")); EXPECT_EQ("google.com", t_url->url()->GetHost()); EXPECT_EQ(L"google.com", t_url->keyword()); // Change the Google base url. - changed_count_ = 0; + test_util_.ResetObserverCount(); SetGoogleBaseURL("http://foo.com/"); - model_->GoogleBaseURLChanged(); + model()->GoogleBaseURLChanged(); VerifyObserverCount(1); // Make sure the host->TemplateURL map was updated appropriately. - ASSERT_EQ(t_url, model_->GetTemplateURLForHost("foo.com")); - EXPECT_TRUE(model_->GetTemplateURLForHost("google.com") == NULL); + ASSERT_EQ(t_url, model()->GetTemplateURLForHost("foo.com")); + EXPECT_TRUE(model()->GetTemplateURLForHost("google.com") == NULL); EXPECT_EQ("foo.com", t_url->url()->GetHost()); EXPECT_EQ(L"foo.com", t_url->keyword()); EXPECT_EQ("http://foo.com/?q=x", t_url->url()->ReplaceSearchTerms(*t_url, @@ -908,7 +767,7 @@ struct QueryHistoryCallbackImpl { // KEYWORD visits. TEST_F(TemplateURLModelTest, GenerateVisitOnKeyword) { VerifyLoad(); - profile_->CreateHistoryService(true, false); + profile()->CreateHistoryService(true, false); // Create a keyword. TemplateURL* t_url = AddKeywordWithDate( @@ -917,7 +776,7 @@ TEST_F(TemplateURLModelTest, GenerateVisitOnKeyword) { // Add a visit that matches the url of the keyword. HistoryService* history = - profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); + profile()->GetHistoryService(Profile::EXPLICIT_ACCESS); history->AddPage( GURL(t_url->url()->ReplaceSearchTerms(*t_url, L"blah", 0, std::wstring())), @@ -925,7 +784,7 @@ TEST_F(TemplateURLModelTest, GenerateVisitOnKeyword) { history::SOURCE_BROWSED, false); // Wait for history to finish processing the request. - profile_->BlockUntilHistoryProcessesPendingRequests(); + profile()->BlockUntilHistoryProcessesPendingRequests(); // Query history for the generated url. CancelableRequestConsumer consumer; @@ -934,7 +793,7 @@ TEST_F(TemplateURLModelTest, GenerateVisitOnKeyword) { NewCallback(&callback, &QueryHistoryCallbackImpl::Callback)); // Wait for the request to be processed. - profile_->BlockUntilHistoryProcessesPendingRequests(); + profile()->BlockUntilHistoryProcessesPendingRequests(); // And make sure the url and visit were added. EXPECT_TRUE(callback.success); @@ -951,13 +810,13 @@ TEST_F(TemplateURLModelTest, LoadDeletesUnusedProvider) { // saves to finish. TemplateURL* t_url = CreatePreloadedTemplateURL(); ChangeModelToLoadState(); - model_->Add(t_url); - ASSERT_TRUE(model_->GetTemplateURLForKeyword(L"unittest") != NULL); + model()->Add(t_url); + ASSERT_TRUE(model()->GetTemplateURLForKeyword(L"unittest") != NULL); BlockTillServiceProcessesRequests(); // Ensure that merging clears this engine. ResetModel(true); - ASSERT_TRUE(model_->GetTemplateURLForKeyword(L"unittest") == NULL); + ASSERT_TRUE(model()->GetTemplateURLForKeyword(L"unittest") == NULL); // Wait for any saves to finish. BlockTillServiceProcessesRequests(); @@ -965,7 +824,7 @@ TEST_F(TemplateURLModelTest, LoadDeletesUnusedProvider) { // Reload the model to verify that the database was updated as a result of the // merge. ResetModel(true); - ASSERT_TRUE(model_->GetTemplateURLForKeyword(L"unittest") == NULL); + ASSERT_TRUE(model()->GetTemplateURLForKeyword(L"unittest") == NULL); } // Make sure that load routine doesn't delete prepopulated engines that no @@ -975,11 +834,11 @@ TEST_F(TemplateURLModelTest, LoadRetainsModifiedProvider) { TemplateURL* t_url = CreatePreloadedTemplateURL(); t_url->set_safe_for_autoreplace(false); ChangeModelToLoadState(); - model_->Add(t_url); + model()->Add(t_url); // Do the copy after t_url is added so that the id is set. TemplateURL copy_t_url = *t_url; - ASSERT_EQ(t_url, model_->GetTemplateURLForKeyword(L"unittest")); + ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(L"unittest")); // Wait for any saves to finish. BlockTillServiceProcessesRequests(); @@ -987,7 +846,7 @@ TEST_F(TemplateURLModelTest, LoadRetainsModifiedProvider) { // Ensure that merging won't clear it if the user has edited it. ResetModel(true); const TemplateURL* url_for_unittest = - model_->GetTemplateURLForKeyword(L"unittest"); + model()->GetTemplateURLForKeyword(L"unittest"); ASSERT_TRUE(url_for_unittest != NULL); AssertEquals(copy_t_url, *url_for_unittest); @@ -996,7 +855,7 @@ TEST_F(TemplateURLModelTest, LoadRetainsModifiedProvider) { // Reload the model to verify that save/reload retains the item. ResetModel(true); - ASSERT_TRUE(model_->GetTemplateURLForKeyword(L"unittest") != NULL); + ASSERT_TRUE(model()->GetTemplateURLForKeyword(L"unittest") != NULL); } // Make sure that load routine doesn't delete @@ -1005,8 +864,8 @@ TEST_F(TemplateURLModelTest, LoadRetainsModifiedProvider) { TEST_F(TemplateURLModelTest, LoadSavesPrepopulatedDefaultSearchProvider) { VerifyLoad(); // Verify that the default search provider is set to something. - ASSERT_TRUE(model_->GetDefaultSearchProvider() != NULL); - TemplateURL default_url = *model_->GetDefaultSearchProvider(); + ASSERT_TRUE(model()->GetDefaultSearchProvider() != NULL); + TemplateURL default_url = *model()->GetDefaultSearchProvider(); // Wait for any saves to finish. BlockTillServiceProcessesRequests(); @@ -1014,8 +873,8 @@ TEST_F(TemplateURLModelTest, LoadSavesPrepopulatedDefaultSearchProvider) { // Reload the model and check that the default search provider // was properly saved. ResetModel(true); - ASSERT_TRUE(model_->GetDefaultSearchProvider() != NULL); - AssertEquals(default_url, *model_->GetDefaultSearchProvider()); + ASSERT_TRUE(model()->GetDefaultSearchProvider() != NULL); + AssertEquals(default_url, *model()->GetDefaultSearchProvider()); } // Make sure that the load routine doesn't delete @@ -1027,14 +886,14 @@ TEST_F(TemplateURLModelTest, LoadRetainsDefaultProvider) { // the result. TemplateURL* t_url = CreatePreloadedTemplateURL(); ChangeModelToLoadState(); - model_->Add(t_url); - model_->SetDefaultSearchProvider(t_url); + model()->Add(t_url); + model()->SetDefaultSearchProvider(t_url); // Do the copy after t_url is added and set as default so that its // internal state is correct. TemplateURL copy_t_url = *t_url; - ASSERT_EQ(t_url, model_->GetTemplateURLForKeyword(L"unittest")); - ASSERT_EQ(t_url, model_->GetDefaultSearchProvider()); + ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(L"unittest")); + ASSERT_EQ(t_url, model()->GetDefaultSearchProvider()); BlockTillServiceProcessesRequests(); // Ensure that merging won't clear the prepopulated template url @@ -1042,10 +901,10 @@ TEST_F(TemplateURLModelTest, LoadRetainsDefaultProvider) { ResetModel(true); { const TemplateURL* keyword_url = - model_->GetTemplateURLForKeyword(L"unittest"); + model()->GetTemplateURLForKeyword(L"unittest"); ASSERT_TRUE(keyword_url != NULL); AssertEquals(copy_t_url, *keyword_url); - ASSERT_EQ(keyword_url, model_->GetDefaultSearchProvider()); + ASSERT_EQ(keyword_url, model()->GetDefaultSearchProvider()); } // Wait for any saves to finish. @@ -1055,10 +914,10 @@ TEST_F(TemplateURLModelTest, LoadRetainsDefaultProvider) { ResetModel(true); { const TemplateURL* keyword_url = - model_->GetTemplateURLForKeyword(L"unittest"); + model()->GetTemplateURLForKeyword(L"unittest"); ASSERT_TRUE(keyword_url != NULL); AssertEquals(copy_t_url, *keyword_url); - ASSERT_EQ(keyword_url, model_->GetDefaultSearchProvider()); + ASSERT_EQ(keyword_url, model()->GetDefaultSearchProvider()); } } @@ -1087,7 +946,7 @@ TEST_F(TemplateURLModelTest, LoadDoesAutoKeywordUpdate) { // Then add it to the model and save it all. ChangeModelToLoadState(); - model_->Add(t_url); + model()->Add(t_url); BlockTillServiceProcessesRequests(); // Now reload the model and verify that the merge updates the url. @@ -1102,26 +961,25 @@ TEST_F(TemplateURLModelTest, LoadDoesAutoKeywordUpdate) { TEST_F(TemplateURLModelTest, FailedInit) { VerifyLoad(); - model_.reset(NULL); - - profile_->GetWebDataService(Profile::EXPLICIT_ACCESS)->UnloadDatabase(); - profile_->GetWebDataService(Profile::EXPLICIT_ACCESS)->set_failed_init(true); + test_util_.ClearModel(); + test_util_.GetWebDataService()->UnloadDatabase(); + test_util_.GetWebDataService()->set_failed_init(true); ResetModel(false); - model_->Load(); + model()->Load(); BlockTillServiceProcessesRequests(); - ASSERT_TRUE(model_->GetDefaultSearchProvider()); + ASSERT_TRUE(model()->GetDefaultSearchProvider()); } // Verifies that if the default search URL preference is managed, we report // the default search as managed. TEST_F(TemplateURLModelTest, ReportDefaultSearchIsManaged) { - TestingPrefService* service = profile_->GetTestingPrefService(); + TestingPrefService* service = profile()->GetTestingPrefService(); service->RegisterStringPref(prefs::kDefaultSearchProviderSearchURL, std::string()); service->SetManagedPref(prefs::kDefaultSearchProviderSearchURL, Value::CreateStringValue("http://test.com/{searchTerms}")); - ASSERT_TRUE(model_->IsDefaultSearchManaged()); + ASSERT_TRUE(model()->IsDefaultSearchManaged()); } diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 2e251e7..725d730 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1216,6 +1216,8 @@ 'browser/safe_browsing/safe_browsing_util_unittest.cc', 'browser/search_engines/keyword_editor_controller_unittest.cc', 'browser/search_engines/search_host_to_urls_map_unittest.cc', + 'browser/search_engines/template_url_model_test_util.cc', + 'browser/search_engines/template_url_model_test_util.h', 'browser/search_engines/template_url_model_unittest.cc', 'browser/search_engines/template_url_parser_unittest.cc', 'browser/search_engines/template_url_prepopulate_data_unittest.cc', |