Chromium Code Reviews| 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 1bee8c053639a4ac4ec9670b050b86044058cf7e..2042286e7ac80118e123dbcc40fa6bf69d179ccb 100644 |
| --- a/content/test/test_blink_web_unit_test_support.cc |
| +++ b/content/test/test_blink_web_unit_test_support.cc |
| @@ -10,6 +10,8 @@ |
| #include "base/files/scoped_temp_dir.h" |
| #include "base/path_service.h" |
| #include "base/strings/utf_string_conversions.h" |
| +#include "base/thread_task_runner_handle.h" |
| +#include "content/child/webthread_impl.h" |
| #include "content/public/common/content_switches.h" |
| #include "content/renderer/scheduler/renderer_scheduler.h" |
| #include "content/renderer/scheduler/web_scheduler_impl.h" |
| @@ -45,6 +47,40 @@ |
| namespace content { |
| +namespace { |
| + |
| +class WebThreadImplForTest : public WebThreadBase { |
| + public: |
| + WebThreadImplForTest() |
| + : owning_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| + thread_id_(base::PlatformThread::CurrentId()) { |
| + } |
| + |
| + ~WebThreadImplForTest() override { |
| + } |
| + |
| + // blink::WebThread: |
| + blink::PlatformThreadId threadId() const override { |
| + return thread_id_; |
| + } |
| + |
| + // WebThreadBase: |
| + base::MessageLoop* MessageLoop() const override { |
| + DCHECK(isCurrentThread()); |
| + return base::MessageLoop::current(); |
| + } |
| + |
| + private: |
| + base::SingleThreadTaskRunner* TaskRunner() const override { |
| + return owning_thread_task_runner_.get(); |
| + } |
| + |
| + scoped_refptr<base::SingleThreadTaskRunner> owning_thread_task_runner_; |
| + blink::PlatformThreadId thread_id_; |
| +}; |
| + |
| +} // namespace |
| + |
| TestBlinkWebUnitTestSupport::TestBlinkWebUnitTestSupport() { |
| #if defined(OS_MACOSX) |
| base::mac::ScopedNSAutoreleasePool autorelease_pool; |
| @@ -60,6 +96,7 @@ TestBlinkWebUnitTestSupport::TestBlinkWebUnitTestSupport() { |
| if (base::MessageLoopProxy::current()) { |
| renderer_scheduler_ = RendererScheduler::Create(); |
| web_scheduler_.reset(new WebSchedulerImpl(renderer_scheduler_.get())); |
| + web_thread_.reset(new WebThreadImplForTest()); |
|
Sami
2015/02/27 17:23:08
Since we're using the real scheduler, it seems lik
sadrul
2015/03/01 10:21:38
Sounds right. Done.
|
| } |
| blink::initialize(this); |
| @@ -319,4 +356,10 @@ blink::WebScheduler* TestBlinkWebUnitTestSupport::scheduler() { |
| return web_scheduler_.get(); |
| } |
| +blink::WebThread* TestBlinkWebUnitTestSupport::currentThread() { |
| + if (web_thread_ && web_thread_->isCurrentThread()) |
| + return web_thread_.get(); |
| + return BlinkPlatformImpl::currentThread(); |
| +} |
| + |
| } // namespace content |