Chromium Code Reviews| Index: cc/scheduler/scheduler_unittest.cc |
| diff --git a/cc/scheduler/scheduler_unittest.cc b/cc/scheduler/scheduler_unittest.cc |
| index c04518320b0016d810846a16a3f0395f8d8b2a97..6a429f7132ab803f31f1427d3c1184a3be11325e 100644 |
| --- a/cc/scheduler/scheduler_unittest.cc |
| +++ b/cc/scheduler/scheduler_unittest.cc |
| @@ -8,6 +8,7 @@ |
| #include "base/logging.h" |
| #include "base/memory/scoped_vector.h" |
| +#include "base/time/time.h" |
| #include "cc/test/scheduler_test_common.h" |
| #include "testing/gmock/include/gmock/gmock.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| @@ -1080,5 +1081,85 @@ TEST(SchedulerTest, ManageTiles) { |
| EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
| } |
| +class SchedulerClientWithFixedEstimates : public FakeSchedulerClient { |
| + public: |
| + SchedulerClientWithFixedEstimates( |
| + base::TimeDelta draw_duration, |
| + base::TimeDelta begin_main_frame_to_commit_duration, |
| + base::TimeDelta commit_to_activate_duration) |
| + : draw_duration_(draw_duration), |
| + begin_main_frame_to_commit_duration_( |
| + begin_main_frame_to_commit_duration), |
| + commit_to_activate_duration_(commit_to_activate_duration) {} |
| + |
| + virtual base::TimeDelta DrawDurationEstimate() OVERRIDE { |
| + return draw_duration_; |
| + } |
| + virtual base::TimeDelta BeginMainFrameToCommitDurationEstimate() OVERRIDE { |
| + return begin_main_frame_to_commit_duration_; |
| + } |
| + virtual base::TimeDelta CommitToActivateDurationEstimate() OVERRIDE { |
| + return commit_to_activate_duration_; |
| + } |
| + |
| + private: |
| + base::TimeDelta draw_duration_; |
| + base::TimeDelta begin_main_frame_to_commit_duration_; |
| + base::TimeDelta commit_to_activate_duration_; |
| +}; |
| + |
| +void MainFrameInHighLatencyMode(int64 begin_main_frame_to_commit_estimate_in_ms, |
| + int64 commit_to_activate_estimate_in_ms, |
| + bool should_send_begin_main_frame) { |
| + // Set up client with specified estimates (draw duration is set to 1). |
| + SchedulerClientWithFixedEstimates client( |
| + base::TimeDelta::FromMilliseconds(1), |
| + base::TimeDelta::FromMilliseconds( |
| + begin_main_frame_to_commit_estimate_in_ms), |
| + base::TimeDelta::FromMilliseconds(commit_to_activate_estimate_in_ms)); |
| + SchedulerSettings scheduler_settings; |
| + scheduler_settings.deadline_scheduling_enabled = true; |
| + scheduler_settings.switch_to_low_latency_if_possible = true; |
| + Scheduler* scheduler = client.CreateScheduler(scheduler_settings); |
| + scheduler->SetCanStart(); |
| + scheduler->SetVisible(true); |
| + scheduler->SetCanDraw(true); |
| + InitializeOutputSurfaceAndFirstCommit(scheduler); |
| + |
| + // Impl thread hits deadline before commit finishes. |
| + client.Reset(); |
| + scheduler->SetNeedsCommit(); |
|
brianderson
2013/11/06 02:38:07
Before you land this, can you check the expected v
|
| + scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| + scheduler->OnBeginImplFrameDeadline(); |
| + scheduler->FinishCommit(); |
| + EXPECT_TRUE(client.HasAction("ScheduledActionSendBeginMainFrame")); |
| + |
| + client.Reset(); |
| + scheduler->SetNeedsCommit(); |
| + scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| + scheduler->OnBeginImplFrameDeadline(); |
| + EXPECT_EQ(client.HasAction("ScheduledActionSendBeginMainFrame"), |
| + should_send_begin_main_frame); |
| +} |
| + |
| +TEST(SchedulerTest, |
| + SkipMainFrameIfHighLatencyAndCanCommitAndActivateBeforeDeadline) { |
| + // Set up client so that estimates indicate that we can commit and activate |
| + // before the deadline (~8ms by default). |
| + MainFrameInHighLatencyMode(1, 1, false); |
| +} |
| + |
| +TEST(SchedulerTest, NotSkipMainFrameIfHighLatencyAndCanCommitTooLong) { |
| + // Set up client so that estimates indicate that the commit cannot finish |
| + // before the deadline (~8ms by default). |
| + MainFrameInHighLatencyMode(10, 1, true); |
| +} |
| + |
| +TEST(SchedulerTest, NotSkipMainFrameIfHighLatencyAndCanActivateTooLong) { |
| + // Set up client so that estimates indicate that the activate cannot finish |
| + // before the deadline (~8ms by default). |
| + MainFrameInHighLatencyMode(1, 10, true); |
| +} |
| + |
| } // namespace |
| } // namespace cc |