OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/scheduler/child/task_queue_manager.h" | 5 #include "components/scheduler/child/task_queue_manager.h" |
6 | 6 |
7 #include "base/location.h" | 7 #include "base/location.h" |
8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
9 #include "base/test/simple_test_tick_clock.h" | 9 #include "base/test/simple_test_tick_clock.h" |
10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
11 #include "cc/test/ordered_simple_task_runner.h" | 11 #include "cc/test/ordered_simple_task_runner.h" |
12 #include "components/scheduler/child/nestable_task_runner_for_test.h" | 12 #include "components/scheduler/child/nestable_task_runner_for_test.h" |
13 #include "components/scheduler/child/scheduler_message_loop_delegate.h" | 13 #include "components/scheduler/child/scheduler_message_loop_delegate.h" |
| 14 #include "components/scheduler/child/task_queue.h" |
14 #include "components/scheduler/child/task_queue_selector.h" | 15 #include "components/scheduler/child/task_queue_selector.h" |
15 #include "components/scheduler/child/test_time_source.h" | 16 #include "components/scheduler/child/test_time_source.h" |
16 #include "components/scheduler/test/test_always_fail_time_source.h" | 17 #include "components/scheduler/test/test_always_fail_time_source.h" |
17 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
18 | 19 |
19 using testing::ElementsAre; | 20 using testing::ElementsAre; |
20 using testing::_; | 21 using testing::_; |
21 | 22 |
22 namespace scheduler { | 23 namespace scheduler { |
23 namespace { | 24 namespace { |
(...skipping 1266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1290 delay1); | 1291 delay1); |
1291 runners[1]->PostDelayedTask(FROM_HERE, base::Bind(&TestTask, 2, &run_order), | 1292 runners[1]->PostDelayedTask(FROM_HERE, base::Bind(&TestTask, 2, &run_order), |
1292 delay2); | 1293 delay2); |
1293 | 1294 |
1294 now_src_->Advance(delay1 * 2); | 1295 now_src_->Advance(delay1 * 2); |
1295 test_task_runner_->RunUntilIdle(); | 1296 test_task_runner_->RunUntilIdle(); |
1296 | 1297 |
1297 EXPECT_THAT(run_order, ElementsAre(2, 1)); | 1298 EXPECT_THAT(run_order, ElementsAre(2, 1)); |
1298 } | 1299 } |
1299 | 1300 |
| 1301 TEST_F(TaskQueueManagerTest, DelayedTaskWithAbsoluteRunTime) { |
| 1302 Initialize(1u, SelectorType::Automatic); |
| 1303 |
| 1304 scoped_refptr<TaskQueue> runner = manager_->TaskRunnerForQueue(0); |
| 1305 |
| 1306 std::vector<int> run_order; |
| 1307 |
| 1308 // One task in the past, two with the exact same run time and one in the |
| 1309 // future. |
| 1310 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(10); |
| 1311 base::TimeTicks runTime1 = now_src_->NowTicks() - delay; |
| 1312 base::TimeTicks runTime2 = now_src_->NowTicks(); |
| 1313 base::TimeTicks runTime3 = now_src_->NowTicks(); |
| 1314 base::TimeTicks runTime4 = now_src_->NowTicks() + delay; |
| 1315 |
| 1316 runner->PostDelayedTaskAt(FROM_HERE, base::Bind(&TestTask, 1, &run_order), |
| 1317 runTime1); |
| 1318 runner->PostDelayedTaskAt(FROM_HERE, base::Bind(&TestTask, 2, &run_order), |
| 1319 runTime2); |
| 1320 runner->PostDelayedTaskAt(FROM_HERE, base::Bind(&TestTask, 3, &run_order), |
| 1321 runTime3); |
| 1322 runner->PostDelayedTaskAt(FROM_HERE, base::Bind(&TestTask, 4, &run_order), |
| 1323 runTime4); |
| 1324 |
| 1325 now_src_->Advance(2 * delay); |
| 1326 test_task_runner_->RunUntilIdle(); |
| 1327 |
| 1328 EXPECT_THAT(run_order, ElementsAre(1, 2, 3, 4)); |
| 1329 } |
| 1330 |
1300 } // namespace scheduler | 1331 } // namespace scheduler |
OLD | NEW |