Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(689)

Side by Side Diff: components/scheduler/child/scheduler_helper_unittest.cc

Issue 1132753008: Replaced TestNowSource with SimpleTestTickClock. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased again. Replaces TimeSource with TickClock in TestAlwaysFailTimeSource Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "cc/test/ordered_simple_task_runner.h" 9 #include "cc/test/ordered_simple_task_runner.h"
9 #include "cc/test/test_now_source.h"
10 #include "components/scheduler/child/nestable_task_runner_for_test.h" 10 #include "components/scheduler/child/nestable_task_runner_for_test.h"
11 #include "components/scheduler/child/scheduler_message_loop_delegate.h" 11 #include "components/scheduler/child/scheduler_message_loop_delegate.h"
12 #include "components/scheduler/child/test_time_source.h" 12 #include "components/scheduler/child/test_time_source.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;
(...skipping 17 matching lines...) Expand all
37 base::Bind(AppendToVectorReentrantTask, base::Unretained(task_runner), 37 base::Bind(AppendToVectorReentrantTask, base::Unretained(task_runner),
38 vector, reentrant_count, max_reentrant_count)); 38 vector, reentrant_count, max_reentrant_count));
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_(cc::TestNowSource::Create(5000)), 47 : clock_(new base::SimpleTestTickClock()),
48 mock_task_runner_(new cc::OrderedSimpleTaskRunner(clock_, false)), 48 mock_task_runner_(new cc::OrderedSimpleTaskRunner(clock_.get(), false)),
49 nestable_task_runner_( 49 nestable_task_runner_(
50 NestableTaskRunnerForTest::Create(mock_task_runner_)), 50 NestableTaskRunnerForTest::Create(mock_task_runner_)),
51 scheduler_helper_( 51 scheduler_helper_(
52 new SchedulerHelper(nestable_task_runner_, 52 new SchedulerHelper(nestable_task_runner_,
53 "test.scheduler", 53 "test.scheduler",
54 TRACE_DISABLED_BY_DEFAULT("test.scheduler"), 54 TRACE_DISABLED_BY_DEFAULT("test.scheduler"),
55 SchedulerHelper::TASK_QUEUE_COUNT)), 55 SchedulerHelper::TASK_QUEUE_COUNT)),
56 default_task_runner_(scheduler_helper_->DefaultTaskRunner()) { 56 default_task_runner_(scheduler_helper_->DefaultTaskRunner()) {
57 clock_->Advance(base::TimeDelta::FromInternalValue(5000));
57 scheduler_helper_->SetTimeSourceForTesting( 58 scheduler_helper_->SetTimeSourceForTesting(
58 make_scoped_ptr(new TestTimeSource(clock_))); 59 make_scoped_ptr(new TestTimeSource(clock_.get())));
59 scheduler_helper_->GetTaskQueueManagerForTesting()->SetTimeSourceForTesting( 60 scheduler_helper_->GetTaskQueueManagerForTesting()->SetTimeSourceForTesting(
60 make_scoped_ptr(new TestTimeSource(clock_))); 61 make_scoped_ptr(new TestTimeSource(clock_.get())));
61 } 62 }
62 63
63 ~SchedulerHelperTest() override {} 64 ~SchedulerHelperTest() override {}
64 65
65 void TearDown() override { 66 void TearDown() override {
66 // Check that all tests stop posting tasks. 67 // Check that all tests stop posting tasks.
67 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); 68 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true);
68 while (mock_task_runner_->RunUntilIdle()) { 69 while (mock_task_runner_->RunUntilIdle()) {
69 } 70 }
70 } 71 }
(...skipping 10 matching lines...) Expand all
81 } 82 }
82 } 83 }
83 84
84 static void CheckAllTaskQueueIdToString() { 85 static void CheckAllTaskQueueIdToString() {
85 CallForEachEnumValue<SchedulerHelper::QueueId>( 86 CallForEachEnumValue<SchedulerHelper::QueueId>(
86 SchedulerHelper::FIRST_QUEUE_ID, SchedulerHelper::TASK_QUEUE_COUNT, 87 SchedulerHelper::FIRST_QUEUE_ID, SchedulerHelper::TASK_QUEUE_COUNT,
87 &SchedulerHelper::TaskQueueIdToString); 88 &SchedulerHelper::TaskQueueIdToString);
88 } 89 }
89 90
90 protected: 91 protected:
91 scoped_refptr<cc::TestNowSource> clock_; 92 scoped_ptr<base::SimpleTestTickClock> clock_;
92 scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_; 93 scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_;
93 94
94 scoped_refptr<NestableSingleThreadTaskRunner> nestable_task_runner_; 95 scoped_refptr<NestableSingleThreadTaskRunner> nestable_task_runner_;
95 scoped_ptr<SchedulerHelper> scheduler_helper_; 96 scoped_ptr<SchedulerHelper> scheduler_helper_;
96 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_; 97 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_;
97 98
98 DISALLOW_COPY_AND_ASSIGN(SchedulerHelperTest); 99 DISALLOW_COPY_AND_ASSIGN(SchedulerHelperTest);
99 }; 100 };
100 101
101 TEST_F(SchedulerHelperTest, TestPostDefaultTask) { 102 TEST_F(SchedulerHelperTest, TestPostDefaultTask) {
(...skipping 29 matching lines...) Expand all
131 132
132 scheduler_helper_->Shutdown(); 133 scheduler_helper_->Shutdown();
133 EXPECT_TRUE(scheduler_helper_->IsShutdown()); 134 EXPECT_TRUE(scheduler_helper_->IsShutdown());
134 } 135 }
135 136
136 TEST_F(SchedulerHelperTest, TaskQueueIdToString) { 137 TEST_F(SchedulerHelperTest, TaskQueueIdToString) {
137 CheckAllTaskQueueIdToString(); 138 CheckAllTaskQueueIdToString();
138 } 139 }
139 140
140 } // namespace scheduler 141 } // namespace scheduler
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698