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

Unified Diff: content/test/test_blink_web_unit_test_support.cc

Issue 1130433002: Adding task runner/ message loop to tests that use IsolateHolder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing mac build. Created 5 years, 7 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 | « no previous file | gin/converter_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/test/test_blink_web_unit_test_support.cc
diff --git a/content/test/test_blink_web_unit_test_support.cc b/content/test/test_blink_web_unit_test_support.cc
index 7405be6f417d040cb42b0292c52396f86b370043..8aa66187af66a49145d8a2c25588f18685f18ad4 100644
--- a/content/test/test_blink_web_unit_test_support.cc
+++ b/content/test/test_blink_web_unit_test_support.cc
@@ -8,7 +8,10 @@
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/path_service.h"
+#include "base/single_thread_task_runner.h"
#include "base/strings/utf_string_conversions.h"
+#include "base/thread_task_runner_handle.h"
+#include "base/threading/platform_thread.h"
#include "components/scheduler/renderer/renderer_scheduler.h"
#include "components/scheduler/renderer/webthread_impl_for_renderer_scheduler.h"
#include "content/test/mock_webclipboard_impl.h"
@@ -41,6 +44,40 @@
#include "gin/v8_initializer.h"
#endif
+namespace {
+
+class DummyTaskRunner : public base::SingleThreadTaskRunner {
+ public:
+ DummyTaskRunner() : thread_id_(base::PlatformThread::CurrentId()) {}
+
+ bool PostDelayedTask(const tracked_objects::Location& from_here,
+ const base::Closure& task,
+ base::TimeDelta delay) override {
+ NOTREACHED();
+ return false;
+ }
+
+ bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
+ const base::Closure& task,
+ base::TimeDelta delay) override {
+ NOTREACHED();
+ return false;
+ }
+
+ bool RunsTasksOnCurrentThread() const override {
+ return thread_id_ == base::PlatformThread::CurrentId();
+ }
+
+ protected:
+ ~DummyTaskRunner() override {}
+
+ base::PlatformThreadId thread_id_;
+
+ DISALLOW_COPY_AND_ASSIGN(DummyTaskRunner);
+};
+
+} // namespace
+
namespace content {
TestBlinkWebUnitTestSupport::TestBlinkWebUnitTestSupport() {
@@ -55,10 +92,23 @@ TestBlinkWebUnitTestSupport::TestBlinkWebUnitTestSupport() {
gin::V8Initializer::LoadV8Snapshot();
#endif
+ scoped_refptr<base::SingleThreadTaskRunner> dummy_task_runner;
+ scoped_ptr<base::ThreadTaskRunnerHandle> dummy_task_runner_handle;
if (base::MessageLoopProxy::current()) {
renderer_scheduler_ = scheduler::RendererScheduler::Create();
web_thread_.reset(new scheduler::WebThreadImplForRendererScheduler(
renderer_scheduler_.get()));
+ } else {
+ // Dummy task runner is initialized here because the blink::initialize
+ // creates IsolateHolder which needs the current task runner handle. There
+ // should be no task posted to this task runner. The message loop is not
+ // created before this initialization because some tests need specific kinds
+ // of message loops, and their types are not known upfront. Some tests also
+ // create their own thread bundles or message loops, and doing the same in
+ // TestBlinkWebUnitTestSupport would introduce a conflict.
+ dummy_task_runner = make_scoped_refptr(new DummyTaskRunner());
+ dummy_task_runner_handle.reset(
+ new base::ThreadTaskRunnerHandle(dummy_task_runner));
}
blink::initialize(this);
« no previous file with comments | « no previous file | gin/converter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698