| 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/base/task_queue_manager.h" | 5 #include "components/scheduler/base/task_queue_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> |
| 8 | 9 |
| 9 #include "base/location.h" | 10 #include "base/location.h" |
| 10 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 11 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 12 #include "base/test/simple_test_tick_clock.h" | 13 #include "base/test/simple_test_tick_clock.h" |
| 13 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
| 14 #include "cc/test/ordered_simple_task_runner.h" | 15 #include "cc/test/ordered_simple_task_runner.h" |
| 15 #include "components/scheduler/base/real_time_domain.h" | 16 #include "components/scheduler/base/real_time_domain.h" |
| 16 #include "components/scheduler/base/task_queue_impl.h" | 17 #include "components/scheduler/base/task_queue_impl.h" |
| 17 #include "components/scheduler/base/task_queue_manager_delegate_for_test.h" | 18 #include "components/scheduler/base/task_queue_manager_delegate_for_test.h" |
| 18 #include "components/scheduler/base/task_queue_selector.h" | 19 #include "components/scheduler/base/task_queue_selector.h" |
| 19 #include "components/scheduler/base/test_always_fail_time_source.h" | 20 #include "components/scheduler/base/test_always_fail_time_source.h" |
| 20 #include "components/scheduler/base/test_time_source.h" | 21 #include "components/scheduler/base/test_time_source.h" |
| 21 #include "components/scheduler/base/virtual_time_domain.h" | 22 #include "components/scheduler/base/virtual_time_domain.h" |
| 22 #include "components/scheduler/base/work_queue.h" | 23 #include "components/scheduler/base/work_queue.h" |
| 23 #include "components/scheduler/base/work_queue_sets.h" | 24 #include "components/scheduler/base/work_queue_sets.h" |
| 24 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
| 25 | 26 |
| 26 using testing::ElementsAre; | 27 using testing::ElementsAre; |
| 27 using testing::ElementsAreArray; | 28 using testing::ElementsAreArray; |
| 28 using testing::_; | 29 using testing::_; |
| 29 using scheduler::internal::EnqueueOrder; | 30 using scheduler::internal::EnqueueOrder; |
| 30 | 31 |
| 31 namespace scheduler { | 32 namespace scheduler { |
| 32 | 33 |
| 33 class MessageLoopTaskRunner : public TaskQueueManagerDelegateForTest { | 34 class MessageLoopTaskRunner : public TaskQueueManagerDelegateForTest { |
| 34 public: | 35 public: |
| 35 static scoped_refptr<MessageLoopTaskRunner> Create( | 36 static scoped_refptr<MessageLoopTaskRunner> Create( |
| 36 scoped_ptr<base::TickClock> tick_clock) { | 37 scoped_ptr<base::TickClock> tick_clock) { |
| 37 return make_scoped_refptr(new MessageLoopTaskRunner(tick_clock.Pass())); | 38 return make_scoped_refptr(new MessageLoopTaskRunner(std::move(tick_clock))); |
| 38 } | 39 } |
| 39 | 40 |
| 40 // NestableTaskRunner implementation. | 41 // NestableTaskRunner implementation. |
| 41 bool IsNested() const override { | 42 bool IsNested() const override { |
| 42 return base::MessageLoop::current()->IsNested(); | 43 return base::MessageLoop::current()->IsNested(); |
| 43 } | 44 } |
| 44 | 45 |
| 45 private: | 46 private: |
| 46 explicit MessageLoopTaskRunner(scoped_ptr<base::TickClock> tick_clock) | 47 explicit MessageLoopTaskRunner(scoped_ptr<base::TickClock> tick_clock) |
| 47 : TaskQueueManagerDelegateForTest(base::MessageLoop::current() | 48 : TaskQueueManagerDelegateForTest(base::MessageLoop::current() |
| 48 ->task_runner(), | 49 ->task_runner(), |
| 49 tick_clock.Pass()) {} | 50 std::move(tick_clock)) {} |
| 50 ~MessageLoopTaskRunner() override {} | 51 ~MessageLoopTaskRunner() override {} |
| 51 }; | 52 }; |
| 52 | 53 |
| 53 class TaskQueueManagerTest : public testing::Test { | 54 class TaskQueueManagerTest : public testing::Test { |
| 54 public: | 55 public: |
| 55 void DeleteTaskQueueManager() { manager_.reset(); } | 56 void DeleteTaskQueueManager() { manager_.reset(); } |
| 56 | 57 |
| 57 protected: | 58 protected: |
| 58 void InitializeWithClock(size_t num_queues, | 59 void InitializeWithClock(size_t num_queues, |
| 59 scoped_ptr<base::TickClock> test_time_source) { | 60 scoped_ptr<base::TickClock> test_time_source) { |
| (...skipping 1638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1698 double ratio = static_cast<double>(linear_delayed_task.count()) / | 1699 double ratio = static_cast<double>(linear_delayed_task.count()) / |
| 1699 static_cast<double>(quadratic_immediate_task.count()); | 1700 static_cast<double>(quadratic_immediate_task.count()); |
| 1700 | 1701 |
| 1701 // This is by design, we want to enforce a strict ordering in task execution | 1702 // This is by design, we want to enforce a strict ordering in task execution |
| 1702 // where by delayed tasks can not skip ahead of non-delayed work. | 1703 // where by delayed tasks can not skip ahead of non-delayed work. |
| 1703 EXPECT_GT(ratio, 0.0); | 1704 EXPECT_GT(ratio, 0.0); |
| 1704 EXPECT_LT(ratio, 0.1); | 1705 EXPECT_LT(ratio, 0.1); |
| 1705 } | 1706 } |
| 1706 | 1707 |
| 1707 } // namespace scheduler | 1708 } // namespace scheduler |
| OLD | NEW |