diff options
author | levin@chromium.org <levin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-03 00:53:31 +0000 |
---|---|---|
committer | levin@chromium.org <levin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-03 00:53:31 +0000 |
commit | 923d733d12d2dcb01aa64ec825c19444d728d978 (patch) | |
tree | ac9cfd8e13a96184f0f5a00fda7001c56c9c00bc | |
parent | d343782a2492ca416da36f9c6560b49042b93b76 (diff) | |
download | chromium_src-923d733d12d2dcb01aa64ec825c19444d728d978.zip chromium_src-923d733d12d2dcb01aa64ec825c19444d728d978.tar.gz chromium_src-923d733d12d2dcb01aa64ec825c19444d728d978.tar.bz2 |
Fix TemplateURLModel::GenerateSearchURL for use on non-UI threads.
BUG=38475
TEST=unit_tests --gtest_filter=Temp*:Sea*:Key*
Review URL: http://codereview.chromium.org/3343002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@58445 0039d316-1c4b-4281-b951-d872f2087c98
8 files changed, 245 insertions, 60 deletions
diff --git a/chrome/browser/search_engines/search_host_to_urls_map.cc b/chrome/browser/search_engines/search_host_to_urls_map.cc index 8ff2ac0..cc01aae 100644 --- a/chrome/browser/search_engines/search_host_to_urls_map.cc +++ b/chrome/browser/search_engines/search_host_to_urls_map.cc @@ -17,22 +17,24 @@ SearchHostToURLsMap::~SearchHostToURLsMap() { } void SearchHostToURLsMap::Init( - const std::vector<const TemplateURL*>& template_urls) { + const std::vector<const TemplateURL*>& template_urls, + const SearchTermsData& search_terms_data) { DCHECK(!initialized_); // Set as initialized here so Add doesn't assert. initialized_ = true; - for (size_t i = 0; i < template_urls.size(); ++i) { - Add(template_urls[i]); - } + for (size_t i = 0; i < template_urls.size(); ++i) + Add(template_urls[i], search_terms_data); } -void SearchHostToURLsMap::Add(const TemplateURL* template_url) { +void SearchHostToURLsMap::Add(const TemplateURL* template_url, + const SearchTermsData& search_terms_data) { DCHECK(initialized_); DCHECK(template_url); - const GURL url(TemplateURLModel::GenerateSearchURL(template_url)); + const GURL url(TemplateURLModel::GenerateSearchURLUsingTermsData( + template_url, search_terms_data)); if (!url.is_valid() || !url.has_host()) return; @@ -59,7 +61,8 @@ void SearchHostToURLsMap::Remove(const TemplateURL* template_url) { } void SearchHostToURLsMap::Update(const TemplateURL* existing_turl, - const TemplateURL& new_values) { + const TemplateURL& new_values, + const SearchTermsData& search_terms_data) { DCHECK(initialized_); DCHECK(existing_turl); @@ -71,10 +74,11 @@ void SearchHostToURLsMap::Update(const TemplateURL* existing_turl, *modifiable_turl = new_values; modifiable_turl->set_id(previous_id); - Add(existing_turl); + Add(existing_turl, search_terms_data); } -void SearchHostToURLsMap::UpdateGoogleBaseURLs() { +void SearchHostToURLsMap::UpdateGoogleBaseURLs( + const SearchTermsData& search_terms_data) { DCHECK(initialized_); // Create a list of the the TemplateURLs to update. @@ -97,7 +101,7 @@ void SearchHostToURLsMap::UpdateGoogleBaseURLs() { RemoveByPointer(t_urls_using_base_url[i]); for (size_t i = 0; i < t_urls_using_base_url.size(); ++i) - Add(t_urls_using_base_url[i]); + Add(t_urls_using_base_url[i], search_terms_data); } const TemplateURL* SearchHostToURLsMap::GetTemplateURLForHost( diff --git a/chrome/browser/search_engines/search_host_to_urls_map.h b/chrome/browser/search_engines/search_host_to_urls_map.h index bf08b0d..e4692fb 100644 --- a/chrome/browser/search_engines/search_host_to_urls_map.h +++ b/chrome/browser/search_engines/search_host_to_urls_map.h @@ -13,6 +13,7 @@ #include "base/basictypes.h" +class SearchTermsData; class TemplateURL; // Holds the host to template url mappings for the search providers. WARNING: @@ -26,11 +27,13 @@ class SearchHostToURLsMap { ~SearchHostToURLsMap(); // Initializes the map. - void Init(const std::vector<const TemplateURL*>& template_urls); + void Init(const std::vector<const TemplateURL*>& template_urls, + const SearchTermsData& search_terms_data); // Adds a new TemplateURL to the map. Since |template_url| is owned // externally, Remove or RemoveAll should be called if it becomes invalid. - void Add(const TemplateURL* template_url); + void Add(const TemplateURL* template_url, + const SearchTermsData& search_terms_data); // Removes the TemplateURL from the lookup. void Remove(const TemplateURL* template_url); @@ -38,10 +41,12 @@ class SearchHostToURLsMap { // Updates information in an existing TemplateURL. Note: Using Remove and // then Add separately would lead to race conditions in reading because the // lock would be released inbetween the calls. - void Update(const TemplateURL* existing_turl, const TemplateURL& new_values); + void Update(const TemplateURL* existing_turl, + const TemplateURL& new_values, + const SearchTermsData& search_terms_data); // Updates all search providers which have a google base url. - void UpdateGoogleBaseURLs(); + void UpdateGoogleBaseURLs(const SearchTermsData& search_terms_data); // Returns the first TemplateURL found with a URL using the specified |host|, // or NULL if there are no such TemplateURLs diff --git a/chrome/browser/search_engines/search_host_to_urls_map_unittest.cc b/chrome/browser/search_engines/search_host_to_urls_map_unittest.cc index 4ba1ac6..6602c25 100644 --- a/chrome/browser/search_engines/search_host_to_urls_map_unittest.cc +++ b/chrome/browser/search_engines/search_host_to_urls_map_unittest.cc @@ -5,6 +5,7 @@ #include "base/basictypes.h" #include "base/scoped_ptr.h" #include "chrome/browser/search_engines/search_host_to_urls_map.h" +#include "chrome/browser/search_engines/search_terms_data.h" #include "chrome/browser/search_engines/template_url.h" #include "testing/gtest/include/gtest/gtest.h" @@ -47,14 +48,16 @@ void SearchHostToURLsMapTest::SetUp() { template_urls.push_back(&t_urls_[1]); provider_map_.reset(new SearchHostToURLsMap); - provider_map_->Init(template_urls); + UIThreadSearchTermsData search_terms_data; + provider_map_->Init(template_urls, search_terms_data); } TEST_F(SearchHostToURLsMapTest, Add) { std::string new_host = "example.com"; TemplateURL new_t_url; new_t_url.SetURL("http://" + new_host + "/", 0, 0); - provider_map_->Add(&new_t_url); + UIThreadSearchTermsData search_terms_data; + provider_map_->Add(&new_t_url, search_terms_data); ASSERT_EQ(&new_t_url, provider_map_->GetTemplateURLForHost(new_host)); } @@ -82,26 +85,28 @@ TEST_F(SearchHostToURLsMapTest, Update) { TemplateURL new_values; new_values.SetURL("http://" + new_host + "/", 0, 0); - provider_map_->Update(&t_urls_[0], new_values); + UIThreadSearchTermsData search_terms_data; + provider_map_->Update(&t_urls_[0], new_values, search_terms_data); ASSERT_EQ(&t_urls_[0], provider_map_->GetTemplateURLForHost(new_host)); ASSERT_EQ(&t_urls_[1], provider_map_->GetTemplateURLForHost(host_)); } TEST_F(SearchHostToURLsMapTest, UpdateGoogleBaseURLs) { + UIThreadSearchTermsData search_terms_data; std::string google_base_url = "google.com"; SetGoogleBaseURL("http://" + google_base_url +"/"); // Add in a url with the templated Google base url. TemplateURL new_t_url; new_t_url.SetURL("{google:baseURL}?q={searchTerms}", 0, 0); - provider_map_->Add(&new_t_url); + provider_map_->Add(&new_t_url, search_terms_data); ASSERT_EQ(&new_t_url, provider_map_->GetTemplateURLForHost(google_base_url)); // Now change the Google base url and verify the result. std::string new_google_base_url = "other.com"; SetGoogleBaseURL("http://" + new_google_base_url +"/"); - provider_map_->UpdateGoogleBaseURLs(); + provider_map_->UpdateGoogleBaseURLs(search_terms_data); ASSERT_EQ(&new_t_url, provider_map_->GetTemplateURLForHost( new_google_base_url)); } diff --git a/chrome/browser/search_engines/template_url.cc b/chrome/browser/search_engines/template_url.cc index 78a8163..9912b35 100644 --- a/chrome/browser/search_engines/template_url.cc +++ b/chrome/browser/search_engines/template_url.cc @@ -185,6 +185,12 @@ std::string TemplateURLRef::ParseURL(const std::string& url, } void TemplateURLRef::ParseIfNecessary() const { + UIThreadSearchTermsData search_terms_data; + ParseIfNecessaryUsingTermsData(search_terms_data); +} + +void TemplateURLRef::ParseIfNecessaryUsingTermsData( + const SearchTermsData& search_terms_data) const { if (!parsed_) { parsed_ = true; parsed_url_ = ParseURL(url_, &replacements_, &valid_); @@ -206,14 +212,13 @@ void TemplateURLRef::ParseIfNecessary() const { // Only parse the host/key if there is one search term. Technically there // could be more than one term, but it's uncommon; so we punt. if (has_only_one_search_term) - ParseHostAndSearchTermKey(); + ParseHostAndSearchTermKey(search_terms_data); } } } -void TemplateURLRef::ParseHostAndSearchTermKey() const { - UIThreadSearchTermsData search_terms_data; - +void TemplateURLRef::ParseHostAndSearchTermKey( + const SearchTermsData& search_terms_data) const { std::string url_string = url_; ReplaceSubstringsAfterOffset(&url_string, 0, kGoogleBaseURLParameterFull, @@ -273,7 +278,7 @@ std::string TemplateURLRef::ReplaceSearchTermsUsingTermsData( int accepted_suggestion, const std::wstring& original_query_for_suggestion, const SearchTermsData& search_terms_data) const { - ParseIfNecessary(); + ParseIfNecessaryUsingTermsData(search_terms_data); if (!valid_) return std::string(); @@ -404,12 +409,24 @@ std::string TemplateURLRef::ReplaceSearchTermsUsingTermsData( } bool TemplateURLRef::SupportsReplacement() const { - ParseIfNecessary(); + UIThreadSearchTermsData search_terms_data; + return SupportsReplacementUsingTermsData(search_terms_data); +} + +bool TemplateURLRef::SupportsReplacementUsingTermsData( + const SearchTermsData& search_terms_data) const { + ParseIfNecessaryUsingTermsData(search_terms_data); return valid_ && supports_replacements_; } bool TemplateURLRef::IsValid() const { - ParseIfNecessary(); + UIThreadSearchTermsData search_terms_data; + return IsValidUsingTermsData(search_terms_data); +} + +bool TemplateURLRef::IsValidUsingTermsData( + const SearchTermsData& search_terms_data) const { + ParseIfNecessaryUsingTermsData(search_terms_data); return valid_; } @@ -524,7 +541,16 @@ GURL TemplateURL::GenerateFaviconURL(const GURL& url) { // static bool TemplateURL::SupportsReplacement(const TemplateURL* turl) { - return turl && turl->url() && turl->url()->SupportsReplacement(); + UIThreadSearchTermsData search_terms_data; + return SupportsReplacementUsingTermsData(turl, search_terms_data); +} + +// static +bool TemplateURL::SupportsReplacementUsingTermsData( + const TemplateURL* turl, + const SearchTermsData& search_terms_data) { + return turl && turl->url() && + turl->url()->SupportsReplacementUsingTermsData(search_terms_data); } TemplateURL::TemplateURL() diff --git a/chrome/browser/search_engines/template_url.h b/chrome/browser/search_engines/template_url.h index 35e88d5..201964f 100644 --- a/chrome/browser/search_engines/template_url.h +++ b/chrome/browser/search_engines/template_url.h @@ -58,6 +58,10 @@ class TemplateURLRef { // Returns true if this URL supports replacement. bool SupportsReplacement() const; + // Like SupportsReplacement but usable on threads other than the UI thread. + bool SupportsReplacementUsingTermsData( + const SearchTermsData& search_terms_data) const; + // Returns a string that is the result of replacing the search terms in // the url with the specified value. // @@ -94,6 +98,9 @@ class TemplateURLRef { // one that contains unknown terms, or invalid characters. bool IsValid() const; + // Like IsValid but usable on threads other than the UI thread. + bool IsValidUsingTermsData(const SearchTermsData& search_terms_data) const; + // Returns a string representation of this TemplateURLRef suitable for // display. The display format is the same as the format used by Firefox. std::wstring DisplayURL() const; @@ -192,8 +199,13 @@ class TemplateURLRef { // search_offset_. void ParseIfNecessary() const; + // Like ParseIfNecessary but usable on threads other than the UI thread. + void ParseIfNecessaryUsingTermsData( + const SearchTermsData& search_terms_data) const; + // Extracts the query key and host from the url. - void ParseHostAndSearchTermKey() const; + void ParseHostAndSearchTermKey( + const SearchTermsData& search_terms_data) const; // Used by tests to set the value for the Google base url. This takes // ownership of the given std::string. @@ -269,6 +281,11 @@ class TemplateURL { // replacement. static bool SupportsReplacement(const TemplateURL* turl); + // Like SupportsReplacement but usable on threads other than the UI thread. + static bool SupportsReplacementUsingTermsData( + const TemplateURL* turl, + const SearchTermsData& search_terms_data); + TemplateURL(); ~TemplateURL(); diff --git a/chrome/browser/search_engines/template_url_model.cc b/chrome/browser/search_engines/template_url_model.cc index 8b2c362..2df8ad0 100644 --- a/chrome/browser/search_engines/template_url_model.cc +++ b/chrome/browser/search_engines/template_url_model.cc @@ -160,25 +160,26 @@ std::wstring TemplateURLModel::CleanUserInputKeyword( GURL TemplateURLModel::GenerateSearchURL(const TemplateURL* t_url) { DCHECK(t_url); UIThreadSearchTermsData search_terms_data; - return GenerateSearchURLWithTermsData(t_url, search_terms_data); + return GenerateSearchURLUsingTermsData(t_url, search_terms_data); } // static -GURL TemplateURLModel::GenerateSearchURLWithTermsData( +GURL TemplateURLModel::GenerateSearchURLUsingTermsData( const TemplateURL* t_url, const SearchTermsData& search_terms_data) { DCHECK(t_url); const TemplateURLRef* search_ref = t_url->url(); // Extension keywords don't have host-based search URLs. - if (!search_ref || !search_ref->IsValid() || t_url->IsExtensionKeyword()) + if (!search_ref || !search_ref->IsValidUsingTermsData(search_terms_data) || + t_url->IsExtensionKeyword()) return GURL(); - if (!search_ref->SupportsReplacement()) + if (!search_ref->SupportsReplacementUsingTermsData(search_terms_data)) return GURL(search_ref->url()); - return GURL(search_ref->ReplaceSearchTerms( + return GURL(search_ref->ReplaceSearchTermsUsingTermsData( *t_url, kReplacementTerm, TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, - std::wstring())); + std::wstring(), search_terms_data)); } bool TemplateURLModel::CanReplaceKeyword( @@ -673,8 +674,10 @@ void TemplateURLModel::RemoveFromKeywordMapByPointer( void TemplateURLModel::AddToMaps(const TemplateURL* template_url) { if (!template_url->keyword().empty()) keyword_to_template_map_[template_url->keyword()] = template_url; - if (loaded_) - provider_map_.Add(template_url); + if (loaded_) { + UIThreadSearchTermsData search_terms_data; + provider_map_.Add(template_url, search_terms_data); + } } void TemplateURLModel::SetTemplateURLs(const std::vector<TemplateURL*>& urls) { @@ -705,7 +708,8 @@ void TemplateURLModel::SetTemplateURLs(const std::vector<TemplateURL*>& urls) { void TemplateURLModel::ChangeToLoadedState() { DCHECK(!loaded_); - provider_map_.Init(template_urls_); + UIThreadSearchTermsData search_terms_data; + provider_map_.Init(template_urls_, search_terms_data); loaded_ = true; } @@ -855,7 +859,8 @@ void TemplateURLModel::Update(const TemplateURL* existing_turl, keyword_to_template_map_.erase(existing_turl->keyword()); // This call handles copying over the values (while retaining the id). - provider_map_.Update(existing_turl, new_values); + UIThreadSearchTermsData search_terms_data; + provider_map_.Update(existing_turl, new_values, search_terms_data); if (!existing_turl->keyword().empty()) keyword_to_template_map_[existing_turl->keyword()] = existing_turl; @@ -1013,7 +1018,8 @@ void TemplateURLModel::GoogleBaseURLChanged() { } if (something_changed && loaded_) { - provider_map_.UpdateGoogleBaseURLs(); + UIThreadSearchTermsData search_terms_data; + provider_map_.UpdateGoogleBaseURLs(search_terms_data); FOR_EACH_OBSERVER(TemplateURLModelObserver, model_observers_, OnTemplateURLModelChanged()); } diff --git a/chrome/browser/search_engines/template_url_model.h b/chrome/browser/search_engines/template_url_model.h index 63f6dc3..ce7ebb4 100644 --- a/chrome/browser/search_engines/template_url_model.h +++ b/chrome/browser/search_engines/template_url_model.h @@ -86,7 +86,7 @@ class TemplateURLModel : public WebDataServiceConsumer, // Just like GenerateSearchURL except that it takes SearchTermsData to supply // the data for some search terms. Most of the time GenerateSearchURL should // be called. - static GURL GenerateSearchURLWithTermsData( + static GURL GenerateSearchURLUsingTermsData( const TemplateURL* t_url, const SearchTermsData& search_terms_data); diff --git a/chrome/browser/search_engines/template_url_model_unittest.cc b/chrome/browser/search_engines/template_url_model_unittest.cc index c67bec9..44665d8 100644 --- a/chrome/browser/search_engines/template_url_model_unittest.cc +++ b/chrome/browser/search_engines/template_url_model_unittest.cc @@ -7,11 +7,13 @@ #include "base/path_service.h" #include "base/scoped_vector.h" #include "base/string_util.h" +#include "base/ref_counted.h" #include "base/thread.h" #include "chrome/browser/chrome_thread.h" #include "chrome/browser/history/history.h" #include "chrome/browser/history/history_notifications.h" #include "chrome/browser/search_engines/search_host_to_urls_map.h" +#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" @@ -30,21 +32,6 @@ using base::TimeDelta; #define MAYBE_Load Load #endif -// Create an URL that appears to have been prepopulated, but won't be in the -// current data. The caller owns the returned TemplateURL*. -static TemplateURL* CreatePreloadedTemplateURL() { - TemplateURL* t_url = new TemplateURL(); - t_url->SetURL("http://www.unittest.com/", 0, 0); - t_url->set_keyword(L"unittest"); - t_url->set_short_name(L"unittest"); - t_url->set_safe_for_autoreplace(true); - GURL favicon_url("http://favicon.url"); - t_url->SetFavIconURL(favicon_url); - t_url->set_date_created(Time::FromTimeT(100)); - t_url->set_prepopulate_id(999999); - return t_url; -} - // A Task used to coordinate when the database has finished processing // requests. See note in BlockTillServiceProcessesRequests for details. // @@ -61,6 +48,74 @@ class QuitTask2 : public Task { MessageLoop* main_loop_; }; +// Test the GenerateSearchURL on a thread or the main thread. +class TestGenerateSearchURL : + public base::RefCountedThreadSafe<TestGenerateSearchURL> { + public: + explicit TestGenerateSearchURL(SearchTermsData* search_terms_data) + : search_terms_data_(search_terms_data), + passed_(false) { + } + + // Run the test cases for GenerateSearchURL. + void RunTest(); + + // Did the test pass? + bool passed() const { return passed_; } + + private: + friend class base::RefCountedThreadSafe<TestGenerateSearchURL>; + ~TestGenerateSearchURL() {} + + SearchTermsData* search_terms_data_; + bool passed_; + + DISALLOW_COPY_AND_ASSIGN(TestGenerateSearchURL); +}; + +// Simple implementation of SearchTermsData. +class TestSearchTermsData : public SearchTermsData { + public: + explicit TestSearchTermsData(const char* google_base_url) + : google_base_url_(google_base_url) { + } + + virtual std::string GoogleBaseURLValue() const { + return google_base_url_; + } + + virtual std::string GetApplicationLocale() const { + return "yy"; + } + +#if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) + // Returns the value for the Chrome Omnibox rlz. + virtual std::wstring GetRlzParameterValue() const { + return std::wstring(); + } +#endif + + private: + std::string google_base_url_; + + DISALLOW_COPY_AND_ASSIGN(TestSearchTermsData); +}; + +// Create an URL that appears to have been prepopulated, but won't be in the +// current data. The caller owns the returned TemplateURL*. +static TemplateURL* CreatePreloadedTemplateURL() { + TemplateURL* t_url = new TemplateURL(); + t_url->SetURL("http://www.unittest.com/", 0, 0); + t_url->set_keyword(L"unittest"); + t_url->set_short_name(L"unittest"); + t_url->set_safe_for_autoreplace(true); + GURL favicon_url("http://favicon.url"); + t_url->SetFavIconURL(favicon_url); + t_url->set_date_created(Time::FromTimeT(100)); + t_url->set_prepopulate_id(999999); + return t_url; +} + // Subclass the TestingProfile so that it can return a WebDataService. class TemplateURLModelTestingProfile : public TestingProfile { public: @@ -182,17 +237,23 @@ class TemplateURLModelTest : public testing::Test, changed_count_ = 0; } - // Blocks the caller until the service has finished servicing all pending + // Blocks the caller until thread has finished servicing all pending // requests. - void BlockTillServiceProcessesRequests() { - // Schedule a task on the DB thread that is processed after all - // pending requests on the DB thread. - ChromeThread::PostTask(ChromeThread::DB, FROM_HERE, new QuitTask2()); + 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()); @@ -262,6 +323,42 @@ class TemplateURLModelTest : public testing::Test, int changed_count_; }; +void TestGenerateSearchURL::RunTest() { + struct GenerateSearchURLCase { + const char* test_name; + const char* url; + const char* expected; + } generate_url_cases[] = { + { "empty TemplateURLRef", NULL, "" }, + { "invalid URL", "foo{searchTerms}", "" }, + { "URL with no replacements", "http://foo/", "http://foo/" }, + { "basic functionality", "http://foo/{searchTerms}", + "http://foo/blah.blah.blah.blah.blah" } + }; + + // Don't use ASSERT/EXPECT since this is run on a thread in one test + // and those macros aren't meant for threads at this time according to + // gtest documentation. + bool everything_passed = true; + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(generate_url_cases); ++i) { + TemplateURL t_url; + if (generate_url_cases[i].url) + t_url.SetURL(generate_url_cases[i].url, 0, 0); + + std::string result = search_terms_data_ ? + TemplateURLModel::GenerateSearchURLUsingTermsData( + &t_url, *search_terms_data_).spec() : + TemplateURLModel::GenerateSearchURL(&t_url).spec(); + if (strcmp(generate_url_cases[i].expected, result.c_str())) { + LOG(ERROR) << generate_url_cases[i].test_name << " failed. Expected " << + generate_url_cases[i].expected << " Actual " << result; + + everything_passed = false; + } + } + passed_ = everything_passed; +} + TemplateURL* TemplateURLModelTest::CreateReplaceablePreloadedTemplateURL( size_t index_offset_from_default, std::wstring* prepopulated_display_url) { @@ -401,6 +498,31 @@ TEST_F(TemplateURLModelTest, GenerateKeyword) { true)); } +TEST_F(TemplateURLModelTest, GenerateSearchURL) { + scoped_refptr<TestGenerateSearchURL> test_generate_search_url( + new TestGenerateSearchURL(NULL)); + test_generate_search_url->RunTest(); + EXPECT_TRUE(test_generate_search_url->passed()); +} + +TEST_F(TemplateURLModelTest, GenerateSearchURLUsingTermsData) { + // Run the test for GenerateSearchURLUsingTermsData on the "IO" thread and + // wait for it to finish. + TestSearchTermsData search_terms_data("http://google.com/"); + scoped_refptr<TestGenerateSearchURL> test_generate_search_url( + new TestGenerateSearchURL(&search_terms_data)); + + ChromeThread io_thread(ChromeThread::IO); + io_thread.Start(); + io_thread.message_loop()->PostTask( + FROM_HERE, + NewRunnableMethod(test_generate_search_url.get(), + &TestGenerateSearchURL::RunTest)); + WaitForThreadToProcessRequests(ChromeThread::IO); + EXPECT_TRUE(test_generate_search_url->passed()); + io_thread.Stop(); +} + TEST_F(TemplateURLModelTest, ClearBrowsingData_Keywords) { Time now = Time::Now(); TimeDelta one_day = TimeDelta::FromDays(1); |