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

Unified Diff: components/history/core/test/history_service_test_util.cc

Issue 1646893003: Moves shared history test helpers into util classes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@history
Patch Set: ASAN. Created 4 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
« no previous file with comments | « components/history/core/test/history_service_test_util.h ('k') | components/omnibox.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/history/core/test/history_service_test_util.cc
diff --git a/components/history/core/test/history_service_test_util.cc b/components/history/core/test/history_service_test_util.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b03c8b832b1dba0076742941cf84cb032a5e4d97
--- /dev/null
+++ b/components/history/core/test/history_service_test_util.cc
@@ -0,0 +1,74 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/history/core/test/history_service_test_util.h"
+
+#include "base/files/file_path.h"
+#include "base/run_loop.h"
+#include "components/history/core/browser/history_backend.h"
+#include "components/history/core/browser/history_database.h"
+#include "components/history/core/browser/history_database_params.h"
+#include "components/history/core/browser/history_db_task.h"
+#include "components/history/core/browser/history_service.h"
+#include "components/history/core/browser/history_service_observer.h"
+#include "components/history/core/browser/url_database.h"
+#include "components/history/core/test/test_history_database.h"
+
+namespace {
+
+class QuitTask : public history::HistoryDBTask {
+ public:
+ QuitTask(const base::Closure& task) : task_(task) {}
+
+ bool RunOnDBThread(history::HistoryBackend* backend,
+ history::HistoryDatabase* db) override {
+ return true;
+ }
+
+ void DoneRunOnMainThread() override { task_.Run(); }
+
+ private:
+ ~QuitTask() override {}
+
+ base::Closure task_;
+
+ DISALLOW_COPY_AND_ASSIGN(QuitTask);
+};
+
+} // namespace
+
+namespace history {
+
+scoped_ptr<HistoryService> CreateHistoryService(
+ const base::FilePath& history_dir,
+ const std::string& accept_languages,
+ bool create_db) {
+ scoped_ptr<HistoryService> history_service(new HistoryService());
+ if (!history_service->Init(
+ !create_db, accept_languages,
+ history::TestHistoryDatabaseParamsForPath(history_dir))) {
+ return nullptr;
+ }
+
+ if (create_db)
+ BlockUntilHistoryProcessesPendingRequests(history_service.get());
+ return history_service;
+}
+
+void BlockUntilHistoryProcessesPendingRequests(
+ HistoryService* history_service) {
+ base::RunLoop run_loop;
+ base::CancelableTaskTracker tracker;
+ history_service->ScheduleDBTask(
+ scoped_ptr<history::HistoryDBTask>(new QuitTask(run_loop.QuitClosure())),
+ &tracker);
+ run_loop.Run();
+
+ // Spin the runloop again until idle. The QuitTask above is destroyed via a
+ // task posted to the current message loop, so spinning allows the task to be
+ // properly destroyed.
+ base::RunLoop().RunUntilIdle();
+}
+
+} // namespace history
« no previous file with comments | « components/history/core/test/history_service_test_util.h ('k') | components/omnibox.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698