| 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/scheduler_helper.h" | 5 #include "components/scheduler/child/scheduler_helper.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/test/simple_test_tick_clock.h" | 8 #include "base/test/simple_test_tick_clock.h" |
| 9 #include "cc/test/ordered_simple_task_runner.h" | 9 #include "cc/test/ordered_simple_task_runner.h" |
| 10 #include "components/scheduler/base/task_queue.h" | 10 #include "components/scheduler/base/task_queue.h" |
| 11 #include "components/scheduler/base/test_time_source.h" | 11 #include "components/scheduler/base/test_time_source.h" |
| 12 #include "components/scheduler/child/scheduler_task_runner_delegate_for_test.h" | 12 #include "components/scheduler/child/scheduler_tqm_delegate_for_test.h" |
| 13 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 using testing::_; | 16 using testing::_; |
| 17 using testing::AnyNumber; | 17 using testing::AnyNumber; |
| 18 using testing::Invoke; | 18 using testing::Invoke; |
| 19 using testing::Return; | 19 using testing::Return; |
| 20 | 20 |
| 21 namespace scheduler { | 21 namespace scheduler { |
| 22 | 22 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 39 } | 39 } |
| 40 } | 40 } |
| 41 | 41 |
| 42 }; // namespace | 42 }; // namespace |
| 43 | 43 |
| 44 class SchedulerHelperTest : public testing::Test { | 44 class SchedulerHelperTest : public testing::Test { |
| 45 public: | 45 public: |
| 46 SchedulerHelperTest() | 46 SchedulerHelperTest() |
| 47 : clock_(new base::SimpleTestTickClock()), | 47 : clock_(new base::SimpleTestTickClock()), |
| 48 mock_task_runner_(new cc::OrderedSimpleTaskRunner(clock_.get(), false)), | 48 mock_task_runner_(new cc::OrderedSimpleTaskRunner(clock_.get(), false)), |
| 49 main_task_runner_( | 49 main_task_runner_(SchedulerTqmDelegateForTest::Create( |
| 50 SchedulerTaskRunnerDelegateForTest::Create(mock_task_runner_)), | 50 mock_task_runner_, |
| 51 make_scoped_ptr(new TestTimeSource(clock_.get())))), |
| 51 scheduler_helper_(new SchedulerHelper( | 52 scheduler_helper_(new SchedulerHelper( |
| 52 main_task_runner_, | 53 main_task_runner_, |
| 53 "test.scheduler", | 54 "test.scheduler", |
| 54 TRACE_DISABLED_BY_DEFAULT("test.scheduler"), | 55 TRACE_DISABLED_BY_DEFAULT("test.scheduler"), |
| 55 TRACE_DISABLED_BY_DEFAULT("test.scheduler.dbg"))), | 56 TRACE_DISABLED_BY_DEFAULT("test.scheduler.dbg"))), |
| 56 default_task_runner_(scheduler_helper_->DefaultTaskRunner()) { | 57 default_task_runner_(scheduler_helper_->DefaultTaskRunner()) { |
| 57 clock_->Advance(base::TimeDelta::FromMicroseconds(5000)); | 58 clock_->Advance(base::TimeDelta::FromMicroseconds(5000)); |
| 58 scheduler_helper_->SetTimeSourceForTesting( | |
| 59 make_scoped_ptr(new TestTimeSource(clock_.get()))); | |
| 60 scheduler_helper_->GetTaskQueueManagerForTesting()->SetTimeSourceForTesting( | |
| 61 make_scoped_ptr(new TestTimeSource(clock_.get()))); | |
| 62 } | 59 } |
| 63 | 60 |
| 64 ~SchedulerHelperTest() override {} | 61 ~SchedulerHelperTest() override {} |
| 65 | 62 |
| 66 void TearDown() override { | 63 void TearDown() override { |
| 67 // Check that all tests stop posting tasks. | 64 // Check that all tests stop posting tasks. |
| 68 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); | 65 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); |
| 69 while (mock_task_runner_->RunUntilIdle()) { | 66 while (mock_task_runner_->RunUntilIdle()) { |
| 70 } | 67 } |
| 71 } | 68 } |
| 72 | 69 |
| 73 void RunUntilIdle() { mock_task_runner_->RunUntilIdle(); } | 70 void RunUntilIdle() { mock_task_runner_->RunUntilIdle(); } |
| 74 | 71 |
| 75 template <typename E> | 72 template <typename E> |
| 76 static void CallForEachEnumValue(E first, | 73 static void CallForEachEnumValue(E first, |
| 77 E last, | 74 E last, |
| 78 const char* (*function)(E)) { | 75 const char* (*function)(E)) { |
| 79 for (E val = first; val < last; | 76 for (E val = first; val < last; |
| 80 val = static_cast<E>(static_cast<int>(val) + 1)) { | 77 val = static_cast<E>(static_cast<int>(val) + 1)) { |
| 81 (*function)(val); | 78 (*function)(val); |
| 82 } | 79 } |
| 83 } | 80 } |
| 84 | 81 |
| 85 protected: | 82 protected: |
| 86 scoped_ptr<base::SimpleTestTickClock> clock_; | 83 scoped_ptr<base::SimpleTestTickClock> clock_; |
| 87 scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_; | 84 scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_; |
| 88 | 85 |
| 89 scoped_refptr<SchedulerTaskRunnerDelegateForTest> main_task_runner_; | 86 scoped_refptr<SchedulerTqmDelegateForTest> main_task_runner_; |
| 90 scoped_ptr<SchedulerHelper> scheduler_helper_; | 87 scoped_ptr<SchedulerHelper> scheduler_helper_; |
| 91 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_; | 88 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_; |
| 92 | 89 |
| 93 DISALLOW_COPY_AND_ASSIGN(SchedulerHelperTest); | 90 DISALLOW_COPY_AND_ASSIGN(SchedulerHelperTest); |
| 94 }; | 91 }; |
| 95 | 92 |
| 96 TEST_F(SchedulerHelperTest, TestPostDefaultTask) { | 93 TEST_F(SchedulerHelperTest, TestPostDefaultTask) { |
| 97 std::vector<std::string> run_order; | 94 std::vector<std::string> run_order; |
| 98 default_task_runner_->PostTask( | 95 default_task_runner_->PostTask( |
| 99 FROM_HERE, base::Bind(&AppendToVectorTestTask, &run_order, "D1")); | 96 FROM_HERE, base::Bind(&AppendToVectorTestTask, &run_order, "D1")); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 scoped_refptr<TaskQueue> task_queue = | 197 scoped_refptr<TaskQueue> task_queue = |
| 201 scheduler_helper_->NewTaskQueue(TaskQueue::Spec("test_queue")); | 198 scheduler_helper_->NewTaskQueue(TaskQueue::Spec("test_queue")); |
| 202 | 199 |
| 203 EXPECT_CALL(observer, OnUnregisterTaskQueue(_)).Times(1); | 200 EXPECT_CALL(observer, OnUnregisterTaskQueue(_)).Times(1); |
| 204 task_queue->UnregisterTaskQueue(); | 201 task_queue->UnregisterTaskQueue(); |
| 205 | 202 |
| 206 scheduler_helper_->SetObserver(nullptr); | 203 scheduler_helper_->SetObserver(nullptr); |
| 207 } | 204 } |
| 208 | 205 |
| 209 } // namespace scheduler | 206 } // namespace scheduler |
| OLD | NEW |