Index: components/scheduler/child/webthread_impl_for_worker_scheduler_unittest.cc |
diff --git a/components/scheduler/child/webthread_impl_for_worker_scheduler_unittest.cc b/components/scheduler/child/webthread_impl_for_worker_scheduler_unittest.cc |
index 7bb1f8990762e426df7004d2c12637105c542941..d1b3582baf58751e8602abc51aafc1c921436772 100644 |
--- a/components/scheduler/child/webthread_impl_for_worker_scheduler_unittest.cc |
+++ b/components/scheduler/child/webthread_impl_for_worker_scheduler_unittest.cc |
@@ -8,6 +8,7 @@ |
#include "components/scheduler/child/worker_scheduler_impl.h" |
#include "testing/gmock/include/gmock/gmock.h" |
#include "testing/gtest/include/gtest/gtest.h" |
+#include "third_party/WebKit/public/platform/WebScheduler.h" |
#include "third_party/WebKit/public/platform/WebTraceLocation.h" |
using testing::_; |
@@ -124,14 +125,45 @@ TEST_F(WebThreadImplForWorkerSchedulerTest, TestDefaultTask) { |
TEST_F(WebThreadImplForWorkerSchedulerTest, |
TestTaskExecutedBeforeThreadDeletion) { |
scoped_ptr<MockTask> task(new MockTask()); |
- base::WaitableEvent completion(false, false); |
+ bool task_ran = false; |
+ base::Lock lock; |
EXPECT_CALL(*task, run()); |
ON_CALL(*task, run()) |
- .WillByDefault(Invoke([&completion]() { completion.Signal(); })); |
+ .WillByDefault(Invoke([&task_ran, &lock]() { |
+ base::AutoLock auto_lock(lock); |
+ task_ran = true; |
+ })); |
+ |
+ thread_->postTask(blink::WebTraceLocation(), task.release()); |
+ thread_.reset(); |
+ { |
+ base::AutoLock auto_lock(lock); |
+ EXPECT_TRUE(task_ran); |
+ } |
+} |
+TEST_F(WebThreadImplForWorkerSchedulerTest, |
+ TestThreadShutdownAfterPreShutdown) { |
+ scoped_ptr<MockTask> task(new MockTask()); |
+ bool task_ran = false; |
+ base::Lock lock; |
+ |
+ ON_CALL(*task, run()) |
+ .WillByDefault(Invoke([&task_ran, &lock]() { |
+ base::AutoLock auto_lock(lock); |
+ task_ran = true; |
+ })); |
+ |
+ // preShutdown should block the postTask, but not the internal shutdown task. |
+ thread_->scheduler()->preShutdown(); |
thread_->postTask(blink::WebTraceLocation(), task.release()); |
thread_.reset(); |
+ |
+ { |
+ base::AutoLock auto_lock(lock); |
+ EXPECT_FALSE(task_ran); |
+ } |
} |
TEST_F(WebThreadImplForWorkerSchedulerTest, TestIdleTask) { |