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

Unified Diff: base/test/scoped_task_scheduler_unittest.cc

Issue 2684273002: Allow ScopedTaskScheduler to be created before a class that overrides MessageLoop::current()'s task… (Closed)
Patch Set: Get rid of extra files in patch Created 3 years, 10 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
« no previous file with comments | « base/test/scoped_task_scheduler.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/test/scoped_task_scheduler_unittest.cc
diff --git a/base/test/scoped_task_scheduler_unittest.cc b/base/test/scoped_task_scheduler_unittest.cc
index 8fb70162b338fa05f9af44534b03455a1c5c0b8d..cc0ffbbe62d5625aba5e3e7d2bed934ef8c442b2 100644
--- a/base/test/scoped_task_scheduler_unittest.cc
+++ b/base/test/scoped_task_scheduler_unittest.cc
@@ -12,9 +12,11 @@
#include "base/task_scheduler/post_task.h"
#include "base/task_scheduler/task_scheduler.h"
#include "base/task_scheduler/test_utils.h"
+#include "base/test/scoped_mock_time_message_loop_task_runner.h"
#include "base/threading/sequenced_task_runner_handle.h"
#include "base/threading/thread_checker.h"
#include "base/threading/thread_task_runner_handle.h"
+#include "base/time/time.h"
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -267,5 +269,33 @@ TEST(ScopedTaskSchedulerTest, DestructorRunsBlockShutdownTasksOnly) {
EXPECT_TRUE(block_shutdown_task_ran);
}
+TEST(ScopedTaskSchedulerTest, ReassignCurrentTaskRunner) {
+ bool first_task_ran = false;
+ bool second_task_ran = false;
+
+ auto TestTaskRan = [](bool* task_ran) { *task_ran = true; };
+
+ ScopedTaskScheduler scoped_task_scheduler;
+ {
+ ScopedMockTimeMessageLoopTaskRunner mock_time_task_runner;
+ PostDelayedTask(FROM_HERE, Bind(TestTaskRan, Unretained(&first_task_ran)),
+ TimeDelta::FromSeconds(1));
+
+ // The delayed task should be queued on |mock_time_task_runner|, not the
+ // default task runner.
+ EXPECT_TRUE(mock_time_task_runner.task_runner()->HasPendingTask());
+ }
+
+ PostDelayedTask(FROM_HERE, Bind(TestTaskRan, Unretained(&second_task_ran)),
+ TimeDelta());
+
+ RunLoop().RunUntilIdle();
+
+ // We never pumped |mock_time_task_runner| so the first task should not have
+ // run.
+ EXPECT_FALSE(first_task_ran);
+ EXPECT_TRUE(second_task_ran);
+}
+
} // namespace test
} // namespace base
« no previous file with comments | « base/test/scoped_task_scheduler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698