Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(177)

Unified Diff: chrome/browser/search_engines/template_url_service_unittest.cc

Issue 17127002: Correctly integrate StoragePartition into TestingProfile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merged to ToT Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/search_engines/template_url_service_unittest.cc
diff --git a/chrome/browser/search_engines/template_url_service_unittest.cc b/chrome/browser/search_engines/template_url_service_unittest.cc
index 94026be9db1c40cfb42e9e1e69e13495b6625e84..6814516f058bcbeabe088789c76118555abf266b 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"
@@ -38,72 +39,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.
@@ -208,6 +143,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);
};
@@ -340,7 +305,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.
@@ -351,7 +316,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);
@@ -397,7 +362,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
@@ -434,7 +399,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"));
@@ -611,25 +576,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) {
@@ -761,7 +715,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);
@@ -809,7 +763,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()));
@@ -888,7 +842,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()));
@@ -1154,7 +1108,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);
@@ -1162,7 +1116,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.
@@ -1185,7 +1139,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);
@@ -1195,7 +1149,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);
@@ -1215,7 +1169,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.
@@ -1279,7 +1233,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.
@@ -1293,7 +1247,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);
@@ -1329,7 +1283,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());
@@ -1343,7 +1297,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.
@@ -1365,7 +1319,7 @@ TEST_F(TemplateURLServiceTest, FailedInit) {
test_util_.ResetModel(false);
model()->Load();
- test_util_.BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
ASSERT_TRUE(model()->GetDefaultSearchProvider());
}
@@ -1521,7 +1475,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
@@ -1558,7 +1512,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"));

Powered by Google App Engine
This is Rietveld 408576698