Chromium Code Reviews| 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" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 using testing::_; | |
| 14 | |
| 13 namespace content { | 15 namespace content { |
| 14 | 16 |
| 15 namespace { | 17 namespace { |
| 16 class FakeInputEvent : public blink::WebInputEvent { | 18 class FakeInputEvent : public blink::WebInputEvent { |
| 17 public: | 19 public: |
| 18 explicit FakeInputEvent(blink::WebInputEvent::Type event_type) | 20 explicit FakeInputEvent(blink::WebInputEvent::Type event_type) |
| 19 : WebInputEvent(sizeof(FakeInputEvent)) { | 21 : WebInputEvent(sizeof(FakeInputEvent)) { |
| 20 type = event_type; | 22 type = event_type; |
| 21 } | 23 } |
| 22 | 24 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 idle_task_runner_->PostIdleTask( | 101 idle_task_runner_->PostIdleTask( |
| 100 FROM_HERE, | 102 FROM_HERE, |
| 101 base::Bind(&AppendToVectorIdleTestTask, run_order, task)); | 103 base::Bind(&AppendToVectorIdleTestTask, run_order, task)); |
| 102 break; | 104 break; |
| 103 default: | 105 default: |
| 104 NOTREACHED(); | 106 NOTREACHED(); |
| 105 } | 107 } |
| 106 } | 108 } |
| 107 } | 109 } |
| 108 | 110 |
| 111 void PostUpdatePolicyOnControlRunner(base::TimeDelta delay) { | |
| 112 base::AutoLock lock(scheduler_->incoming_signals_lock_); | |
| 113 scheduler_->PostUpdatePolicyOnControlRunnerLocked(delay); | |
| 114 } | |
| 115 | |
| 109 protected: | 116 protected: |
| 110 static base::TimeDelta priority_escalation_after_input_duration() { | 117 static base::TimeDelta priority_escalation_after_input_duration() { |
| 111 return base::TimeDelta::FromMilliseconds( | 118 return base::TimeDelta::FromMilliseconds( |
| 112 RendererSchedulerImpl::kPriorityEscalationAfterInputMillis); | 119 RendererSchedulerImpl::kPriorityEscalationAfterInputMillis); |
| 113 } | 120 } |
| 114 | 121 |
| 115 scoped_refptr<cc::TestNowSource> clock_; | 122 scoped_refptr<cc::TestNowSource> clock_; |
| 116 scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_; | 123 scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_; |
| 117 | 124 |
| 118 scoped_ptr<RendererSchedulerImpl> scheduler_; | 125 scoped_ptr<RendererSchedulerImpl> scheduler_; |
| (...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 840 RunUntilIdle(); | 847 RunUntilIdle(); |
| 841 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); | 848 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); |
| 842 | 849 |
| 843 // Process the input event with a new BeginMainFrame. | 850 // Process the input event with a new BeginMainFrame. |
| 844 DoMainFrame(); | 851 DoMainFrame(); |
| 845 clock_->AdvanceNow(2 * priority_escalation_after_input_duration()); | 852 clock_->AdvanceNow(2 * priority_escalation_after_input_duration()); |
| 846 RunUntilIdle(); | 853 RunUntilIdle(); |
| 847 EXPECT_EQ(Policy::NORMAL, CurrentPolicy()); | 854 EXPECT_EQ(Policy::NORMAL, CurrentPolicy()); |
| 848 } | 855 } |
| 849 | 856 |
| 857 class MockRendererSchedulerImpl : public RendererSchedulerImpl { | |
| 858 public: | |
| 859 MockRendererSchedulerImpl( | |
| 860 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner) | |
| 861 : RendererSchedulerImpl(main_task_runner), update_policy_count_(0) {} | |
| 862 | |
| 863 void UpdatePolicy(bool clear_pending_non_delayed_update_policy) override { | |
| 864 update_policy_count_++; | |
| 865 RendererSchedulerImpl::UpdatePolicy( | |
| 866 clear_pending_non_delayed_update_policy); | |
| 867 } | |
| 868 | |
| 869 int update_policy_count_; | |
| 870 }; | |
| 871 | |
| 872 TEST_F(RendererSchedulerImplTest, OnlyOnePendingNonDelayedUpdatePolicy) { | |
| 873 MockRendererSchedulerImpl* mock_scheduler = | |
| 874 new MockRendererSchedulerImpl(mock_task_runner_); | |
| 875 scheduler_.reset(mock_scheduler); | |
| 876 | |
| 877 PostUpdatePolicyOnControlRunner(base::TimeDelta()); | |
|
Sami
2015/03/10 16:19:38
Do we know what triggered the bug in the first pla
alex clarke (OOO till 29th)
2015/03/11 10:59:05
Anything that calls MaybeUpdatePolicy can potentia
| |
| 878 PostUpdatePolicyOnControlRunner(base::TimeDelta()); | |
| 879 PostUpdatePolicyOnControlRunner(base::TimeDelta()); | |
| 880 PostUpdatePolicyOnControlRunner(base::TimeDelta()); | |
| 881 | |
| 882 RunUntilIdle(); | |
| 883 | |
| 884 EXPECT_EQ(1, mock_scheduler->update_policy_count_); | |
| 885 } | |
| 886 | |
| 887 TEST_F(RendererSchedulerImplTest, OnlyOnePendingDelayedUpdatePolicy) { | |
| 888 MockRendererSchedulerImpl* mock_scheduler = | |
| 889 new MockRendererSchedulerImpl(mock_task_runner_); | |
| 890 scheduler_.reset(mock_scheduler); | |
| 891 scheduler_->SetTimeSourceForTesting(clock_); | |
| 892 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); | |
| 893 | |
| 894 PostUpdatePolicyOnControlRunner(base::TimeDelta::FromMilliseconds(1)); | |
| 895 PostUpdatePolicyOnControlRunner(base::TimeDelta::FromMilliseconds(10)); | |
| 896 PostUpdatePolicyOnControlRunner(base::TimeDelta::FromMilliseconds(100)); | |
| 897 PostUpdatePolicyOnControlRunner(base::TimeDelta::FromMilliseconds(1000)); | |
| 898 | |
| 899 RunUntilIdle(); | |
| 900 | |
| 901 EXPECT_EQ(1, mock_scheduler->update_policy_count_); | |
| 902 } | |
| 903 | |
| 904 TEST_F(RendererSchedulerImplTest, | |
| 905 OnePendingDelayedAndOneNonDelayedUpdatePolicy) { | |
| 906 MockRendererSchedulerImpl* mock_scheduler = | |
| 907 new MockRendererSchedulerImpl(mock_task_runner_); | |
| 908 scheduler_.reset(mock_scheduler); | |
| 909 scheduler_->SetTimeSourceForTesting(clock_); | |
| 910 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); | |
| 911 | |
| 912 PostUpdatePolicyOnControlRunner(base::TimeDelta()); | |
| 913 PostUpdatePolicyOnControlRunner(base::TimeDelta::FromMilliseconds(1)); | |
|
Sami
2015/03/10 16:19:38
Could you also try this the other way around to ma
alex clarke (OOO till 29th)
2015/03/11 10:59:05
It's now hard to test this directly. If you're ke
| |
| 914 | |
| 915 RunUntilIdle(); | |
| 916 | |
| 917 EXPECT_EQ(2, mock_scheduler->update_policy_count_); | |
| 918 } | |
| 919 | |
| 850 } // namespace content | 920 } // namespace content |
| OLD | NEW |