OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
7 #include "base/test/launcher/unit_test_launcher.h" | 7 #include "base/test/launcher/unit_test_launcher.h" |
8 #include "base/test/test_suite.h" | 8 #include "base/test/test_suite.h" |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "components/scheduler/child/scheduler_task_runner_delegate_impl.h" |
| 11 #include "components/scheduler/child/web_task_runner_impl.h" |
| 12 #include "components/scheduler/renderer/renderer_scheduler_impl.h" |
| 13 #include "components/scheduler/renderer/renderer_web_scheduler_impl.h" |
| 14 #include "components/scheduler/test/lazy_scheduler_message_loop_delegate_for_tes
ts.h" |
10 #include "media/base/media.h" | 15 #include "media/base/media.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
12 #include "third_party/WebKit/public/platform/WebScheduler.h" | 17 #include "third_party/WebKit/public/platform/WebScheduler.h" |
13 #include "third_party/WebKit/public/platform/WebTaskRunner.h" | 18 #include "third_party/WebKit/public/platform/WebTaskRunner.h" |
14 #include "third_party/WebKit/public/platform/WebThread.h" | 19 #include "third_party/WebKit/public/platform/WebThread.h" |
15 #include "third_party/WebKit/public/web/WebKit.h" | 20 #include "third_party/WebKit/public/web/WebKit.h" |
16 | 21 |
17 #if defined(OS_ANDROID) | 22 #if defined(OS_ANDROID) |
18 #include "base/android/jni_android.h" | 23 #include "base/android/jni_android.h" |
19 #include "media/base/android/media_jni_registrar.h" | 24 #include "media/base/android/media_jni_registrar.h" |
20 #include "ui/gl/android/gl_jni_registrar.h" | 25 #include "ui/gl/android/gl_jni_registrar.h" |
21 #endif | 26 #endif |
22 | 27 |
23 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 28 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
24 #include "gin/v8_initializer.h" | 29 #include "gin/v8_initializer.h" |
25 #endif | 30 #endif |
26 | 31 |
27 class SimpleWebTaskRunner : public blink::WebTaskRunner { | 32 class CurrentThreadMock : public blink::WebThread { |
28 public: | 33 public: |
29 void postTask(const blink::WebTraceLocation& ignored, Task* task) override { | 34 CurrentThreadMock() |
30 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(&RunIt, task)); | 35 : task_runner_delegate_( |
| 36 scheduler::LazySchedulerMessageLoopDelegateForTests::Create()), |
| 37 scheduler_( |
| 38 new scheduler::RendererSchedulerImpl(task_runner_delegate_.get())), |
| 39 web_scheduler_( |
| 40 new scheduler::RendererWebSchedulerImpl(scheduler_.get())), |
| 41 web_task_runner_( |
| 42 new scheduler::WebTaskRunnerImpl(scheduler_->DefaultTaskRunner())) { |
31 } | 43 } |
32 | 44 |
33 void postDelayedTask(const blink::WebTraceLocation&, | 45 ~CurrentThreadMock() override { |
34 Task* task, | 46 scheduler_->Shutdown(); |
35 long long delayMs) override { | 47 } |
36 base::MessageLoop::current()->PostDelayedTask( | |
37 FROM_HERE, base::Bind(&RunIt, base::Owned(task)), | |
38 base::TimeDelta::FromMilliseconds(delayMs)); | |
39 }; | |
40 | 48 |
41 private: | 49 blink::WebTaskRunner* taskRunner() override { return web_task_runner_.get(); } |
42 static void RunIt(Task* task) { task->run(); } | |
43 }; | |
44 | |
45 class SimpleWebScheduler : public blink::WebScheduler { | |
46 public: | |
47 SimpleWebScheduler(blink::WebTaskRunner* task_runner) | |
48 : task_runner_(task_runner) {} | |
49 blink::WebTaskRunner* loadingTaskRunner() override { return task_runner_; } | |
50 | |
51 blink::WebTaskRunner* timerTaskRunner() override { return task_runner_; } | |
52 | |
53 private: | |
54 blink::WebTaskRunner* task_runner_; | |
55 }; | |
56 | |
57 class CurrentThreadMock : public blink::WebThread { | |
58 public: | |
59 CurrentThreadMock() : m_taskRunner(), m_webScheduler(&m_taskRunner) {} | |
60 | |
61 ~CurrentThreadMock() override {} | |
62 | |
63 blink::WebTaskRunner* taskRunner() override { return &m_taskRunner; } | |
64 | 50 |
65 bool isCurrentThread() const override { return true; } | 51 bool isCurrentThread() const override { return true; } |
66 | 52 |
67 blink::PlatformThreadId threadId() const override { return 17; } | 53 blink::PlatformThreadId threadId() const override { return 17; } |
68 | 54 |
69 blink::WebScheduler* scheduler() const override { return &m_webScheduler; } | 55 blink::WebScheduler* scheduler() const override { |
| 56 return web_scheduler_.get(); |
| 57 } |
70 | 58 |
71 private: | 59 private: |
72 SimpleWebTaskRunner m_taskRunner; | 60 scoped_refptr<scheduler::SchedulerTaskRunnerDelegate> task_runner_delegate_; |
73 mutable SimpleWebScheduler m_webScheduler; | 61 scoped_ptr<scheduler::RendererScheduler> scheduler_; |
| 62 scoped_ptr<blink::WebScheduler> web_scheduler_; |
| 63 scoped_ptr<blink::WebTaskRunner> web_task_runner_; |
74 }; | 64 }; |
75 | 65 |
76 class TestBlinkPlatformSupport : NON_EXPORTED_BASE(public blink::Platform) { | 66 class TestBlinkPlatformSupport : NON_EXPORTED_BASE(public blink::Platform) { |
77 public: | 67 public: |
78 ~TestBlinkPlatformSupport() override; | 68 ~TestBlinkPlatformSupport() override; |
79 | 69 |
80 void cryptographicallyRandomValues(unsigned char* buffer, | 70 void cryptographicallyRandomValues(unsigned char* buffer, |
81 size_t length) override; | 71 size_t length) override; |
82 const unsigned char* getTraceCategoryEnabledFlag( | 72 const unsigned char* getTraceCategoryEnabledFlag( |
83 const char* categoryName) override; | 73 const char* categoryName) override; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 blink::initialize(blink_platform_support_.get()); | 139 blink::initialize(blink_platform_support_.get()); |
150 } | 140 } |
151 | 141 |
152 int main(int argc, char** argv) { | 142 int main(int argc, char** argv) { |
153 BlinkMediaTestSuite test_suite(argc, argv); | 143 BlinkMediaTestSuite test_suite(argc, argv); |
154 | 144 |
155 return base::LaunchUnitTests( | 145 return base::LaunchUnitTests( |
156 argc, argv, base::Bind(&BlinkMediaTestSuite::Run, | 146 argc, argv, base::Bind(&BlinkMediaTestSuite::Run, |
157 base::Unretained(&test_suite))); | 147 base::Unretained(&test_suite))); |
158 } | 148 } |
OLD | NEW |