Index: ui/display/chromeos/display_configurator_unittest.cc |
diff --git a/ui/display/chromeos/display_configurator_unittest.cc b/ui/display/chromeos/display_configurator_unittest.cc |
index ee3569aaf61ae29955398294308dd28d62cd6238..6c94b6f9120b39e484a526c375e981cea1ab8400 100644 |
--- a/ui/display/chromeos/display_configurator_unittest.cc |
+++ b/ui/display/chromeos/display_configurator_unittest.cc |
@@ -117,7 +117,9 @@ class DisplayConfiguratorTest : public testing::Test { |
: small_mode_(gfx::Size(1366, 768), false, 60.0f), |
big_mode_(gfx::Size(2560, 1600), false, 60.0f), |
observer_(&configurator_), |
- test_api_(&configurator_) {} |
+ test_api_(&configurator_), |
+ callback_status_(false), |
+ callback_called_(false) {} |
~DisplayConfiguratorTest() override {} |
void SetUp() override { |
@@ -153,6 +155,11 @@ class DisplayConfiguratorTest : public testing::Test { |
UpdateOutputs(2, false); |
} |
+ void OnConfiguredCallback(bool status) { |
+ callback_called_ = true; |
+ callback_status_ = status; |
+ } |
+ |
// Predefined modes that can be used by outputs. |
const DisplayMode small_mode_; |
const DisplayMode big_mode_; |
@@ -192,6 +199,14 @@ class DisplayConfiguratorTest : public testing::Test { |
log_->GetActionsAndClear()); |
} |
+ void CheckAndResetCallback(bool expected_status) { |
+ EXPECT_TRUE(callback_called_); |
+ EXPECT_EQ(expected_status, callback_status_); |
+ |
+ callback_status_ = false; |
+ callback_called_ = false; |
+ } |
+ |
base::MessageLoop message_loop_; |
TestStateController state_controller_; |
TestMirroringController mirroring_controller_; |
@@ -203,6 +218,9 @@ class DisplayConfiguratorTest : public testing::Test { |
TestDisplaySnapshot outputs_[2]; |
+ bool callback_status_; |
+ bool callback_called_; |
+ |
private: |
DISALLOW_COPY_AND_ASSIGN(DisplayConfiguratorTest); |
}; |
@@ -429,7 +447,10 @@ TEST_F(DisplayConfiguratorTest, SetDisplayPower) { |
observer_.Reset(); |
configurator_.SetDisplayPower( |
chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, |
- DisplayConfigurator::kSetDisplayPowerNoFlags); |
+ DisplayConfigurator::kSetDisplayPowerNoFlags, |
+ base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, |
+ base::Unretained(this))); |
+ CheckAndResetCallback(true); |
Daniel Erat
2015/01/30 17:14:07
CheckAndResetCallback() failures won't produce mea
dnicoara
2015/01/30 18:25:28
Done.
|
EXPECT_EQ( |
JoinActions( |
kGrab, |
@@ -447,8 +468,12 @@ TEST_F(DisplayConfiguratorTest, SetDisplayPower) { |
// When all displays are turned off, the framebuffer should switch back |
// to the mirrored size. |
observer_.Reset(); |
- configurator_.SetDisplayPower(chromeos::DISPLAY_POWER_ALL_OFF, |
- DisplayConfigurator::kSetDisplayPowerNoFlags); |
+ configurator_.SetDisplayPower( |
+ chromeos::DISPLAY_POWER_ALL_OFF, |
+ DisplayConfigurator::kSetDisplayPowerNoFlags, |
+ base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, |
+ base::Unretained(this))); |
+ CheckAndResetCallback(true); |
EXPECT_EQ( |
JoinActions(kGrab, |
GetFramebufferAction( |
@@ -464,8 +489,12 @@ TEST_F(DisplayConfiguratorTest, SetDisplayPower) { |
// Turn all displays on and check that mirroring is still used. |
observer_.Reset(); |
- configurator_.SetDisplayPower(chromeos::DISPLAY_POWER_ALL_ON, |
- DisplayConfigurator::kSetDisplayPowerNoFlags); |
+ configurator_.SetDisplayPower( |
+ chromeos::DISPLAY_POWER_ALL_ON, |
+ DisplayConfigurator::kSetDisplayPowerNoFlags, |
+ base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, |
+ base::Unretained(this))); |
+ CheckAndResetCallback(true); |
EXPECT_EQ( |
JoinActions( |
kGrab, |
@@ -515,7 +544,10 @@ TEST_F(DisplayConfiguratorTest, SetDisplayPower) { |
observer_.Reset(); |
configurator_.SetDisplayPower( |
chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, |
- DisplayConfigurator::kSetDisplayPowerNoFlags); |
+ DisplayConfigurator::kSetDisplayPowerNoFlags, |
+ base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, |
+ base::Unretained(this))); |
+ CheckAndResetCallback(true); |
EXPECT_EQ( |
JoinActions( |
kGrab, |
@@ -534,8 +566,12 @@ TEST_F(DisplayConfiguratorTest, SetDisplayPower) { |
// When all displays are turned off, the framebuffer should switch back |
// to the extended + software mirroring. |
observer_.Reset(); |
- configurator_.SetDisplayPower(chromeos::DISPLAY_POWER_ALL_OFF, |
- DisplayConfigurator::kSetDisplayPowerNoFlags); |
+ configurator_.SetDisplayPower( |
+ chromeos::DISPLAY_POWER_ALL_OFF, |
+ DisplayConfigurator::kSetDisplayPowerNoFlags, |
+ base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, |
+ base::Unretained(this))); |
+ CheckAndResetCallback(true); |
EXPECT_EQ( |
JoinActions( |
kGrab, |
@@ -559,8 +595,12 @@ TEST_F(DisplayConfiguratorTest, SetDisplayPower) { |
// Turn all displays on and check that mirroring is still used. |
observer_.Reset(); |
- configurator_.SetDisplayPower(chromeos::DISPLAY_POWER_ALL_ON, |
- DisplayConfigurator::kSetDisplayPowerNoFlags); |
+ configurator_.SetDisplayPower( |
+ chromeos::DISPLAY_POWER_ALL_ON, |
+ DisplayConfigurator::kSetDisplayPowerNoFlags, |
+ base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, |
+ base::Unretained(this))); |
+ CheckAndResetCallback(true); |
EXPECT_EQ( |
JoinActions( |
kGrab, |
@@ -606,8 +646,12 @@ TEST_F(DisplayConfiguratorTest, SuspendAndResume) { |
// Now turn the display off before suspending and check that the |
// configurator turns it back on and syncs with the server. |
- configurator_.SetDisplayPower(chromeos::DISPLAY_POWER_ALL_OFF, |
- DisplayConfigurator::kSetDisplayPowerNoFlags); |
+ configurator_.SetDisplayPower( |
+ chromeos::DISPLAY_POWER_ALL_OFF, |
+ DisplayConfigurator::kSetDisplayPowerNoFlags, |
+ base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, |
+ base::Unretained(this))); |
+ CheckAndResetCallback(true); |
EXPECT_EQ( |
JoinActions( |
kGrab, |
@@ -656,8 +700,12 @@ TEST_F(DisplayConfiguratorTest, SuspendAndResume) { |
NULL), |
log_->GetActionsAndClear()); |
- configurator_.SetDisplayPower(chromeos::DISPLAY_POWER_ALL_OFF, |
- DisplayConfigurator::kSetDisplayPowerNoFlags); |
+ configurator_.SetDisplayPower( |
+ chromeos::DISPLAY_POWER_ALL_OFF, |
+ DisplayConfigurator::kSetDisplayPowerNoFlags, |
+ base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, |
+ base::Unretained(this))); |
+ CheckAndResetCallback(true); |
EXPECT_EQ( |
JoinActions(kGrab, |
GetFramebufferAction( |
@@ -698,11 +746,19 @@ TEST_F(DisplayConfiguratorTest, Headless) { |
// Not much should happen when the display power state is changed while |
// no displays are connected. |
- configurator_.SetDisplayPower(chromeos::DISPLAY_POWER_ALL_OFF, |
- DisplayConfigurator::kSetDisplayPowerNoFlags); |
+ configurator_.SetDisplayPower( |
+ chromeos::DISPLAY_POWER_ALL_OFF, |
+ DisplayConfigurator::kSetDisplayPowerNoFlags, |
+ base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, |
+ base::Unretained(this))); |
+ CheckAndResetCallback(true); |
EXPECT_EQ(JoinActions(kGrab, kUngrab, NULL), log_->GetActionsAndClear()); |
- configurator_.SetDisplayPower(chromeos::DISPLAY_POWER_ALL_ON, |
- DisplayConfigurator::kSetDisplayPowerNoFlags); |
+ configurator_.SetDisplayPower( |
+ chromeos::DISPLAY_POWER_ALL_ON, |
+ DisplayConfigurator::kSetDisplayPowerNoFlags, |
+ base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, |
+ base::Unretained(this))); |
+ CheckAndResetCallback(true); |
EXPECT_EQ(JoinActions(kGrab, kForceDPMS, kUngrab, NULL), |
log_->GetActionsAndClear()); |
@@ -1071,7 +1127,10 @@ TEST_F(DisplayConfiguratorTest, SaveDisplayPowerStateOnConfigFailure) { |
// Turn off the internal display, simulating docked mode. |
configurator_.SetDisplayPower( |
chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, |
- DisplayConfigurator::kSetDisplayPowerNoFlags); |
+ DisplayConfigurator::kSetDisplayPowerNoFlags, |
+ base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, |
+ base::Unretained(this))); |
+ CheckAndResetCallback(true); |
EXPECT_EQ(1, observer_.num_changes()); |
EXPECT_EQ(0, observer_.num_failures()); |
log_->GetActionsAndClear(); |
@@ -1079,8 +1138,12 @@ TEST_F(DisplayConfiguratorTest, SaveDisplayPowerStateOnConfigFailure) { |
// Make all subsequent configuration requests fail and try to turn the |
// internal display back on. |
native_display_delegate_->set_max_configurable_pixels(1); |
- configurator_.SetDisplayPower(chromeos::DISPLAY_POWER_ALL_ON, |
- DisplayConfigurator::kSetDisplayPowerNoFlags); |
+ configurator_.SetDisplayPower( |
+ chromeos::DISPLAY_POWER_ALL_ON, |
+ DisplayConfigurator::kSetDisplayPowerNoFlags, |
+ base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, |
+ base::Unretained(this))); |
+ CheckAndResetCallback(false); |
EXPECT_EQ(1, observer_.num_changes()); |
EXPECT_EQ(1, observer_.num_failures()); |
log_->GetActionsAndClear(); |
@@ -1112,7 +1175,10 @@ TEST_F(DisplayConfiguratorTest, DontRestoreStalePowerStateAfterResume) { |
// Turn off the internal display, simulating docked mode. |
configurator_.SetDisplayPower( |
chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, |
- DisplayConfigurator::kSetDisplayPowerNoFlags); |
+ DisplayConfigurator::kSetDisplayPowerNoFlags, |
+ base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, |
+ base::Unretained(this))); |
+ CheckAndResetCallback(true); |
EXPECT_EQ(1, observer_.num_changes()); |
EXPECT_EQ(0, observer_.num_failures()); |
EXPECT_EQ( |
@@ -1133,8 +1199,12 @@ TEST_F(DisplayConfiguratorTest, DontRestoreStalePowerStateAfterResume) { |
configurator_.ResumeDisplays(); |
// Before the task runs, exit docked mode. |
- configurator_.SetDisplayPower(chromeos::DISPLAY_POWER_ALL_ON, |
- DisplayConfigurator::kSetDisplayPowerNoFlags); |
+ configurator_.SetDisplayPower( |
+ chromeos::DISPLAY_POWER_ALL_ON, |
+ DisplayConfigurator::kSetDisplayPowerNoFlags, |
+ base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, |
+ base::Unretained(this))); |
+ CheckAndResetCallback(true); |
EXPECT_EQ(2, observer_.num_changes()); |
EXPECT_EQ(0, observer_.num_failures()); |
EXPECT_EQ( |