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

Unified Diff: cc/scheduler/scheduler_unittest.cc

Issue 554973002: Disable scheduler deadline task on battery power in Windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address code review nit Created 6 years, 3 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: cc/scheduler/scheduler_unittest.cc
diff --git a/cc/scheduler/scheduler_unittest.cc b/cc/scheduler/scheduler_unittest.cc
index 256acd5bd8f6a211637b8d72b24e295485d0db86..a93eb2a7cf0d946c13dc175c9016602609e49be5 100644
--- a/cc/scheduler/scheduler_unittest.cc
+++ b/cc/scheduler/scheduler_unittest.cc
@@ -10,6 +10,8 @@
#include "base/logging.h"
#include "base/memory/scoped_vector.h"
#include "base/message_loop/message_loop.h"
+#include "base/power_monitor/power_monitor.h"
+#include "base/power_monitor/power_monitor_source.h"
#include "base/run_loop.h"
#include "base/time/time.h"
#include "cc/test/begin_frame_args_test.h"
@@ -90,13 +92,17 @@ class FakeSchedulerClient : public SchedulerClient {
scheduler_->settings().throttle_frame_production;
if (external_begin_frame) {
- scheduler_->BeginFrame(CreateBeginFrameArgsForTesting(now_src_));
+ SendBeginFrame();
}
EXPECT_TRUE(task_runner().RunTasksWhile(ImplFrameDeadlinePending(false)));
EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
}
+ void SendBeginFrame() {
brianderson 2014/09/12 22:05:27 Can you call this AdvanceFrameSynchronousDeadline
sunnyps 2014/09/15 21:52:48 Done.
+ scheduler_->BeginFrame(CreateBeginFrameArgsForTesting(now_src_));
+ }
+
OrderedSimpleTaskRunner& task_runner() { return scheduler_->task_runner(); }
TestNowSource* now_src() { return now_src_.get(); }
@@ -1909,5 +1915,90 @@ TEST(SchedulerTest,
EXPECT_FALSE(scheduler->IsSyntheticBeginFrameSourceActive());
}
+class FakePowerMonitorSource : public base::PowerMonitorSource {
brianderson 2014/09/12 22:05:27 +bajones to make sure this FakePowerMonitorSource
sunnyps 2014/09/15 21:52:48 Done.
+ public:
+ FakePowerMonitorSource() {}
+ virtual ~FakePowerMonitorSource() {}
+ void GeneratePowerStateEvent(bool on_battery_power) {
+ on_battery_power_impl_ = on_battery_power;
+ ProcessPowerEvent(POWER_STATE_EVENT);
+ base::MessageLoop::current()->RunUntilIdle();
+ }
+ virtual bool IsOnBatteryPowerImpl() OVERRIDE {
+ return on_battery_power_impl_;
+ }
+
+ private:
+ bool on_battery_power_impl_;
+};
+
+TEST(SchedulerTest, HighLatencyModeOnBattery) {
brianderson 2014/09/12 22:05:27 This test looks good, however please create a vers
sunnyps 2014/09/15 21:52:48 I thought we decided to remove that test because r
+ // Create the power monitor before creating the scheduler
+ FakePowerMonitorSource* power_monitor_source = new FakePowerMonitorSource;
+ base::PowerMonitor power_monitor(
+ (scoped_ptr<base::PowerMonitorSource>(power_monitor_source)));
+
+ FakeSchedulerClient client;
+ SchedulerSettings settings;
+ settings.high_latency_mode_on_battery = true;
+ TestScheduler* scheduler = client.CreateScheduler(settings);
+
+ scheduler->SetCanStart();
+ scheduler->SetVisible(true);
+ scheduler->SetCanDraw(true);
+
+ EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client);
+ InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
+
+ // On non-battery power
+ EXPECT_FALSE(power_monitor.IsOnBatteryPower());
+
+ client.Reset();
+ scheduler->SetNeedsCommit();
+ EXPECT_TRUE(client.needs_begin_frame());
+ EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client);
+ client.Reset();
+
+ client.SendBeginFrame();
+ EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
+ // The scheduler schedules a BeginMainFrame because it NeedsCommit
+ EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2);
+ // The scheduler waits for the renderer
+ EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
+ client.Reset();
+
+ client.task_runner().RunPendingTasks(); // Run posted deadline.
+ EXPECT_NO_ACTION(client);
+ EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
+ EXPECT_TRUE(client.needs_begin_frame());
+ client.Reset();
+
+ // Switch to battery power
+ power_monitor_source->GeneratePowerStateEvent(true);
+ EXPECT_TRUE(power_monitor.IsOnBatteryPower());
+
+ client.SendBeginFrame();
+ EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
+ // The scheduler does not post a deadline task, neither does it schedule
+ // another BeginMainFrame because it's still waiting for the last one
+ EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
+ client.Reset();
+
+ // Do nothing until the next BeginFrame is called
+ EXPECT_NO_ACTION(client);
+ EXPECT_TRUE(client.needs_begin_frame());
+ client.Reset();
+
+ // Switch to non-battery power
+ power_monitor_source->GeneratePowerStateEvent(false);
+ EXPECT_FALSE(power_monitor.IsOnBatteryPower());
+
+ client.SendBeginFrame();
+ EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
+ // The scheduler waits for the renderer
+ EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
+ client.Reset();
+}
+
} // namespace
} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698