| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "platform/scheduler/child/worker_global_scope_scheduler.h" | 5 #include "platform/scheduler/child/worker_global_scope_scheduler.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/test/simple_test_tick_clock.h" | 9 #include "base/test/simple_test_tick_clock.h" |
| 10 #include "base/test/test_simple_task_runner.h" | 10 #include "base/test/test_simple_task_runner.h" |
| 11 #include "platform/scheduler/base/test_time_source.h" | 11 #include "platform/scheduler/base/test_time_source.h" |
| 12 #include "platform/scheduler/child/scheduler_tqm_delegate_for_test.h" | 12 #include "platform/scheduler/child/scheduler_tqm_delegate_for_test.h" |
| 13 #include "platform/scheduler/child/worker_scheduler_impl.h" | 13 #include "platform/scheduler/child/worker_scheduler_impl.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 16 |
| 17 using testing::ElementsAreArray; | 17 using ::testing::ElementsAreArray; |
| 18 | 18 |
| 19 namespace blink { | 19 namespace blink { |
| 20 namespace scheduler { | 20 namespace scheduler { |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 void AppendToVectorTestTask(std::vector<std::string>* vector, | 24 void AppendToVectorTestTask(std::vector<std::string>* vector, |
| 25 std::string value) { | 25 std::string value) { |
| 26 vector->push_back(value); | 26 vector->push_back(value); |
| 27 } | 27 } |
| 28 | 28 |
| 29 } // namespace | 29 } // namespace |
| 30 | 30 |
| 31 class WorkerGlobalScopeSchedulerTest : public testing::Test { | 31 class WorkerGlobalScopeSchedulerTest : public ::testing::Test { |
| 32 public: | 32 public: |
| 33 WorkerGlobalScopeSchedulerTest() | 33 WorkerGlobalScopeSchedulerTest() |
| 34 : clock_(new base::SimpleTestTickClock()), | 34 : clock_(new base::SimpleTestTickClock()), |
| 35 mock_task_runner_(new base::TestSimpleTaskRunner()), | 35 mock_task_runner_(new base::TestSimpleTaskRunner()), |
| 36 main_task_runner_(SchedulerTqmDelegateForTest::Create( | 36 main_task_runner_(SchedulerTqmDelegateForTest::Create( |
| 37 mock_task_runner_, | 37 mock_task_runner_, |
| 38 base::WrapUnique(new TestTimeSource(clock_.get())))), | 38 base::WrapUnique(new TestTimeSource(clock_.get())))), |
| 39 scheduler_(new WorkerSchedulerImpl(main_task_runner_)) { | 39 scheduler_(new WorkerSchedulerImpl(main_task_runner_)) { |
| 40 clock_->Advance(base::TimeDelta::FromMicroseconds(5000)); | 40 clock_->Advance(base::TimeDelta::FromMicroseconds(5000)); |
| 41 } | 41 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 69 DISALLOW_COPY_AND_ASSIGN(WorkerGlobalScopeSchedulerTest); | 69 DISALLOW_COPY_AND_ASSIGN(WorkerGlobalScopeSchedulerTest); |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 TEST_F(WorkerGlobalScopeSchedulerTest, TestPostTasks) { | 72 TEST_F(WorkerGlobalScopeSchedulerTest, TestPostTasks) { |
| 73 std::vector<std::string> run_order; | 73 std::vector<std::string> run_order; |
| 74 PostTestTask(&run_order, "T1"); | 74 PostTestTask(&run_order, "T1"); |
| 75 PostTestTask(&run_order, "T2"); | 75 PostTestTask(&run_order, "T2"); |
| 76 RunUntilIdle(); | 76 RunUntilIdle(); |
| 77 PostTestTask(&run_order, "T3"); | 77 PostTestTask(&run_order, "T3"); |
| 78 RunUntilIdle(); | 78 RunUntilIdle(); |
| 79 EXPECT_THAT(run_order, testing::ElementsAre("T1", "T2", "T3")); | 79 EXPECT_THAT(run_order, ::testing::ElementsAre("T1", "T2", "T3")); |
| 80 | 80 |
| 81 // Tasks should not run after the scheduler is disposed of. | 81 // Tasks should not run after the scheduler is disposed of. |
| 82 global_scope_scheduler_->Dispose(); | 82 global_scope_scheduler_->Dispose(); |
| 83 run_order.clear(); | 83 run_order.clear(); |
| 84 PostTestTask(&run_order, "T4"); | 84 PostTestTask(&run_order, "T4"); |
| 85 PostTestTask(&run_order, "T5"); | 85 PostTestTask(&run_order, "T5"); |
| 86 RunUntilIdle(); | 86 RunUntilIdle(); |
| 87 EXPECT_TRUE(run_order.empty()); | 87 EXPECT_TRUE(run_order.empty()); |
| 88 } | 88 } |
| 89 | 89 |
| 90 } // namespace scheduler | 90 } // namespace scheduler |
| 91 } // namespace blink | 91 } // namespace blink |
| OLD | NEW |