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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « base/test/scoped_task_scheduler.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/test/scoped_task_scheduler.h" 5 #include "base/test/scoped_task_scheduler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
11 #include "base/sequence_checker.h" 11 #include "base/sequence_checker.h"
12 #include "base/task_scheduler/post_task.h" 12 #include "base/task_scheduler/post_task.h"
13 #include "base/task_scheduler/task_scheduler.h" 13 #include "base/task_scheduler/task_scheduler.h"
14 #include "base/task_scheduler/test_utils.h" 14 #include "base/task_scheduler/test_utils.h"
15 #include "base/test/scoped_mock_time_message_loop_task_runner.h"
15 #include "base/threading/sequenced_task_runner_handle.h" 16 #include "base/threading/sequenced_task_runner_handle.h"
16 #include "base/threading/thread_checker.h" 17 #include "base/threading/thread_checker.h"
17 #include "base/threading/thread_task_runner_handle.h" 18 #include "base/threading/thread_task_runner_handle.h"
19 #include "base/time/time.h"
18 #include "build/build_config.h" 20 #include "build/build_config.h"
19 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
20 22
21 namespace base { 23 namespace base {
22 namespace test { 24 namespace test {
23 25
24 TEST(ScopedTaskSchedulerTest, PostTask) { 26 TEST(ScopedTaskSchedulerTest, PostTask) {
25 ScopedTaskScheduler scoped_task_scheduler; 27 ScopedTaskScheduler scoped_task_scheduler;
26 28
27 bool first_task_ran = false; 29 bool first_task_ran = false;
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 TaskShutdownBehavior::BLOCK_SHUTDOWN), 262 TaskShutdownBehavior::BLOCK_SHUTDOWN),
261 Bind( 263 Bind(
262 [](bool* block_shutdown_task_ran) { 264 [](bool* block_shutdown_task_ran) {
263 *block_shutdown_task_ran = true; 265 *block_shutdown_task_ran = true;
264 }, 266 },
265 Unretained(&block_shutdown_task_ran))); 267 Unretained(&block_shutdown_task_ran)));
266 } 268 }
267 EXPECT_TRUE(block_shutdown_task_ran); 269 EXPECT_TRUE(block_shutdown_task_ran);
268 } 270 }
269 271
272 TEST(ScopedTaskSchedulerTest, ReassignCurrentTaskRunner) {
273 bool first_task_ran = false;
274 bool second_task_ran = false;
275
276 auto TestTaskRan = [](bool* task_ran) { *task_ran = true; };
277
278 ScopedTaskScheduler scoped_task_scheduler;
279 {
280 ScopedMockTimeMessageLoopTaskRunner mock_time_task_runner;
281 PostDelayedTask(FROM_HERE, Bind(TestTaskRan, Unretained(&first_task_ran)),
282 TimeDelta::FromSeconds(1));
283
284 // The delayed task should be queued on |mock_time_task_runner|, not the
285 // default task runner.
286 EXPECT_TRUE(mock_time_task_runner.task_runner()->HasPendingTask());
287 }
288
289 PostDelayedTask(FROM_HERE, Bind(TestTaskRan, Unretained(&second_task_ran)),
290 TimeDelta());
291
292 RunLoop().RunUntilIdle();
293
294 // We never pumped |mock_time_task_runner| so the first task should not have
295 // run.
296 EXPECT_FALSE(first_task_ran);
297 EXPECT_TRUE(second_task_ran);
298 }
299
270 } // namespace test 300 } // namespace test
271 } // namespace base 301 } // namespace base
OLDNEW
« 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