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

Side by Side Diff: components/scheduler/renderer/renderer_scheduler_impl_unittest.cc

Issue 1303353003: scheduler: Disable expensive timers during main thread user input (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments. Created 5 years, 4 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/renderer/renderer_scheduler_impl.h" 5 #include "components/scheduler/renderer/renderer_scheduler_impl.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/test/simple_test_tick_clock.h" 8 #include "base/test/simple_test_tick_clock.h"
9 #include "cc/output/begin_frame_args.h" 9 #include "cc/output/begin_frame_args.h"
10 #include "cc/test/ordered_simple_task_runner.h" 10 #include "cc/test/ordered_simple_task_runner.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 bool* is_anticipated_before, 131 bool* is_anticipated_before,
132 bool* is_anticipated_after) { 132 bool* is_anticipated_after) {
133 *is_anticipated_before = scheduler->IsHighPriorityWorkAnticipated(); 133 *is_anticipated_before = scheduler->IsHighPriorityWorkAnticipated();
134 if (simulate_input) { 134 if (simulate_input) {
135 scheduler->DidHandleInputEventOnCompositorThread( 135 scheduler->DidHandleInputEventOnCompositorThread(
136 FakeInputEvent(blink::WebInputEvent::GestureFlingStart), 136 FakeInputEvent(blink::WebInputEvent::GestureFlingStart),
137 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); 137 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR);
138 } 138 }
139 *is_anticipated_after = scheduler->IsHighPriorityWorkAnticipated(); 139 *is_anticipated_after = scheduler->IsHighPriorityWorkAnticipated();
140 } 140 }
141
141 }; // namespace 142 }; // namespace
142 143
143 class RendererSchedulerImplForTest : public RendererSchedulerImpl { 144 class RendererSchedulerImplForTest : public RendererSchedulerImpl {
144 public: 145 public:
145 using RendererSchedulerImpl::OnIdlePeriodEnded; 146 using RendererSchedulerImpl::OnIdlePeriodEnded;
146 using RendererSchedulerImpl::OnIdlePeriodStarted; 147 using RendererSchedulerImpl::OnIdlePeriodStarted;
147 using RendererSchedulerImpl::Policy; 148 using RendererSchedulerImpl::Policy;
148 using RendererSchedulerImpl::PolicyToString; 149 using RendererSchedulerImpl::PolicyToString;
149 150
150 RendererSchedulerImplForTest( 151 RendererSchedulerImplForTest(
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 612
612 scheduler_->DidAnimateForInputOnCompositorThread(); 613 scheduler_->DidAnimateForInputOnCompositorThread();
613 EnableIdleTasks(); 614 EnableIdleTasks();
614 RunUntilIdle(); 615 RunUntilIdle();
615 EXPECT_THAT(run_order, 616 EXPECT_THAT(run_order,
616 testing::ElementsAre(std::string("C1"), std::string("C2"), 617 testing::ElementsAre(std::string("C1"), std::string("C2"),
617 std::string("D1"), std::string("D2"), 618 std::string("D1"), std::string("D2"),
618 std::string("I1"))); 619 std::string("I1")));
619 } 620 }
620 621
621 TEST_F(RendererSchedulerImplTest, 622 TEST_F(
622 TestCompositorPolicy_TimersOnlyRunWhenIdle_MainThreadOnCriticalPath) { 623 RendererSchedulerImplTest,
624 TestCompositorPolicy_ExpensiveTimersDontRunWhenMainThreadOnCriticalPath) {
623 std::vector<std::string> run_order; 625 std::vector<std::string> run_order;
626
627 // Simulate a bunch of expensive timer tasks
628 for (int i = 0; i < 10; i++) {
629 timer_task_runner_->PostTask(
630 FROM_HERE, base::Bind(&base::SimpleTestTickClock::Advance,
631 base::Unretained(clock_.get()),
632 base::TimeDelta::FromMilliseconds(500)));
633 }
634 RunUntilIdle();
635
636 // Timers should now be disabled during main thread user userinteractions.
624 PostTestTasks(&run_order, "C1 T1"); 637 PostTestTasks(&run_order, "C1 T1");
625 638
626 scheduler_->DidAnimateForInputOnCompositorThread(); 639 scheduler_->DidAnimateForInputOnCompositorThread();
627 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( 640 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create(
628 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(), 641 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(),
629 base::TimeDelta::FromMilliseconds(16), cc::BeginFrameArgs::NORMAL)); 642 base::TimeDelta::FromMilliseconds(16), cc::BeginFrameArgs::NORMAL));
630 scheduler_->DidCommitFrameToCompositor(); // Starts Idle Period
631 RunUntilIdle();
632
633 EXPECT_THAT(run_order,
634 testing::ElementsAre(std::string("C1"), std::string("T1")));
635
636 // End the idle period.
637 clock_->Advance(base::TimeDelta::FromMilliseconds(500));
638 scheduler_->DidAnimateForInputOnCompositorThread();
639 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create(
640 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(),
641 base::TimeDelta::FromMilliseconds(16), cc::BeginFrameArgs::NORMAL));
642
643 run_order.clear();
644 PostTestTasks(&run_order, "C1 T1");
645 RunUntilIdle(); 643 RunUntilIdle();
646 644
647 EXPECT_THAT(run_order, testing::ElementsAre(std::string("C1"))); 645 EXPECT_THAT(run_order, testing::ElementsAre(std::string("C1")));
646 clock_->Advance(priority_escalation_after_input_duration() * 2);
647
648 run_order.clear();
649 RunUntilIdle();
650 EXPECT_THAT(run_order, testing::ElementsAre(std::string("T1")));
648 } 651 }
649 652
650 TEST_F(RendererSchedulerImplTest, 653 TEST_F(RendererSchedulerImplTest,
651 TestCompositorPolicy_TimersAlwaysRunIfNoRecentIdlePeriod) { 654 TestCompositorPolicy_TimersAlwaysRunIfNoRecentIdlePeriod) {
652 std::vector<std::string> run_order; 655 std::vector<std::string> run_order;
653 PostTestTasks(&run_order, "C1 T1"); 656 PostTestTasks(&run_order, "C1 T1");
654 657
655 // Simulate no recent idle period. 658 // Simulate no recent idle period.
656 clock_->Advance(idle_period_starvation_threshold() * 2); 659 clock_->Advance(idle_period_starvation_threshold() * 2);
657 660
(...skipping 1120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1778 1781
1779 TEST_F(RendererSchedulerImplTest, ShutdownPreventsPostingOfNewTasks) { 1782 TEST_F(RendererSchedulerImplTest, ShutdownPreventsPostingOfNewTasks) {
1780 scheduler_->Shutdown(); 1783 scheduler_->Shutdown();
1781 std::vector<std::string> run_order; 1784 std::vector<std::string> run_order;
1782 PostTestTasks(&run_order, "D1 C1"); 1785 PostTestTasks(&run_order, "D1 C1");
1783 RunUntilIdle(); 1786 RunUntilIdle();
1784 EXPECT_TRUE(run_order.empty()); 1787 EXPECT_TRUE(run_order.empty());
1785 } 1788 }
1786 1789
1787 } // namespace scheduler 1790 } // namespace scheduler
OLDNEW
« no previous file with comments | « components/scheduler/renderer/renderer_scheduler_impl.cc ('k') | components/scheduler/renderer/task_cost_estimator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698