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

Side by Side Diff: third_party/WebKit/Source/platform/scheduler/renderer/idle_time_estimator_unittest.cc

Issue 2122543002: Replace Closure in TaskRunner::PostTask with OneShotCallback (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@07_oneshot
Patch Set: fix Created 4 years, 3 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/renderer/idle_time_estimator.h" 5 #include "platform/scheduler/renderer/idle_time_estimator.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.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 "platform/scheduler/base/task_queue_manager.h" 10 #include "platform/scheduler/base/task_queue_manager.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 "test.scheduler.debug"); 50 "test.scheduler.debug");
51 compositor_task_runner_ = 51 compositor_task_runner_ =
52 manager_->NewTaskQueue(TaskQueue::Spec("compositor_tq")); 52 manager_->NewTaskQueue(TaskQueue::Spec("compositor_tq"));
53 estimator_.reset(new IdleTimeEstimatorForTest( 53 estimator_.reset(new IdleTimeEstimatorForTest(
54 compositor_task_runner_, test_time_source_.get(), 10, 50)); 54 compositor_task_runner_, test_time_source_.get(), 10, 50));
55 } 55 }
56 56
57 void SimulateFrameWithOneCompositorTask(int compositor_time) { 57 void SimulateFrameWithOneCompositorTask(int compositor_time) {
58 base::TimeDelta non_idle_time = 58 base::TimeDelta non_idle_time =
59 base::TimeDelta::FromMilliseconds(compositor_time); 59 base::TimeDelta::FromMilliseconds(compositor_time);
60 base::PendingTask task(FROM_HERE, base::Closure()); 60 base::PendingTask task(FROM_HERE, base::OnceClosure());
61 estimator_->WillProcessTask(task); 61 estimator_->WillProcessTask(task);
62 clock_->Advance(non_idle_time); 62 clock_->Advance(non_idle_time);
63 estimator_->DidCommitFrameToCompositor(); 63 estimator_->DidCommitFrameToCompositor();
64 estimator_->DidProcessTask(task); 64 estimator_->DidProcessTask(task);
65 if (non_idle_time < frame_length_) 65 if (non_idle_time < frame_length_)
66 clock_->Advance(frame_length_ - non_idle_time); 66 clock_->Advance(frame_length_ - non_idle_time);
67 } 67 }
68 68
69 void SimulateFrameWithTwoCompositorTasks(int compositor_time1, 69 void SimulateFrameWithTwoCompositorTasks(int compositor_time1,
70 int compositor_time2) { 70 int compositor_time2) {
71 base::TimeDelta non_idle_time1 = 71 base::TimeDelta non_idle_time1 =
72 base::TimeDelta::FromMilliseconds(compositor_time1); 72 base::TimeDelta::FromMilliseconds(compositor_time1);
73 base::TimeDelta non_idle_time2 = 73 base::TimeDelta non_idle_time2 =
74 base::TimeDelta::FromMilliseconds(compositor_time2); 74 base::TimeDelta::FromMilliseconds(compositor_time2);
75 base::PendingTask task(FROM_HERE, base::Closure()); 75 base::PendingTask task(FROM_HERE, base::OnceClosure());
76 estimator_->WillProcessTask(task); 76 estimator_->WillProcessTask(task);
77 clock_->Advance(non_idle_time1); 77 clock_->Advance(non_idle_time1);
78 estimator_->DidProcessTask(task); 78 estimator_->DidProcessTask(task);
79 79
80 estimator_->WillProcessTask(task); 80 estimator_->WillProcessTask(task);
81 clock_->Advance(non_idle_time2); 81 clock_->Advance(non_idle_time2);
82 estimator_->DidCommitFrameToCompositor(); 82 estimator_->DidCommitFrameToCompositor();
83 estimator_->DidProcessTask(task); 83 estimator_->DidProcessTask(task);
84 84
85 base::TimeDelta idle_time = frame_length_ - non_idle_time1 - non_idle_time2; 85 base::TimeDelta idle_time = frame_length_ - non_idle_time1 - non_idle_time2;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 SimulateFrameWithTwoCompositorTasks(1, 4); 146 SimulateFrameWithTwoCompositorTasks(1, 4);
147 147
148 EXPECT_EQ(base::TimeDelta::FromMilliseconds(11), 148 EXPECT_EQ(base::TimeDelta::FromMilliseconds(11),
149 estimator_->GetExpectedIdleDuration(frame_length_)); 149 estimator_->GetExpectedIdleDuration(frame_length_));
150 } 150 }
151 151
152 TEST_F(IdleTimeEstimatorTest, IgnoresNestedTasks) { 152 TEST_F(IdleTimeEstimatorTest, IgnoresNestedTasks) {
153 SimulateFrameWithOneCompositorTask(5); 153 SimulateFrameWithOneCompositorTask(5);
154 SimulateFrameWithOneCompositorTask(5); 154 SimulateFrameWithOneCompositorTask(5);
155 155
156 base::PendingTask task(FROM_HERE, base::Closure()); 156 base::PendingTask task(FROM_HERE, base::OnceClosure());
157 estimator_->WillProcessTask(task); 157 estimator_->WillProcessTask(task);
158 SimulateFrameWithTwoCompositorTasks(4, 4); 158 SimulateFrameWithTwoCompositorTasks(4, 4);
159 SimulateFrameWithTwoCompositorTasks(4, 4); 159 SimulateFrameWithTwoCompositorTasks(4, 4);
160 SimulateFrameWithTwoCompositorTasks(4, 4); 160 SimulateFrameWithTwoCompositorTasks(4, 4);
161 SimulateFrameWithTwoCompositorTasks(4, 4); 161 SimulateFrameWithTwoCompositorTasks(4, 4);
162 estimator_->DidCommitFrameToCompositor(); 162 estimator_->DidCommitFrameToCompositor();
163 estimator_->DidProcessTask(task); 163 estimator_->DidProcessTask(task);
164 164
165 EXPECT_EQ(base::TimeDelta::FromMilliseconds(11), 165 EXPECT_EQ(base::TimeDelta::FromMilliseconds(11),
166 estimator_->GetExpectedIdleDuration(frame_length_)); 166 estimator_->GetExpectedIdleDuration(frame_length_));
167 } 167 }
168 168
169 } // namespace scheduler 169 } // namespace scheduler
170 } // namespace blink 170 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698