OLD | NEW |
---|---|
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 "content/renderer/scheduler/renderer_scheduler_impl.h" | 5 #include "content/renderer/scheduler/renderer_scheduler_impl.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "cc/output/begin_frame_args.h" | 8 #include "cc/output/begin_frame_args.h" |
9 #include "cc/test/ordered_simple_task_runner.h" | 9 #include "cc/test/ordered_simple_task_runner.h" |
10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
49 mock_task_runner_(new cc::OrderedSimpleTaskRunner(clock_, false)), | 49 mock_task_runner_(new cc::OrderedSimpleTaskRunner(clock_, false)), |
50 scheduler_(new RendererSchedulerImpl(mock_task_runner_)), | 50 scheduler_(new RendererSchedulerImpl(mock_task_runner_)), |
51 default_task_runner_(scheduler_->DefaultTaskRunner()), | 51 default_task_runner_(scheduler_->DefaultTaskRunner()), |
52 compositor_task_runner_(scheduler_->CompositorTaskRunner()), | 52 compositor_task_runner_(scheduler_->CompositorTaskRunner()), |
53 loading_task_runner_(scheduler_->LoadingTaskRunner()), | 53 loading_task_runner_(scheduler_->LoadingTaskRunner()), |
54 idle_task_runner_(scheduler_->IdleTaskRunner()) { | 54 idle_task_runner_(scheduler_->IdleTaskRunner()) { |
55 scheduler_->SetTimeSourceForTesting(clock_); | 55 scheduler_->SetTimeSourceForTesting(clock_); |
56 } | 56 } |
57 ~RendererSchedulerImplTest() override {} | 57 ~RendererSchedulerImplTest() override {} |
58 | 58 |
59 void RunUntilIdle() { mock_task_runner_->RunUntilIdle(); } | 59 void TearDown() override { |
60 // Check that all tests stop posting tasks. | |
61 while (RunUntilIdle()) { | |
62 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(100)); | |
Sami
2015/03/11 16:58:25
Thanks for adding this. By the way, would SetAutoA
alex clarke (OOO till 29th)
2015/03/12 13:41:32
Seems so.
| |
63 } | |
64 } | |
65 | |
66 bool RunUntilIdle() { return mock_task_runner_->RunUntilIdle(); } | |
60 | 67 |
61 void DoMainFrame() { | 68 void DoMainFrame() { |
62 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( | 69 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( |
63 BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(), | 70 BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(), |
64 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); | 71 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); |
65 scheduler_->DidCommitFrameToCompositor(); | 72 scheduler_->DidCommitFrameToCompositor(); |
66 } | 73 } |
67 | 74 |
68 void EnableIdleTasks() { DoMainFrame(); } | 75 void EnableIdleTasks() { DoMainFrame(); } |
69 | 76 |
70 Policy CurrentPolicy() { return scheduler_->current_policy_; } | 77 Policy CurrentPolicy() { return scheduler_->current_policy_; } |
71 | 78 |
79 void ScheduleUrgentPolicyUpdate() { | |
80 base::AutoLock lock(scheduler_->incoming_signals_lock_); | |
81 scheduler_->ScheduleUrgentPolicyUpdate(FROM_HERE); | |
82 } | |
83 | |
72 // Helper for posting several tasks of specific types. |task_descriptor| is a | 84 // Helper for posting several tasks of specific types. |task_descriptor| is a |
73 // string with space delimited task identifiers. The first letter of each | 85 // string with space delimited task identifiers. The first letter of each |
74 // task identifier specifies the task type: | 86 // task identifier specifies the task type: |
75 // - 'D': Default task | 87 // - 'D': Default task |
76 // - 'C': Compositor task | 88 // - 'C': Compositor task |
77 // - 'L': Loading task | 89 // - 'L': Loading task |
78 // - 'I': Idle task | 90 // - 'I': Idle task |
79 void PostTestTasks(std::vector<std::string>* run_order, | 91 void PostTestTasks(std::vector<std::string>* run_order, |
80 const std::string& task_descriptor) { | 92 const std::string& task_descriptor) { |
81 std::istringstream stream(task_descriptor); | 93 std::istringstream stream(task_descriptor); |
(...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
840 RunUntilIdle(); | 852 RunUntilIdle(); |
841 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); | 853 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); |
842 | 854 |
843 // Process the input event with a new BeginMainFrame. | 855 // Process the input event with a new BeginMainFrame. |
844 DoMainFrame(); | 856 DoMainFrame(); |
845 clock_->AdvanceNow(2 * priority_escalation_after_input_duration()); | 857 clock_->AdvanceNow(2 * priority_escalation_after_input_duration()); |
846 RunUntilIdle(); | 858 RunUntilIdle(); |
847 EXPECT_EQ(Policy::NORMAL, CurrentPolicy()); | 859 EXPECT_EQ(Policy::NORMAL, CurrentPolicy()); |
848 } | 860 } |
849 | 861 |
862 class MockRendererSchedulerImpl : public RendererSchedulerImpl { | |
863 public: | |
864 MockRendererSchedulerImpl( | |
865 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner) | |
866 : RendererSchedulerImpl(main_task_runner), update_policy_count_(0) {} | |
867 | |
868 void UpdatePolicyLocked() override { | |
Sami
2015/03/11 16:58:25
The way we have to reach into the internals to tes
alex clarke (OOO till 29th)
2015/03/12 13:41:32
I think we should pick one style and stick to it.
| |
869 update_policy_count_++; | |
870 RendererSchedulerImpl::UpdatePolicyLocked(); | |
871 } | |
872 | |
873 int update_policy_count_; | |
874 }; | |
875 | |
876 TEST_F(RendererSchedulerImplTest, OnlyOnePendingNonDelayedUpdatePolicy) { | |
877 MockRendererSchedulerImpl* mock_scheduler = | |
878 new MockRendererSchedulerImpl(mock_task_runner_); | |
879 scheduler_.reset(mock_scheduler); | |
880 | |
881 ScheduleUrgentPolicyUpdate(); | |
882 ScheduleUrgentPolicyUpdate(); | |
883 ScheduleUrgentPolicyUpdate(); | |
884 ScheduleUrgentPolicyUpdate(); | |
885 | |
886 RunUntilIdle(); | |
887 | |
888 EXPECT_EQ(1, mock_scheduler->update_policy_count_); | |
889 } | |
890 | |
891 TEST_F(RendererSchedulerImplTest, UpdatePolicyCountTriggeredByOneInputEvent) { | |
892 MockRendererSchedulerImpl* mock_scheduler = | |
893 new MockRendererSchedulerImpl(mock_task_runner_); | |
894 scheduler_.reset(mock_scheduler); | |
895 scheduler_->SetTimeSourceForTesting(clock_); | |
896 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); | |
897 | |
898 scheduler_->DidReceiveInputEventOnCompositorThread( | |
899 FakeInputEvent(blink::WebInputEvent::TouchStart)); | |
900 | |
901 RunUntilIdle(); | |
902 | |
903 EXPECT_EQ(2, mock_scheduler->update_policy_count_); | |
Sami
2015/03/11 16:58:25
Could you add a comment saying which two updates t
alex clarke (OOO till 29th)
2015/03/12 13:41:32
Done.
| |
904 } | |
905 | |
906 TEST_F(RendererSchedulerImplTest, UpdatePolicyCountTriggeredByTwoInputEvents) { | |
907 MockRendererSchedulerImpl* mock_scheduler = | |
908 new MockRendererSchedulerImpl(mock_task_runner_); | |
909 scheduler_.reset(mock_scheduler); | |
910 scheduler_->SetTimeSourceForTesting(clock_); | |
911 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); | |
912 | |
913 scheduler_->DidReceiveInputEventOnCompositorThread( | |
914 FakeInputEvent(blink::WebInputEvent::TouchStart)); | |
915 scheduler_->DidReceiveInputEventOnCompositorThread( | |
916 FakeInputEvent(blink::WebInputEvent::TouchMove)); | |
917 | |
918 RunUntilIdle(); | |
919 | |
920 EXPECT_EQ(2, mock_scheduler->update_policy_count_); | |
921 } | |
922 | |
923 TEST_F(RendererSchedulerImplTest, EnsureUpdatePolicyNotTriggeredTooOften) { | |
924 MockRendererSchedulerImpl* mock_scheduler = | |
925 new MockRendererSchedulerImpl(mock_task_runner_); | |
926 scheduler_.reset(mock_scheduler); | |
927 scheduler_->SetTimeSourceForTesting(clock_); | |
928 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); | |
929 | |
930 scheduler_->DidReceiveInputEventOnCompositorThread( | |
931 FakeInputEvent(blink::WebInputEvent::TouchStart)); | |
932 scheduler_->DidReceiveInputEventOnCompositorThread( | |
933 FakeInputEvent(blink::WebInputEvent::TouchMove)); | |
934 | |
935 // We expect the first call to IsHighPriorityWorkAnticipated to be called | |
936 // after recieving an input event (but before the UpdateTask was processed) to | |
937 // call UpdatePolicy. | |
938 EXPECT_EQ(0, mock_scheduler->update_policy_count_); | |
939 scheduler_->IsHighPriorityWorkAnticipated(); | |
940 EXPECT_EQ(1, mock_scheduler->update_policy_count_); | |
941 // Subsequent calls should not call UpdateTask. | |
942 scheduler_->IsHighPriorityWorkAnticipated(); | |
943 scheduler_->IsHighPriorityWorkAnticipated(); | |
944 scheduler_->IsHighPriorityWorkAnticipated(); | |
945 scheduler_->ShouldYieldForHighPriorityWork(); | |
946 scheduler_->ShouldYieldForHighPriorityWork(); | |
947 scheduler_->ShouldYieldForHighPriorityWork(); | |
948 scheduler_->ShouldYieldForHighPriorityWork(); | |
949 | |
950 EXPECT_EQ(1, mock_scheduler->update_policy_count_); | |
951 | |
952 // There should be only two UpdatePolicy tasks posted. | |
953 RunUntilIdle(); | |
954 EXPECT_EQ(3, mock_scheduler->update_policy_count_); | |
955 } | |
956 | |
850 } // namespace content | 957 } // namespace content |
OLD | NEW |