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

Unified Diff: components/scheduler/child/webthread_impl_for_worker_scheduler_unittest.cc

Issue 1101703003: Adds a SHUTDOWN_TASK_QUEUE and a PreShutdown api to the scheduler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix comment Created 5 years, 8 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
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) {
« no previous file with comments | « components/scheduler/child/webthread_impl_for_worker_scheduler.cc ('k') | components/scheduler/child/worker_scheduler_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698