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 "cc/test/ordered_simple_task_runner.h" |
| 6 |
| 7 #include <memory> |
5 #include <string> | 8 #include <string> |
6 | 9 |
7 #include "base/cancelable_callback.h" | 10 #include "base/cancelable_callback.h" |
8 #include "base/format_macros.h" | 11 #include "base/format_macros.h" |
9 #include "base/macros.h" | 12 #include "base/macros.h" |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
12 #include "base/test/test_pending_task.h" | 14 #include "base/test/test_pending_task.h" |
13 #include "cc/test/ordered_simple_task_runner.h" | |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 | 16 |
16 // We pass EXPECT_TRUE / EXPECT_FALSE macros rather than a boolean as on some | 17 // We pass EXPECT_TRUE / EXPECT_FALSE macros rather than a boolean as on some |
17 // compilers EXPECT_EQ(false, XXXX) fails to compile as gtest tries to convert | 18 // compilers EXPECT_EQ(false, XXXX) fails to compile as gtest tries to convert |
18 // the false value to null causing a -Werror=conversion-null error. | 19 // the false value to null causing a -Werror=conversion-null error. |
19 #define RUN_AND_CHECK_RESULT( \ | 20 #define RUN_AND_CHECK_RESULT( \ |
20 tasks_remain_expect_macro, run_func, expected_result) \ | 21 tasks_remain_expect_macro, run_func, expected_result) \ |
21 tasks_remain_expect_macro(task_runner_->run_func); \ | 22 tasks_remain_expect_macro(task_runner_->run_func); \ |
22 EXPECT_EQ(expected_result, executed_tasks_); \ | 23 EXPECT_EQ(expected_result, executed_tasks_); \ |
23 executed_tasks_ = ""; | 24 executed_tasks_ = ""; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 | 57 |
57 class OrderedSimpleTaskRunnerTest : public testing::Test { | 58 class OrderedSimpleTaskRunnerTest : public testing::Test { |
58 public: | 59 public: |
59 OrderedSimpleTaskRunnerTest() | 60 OrderedSimpleTaskRunnerTest() |
60 : now_src_(new base::SimpleTestTickClock()), | 61 : now_src_(new base::SimpleTestTickClock()), |
61 task_runner_(new OrderedSimpleTaskRunner(now_src_.get(), true)) {} | 62 task_runner_(new OrderedSimpleTaskRunner(now_src_.get(), true)) {} |
62 ~OrderedSimpleTaskRunnerTest() override {} | 63 ~OrderedSimpleTaskRunnerTest() override {} |
63 | 64 |
64 protected: | 65 protected: |
65 std::string executed_tasks_; | 66 std::string executed_tasks_; |
66 scoped_ptr<base::SimpleTestTickClock> now_src_; | 67 std::unique_ptr<base::SimpleTestTickClock> now_src_; |
67 scoped_refptr<OrderedSimpleTaskRunner> task_runner_; | 68 scoped_refptr<OrderedSimpleTaskRunner> task_runner_; |
68 | 69 |
69 void PostTask(int task_num, base::TimeDelta delay) { | 70 void PostTask(int task_num, base::TimeDelta delay) { |
70 base::Closure test_task = base::Bind(&OrderedSimpleTaskRunnerTest::Task, | 71 base::Closure test_task = base::Bind(&OrderedSimpleTaskRunnerTest::Task, |
71 base::Unretained(this), | 72 base::Unretained(this), |
72 task_num); | 73 task_num); |
73 task_runner_->PostDelayedTask(FROM_HERE, test_task, delay); | 74 task_runner_->PostDelayedTask(FROM_HERE, test_task, delay); |
74 } | 75 } |
75 | 76 |
76 void PostTaskWhichPostsInstantTask(int task_num, base::TimeDelta delay) { | 77 void PostTaskWhichPostsInstantTask(int task_num, base::TimeDelta delay) { |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 | 436 |
436 task_runner_->SetRunTaskLimit(0); | 437 task_runner_->SetRunTaskLimit(0); |
437 RUN_AND_CHECK_RESULT(EXPECT_TRUE, RunUntilTime(run_to), ""); | 438 RUN_AND_CHECK_RESULT(EXPECT_TRUE, RunUntilTime(run_to), ""); |
438 | 439 |
439 task_runner_->SetRunTaskLimit(100); | 440 task_runner_->SetRunTaskLimit(100); |
440 RUN_AND_CHECK_RESULT(EXPECT_FALSE, RunUntilTime(run_to), "4(4ms) 5(5ms)"); | 441 RUN_AND_CHECK_RESULT(EXPECT_FALSE, RunUntilTime(run_to), "4(4ms) 5(5ms)"); |
441 EXPECT_EQ(run_to, now_src_->NowTicks()); | 442 EXPECT_EQ(run_to, now_src_->NowTicks()); |
442 } | 443 } |
443 | 444 |
444 } // namespace cc | 445 } // namespace cc |
OLD | NEW |