summaryrefslogtreecommitdiffstats
path: root/chrome/browser/search_engines
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/search_engines')
-rw-r--r--chrome/browser/search_engines/search_provider_install_data_unittest.cc145
-rw-r--r--chrome/browser/search_engines/template_url_fetcher_unittest.cc3
-rw-r--r--chrome/browser/search_engines/template_url_service_sync_unittest.cc3
-rw-r--r--chrome/browser/search_engines/template_url_service_test_util.cc95
-rw-r--r--chrome/browser/search_engines/template_url_service_test_util.h21
-rw-r--r--chrome/browser/search_engines/template_url_service_unittest.cc150
6 files changed, 109 insertions, 308 deletions
diff --git a/chrome/browser/search_engines/search_provider_install_data_unittest.cc b/chrome/browser/search_engines/search_provider_install_data_unittest.cc
index 019c2c1..15aa4df 100644
--- a/chrome/browser/search_engines/search_provider_install_data_unittest.cc
+++ b/chrome/browser/search_engines/search_provider_install_data_unittest.cc
@@ -8,6 +8,7 @@
#include "base/bind.h"
#include "base/memory/ref_counted.h"
#include "base/message_loop/message_loop.h"
+#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/search_engines/search_provider_install_data.h"
@@ -30,113 +31,72 @@ namespace {
// TestGetInstallState --------------------------------------------------------
// Test the SearchProviderInstallData::GetInstallState.
-class TestGetInstallState :
- public base::RefCountedThreadSafe<TestGetInstallState> {
+class TestGetInstallState {
public:
explicit TestGetInstallState(SearchProviderInstallData* install_data);
- void set_search_provider_host(
- const std::string& search_provider_host) {
- search_provider_host_ = search_provider_host;
- }
-
- void set_default_search_provider_host(
- const std::string& default_search_provider_host) {
- default_search_provider_host_ = default_search_provider_host;
- }
-
- // Runs the test. Returns true if all passed. False if any failed.
- bool RunTests();
+ // Runs all of the test cases.
+ void RunTests(const std::string& search_provider_host,
+ const std::string& default_search_provider_host);
private:
- friend class base::RefCountedThreadSafe<TestGetInstallState>;
- ~TestGetInstallState();
-
- // Starts the test run on the IO thread.
- void StartTestOnIOThread();
-
// Callback for when SearchProviderInstallData is ready to have
// GetInstallState called. Runs all of the test cases.
- void DoInstallStateTests();
+ void DoInstallStateTests(const std::string& search_provider_host,
+ const std::string& default_search_provider_host);
// Does a verification for one url and its expected state.
void VerifyInstallState(SearchProviderInstallData::State expected_state,
const std::string& url);
SearchProviderInstallData* install_data_;
- base::MessageLoop* main_loop_;
-
- // A host which should be a search provider but not the default.
- std::string search_provider_host_;
-
- // A host which should be a search provider but not the default.
- std::string default_search_provider_host_;
-
- // Used to indicate if DoInstallStateTests passed all test.
- bool passed_;
DISALLOW_COPY_AND_ASSIGN(TestGetInstallState);
};
TestGetInstallState::TestGetInstallState(
SearchProviderInstallData* install_data)
- : install_data_(install_data),
- main_loop_(NULL),
- passed_(false) {
-}
-
-bool TestGetInstallState::RunTests() {
- passed_ = true;
-
- main_loop_ = base::MessageLoop::current();
-
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)->PostTask(
- FROM_HERE,
- base::Bind(&TestGetInstallState::StartTestOnIOThread, this));
- // Run the current message loop. When the test is finished on the I/O thread,
- // it invokes Quit, which unblocks this.
- base::MessageLoop::current()->Run();
- main_loop_ = NULL;
-
- // Let the testing code know what the result is.
- return passed_;
+ : install_data_(install_data) {
}
-TestGetInstallState::~TestGetInstallState() {
-}
-
-void TestGetInstallState::StartTestOnIOThread() {
+void TestGetInstallState::RunTests(
+ const std::string& search_provider_host,
+ const std::string& default_search_provider_host) {
install_data_->CallWhenLoaded(
- base::Bind(&TestGetInstallState::DoInstallStateTests, this));
+ base::Bind(&TestGetInstallState::DoInstallStateTests,
+ base::Unretained(this),
+ search_provider_host, default_search_provider_host));
+ base::RunLoop().RunUntilIdle();
}
-void TestGetInstallState::DoInstallStateTests() {
+void TestGetInstallState::DoInstallStateTests(
+ const std::string& search_provider_host,
+ const std::string& default_search_provider_host) {
+ SCOPED_TRACE("search provider: " + search_provider_host +
+ ", default search provider: " + default_search_provider_host);
// Installed but not default.
VerifyInstallState(SearchProviderInstallData::INSTALLED_BUT_NOT_DEFAULT,
- "http://" + search_provider_host_ + "/");
+ "http://" + search_provider_host + "/");
VerifyInstallState(SearchProviderInstallData::INSTALLED_BUT_NOT_DEFAULT,
- "http://" + search_provider_host_ + ":80/");
+ "http://" + search_provider_host + ":80/");
// Not installed.
VerifyInstallState(SearchProviderInstallData::NOT_INSTALLED,
- "http://" + search_provider_host_ + ":96/");
+ "http://" + search_provider_host + ":96/");
// Not installed due to different scheme.
VerifyInstallState(SearchProviderInstallData::NOT_INSTALLED,
- "https://" + search_provider_host_ + "/");
+ "https://" + search_provider_host + "/");
// Not installed.
VerifyInstallState(SearchProviderInstallData::NOT_INSTALLED,
- "http://a" + search_provider_host_ + "/");
+ "http://a" + search_provider_host + "/");
// Installed as default.
- if (!default_search_provider_host_.empty()) {
+ if (!default_search_provider_host.empty()) {
VerifyInstallState(SearchProviderInstallData::INSTALLED_AS_DEFAULT,
- "http://" + default_search_provider_host_ + "/");
+ "http://" + default_search_provider_host + "/");
}
-
- // All done.
- main_loop_->PostTask(FROM_HERE, base::MessageLoop::QuitClosure());
}
void TestGetInstallState::VerifyInstallState(
@@ -145,16 +105,12 @@ void TestGetInstallState::VerifyInstallState(
SearchProviderInstallData::State actual_state =
install_data_->GetInstallState(GURL(url));
- if (expected_state == actual_state)
- return;
-
- passed_ = false;
- LOG(ERROR) << "GetInstallState for " << url << " failed. Expected " <<
- expected_state << ". Actual " << actual_state << ".";
+ EXPECT_EQ(expected_state, actual_state)
+ << "GetInstallState for " << url << " failed. Expected "
+ << expected_state << ". Actual " << actual_state << ".";
}
-}; // namespace
-
+} // namespace
// SearchProviderInstallDataTest ----------------------------------------------
@@ -193,7 +149,6 @@ void SearchProviderInstallDataTest::SetUp() {
std::string() /* unknown country code */);
#endif
util_.SetUp();
- util_.StartIOThread();
install_data_ = new SearchProviderInstallData(util_.profile(),
content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
content::Source<SearchProviderInstallDataTest>(this));
@@ -247,7 +202,6 @@ TemplateURL* SearchProviderInstallDataTest::AddNewTemplateURL(
return t_url;
}
-
// Actual tests ---------------------------------------------------------------
TEST_F(SearchProviderInstallDataTest, GetInstallState) {
@@ -257,24 +211,20 @@ TEST_F(SearchProviderInstallDataTest, GetInstallState) {
AddNewTemplateURL("http://" + host + "/path", ASCIIToUTF16("unittest"));
// Wait for the changes to be saved.
- TemplateURLServiceTestUtil::BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
// Verify the search providers install state (with no default set).
- scoped_refptr<TestGetInstallState> test_get_install_state(
- new TestGetInstallState(install_data_));
- test_get_install_state->set_search_provider_host(host);
- EXPECT_TRUE(test_get_install_state->RunTests());
+ TestGetInstallState test_get_install_state(install_data_);
+ test_get_install_state.RunTests(host, std::string());
// Set-up a default and try it all one more time.
std::string default_host = "www.mmm.com";
TemplateURL* default_url =
AddNewTemplateURL("http://" + default_host + "/", ASCIIToUTF16("mmm"));
util_.model()->SetDefaultSearchProvider(default_url);
- test_get_install_state->set_default_search_provider_host(default_host);
- EXPECT_TRUE(test_get_install_state->RunTests());
+ test_get_install_state.RunTests(host, default_host);
}
-
TEST_F(SearchProviderInstallDataTest, ManagedDefaultSearch) {
// Set up the database.
util_.ChangeModelToLoadState();
@@ -288,28 +238,23 @@ TEST_F(SearchProviderInstallDataTest, ManagedDefaultSearch) {
EXPECT_TRUE(util_.model()->is_default_search_managed());
// Wait for the changes to be saved.
- util_.BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
// Verify the search providers install state. The default search should be
// the managed one we previously set.
- scoped_refptr<TestGetInstallState> test_get_install_state(
- new TestGetInstallState(install_data_));
- test_get_install_state->set_search_provider_host(host);
- test_get_install_state->set_default_search_provider_host(host2);
- EXPECT_TRUE(test_get_install_state->RunTests());
+ TestGetInstallState test_get_install_state(install_data_);
+ test_get_install_state.RunTests(host, host2);
}
-
TEST_F(SearchProviderInstallDataTest, GoogleBaseUrlChange) {
- scoped_refptr<TestGetInstallState> test_get_install_state(
- new TestGetInstallState(install_data_));
+ TestGetInstallState test_get_install_state(install_data_);
// Set up the database.
util_.ChangeModelToLoadState();
std::string google_host = "w.com";
util_.SetGoogleBaseURL(GURL("http://" + google_host + "/"));
// Wait for the I/O thread to process the update notification.
- TemplateURLServiceTestUtil::BlockTillIOThreadProcessesRequests();
+ base::RunLoop().RunUntilIdle();
AddNewTemplateURL("{google:baseURL}?q={searchTerms}", ASCIIToUTF16("t"));
TemplateURL* default_url =
@@ -317,19 +262,17 @@ TEST_F(SearchProviderInstallDataTest, GoogleBaseUrlChange) {
util_.model()->SetDefaultSearchProvider(default_url);
// Wait for the changes to be saved.
- TemplateURLServiceTestUtil::BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
// Verify the search providers install state (with no default set).
- test_get_install_state->set_search_provider_host(google_host);
- EXPECT_TRUE(test_get_install_state->RunTests());
+ test_get_install_state.RunTests(google_host, std::string());
// Change the Google base url.
google_host = "foo.com";
util_.SetGoogleBaseURL(GURL("http://" + google_host + "/"));
// Wait for the I/O thread to process the update notification.
- TemplateURLServiceTestUtil::BlockTillIOThreadProcessesRequests();
+ base::RunLoop().RunUntilIdle();
// Verify that the change got picked up.
- test_get_install_state->set_search_provider_host(google_host);
- EXPECT_TRUE(test_get_install_state->RunTests());
+ test_get_install_state.RunTests(google_host, std::string());
}
diff --git a/chrome/browser/search_engines/template_url_fetcher_unittest.cc b/chrome/browser/search_engines/template_url_fetcher_unittest.cc
index e2eaec1..f55aca1 100644
--- a/chrome/browser/search_engines/template_url_fetcher_unittest.cc
+++ b/chrome/browser/search_engines/template_url_fetcher_unittest.cc
@@ -15,6 +15,7 @@
#include "chrome/browser/search_engines/template_url_service_test_util.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/test/base/testing_profile.h"
+#include "content/public/browser/browser_thread.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
@@ -46,12 +47,10 @@ class TemplateURLFetcherTest : public testing::Test {
virtual void SetUp() OVERRIDE {
test_util_.SetUp();
- test_util_.StartIOThread();
TestingProfile* profile = test_util_.profile();
ASSERT_TRUE(profile);
ASSERT_TRUE(TemplateURLFetcherFactory::GetForProfile(profile));
- profile->CreateRequestContext();
ASSERT_TRUE(profile->GetRequestContext());
ASSERT_TRUE(test_server_.InitializeAndWaitUntilReady());
}
diff --git a/chrome/browser/search_engines/template_url_service_sync_unittest.cc b/chrome/browser/search_engines/template_url_service_sync_unittest.cc
index 9b8461b..643e7d38 100644
--- a/chrome/browser/search_engines/template_url_service_sync_unittest.cc
+++ b/chrome/browser/search_engines/template_url_service_sync_unittest.cc
@@ -4,6 +4,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
+#include "base/run_loop.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
@@ -1895,7 +1896,7 @@ TEST_F(TemplateURLServiceSyncTest, PreSyncUpdates) {
// Merge the prepopulate search engines.
base::Time pre_merge_time = base::Time::Now();
- test_util_a_.BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
test_util_a_.ResetModel(true);
// The newly added search engine should have been safely merged, with an
diff --git a/chrome/browser/search_engines/template_url_service_test_util.cc b/chrome/browser/search_engines/template_url_service_test_util.cc
index 850b5e3..5c5e43c 100644
--- a/chrome/browser/search_engines/template_url_service_test_util.cc
+++ b/chrome/browser/search_engines/template_url_service_test_util.cc
@@ -5,9 +5,7 @@
#include "chrome/browser/search_engines/template_url_service_test_util.h"
#include "base/bind.h"
-#include "base/message_loop/message_loop.h"
-#include "base/path_service.h"
-#include "base/synchronization/waitable_event.h"
+#include "base/run_loop.h"
#include "base/threading/thread.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/google/google_url_tracker.h"
@@ -20,43 +18,12 @@
#include "chrome/test/base/testing_pref_service_syncable.h"
#include "chrome/test/base/testing_profile.h"
#include "content/public/browser/notification_service.h"
-#include "content/public/test/test_browser_thread.h"
#include "testing/gtest/include/gtest/gtest.h"
-
#if defined(OS_CHROMEOS)
#include "chrome/browser/google/google_util_chromeos.h"
#endif
-using content::BrowserThread;
-
-namespace {
-
-// A callback used to coordinate when the database has finished processing
-// requests. See note in BlockTillServiceProcessesRequests for details.
-//
-// Schedules a QuitClosure on the message loop it was created with.
-void QuitCallback(base::MessageLoop* message_loop) {
- message_loop->PostTask(FROM_HERE, base::MessageLoop::QuitClosure());
-}
-
-// Blocks the caller until thread has finished servicing all pending
-// requests.
-static void WaitForThreadToProcessRequests(BrowserThread::ID identifier) {
- // Schedule a task on the thread that is processed after all
- // pending requests on the thread.
- BrowserThread::PostTask(
- identifier,
- FROM_HERE,
- base::Bind(&QuitCallback, base::MessageLoop::current()));
- base::MessageLoop::current()->Run();
-}
-
-} // namespace
-
-
-// TestingTemplateURLService --------------------------------------------------
-
// Trivial subclass of TemplateURLService that records the last invocation of
// SetKeywordSearchTermsForURL.
class TestingTemplateURLService : public TemplateURLService {
@@ -88,14 +55,14 @@ class TestingTemplateURLService : public TemplateURLService {
DISALLOW_COPY_AND_ASSIGN(TestingTemplateURLService);
};
-
// TemplateURLServiceTestUtilBase ---------------------------------------------
TemplateURLServiceTestUtilBase::TemplateURLServiceTestUtilBase()
: changed_count_(0) {
}
-TemplateURLServiceTestUtilBase::~TemplateURLServiceTestUtilBase() {}
+TemplateURLServiceTestUtilBase::~TemplateURLServiceTestUtilBase() {
+}
void TemplateURLServiceTestUtilBase::CreateTemplateUrlService() {
profile()->CreateWebDataService();
@@ -118,18 +85,10 @@ void TemplateURLServiceTestUtilBase::ResetObserverCount() {
changed_count_ = 0;
}
-void TemplateURLServiceTestUtilBase::BlockTillServiceProcessesRequests() {
- WaitForThreadToProcessRequests(BrowserThread::DB);
-}
-
-void TemplateURLServiceTestUtilBase::BlockTillIOThreadProcessesRequests() {
- WaitForThreadToProcessRequests(BrowserThread::IO);
-}
-
void TemplateURLServiceTestUtilBase::VerifyLoad() {
ASSERT_FALSE(model()->loaded());
model()->Load();
- BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
EXPECT_EQ(1, GetObserverCount());
ResetObserverCount();
}
@@ -140,7 +99,7 @@ void TemplateURLServiceTestUtilBase::ChangeModelToLoadState() {
// any changes made.
model()->service_ = WebDataService::FromBrowserContext(profile());
- BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
}
void TemplateURLServiceTestUtilBase::ClearModel() {
@@ -238,9 +197,7 @@ TemplateURLService* TemplateURLServiceTestUtilBase::model() const {
// TemplateURLServiceTestUtil -------------------------------------------------
TemplateURLServiceTestUtil::TemplateURLServiceTestUtil()
- : ui_thread_(BrowserThread::UI, &message_loop_),
- db_thread_(BrowserThread::DB),
- io_thread_(BrowserThread::IO) {
+ : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {
}
TemplateURLServiceTestUtil::~TemplateURLServiceTestUtil() {
@@ -250,7 +207,6 @@ void TemplateURLServiceTestUtil::SetUp() {
// Make unique temp directory.
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
profile_.reset(new TestingProfile(temp_dir_.path()));
- db_thread_.Start();
TemplateURLServiceTestUtilBase::CreateTemplateUrlService();
@@ -260,49 +216,14 @@ void TemplateURLServiceTestUtil::SetUp() {
}
void TemplateURLServiceTestUtil::TearDown() {
- if (profile_.get()) {
- // Clear the request context so it will get deleted. This should be done
- // before shutting down the I/O thread to avoid memory leaks.
- profile_->ResetRequestContext();
- profile_.reset();
- }
-
- // Wait for the delete of the request context to happen.
- if (io_thread_.IsRunning())
- TemplateURLServiceTestUtilBase::BlockTillIOThreadProcessesRequests();
-
- // The I/O thread must be shutdown before the DB thread.
- io_thread_.Stop();
-
- // 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.
- // Schedule another task on the DB thread to notify us that it's safe to
- // carry on with the test.
- base::WaitableEvent done(false, false);
- BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
- base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done)));
- done.Wait();
- base::MessageLoop::current()->PostTask(FROM_HERE,
- base::MessageLoop::QuitClosure());
- base::MessageLoop::current()->Run();
- db_thread_.Stop();
+ profile_.reset();
UIThreadSearchTermsData::SetGoogleBaseURL(std::string());
// Flush the message loop to make application verifiers happy.
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
}
TestingProfile* TemplateURLServiceTestUtil::profile() const {
return profile_.get();
}
-
-void TemplateURLServiceTestUtil::StartIOThread() {
- io_thread_.StartIOThread();
-}
-
-void TemplateURLServiceTestUtil::PumpLoop() {
- message_loop_.RunUntilIdle();
-}
diff --git a/chrome/browser/search_engines/template_url_service_test_util.h b/chrome/browser/search_engines/template_url_service_test_util.h
index 7ddd4fd..6c7c379 100644
--- a/chrome/browser/search_engines/template_url_service_test_util.h
+++ b/chrome/browser/search_engines/template_url_service_test_util.h
@@ -15,7 +15,7 @@
#include "base/strings/string16.h"
#include "chrome/browser/search_engines/template_url_service_observer.h"
#include "chrome/test/base/testing_browser_process.h"
-#include "content/public/test/test_browser_thread.h"
+#include "content/public/test/test_browser_thread_bundle.h"
class GURL;
class TemplateURLService;
@@ -42,14 +42,6 @@ class TemplateURLServiceTestUtilBase : public TemplateURLServiceObserver {
// Sets the observer count to 0.
void ResetObserverCount();
- // Blocks the caller until the service has finished servicing all pending
- // requests.
- static void BlockTillServiceProcessesRequests();
-
- // Blocks the caller until the I/O thread has finished servicing all pending
- // requests.
- static void BlockTillIOThreadProcessesRequests();
-
// Makes sure the load was successful and sent the correct notification.
void VerifyLoad();
@@ -119,19 +111,10 @@ class TemplateURLServiceTestUtil : public TemplateURLServiceTestUtilBase {
// Returns the TestingProfile.
virtual TestingProfile* profile() const OVERRIDE;
- // Starts an I/O thread.
- void StartIOThread();
-
- // Runs all pending tasks on the UI loop.
- void PumpLoop();
-
private:
- base::MessageLoopForUI message_loop_;
// Needed to make the DeleteOnUIThread trait of WebDataService work
// properly.
- content::TestBrowserThread ui_thread_;
- content::TestBrowserThread db_thread_;
- content::TestBrowserThread io_thread_;
+ content::TestBrowserThreadBundle thread_bundle_;
scoped_ptr<TestingProfile> profile_;
base::ScopedTempDir temp_dir_;
diff --git a/chrome/browser/search_engines/template_url_service_unittest.cc b/chrome/browser/search_engines/template_url_service_unittest.cc
index b1e95de..a230386 100644
--- a/chrome/browser/search_engines/template_url_service_unittest.cc
+++ b/chrome/browser/search_engines/template_url_service_unittest.cc
@@ -7,6 +7,7 @@
#include "base/callback.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_vector.h"
+#include "base/run_loop.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
@@ -41,72 +42,6 @@ using ::testing::StrictMock;
namespace {
-// TestGenerateSearchURL ------------------------------------------------------
-
-// Test the GenerateSearchURL on a thread or the main thread.
-class TestGenerateSearchURL
- : public base::RefCountedThreadSafe<TestGenerateSearchURL> {
- public:
- explicit TestGenerateSearchURL(SearchTermsData* search_terms_data);
-
- // 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);
-};
-
-TestGenerateSearchURL::TestGenerateSearchURL(SearchTermsData* search_terms_data)
- : search_terms_data_(search_terms_data),
- passed_(false) {
-}
-
-void TestGenerateSearchURL::RunTest() {
- struct GenerateSearchURLCase {
- const char* test_name;
- const char* url;
- const char* expected;
- } generate_url_cases[] = {
- { "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) {
- TemplateURLData data;
- data.SetURL(generate_url_cases[i].url);
- TemplateURL t_url(NULL, data);
- std::string result = (search_terms_data_ ?
- TemplateURLService::GenerateSearchURLUsingTermsData(&t_url,
- *search_terms_data_) :
- TemplateURLService::GenerateSearchURL(&t_url)).spec();
- if (result != generate_url_cases[i].expected) {
- LOG(ERROR) << generate_url_cases[i].test_name << " failed. Expected " <<
- generate_url_cases[i].expected << " Actual " << result;
- everything_passed = false;
- }
- }
- passed_ = everything_passed;
-}
-
-TestGenerateSearchURL::~TestGenerateSearchURL() {
-}
-
-
// TestSearchTermsData --------------------------------------------------------
// Simple implementation of SearchTermsData.
@@ -303,6 +238,36 @@ class TemplateURLServiceTest : public testing::Test {
protected:
TemplateURLServiceTestUtil test_util_;
+ void TestGenerateSearchURL(SearchTermsData* search_terms_data) {
+ struct GenerateSearchURLCase {
+ const char* test_name;
+ const char* url;
+ const char* expected;
+ } generate_url_cases[] = {
+ { "invalid URL", "foo{searchTerms}", "" },
+ { "URL with no replacements", "http://foo/", "http://foo/" },
+ { "basic functionality", "http://foo/{searchTerms}",
+ "http://foo/blah.blah.blah.blah.blah" }
+ };
+
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(generate_url_cases); ++i) {
+ TemplateURLData data;
+ data.SetURL(generate_url_cases[i].url);
+ TemplateURL t_url(NULL, data);
+ std::string result;
+ if (search_terms_data) {
+ result = TemplateURLService::GenerateSearchURLUsingTermsData(
+ &t_url, *search_terms_data).spec();
+ } else {
+ result = TemplateURLService::GenerateSearchURL(&t_url).spec();
+ }
+ EXPECT_EQ(result, generate_url_cases[i].expected)
+ << generate_url_cases[i].test_name << " failed. Expected "
+ << generate_url_cases[i].expected << " Actual " << result;
+ }
+ }
+
+
DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceTest);
};
@@ -405,7 +370,7 @@ void TemplateURLServiceTest::TestLoadUpdatingPreloadedURL(
ASSERT_TRUE(keyword_url != NULL);
EXPECT_EQ(t_url, keyword_url);
EXPECT_EQ(original_url, keyword_url->url_ref().DisplayURL());
- test_util_.BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
// Now reload the model and verify that the merge updates the url, and
// preserves the sync GUID.
@@ -416,7 +381,7 @@ void TemplateURLServiceTest::TestLoadUpdatingPreloadedURL(
EXPECT_EQ(original_guid, keyword_url->sync_guid());
// Wait for any saves to finish.
- test_util_.BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
// Reload the model to verify that change was saved correctly.
test_util_.ResetModel(true);
@@ -462,7 +427,7 @@ TEST_F(TemplateURLServiceTest, AddUpdateRemove) {
ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("keyword"), GURL(),
NULL));
VerifyObserverCount(1);
- test_util_.BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size());
ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(t_url->keyword()));
// We need to make a second copy as the model takes ownership of |t_url| and
@@ -499,7 +464,7 @@ TEST_F(TemplateURLServiceTest, AddUpdateRemove) {
NULL));
ASSERT_FALSE(model()->CanReplaceKeyword(ASCIIToUTF16("b"), GURL(), NULL));
cloned_url.reset(new TemplateURL(loaded_url->profile(), loaded_url->data()));
- test_util_.BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
test_util_.ResetModel(true);
ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size());
loaded_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("b"));
@@ -676,25 +641,14 @@ TEST_F(TemplateURLServiceTest, GenerateKeyword) {
}
TEST_F(TemplateURLServiceTest, GenerateSearchURL) {
- scoped_refptr<TestGenerateSearchURL> test_generate_search_url(
- new TestGenerateSearchURL(NULL));
- test_generate_search_url->RunTest();
- EXPECT_TRUE(test_generate_search_url->passed());
+ TestGenerateSearchURL(NULL);
}
TEST_F(TemplateURLServiceTest, 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));
-
- test_util_.StartIOThread();
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)->PostTask(
- FROM_HERE, base::Bind(&TestGenerateSearchURL::RunTest,
- test_generate_search_url.get()));
- TemplateURLServiceTestUtil::BlockTillIOThreadProcessesRequests();
- EXPECT_TRUE(test_generate_search_url->passed());
+ TestGenerateSearchURL(&search_terms_data);
}
TEST_F(TemplateURLServiceTest, ClearBrowsingData_Keywords) {
@@ -826,7 +780,7 @@ TEST_F(TemplateURLServiceTest, Reset) {
model()->Add(t_url);
VerifyObserverCount(1);
- test_util_.BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
StrictMock<base::MockTimeProvider> mock_time;
model()->set_time_provider(&base::MockTimeProvider::StaticNow);
@@ -874,7 +828,7 @@ TEST_F(TemplateURLServiceTest, DefaultSearchProvider) {
// Setting the default search provider should have caused notification.
VerifyObserverCount(1);
- test_util_.BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(),
t_url->data()));
@@ -953,7 +907,7 @@ TEST_F(TemplateURLServiceTest, DefaultSearchProviderLoadedFromPrefs) {
const TemplateURLID id = t_url->id();
model()->SetDefaultSearchProvider(t_url);
- test_util_.BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(),
t_url->data()));
@@ -1243,7 +1197,7 @@ TEST_F(TemplateURLServiceTest, LoadDeletesUnusedProvider) {
model()->Add(t_url);
ASSERT_TRUE(
model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) != NULL);
- test_util_.BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
// Ensure that merging clears this engine.
test_util_.ResetModel(true);
@@ -1251,7 +1205,7 @@ TEST_F(TemplateURLServiceTest, LoadDeletesUnusedProvider) {
model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) == NULL);
// Wait for any saves to finish.
- test_util_.BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
// Reload the model to verify that the database was updated as a result of the
// merge.
@@ -1274,7 +1228,7 @@ TEST_F(TemplateURLServiceTest, LoadRetainsModifiedProvider) {
ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")));
// Wait for any saves to finish.
- test_util_.BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
// Ensure that merging won't clear it if the user has edited it.
test_util_.ResetModel(true);
@@ -1284,7 +1238,7 @@ TEST_F(TemplateURLServiceTest, LoadRetainsModifiedProvider) {
AssertEquals(*cloned_url, *url_for_unittest);
// Wait for any saves to finish.
- test_util_.BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
// Reload the model to verify that save/reload retains the item.
test_util_.ResetModel(true);
@@ -1304,7 +1258,7 @@ TEST_F(TemplateURLServiceTest, LoadSavesPrepopulatedDefaultSearchProvider) {
default_search->data()));
// Wait for any saves to finish.
- test_util_.BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
// Reload the model and check that the default search provider
// was properly saved.
@@ -1368,7 +1322,7 @@ TEST_F(TemplateURLServiceTest, LoadRetainsDefaultProvider) {
ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")));
ASSERT_EQ(t_url, model()->GetDefaultSearchProvider());
- test_util_.BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
// Ensure that merging won't clear the prepopulated template url
// which is no longer present if it's the default engine.
@@ -1382,7 +1336,7 @@ TEST_F(TemplateURLServiceTest, LoadRetainsDefaultProvider) {
}
// Wait for any saves to finish.
- test_util_.BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
// Reload the model to verify that the update was saved.
test_util_.ResetModel(true);
@@ -1418,7 +1372,7 @@ TEST_F(TemplateURLServiceTest, LoadEnsuresDefaultSearchProviderExists) {
// Now remove it.
model()->SetDefaultSearchProvider(NULL);
model()->Remove(old_default);
- test_util_.BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
EXPECT_FALSE(model()->GetDefaultSearchProvider());
@@ -1432,7 +1386,7 @@ TEST_F(TemplateURLServiceTest, LoadEnsuresDefaultSearchProviderExists) {
model()->ResetTemplateURL(model()->GetDefaultSearchProvider(),
ASCIIToUTF16("test"), ASCIIToUTF16("test"),
"http://example.com/");
- test_util_.BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
// Reset the model and load it. There should be a usable default search
// provider.
@@ -1454,7 +1408,7 @@ TEST_F(TemplateURLServiceTest, FailedInit) {
test_util_.ResetModel(false);
model()->Load();
- test_util_.BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
ASSERT_TRUE(model()->GetDefaultSearchProvider());
}
@@ -1610,7 +1564,7 @@ TEST_F(TemplateURLServiceTest, PatchEmptySyncGUID) {
model()->Add(t_url);
VerifyObserverCount(1);
- test_util_.BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size());
// Reload the model to verify it was actually saved to the database and
@@ -1647,7 +1601,7 @@ TEST_F(TemplateURLServiceTest, DuplicateInputEncodings) {
model()->Add(t_url);
VerifyObserverCount(1);
- test_util_.BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size());
const TemplateURL* loaded_url =
model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"));