OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "platform/scheduler/child/webthread_impl_for_worker_scheduler.h" | 5 #include "platform/scheduler/child/webthread_impl_for_worker_scheduler.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/synchronization/waitable_event.h" | 8 #include "base/synchronization/waitable_event.h" |
9 #include "platform/WebTaskRunner.h" | 9 #include "platform/WebTaskRunner.h" |
10 #include "platform/scheduler/child/web_scheduler_impl.h" | 10 #include "platform/scheduler/child/web_scheduler_impl.h" |
11 #include "platform/scheduler/child/worker_scheduler_impl.h" | 11 #include "platform/scheduler/child/worker_scheduler_impl.h" |
12 #include "public/platform/WebTraceLocation.h" | 12 #include "public/platform/WebTraceLocation.h" |
13 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 | 15 |
16 using testing::_; | 16 using ::testing::_; |
17 using testing::AnyOf; | 17 using ::testing::AnyOf; |
18 using testing::ElementsAre; | 18 using ::testing::ElementsAre; |
19 using testing::Invoke; | 19 using ::testing::Invoke; |
20 | 20 |
21 namespace blink { | 21 namespace blink { |
22 namespace scheduler { | 22 namespace scheduler { |
23 namespace { | 23 namespace { |
24 | 24 |
25 class MockTask { | 25 class MockTask { |
26 public: | 26 public: |
27 MOCK_METHOD0(Run, void()); | 27 MOCK_METHOD0(Run, void()); |
28 }; | 28 }; |
29 | 29 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 } | 63 } |
64 | 64 |
65 void ShutdownOnThread(WebThreadImplForWorkerScheduler* thread) { | 65 void ShutdownOnThread(WebThreadImplForWorkerScheduler* thread) { |
66 WebSchedulerImpl* web_scheduler_impl = | 66 WebSchedulerImpl* web_scheduler_impl = |
67 static_cast<WebSchedulerImpl*>(thread->Scheduler()); | 67 static_cast<WebSchedulerImpl*>(thread->Scheduler()); |
68 web_scheduler_impl->Shutdown(); | 68 web_scheduler_impl->Shutdown(); |
69 } | 69 } |
70 | 70 |
71 } // namespace | 71 } // namespace |
72 | 72 |
73 class WebThreadImplForWorkerSchedulerTest : public testing::Test { | 73 class WebThreadImplForWorkerSchedulerTest : public ::testing::Test { |
74 public: | 74 public: |
75 WebThreadImplForWorkerSchedulerTest() {} | 75 WebThreadImplForWorkerSchedulerTest() {} |
76 | 76 |
77 ~WebThreadImplForWorkerSchedulerTest() override {} | 77 ~WebThreadImplForWorkerSchedulerTest() override {} |
78 | 78 |
79 void SetUp() override { | 79 void SetUp() override { |
80 thread_.reset(new WebThreadImplForWorkerScheduler("test thread")); | 80 thread_.reset(new WebThreadImplForWorkerScheduler("test thread")); |
81 thread_->Init(); | 81 thread_->Init(); |
82 } | 82 } |
83 | 83 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 thread_->GetWebTaskRunner()->PostTask( | 166 thread_->GetWebTaskRunner()->PostTask( |
167 BLINK_FROM_HERE, WTF::Bind(&RunTestTask, WTF::Unretained(&calls))); | 167 BLINK_FROM_HERE, WTF::Bind(&RunTestTask, WTF::Unretained(&calls))); |
168 RunOnWorkerThread(FROM_HERE, | 168 RunOnWorkerThread(FROM_HERE, |
169 base::Bind(&RemoveTaskObserver, thread_.get(), &observer)); | 169 base::Bind(&RemoveTaskObserver, thread_.get(), &observer)); |
170 | 170 |
171 // We need to be careful what we test here. We want to make sure the | 171 // We need to be careful what we test here. We want to make sure the |
172 // observers are un in the expected order before and after the task. | 172 // observers are un in the expected order before and after the task. |
173 // Sometimes we get an internal scheduler task running before or after | 173 // Sometimes we get an internal scheduler task running before or after |
174 // TestTask as well. This is not a bug, and we need to make sure the test | 174 // TestTask as well. This is not a bug, and we need to make sure the test |
175 // doesn't fail when that happens. | 175 // doesn't fail when that happens. |
176 EXPECT_THAT(calls, testing::HasSubstr("willProcessTask run didProcessTask")); | 176 EXPECT_THAT(calls, |
| 177 ::testing::HasSubstr("willProcessTask run didProcessTask")); |
177 } | 178 } |
178 | 179 |
179 TEST_F(WebThreadImplForWorkerSchedulerTest, TestShutdown) { | 180 TEST_F(WebThreadImplForWorkerSchedulerTest, TestShutdown) { |
180 MockTask task; | 181 MockTask task; |
181 MockTask delayed_task; | 182 MockTask delayed_task; |
182 | 183 |
183 EXPECT_CALL(task, Run()).Times(0); | 184 EXPECT_CALL(task, Run()).Times(0); |
184 EXPECT_CALL(delayed_task, Run()).Times(0); | 185 EXPECT_CALL(delayed_task, Run()).Times(0); |
185 | 186 |
186 RunOnWorkerThread(FROM_HERE, base::Bind(&ShutdownOnThread, thread_.get())); | 187 RunOnWorkerThread(FROM_HERE, base::Bind(&ShutdownOnThread, thread_.get())); |
187 thread_->GetWebTaskRunner()->PostTask( | 188 thread_->GetWebTaskRunner()->PostTask( |
188 BLINK_FROM_HERE, WTF::Bind(&MockTask::Run, WTF::Unretained(&task))); | 189 BLINK_FROM_HERE, WTF::Bind(&MockTask::Run, WTF::Unretained(&task))); |
189 thread_->GetWebTaskRunner()->PostDelayedTask( | 190 thread_->GetWebTaskRunner()->PostDelayedTask( |
190 BLINK_FROM_HERE, | 191 BLINK_FROM_HERE, |
191 WTF::Bind(&MockTask::Run, WTF::Unretained(&delayed_task)), | 192 WTF::Bind(&MockTask::Run, WTF::Unretained(&delayed_task)), |
192 TimeDelta::FromMilliseconds(50)); | 193 TimeDelta::FromMilliseconds(50)); |
193 thread_.reset(); | 194 thread_.reset(); |
194 } | 195 } |
195 | 196 |
196 } // namespace scheduler | 197 } // namespace scheduler |
197 } // namespace blink | 198 } // namespace blink |
OLD | NEW |