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

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

Issue 2495053003: Wait for history backend in popup blocker test (Closed)
Patch Set: Created 4 years, 1 month 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/history_browsertest.cc
diff --git a/chrome/browser/history/history_browsertest.cc b/chrome/browser/history/history_browsertest.cc
index 8a12511c449c2c7d3fd6683715314412e15c5383..13af0c33e7d4626556b5b430cc93c6973f025704 100644
--- a/chrome/browser/history/history_browsertest.cc
+++ b/chrome/browser/history/history_browsertest.cc
@@ -14,6 +14,7 @@
#include "build/build_config.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/history/history_service_factory.h"
+#include "chrome/browser/history/history_test_utils.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
@@ -40,33 +41,6 @@ namespace {
const base::FilePath::CharType kDocRoot[] =
FILE_PATH_LITERAL("chrome/test/data");
-// Note: WaitableEvent is not used for synchronization between the main thread
-// and history backend thread because the history subsystem posts tasks back
-// to the main thread. Had we tried to Signal an event in such a task
-// and Wait for it on the main thread, the task would not run at all because
-// the main thread would be blocked on the Wait call, resulting in a deadlock.
-
-// A task to be scheduled on the history backend thread.
-// Notifies the main thread after all history backend thread tasks have run.
-class WaitForHistoryTask : public history::HistoryDBTask {
- public:
- WaitForHistoryTask() {}
-
- bool RunOnDBThread(history::HistoryBackend* backend,
- history::HistoryDatabase* db) override {
- return true;
- }
-
- void DoneRunOnMainThread() override {
- base::MessageLoop::current()->QuitWhenIdle();
- }
-
- private:
- ~WaitForHistoryTask() override {}
-
- DISALLOW_COPY_AND_ASSIGN(WaitForHistoryTask);
-};
-
} // namespace
class HistoryBrowserTest : public InProcessBrowserTest {
@@ -99,15 +73,6 @@ class HistoryBrowserTest : public InProcessBrowserTest {
base::FilePath(FILE_PATH_LITERAL("title2.html")));
}
- void WaitForHistoryBackendToRun() {
- base::CancelableTaskTracker task_tracker;
- std::unique_ptr<history::HistoryDBTask> task(new WaitForHistoryTask());
- history::HistoryService* history = HistoryServiceFactory::GetForProfile(
- GetProfile(), ServiceAccessType::EXPLICIT_ACCESS);
- history->ScheduleDBTask(std::move(task), &task_tracker);
- content::RunMessageLoop();
- }
-
void ExpectEmptyHistory() {
std::vector<GURL> urls(GetHistoryContents());
EXPECT_EQ(0U, urls.size());
@@ -144,7 +109,7 @@ IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, SavingHistoryEnabled) {
ExpectEmptyHistory();
ui_test_utils::NavigateToURL(browser(), GetTestUrl());
- WaitForHistoryBackendToRun();
+ WaitForHistoryBackendToRun(GetProfile());
{
std::vector<GURL> urls(GetHistoryContents());
@@ -167,7 +132,7 @@ IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, SavingHistoryDisabled) {
ExpectEmptyHistory();
ui_test_utils::NavigateToURL(browser(), GetTestUrl());
- WaitForHistoryBackendToRun();
+ WaitForHistoryBackendToRun(GetProfile());
ExpectEmptyHistory();
}
@@ -180,7 +145,7 @@ IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, SavingHistoryEnabledThenDisabled) {
browser()->profile(), ServiceAccessType::EXPLICIT_ACCESS));
ui_test_utils::NavigateToURL(browser(), GetTestUrl());
- WaitForHistoryBackendToRun();
+ WaitForHistoryBackendToRun(GetProfile());
{
std::vector<GURL> urls(GetHistoryContents());
@@ -191,7 +156,7 @@ IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, SavingHistoryEnabledThenDisabled) {
GetPrefs()->SetBoolean(prefs::kSavingBrowserHistoryDisabled, true);
ui_test_utils::NavigateToURL(browser(), GetTestUrl());
- WaitForHistoryBackendToRun();
+ WaitForHistoryBackendToRun(GetProfile());
{
// No additional entries should be present in the history.
@@ -211,13 +176,13 @@ IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, SavingHistoryDisabledThenEnabled) {
ExpectEmptyHistory();
ui_test_utils::NavigateToURL(browser(), GetTestUrl());
- WaitForHistoryBackendToRun();
+ WaitForHistoryBackendToRun(GetProfile());
ExpectEmptyHistory();
GetPrefs()->SetBoolean(prefs::kSavingBrowserHistoryDisabled, false);
ui_test_utils::NavigateToURL(browser(), GetTestUrl());
- WaitForHistoryBackendToRun();
+ WaitForHistoryBackendToRun(GetProfile());
{
std::vector<GURL> urls(GetHistoryContents());

Powered by Google App Engine
This is Rietveld 408576698