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

Unified Diff: chrome/browser/history/in_memory_url_index_unittest.cc

Issue 879763002: Remove dependencies of InMemoryURLIndex on Profile (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@773103004
Patch Set: Created 5 years, 11 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/history/in_memory_url_index_unittest.cc
diff --git a/chrome/browser/history/in_memory_url_index_unittest.cc b/chrome/browser/history/in_memory_url_index_unittest.cc
index 3e25d3c3edc0ccdca5f8affbaf8276a61c27166c..af4d001c28a0829cb0f270a6aaa66019bda7823a 100644
--- a/chrome/browser/history/in_memory_url_index_unittest.cc
+++ b/chrome/browser/history/in_memory_url_index_unittest.cc
@@ -35,6 +35,7 @@ using base::ASCIIToUTF16;
namespace {
const size_t kMaxMatches = 3;
+const char kTestLanguages[] = "en,ja,hi,zh";
} // namespace
// The test version of the history url database table ('url') is contained in
@@ -88,11 +89,18 @@ class InMemoryURLIndexTest : public testing::Test {
protected:
// Test setup.
void SetUp() override;
+ void TearDown() override;
// Allows the database containing the test data to be customized by
// subclasses.
virtual base::FilePath::StringType TestDBName() const;
+ // Allows the test to control when the InMemoryURLIndex is initialized.
+ virtual bool InitializeInMemoryURLIndexInSetUp() const;
+
+ // Initialize the InMemoryURLIndex for the tests.
+ void InitializeInMemoryURLIndex();
+
// Validates that the given |term| is contained in |cache| and that it is
// marked as in-use.
void CheckTerm(const URLIndexPrivateData::SearchTermCacheMap& cache,
@@ -123,10 +131,9 @@ class InMemoryURLIndexTest : public testing::Test {
const URLIndexPrivateData& actual);
content::TestBrowserThreadBundle thread_bundle_;
+ scoped_ptr<InMemoryURLIndex> url_index_;
TestingProfile profile_;
HistoryService* history_service_;
-
- scoped_ptr<InMemoryURLIndex> url_index_;
HistoryDatabase* history_database_;
};
@@ -273,19 +280,34 @@ void InMemoryURLIndexTest::SetUp() {
transaction.Commit();
}
- url_index_.reset(new InMemoryURLIndex(&profile_,
- history_service_,
- base::FilePath(),
- "en,ja,hi,zh",
- history_service_->history_client()));
- url_index_->Init();
- url_index_->RebuildFromHistory(history_database_);
+ if (InitializeInMemoryURLIndexInSetUp())
+ InitializeInMemoryURLIndex();
+}
+
+void InMemoryURLIndexTest::TearDown() {
+ // Ensure that the InMemoryURLIndex no longer observer HistoryService before
+ // it is destroyed in order to prevent HistoryService calling dead observer.
+ if (url_index_)
+ url_index_->ShutDown();
}
base::FilePath::StringType InMemoryURLIndexTest::TestDBName() const {
return FILE_PATH_LITERAL("url_history_provider_test.db.txt");
}
+bool InMemoryURLIndexTest::InitializeInMemoryURLIndexInSetUp() const {
+ return true;
+}
+
+void InMemoryURLIndexTest::InitializeInMemoryURLIndex() {
+ DCHECK(!url_index_);
+ url_index_.reset(new InMemoryURLIndex(history_service_, base::FilePath(),
+ kTestLanguages,
+ history_service_->history_client()));
+ url_index_->Init();
+ url_index_->RebuildFromHistory(history_database_);
+}
+
void InMemoryURLIndexTest::CheckTerm(
const URLIndexPrivateData::SearchTermCacheMap& cache,
base::string16 term) const {
@@ -420,12 +442,17 @@ void InMemoryURLIndexTest::ExpectPrivateDataEqual(
class LimitedInMemoryURLIndexTest : public InMemoryURLIndexTest {
protected:
base::FilePath::StringType TestDBName() const override;
+ bool InitializeInMemoryURLIndexInSetUp() const override;
};
base::FilePath::StringType LimitedInMemoryURLIndexTest::TestDBName() const {
return FILE_PATH_LITERAL("url_history_provider_test_limited.db.txt");
}
+bool LimitedInMemoryURLIndexTest::InitializeInMemoryURLIndexInSetUp() const {
+ return false;
+}
+
TEST_F(LimitedInMemoryURLIndexTest, Initialization) {
// Verify that the database contains the expected number of items, which
// is the pre-filtered count, i.e. all of the items.
@@ -434,13 +461,8 @@ TEST_F(LimitedInMemoryURLIndexTest, Initialization) {
uint64 row_count = 0;
while (statement.Step()) ++row_count;
EXPECT_EQ(1U, row_count);
- url_index_.reset(new InMemoryURLIndex(&profile_,
- history_service_,
- base::FilePath(),
- "en,ja,hi,zh",
- history_service_->history_client()));
- url_index_->Init();
- url_index_->RebuildFromHistory(history_database_);
+
+ InitializeInMemoryURLIndex();
URLIndexPrivateData& private_data(*GetPrivateData());
// history_info_map_ should have the same number of items as were filtered.
@@ -1184,10 +1206,9 @@ class InMemoryURLIndexCacheTest : public testing::Test {
void InMemoryURLIndexCacheTest::SetUp() {
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
- HistoryClient history_client;
base::FilePath path(temp_dir_.path());
- url_index_.reset(new InMemoryURLIndex(
- NULL, nullptr, path, "en,ja,hi,zh", &history_client));
+ url_index_.reset(
+ new InMemoryURLIndex(nullptr, path, kTestLanguages, nullptr));
}
void InMemoryURLIndexCacheTest::set_history_dir(

Powered by Google App Engine
This is Rietveld 408576698