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

Unified Diff: components/scheduler/renderer/renderer_scheduler_impl_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 side-by-side diff with in-line comments
Download patch
Index: components/scheduler/renderer/renderer_scheduler_impl_unittest.cc
diff --git a/components/scheduler/renderer/renderer_scheduler_impl_unittest.cc b/components/scheduler/renderer/renderer_scheduler_impl_unittest.cc
index 9a6cb38d668df57ce96719abad6bca062267f8df..c94534d7442908ab116338505f8ef5a271fa3487 100644
--- a/components/scheduler/renderer/renderer_scheduler_impl_unittest.cc
+++ b/components/scheduler/renderer/renderer_scheduler_impl_unittest.cc
@@ -5,9 +5,9 @@
#include "components/scheduler/renderer/renderer_scheduler_impl.h"
#include "base/callback.h"
+#include "base/test/simple_test_tick_clock.h"
#include "cc/output/begin_frame_args.h"
#include "cc/test/ordered_simple_task_runner.h"
-#include "cc/test/test_now_source.h"
#include "components/scheduler/child/nestable_task_runner_for_test.h"
#include "components/scheduler/child/scheduler_message_loop_delegate.h"
#include "components/scheduler/child/test_time_source.h"
@@ -81,7 +81,7 @@ void RepostingIdleTestTask(SingleThreadIdleTaskRunner* idle_task_runner,
void RepostingUpdateClockIdleTestTask(
SingleThreadIdleTaskRunner* idle_task_runner,
int* run_count,
- scoped_refptr<cc::TestNowSource> clock,
+ base::SimpleTestTickClock* clock,
base::TimeDelta advance_time,
std::vector<base::TimeTicks>* deadlines,
base::TimeTicks deadline) {
@@ -93,22 +93,21 @@ void RepostingUpdateClockIdleTestTask(
}
deadlines->push_back(deadline);
(*run_count)++;
- clock->AdvanceNow(advance_time);
+ clock->Advance(advance_time);
}
void WillBeginFrameIdleTask(RendererScheduler* scheduler,
- scoped_refptr<cc::TestNowSource> clock,
+ base::SimpleTestTickClock* clock,
base::TimeTicks deadline) {
scheduler->WillBeginFrame(cc::BeginFrameArgs::Create(
- BEGINFRAME_FROM_HERE, clock->Now(), base::TimeTicks(),
+ BEGINFRAME_FROM_HERE, clock->NowTicks(), base::TimeTicks(),
base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL));
}
-void UpdateClockToDeadlineIdleTestTask(
- cc::TestNowSource* clock,
- int* run_count,
- base::TimeTicks deadline) {
- clock->SetNow(deadline);
+void UpdateClockToDeadlineIdleTestTask(base::SimpleTestTickClock* clock,
+ int* run_count,
+ base::TimeTicks deadline) {
+ clock->Advance(deadline - clock->NowTicks());
(*run_count)++;
}
@@ -145,10 +144,14 @@ class RendererSchedulerImplTest : public testing::Test {
public:
using Policy = RendererSchedulerImpl::Policy;
- RendererSchedulerImplTest() : clock_(cc::TestNowSource::Create(5000)) {}
+ RendererSchedulerImplTest() : clock_(new base::SimpleTestTickClock()) {
+ clock_->Advance(base::TimeDelta::FromInternalValue(5000));
+ }
RendererSchedulerImplTest(base::MessageLoop* message_loop)
- : clock_(cc::TestNowSource::Create(5000)), message_loop_(message_loop) {}
+ : clock_(new base::SimpleTestTickClock()), message_loop_(message_loop) {
+ clock_->Advance(base::TimeDelta::FromInternalValue(5000));
+ }
~RendererSchedulerImplTest() override {}
@@ -157,8 +160,8 @@ class RendererSchedulerImplTest : public testing::Test {
nestable_task_runner_ =
SchedulerMessageLoopDelegate::Create(message_loop_.get());
} else {
- mock_task_runner_ =
- make_scoped_refptr(new cc::OrderedSimpleTaskRunner(clock_, false));
+ mock_task_runner_ = make_scoped_refptr(
+ new cc::OrderedSimpleTaskRunner(clock_.get(), false));
nestable_task_runner_ =
NestableTaskRunnerForTest::Create(mock_task_runner_);
}
@@ -174,10 +177,11 @@ class RendererSchedulerImplTest : public testing::Test {
idle_task_runner_ = scheduler_->IdleTaskRunner();
timer_task_runner_ = scheduler_->TimerTaskRunner();
scheduler_->GetSchedulerHelperForTesting()->SetTimeSourceForTesting(
- make_scoped_ptr(new TestTimeSource(clock_)));
+ make_scoped_ptr(new TestTimeSource(clock_.get())));
scheduler_->GetSchedulerHelperForTesting()
->GetTaskQueueManagerForTesting()
- ->SetTimeSourceForTesting(make_scoped_ptr(new TestTimeSource(clock_)));
+ ->SetTimeSourceForTesting(
+ make_scoped_ptr(new TestTimeSource(clock_.get())));
}
void TearDown() override {
@@ -205,7 +209,7 @@ class RendererSchedulerImplTest : public testing::Test {
void DoMainFrame() {
scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create(
- BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(),
+ BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(),
base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL));
scheduler_->DidCommitFrameToCompositor();
}
@@ -296,7 +300,7 @@ class RendererSchedulerImplTest : public testing::Test {
&RendererSchedulerImpl::PolicyToString);
}
- scoped_refptr<cc::TestNowSource> clock_;
+ scoped_ptr<base::SimpleTestTickClock> clock_;
// Only one of mock_task_runner_ or message_loop_ will be set.
scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_;
scoped_ptr<base::MessageLoop> message_loop_;
@@ -376,10 +380,10 @@ TEST_F(RendererSchedulerImplTest, TestRentrantTask) {
TEST_F(RendererSchedulerImplTest, TestPostIdleTask) {
int run_count = 0;
base::TimeTicks expected_deadline =
- clock_->Now() + base::TimeDelta::FromMilliseconds(2300);
+ clock_->NowTicks() + base::TimeDelta::FromMilliseconds(2300);
base::TimeTicks deadline_in_task;
- clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(100));
+ clock_->Advance(base::TimeDelta::FromMilliseconds(100));
idle_task_runner_->PostIdleTask(
FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task));
@@ -387,20 +391,20 @@ TEST_F(RendererSchedulerImplTest, TestPostIdleTask) {
EXPECT_EQ(0, run_count); // Shouldn't run yet as no WillBeginFrame.
scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create(
- BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(),
+ BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(),
base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL));
RunUntilIdle();
EXPECT_EQ(0, run_count); // Shouldn't run as no DidCommitFrameToCompositor.
- clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(1200));
+ clock_->Advance(base::TimeDelta::FromMilliseconds(1200));
scheduler_->DidCommitFrameToCompositor();
RunUntilIdle();
EXPECT_EQ(0, run_count); // We missed the deadline.
scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create(
- BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(),
+ BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(),
base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL));
- clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(800));
+ clock_->Advance(base::TimeDelta::FromMilliseconds(800));
scheduler_->DidCommitFrameToCompositor();
RunUntilIdle();
EXPECT_EQ(1, run_count);
@@ -434,10 +438,10 @@ TEST_F(RendererSchedulerImplTest, TestIdleTaskExceedsDeadline) {
// Post two UpdateClockToDeadlineIdleTestTask tasks.
idle_task_runner_->PostIdleTask(
FROM_HERE,
- base::Bind(&UpdateClockToDeadlineIdleTestTask, clock_, &run_count));
+ base::Bind(&UpdateClockToDeadlineIdleTestTask, clock_.get(), &run_count));
idle_task_runner_->PostIdleTask(
FROM_HERE,
- base::Bind(&UpdateClockToDeadlineIdleTestTask, clock_, &run_count));
+ base::Bind(&UpdateClockToDeadlineIdleTestTask, clock_.get(), &run_count));
EnableIdleTasks();
RunUntilIdle();
@@ -521,15 +525,15 @@ TEST_F(RendererSchedulerImplTest, TestDelayedEndIdlePeriodCanceled) {
// Trigger the beginning of an idle period for 1000ms.
scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create(
- BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(),
+ BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(),
base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL));
DoMainFrame();
// End the idle period early (after 500ms), and send a WillBeginFrame which
// specifies that the next idle period should end 1000ms from now.
- clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(500));
+ clock_->Advance(base::TimeDelta::FromMilliseconds(500));
scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create(
- BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(),
+ BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(),
base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL));
RunUntilIdle();
@@ -537,13 +541,13 @@ TEST_F(RendererSchedulerImplTest, TestDelayedEndIdlePeriodCanceled) {
// Trigger the start of the idle period before the task to end the previous
// idle period has been triggered.
- clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(400));
+ clock_->Advance(base::TimeDelta::FromMilliseconds(400));
scheduler_->DidCommitFrameToCompositor();
// Post a task which simulates running until after the previous end idle
// period delayed task was scheduled for
scheduler_->DefaultTaskRunner()->PostTask(FROM_HERE, base::Bind(NullTask));
- clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(300));
+ clock_->Advance(base::TimeDelta::FromMilliseconds(300));
RunUntilIdle();
EXPECT_EQ(1, run_count); // We should still be in the new idle period.
@@ -867,7 +871,7 @@ TEST_F(RendererSchedulerImplTest,
std::string("D1"), std::string("D2")));
run_order.clear();
- clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(1000));
+ clock_->Advance(base::TimeDelta::FromMilliseconds(1000));
PostTestTasks(&run_order, "D1 C1 D2 C2");
// Compositor policy mode should have ended now that the clock has advanced.
@@ -893,7 +897,7 @@ TEST_F(RendererSchedulerImplTest,
std::string("D1"), std::string("D2")));
run_order.clear();
- clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(1000));
+ clock_->Advance(base::TimeDelta::FromMilliseconds(1000));
PostTestTasks(&run_order, "D1 C1 D2 C2");
// Compositor policy mode should have ended now that the clock has advanced.
@@ -916,7 +920,7 @@ TEST_F(RendererSchedulerImplTest, TestTouchstartPolicyEndsAfterTimeout) {
std::string("D1"), std::string("D2")));
run_order.clear();
- clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(1000));
+ clock_->Advance(base::TimeDelta::FromMilliseconds(1000));
// Don't post any compositor tasks to simulate a very long running event
// handler.
@@ -986,7 +990,7 @@ TEST_F(RendererSchedulerImplTest, TestIsHighPriorityWorkAnticipated) {
EXPECT_FALSE(is_anticipated_before);
EXPECT_TRUE(is_anticipated_after);
- clock_->AdvanceNow(priority_escalation_after_input_duration() * 2);
+ clock_->Advance(priority_escalation_after_input_duration() * 2);
simulate_input = false;
default_task_runner_->PostTask(
FROM_HERE,
@@ -1052,7 +1056,7 @@ TEST_F(RendererSchedulerImplTest, SlowMainThreadInputEvent) {
// Simulate the input event being queued for a very long time. The compositor
// task we post here represents the enqueued input task.
- clock_->AdvanceNow(priority_escalation_after_input_duration() * 2);
+ clock_->Advance(priority_escalation_after_input_duration() * 2);
scheduler_->DidHandleInputEventOnMainThread(
FakeInputEvent(blink::WebInputEvent::GestureFlingStart));
RunUntilIdle();
@@ -1062,7 +1066,7 @@ TEST_F(RendererSchedulerImplTest, SlowMainThreadInputEvent) {
EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy());
// After the escalation period ends we should go back into normal mode.
- clock_->AdvanceNow(priority_escalation_after_input_duration() * 2);
+ clock_->Advance(priority_escalation_after_input_duration() * 2);
RunUntilIdle();
EXPECT_EQ(Policy::NORMAL, CurrentPolicy());
}
@@ -1071,8 +1075,8 @@ class RendererSchedulerImplWithMockSchedulerTest
: public RendererSchedulerImplTest {
public:
void SetUp() override {
- mock_task_runner_ =
- make_scoped_refptr(new cc::OrderedSimpleTaskRunner(clock_, false));
+ mock_task_runner_ = make_scoped_refptr(
+ new cc::OrderedSimpleTaskRunner(clock_.get(), false));
nestable_task_runner_ =
NestableTaskRunnerForTest::Create(mock_task_runner_);
mock_scheduler_ = new RendererSchedulerImplForTest(nestable_task_runner_);
@@ -1100,7 +1104,7 @@ TEST_F(RendererSchedulerImplWithMockSchedulerTest,
mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true);
mock_scheduler_->ScheduleDelayedPolicyUpdate(
- clock_->Now(), base::TimeDelta::FromMilliseconds(1));
+ clock_->NowTicks(), base::TimeDelta::FromMilliseconds(1));
mock_scheduler_->EnsureUrgentPolicyUpdatePostedOnMainThread();
RunUntilIdle();
@@ -1115,7 +1119,7 @@ TEST_F(RendererSchedulerImplWithMockSchedulerTest,
mock_scheduler_->EnsureUrgentPolicyUpdatePostedOnMainThread();
mock_scheduler_->ScheduleDelayedPolicyUpdate(
- clock_->Now(), base::TimeDelta::FromMilliseconds(1));
+ clock_->NowTicks(), base::TimeDelta::FromMilliseconds(1));
RunUntilIdle();
@@ -1138,7 +1142,7 @@ TEST_F(RendererSchedulerImplWithMockSchedulerTest,
FakeInputEvent(blink::WebInputEvent::TouchStart));
EXPECT_EQ(1, mock_scheduler_->update_policy_count_);
- clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(1000));
+ clock_->Advance(base::TimeDelta::FromMilliseconds(1000));
RunUntilIdle();
// We finally expect a delayed policy update 100ms later.
@@ -1187,7 +1191,7 @@ TEST_F(RendererSchedulerImplWithMockSchedulerTest,
FakeInputEvent(blink::WebInputEvent::TouchMove));
EXPECT_EQ(2, mock_scheduler_->update_policy_count_);
- clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(1000));
+ clock_->Advance(base::TimeDelta::FromMilliseconds(1000));
RunUntilIdle();
// We finally expect a delayed policy update.
@@ -1209,7 +1213,7 @@ TEST_F(RendererSchedulerImplWithMockSchedulerTest,
FakeInputEvent(blink::WebInputEvent::TouchStart));
EXPECT_EQ(1, mock_scheduler_->update_policy_count_);
- clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(1000));
+ clock_->Advance(base::TimeDelta::FromMilliseconds(1000));
RunUntilIdle();
// We expect a delayed policy update.
EXPECT_EQ(2, mock_scheduler_->update_policy_count_);
@@ -1227,7 +1231,7 @@ TEST_F(RendererSchedulerImplWithMockSchedulerTest,
FakeInputEvent(blink::WebInputEvent::TouchMove));
EXPECT_EQ(3, mock_scheduler_->update_policy_count_);
- clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(1000));
+ clock_->Advance(base::TimeDelta::FromMilliseconds(1000));
RunUntilIdle();
// We finally expect a delayed policy update.
@@ -1335,7 +1339,7 @@ TEST_F(RendererSchedulerImplWithMessageLoopTest,
TEST_F(RendererSchedulerImplTest, TestLongIdlePeriod) {
base::TimeTicks expected_deadline =
- clock_->Now() + maximum_idle_period_duration();
+ clock_->NowTicks() + maximum_idle_period_duration();
base::TimeTicks deadline_in_task;
int run_count = 0;
@@ -1353,7 +1357,7 @@ TEST_F(RendererSchedulerImplTest, TestLongIdlePeriod) {
TEST_F(RendererSchedulerImplTest, TestLongIdlePeriodWithPendingDelayedTask) {
base::TimeDelta pending_task_delay = base::TimeDelta::FromMilliseconds(30);
- base::TimeTicks expected_deadline = clock_->Now() + pending_task_delay;
+ base::TimeTicks expected_deadline = clock_->NowTicks() + pending_task_delay;
base::TimeTicks deadline_in_task;
int run_count = 0;
@@ -1378,7 +1382,7 @@ TEST_F(RendererSchedulerImplTest,
pending_task_delay);
// Advance clock until after delayed task was meant to be run.
- clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(20));
+ clock_->Advance(base::TimeDelta::FromMilliseconds(20));
// Post an idle task and BeginFrameNotExpectedSoon to initiate a long idle
// period. Since there is a late pending delayed task this shouldn't actually
@@ -1390,7 +1394,7 @@ TEST_F(RendererSchedulerImplTest,
EXPECT_EQ(0, run_count);
// After the delayed task has been run we should trigger an idle period.
- clock_->AdvanceNow(maximum_idle_period_duration());
+ clock_->Advance(maximum_idle_period_duration());
RunUntilIdle();
EXPECT_EQ(1, run_count);
}
@@ -1401,12 +1405,12 @@ TEST_F(RendererSchedulerImplTest, TestLongIdlePeriodRepeating) {
int run_count = 0;
max_idle_task_reposts = 3;
- base::TimeTicks clock_before(clock_->Now());
+ base::TimeTicks clock_before(clock_->NowTicks());
base::TimeDelta idle_task_runtime(base::TimeDelta::FromMilliseconds(10));
idle_task_runner_->PostIdleTask(
- FROM_HERE,
- base::Bind(&RepostingUpdateClockIdleTestTask, idle_task_runner_,
- &run_count, clock_, idle_task_runtime, &actual_deadlines));
+ FROM_HERE, base::Bind(&RepostingUpdateClockIdleTestTask,
+ idle_task_runner_, &run_count, clock_.get(),
+ idle_task_runtime, &actual_deadlines));
scheduler_->BeginFrameNotExpectedSoon();
RunUntilIdle();
EXPECT_EQ(3, run_count);
@@ -1422,12 +1426,12 @@ TEST_F(RendererSchedulerImplTest, TestLongIdlePeriodRepeating) {
// new BeginMainFrame.
max_idle_task_reposts = 5;
idle_task_runner_->PostIdleTask(
- FROM_HERE,
- base::Bind(&RepostingUpdateClockIdleTestTask, idle_task_runner_,
- &run_count, clock_, idle_task_runtime, &actual_deadlines));
+ FROM_HERE, base::Bind(&RepostingUpdateClockIdleTestTask,
+ idle_task_runner_, &run_count, clock_.get(),
+ idle_task_runtime, &actual_deadlines));
idle_task_runner_->PostIdleTask(
FROM_HERE, base::Bind(&WillBeginFrameIdleTask,
- base::Unretained(scheduler_.get()), clock_));
+ base::Unretained(scheduler_.get()), clock_.get()));
RunUntilIdle();
EXPECT_EQ(4, run_count);
}
@@ -1444,7 +1448,7 @@ TEST_F(RendererSchedulerImplTest, TestLongIdlePeriodDoesNotWakeScheduler) {
// idle period.
base::TimeTicks idle_period_deadline =
scheduler_->CurrentIdleTaskDeadlineForTesting();
- clock_->AdvanceNow(maximum_idle_period_duration());
+ clock_->Advance(maximum_idle_period_duration());
RunUntilIdle();
base::TimeTicks new_idle_period_deadline =
@@ -1486,7 +1490,7 @@ TEST_F(RendererSchedulerImplTest, TestLongIdlePeriodInTouchStartPolicy) {
EXPECT_EQ(0, run_count);
// The long idle period should start after the touchstart policy has finished.
- clock_->AdvanceNow(priority_escalation_after_input_duration());
+ clock_->Advance(priority_escalation_after_input_duration());
RunUntilIdle();
EXPECT_EQ(1, run_count);
}
@@ -1531,7 +1535,7 @@ TEST_F(RendererSchedulerImplTest, CanExceedIdleDeadlineIfRequired) {
// Next long idle period will be for the maximum time, so
// CanExceedIdleDeadlineIfRequired should return true.
- clock_->AdvanceNow(maximum_idle_period_duration());
+ clock_->Advance(maximum_idle_period_duration());
idle_task_runner_->PostIdleTask(
FROM_HERE,
base::Bind(&TestCanExceedIdleDeadlineIfRequiredTask, scheduler_.get(),
@@ -1543,7 +1547,7 @@ TEST_F(RendererSchedulerImplTest, CanExceedIdleDeadlineIfRequired) {
// Next long idle period will be for the maximum time, so
// CanExceedIdleDeadlineIfRequired should return true.
scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create(
- BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(),
+ BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(),
base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL));
EXPECT_FALSE(scheduler_->CanExceedIdleDeadlineIfRequired());
}
@@ -1573,8 +1577,8 @@ TEST_F(RendererSchedulerImplTest, TestRendererHiddenIdlePeriod) {
idle_task_runner_->PostIdleTask(
FROM_HERE,
base::Bind(&RepostingIdleTestTask, idle_task_runner_, &run_count));
- clock_->AdvanceNow(end_idle_when_hidden_delay() +
- base::TimeDelta::FromMilliseconds(10));
+ clock_->Advance(end_idle_when_hidden_delay() +
+ base::TimeDelta::FromMilliseconds(10));
RunUntilIdle();
EXPECT_EQ(2, run_count);
}

Powered by Google App Engine
This is Rietveld 408576698