Commit 48e041d7 authored by Olivier Li's avatar Olivier Li Committed by Commit Bot

Prepare HistoryService tests for HistoryServiceUsesTaskScheduler activation.

The feature will soon be flipped to ENABLED_BY_DEFAULT. This will make
HistoryServiceBackend's task runner dispatch to the ThreadPool instead
of a dedicated base::Thread. The tests need to be prepared to stay
functional when that happens.

This is done as the last mile of the chrome-wide effort to coalesce as
much work as possible to the ThreadPool.

Bug: 661143
Change-Id: I7bdbdb5152edafc5394aeab187ea8a8602f5330e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1972305
Commit-Queue: Oliver Li <olivierli@chromium.org>
Auto-Submit: Oliver Li <olivierli@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#726361}
parent b6093335
...@@ -241,6 +241,7 @@ class HistoryBackendTestBase : public testing::Test { ...@@ -241,6 +241,7 @@ class HistoryBackendTestBase : public testing::Test {
mem_backend_->OnKeywordSearchTermDeleted(nullptr, url_id); mem_backend_->OnKeywordSearchTermDeleted(nullptr, url_id);
} }
base::test::TaskEnvironment task_environment_;
history::HistoryClientFakeBookmarks history_client_; history::HistoryClientFakeBookmarks history_client_;
scoped_refptr<HistoryBackend> backend_; // Will be NULL on init failure. scoped_refptr<HistoryBackend> backend_; // Will be NULL on init failure.
std::unique_ptr<InMemoryHistoryBackend> mem_backend_; std::unique_ptr<InMemoryHistoryBackend> mem_backend_;
...@@ -282,7 +283,6 @@ class HistoryBackendTestBase : public testing::Test { ...@@ -282,7 +283,6 @@ class HistoryBackendTestBase : public testing::Test {
URLsModifiedList urls_modified_notifications_; URLsModifiedList urls_modified_notifications_;
URLsDeletedList urls_deleted_notifications_; URLsDeletedList urls_deleted_notifications_;
base::test::SingleThreadTaskEnvironment task_environment_;
base::FilePath test_dir_; base::FilePath test_dir_;
DISALLOW_COPY_AND_ASSIGN(HistoryBackendTestBase); DISALLOW_COPY_AND_ASSIGN(HistoryBackendTestBase);
...@@ -3578,28 +3578,6 @@ TEST_F(HistoryBackendTest, DeleteMatchingUrlsForKeyword) { ...@@ -3578,28 +3578,6 @@ TEST_F(HistoryBackendTest, DeleteMatchingUrlsForKeyword) {
EXPECT_FALSE(backend_->db()->GetKeywordSearchTermRow(url3_id, nullptr)); EXPECT_FALSE(backend_->db()->GetKeywordSearchTermRow(url3_id, nullptr));
} }
// Simple test that removes a bookmark. This test exercises the code paths in
// History that block till bookmark bar model is loaded.
TEST_F(HistoryBackendTest, RemoveNotification) {
base::ScopedTempDir scoped_temp_dir;
EXPECT_TRUE(scoped_temp_dir.CreateUniqueTempDirUnderPath(test_dir()));
// Add a URL.
GURL url("http://www.google.com");
std::unique_ptr<HistoryService> service(
new HistoryService(std::make_unique<HistoryClientFakeBookmarks>(),
std::unique_ptr<history::VisitDelegate>()));
EXPECT_TRUE(service->Init(
TestHistoryDatabaseParamsForPath(scoped_temp_dir.GetPath())));
service->AddPage(url, base::Time::Now(), nullptr, 1, GURL(), RedirectList(),
ui::PAGE_TRANSITION_TYPED, SOURCE_BROWSED, false);
// This won't actually delete the URL, rather it'll empty out the visits.
// This triggers blocking on the BookmarkModel.
service->DeleteURLs({url});
}
// Test DeleteFTSIndexDatabases deletes expected files. // Test DeleteFTSIndexDatabases deletes expected files.
TEST_F(HistoryBackendTest, DeleteFTSIndexDatabases) { TEST_F(HistoryBackendTest, DeleteFTSIndexDatabases) {
ASSERT_TRUE(backend_.get()); ASSERT_TRUE(backend_.get());
......
...@@ -194,7 +194,7 @@ class HistoryQueryTest : public testing::Test { ...@@ -194,7 +194,7 @@ class HistoryQueryTest : public testing::Test {
base::ScopedTempDir temp_dir_; base::ScopedTempDir temp_dir_;
base::test::SingleThreadTaskEnvironment task_environment_; base::test::TaskEnvironment task_environment_;
base::FilePath history_dir_; base::FilePath history_dir_;
......
...@@ -58,10 +58,7 @@ namespace history { ...@@ -58,10 +58,7 @@ namespace history {
class HistoryServiceTest : public testing::Test { class HistoryServiceTest : public testing::Test {
public: public:
HistoryServiceTest() HistoryServiceTest() = default;
: task_environment_(
base::test::SingleThreadTaskEnvironment::MainThreadType::UI) {}
~HistoryServiceTest() override {} ~HistoryServiceTest() override {}
protected: protected:
...@@ -156,7 +153,7 @@ class HistoryServiceTest : public testing::Test { ...@@ -156,7 +153,7 @@ class HistoryServiceTest : public testing::Test {
base::ScopedTempDir temp_dir_; base::ScopedTempDir temp_dir_;
base::test::SingleThreadTaskEnvironment task_environment_; base::test::TaskEnvironment task_environment_;
MostVisitedURLList most_visited_urls_; MostVisitedURLList most_visited_urls_;
...@@ -179,6 +176,23 @@ class HistoryServiceTest : public testing::Test { ...@@ -179,6 +176,23 @@ class HistoryServiceTest : public testing::Test {
history::QueryURLResult query_url_result_; history::QueryURLResult query_url_result_;
}; };
// Simple test that removes a bookmark. This test exercises the code paths in
// History that block till BookmarkModel is loaded.
TEST_F(HistoryServiceTest, RemoveNotification) {
ASSERT_TRUE(history_service_.get());
// Add a URL.
GURL url("http://www.google.com");
history_service_->AddPage(url, base::Time::Now(), nullptr, 1, GURL(),
RedirectList(), ui::PAGE_TRANSITION_TYPED,
SOURCE_BROWSED, false);
// This won't actually delete the URL, rather it'll empty out the visits.
// This triggers blocking on the BookmarkModel.
history_service_->DeleteURLs({url});
}
TEST_F(HistoryServiceTest, AddPage) { TEST_F(HistoryServiceTest, AddPage) {
ASSERT_TRUE(history_service_.get()); ASSERT_TRUE(history_service_.get());
// Add the page once from a child frame. // Add the page once from a child frame.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment