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 "ui/display/chromeos/display_configurator.h" | 5 #include "ui/display/chromeos/display_configurator.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/callback_helpers.h" | |
| 10 #include "base/macros.h" | 11 #include "base/macros.h" |
| 11 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 12 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
| 13 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 14 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "ui/display/chromeos/test/action_logger_util.h" | 17 #include "ui/display/chromeos/test/action_logger_util.h" |
| 17 #include "ui/display/chromeos/test/test_display_snapshot.h" | 18 #include "ui/display/chromeos/test/test_display_snapshot.h" |
| 18 #include "ui/display/chromeos/test/test_native_display_delegate.h" | 19 #include "ui/display/chromeos/test/test_native_display_delegate.h" |
| 19 #include "ui/display/util/display_util.h" | 20 #include "ui/display/util/display_util.h" |
| 20 | 21 |
| 21 namespace ui { | 22 namespace ui { |
| 22 namespace test { | 23 namespace test { |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| 27 enum CallbackResult { | |
| 28 CALLBACK_FAILURE, | |
| 29 CALLBACK_SUCCESS, | |
| 30 CALLBACK_NOT_CALLED, | |
| 31 }; | |
| 32 | |
| 26 class TestObserver : public DisplayConfigurator::Observer { | 33 class TestObserver : public DisplayConfigurator::Observer { |
| 27 public: | 34 public: |
| 28 explicit TestObserver(DisplayConfigurator* configurator) | 35 explicit TestObserver(DisplayConfigurator* configurator) |
| 29 : configurator_(configurator) { | 36 : configurator_(configurator) { |
| 30 Reset(); | 37 Reset(); |
| 31 configurator_->AddObserver(this); | 38 configurator_->AddObserver(this); |
| 32 } | 39 } |
| 33 ~TestObserver() override { configurator_->RemoveObserver(this); } | 40 ~TestObserver() override { configurator_->RemoveObserver(this); } |
| 34 | 41 |
| 35 int num_changes() const { return num_changes_; } | 42 int num_changes() const { return num_changes_; } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 bool SoftwareMirroringEnabled() const override { | 119 bool SoftwareMirroringEnabled() const override { |
| 113 return software_mirroring_enabled_; | 120 return software_mirroring_enabled_; |
| 114 } | 121 } |
| 115 | 122 |
| 116 private: | 123 private: |
| 117 bool software_mirroring_enabled_; | 124 bool software_mirroring_enabled_; |
| 118 | 125 |
| 119 DISALLOW_COPY_AND_ASSIGN(TestMirroringController); | 126 DISALLOW_COPY_AND_ASSIGN(TestMirroringController); |
| 120 }; | 127 }; |
| 121 | 128 |
| 129 // Abstracts waiting for the display configuration to be completed and getting | |
| 130 // the time it took to complete. | |
| 131 class ConfigurationWaiter { | |
| 132 public: | |
| 133 using OnConfigurationCallback = base::Callback<void(bool)>; | |
| 134 | |
| 135 ConfigurationWaiter() | |
| 136 : on_configured_callback_(base::Bind(&ConfigurationWaiter::OnConfigured, | |
| 137 base::Unretained(this))), | |
| 138 start_(base::TimeTicks::Now()), | |
| 139 end_(base::TimeTicks::Max()), | |
| 140 callback_result_(CALLBACK_NOT_CALLED), | |
| 141 pending_configuration_(true) { | |
| 142 } | |
| 143 | |
| 144 ~ConfigurationWaiter() = default; | |
| 145 | |
| 146 void Reset() { | |
| 147 start_ = base::TimeTicks::Now(); | |
| 148 end_ = base::TimeTicks::Max(); | |
| 149 callback_result_ = CALLBACK_NOT_CALLED; | |
| 150 pending_configuration_ = true; | |
| 151 } | |
| 152 | |
| 153 base::TimeDelta Wait() { | |
|
Daniel Erat
2016/10/21 21:09:45
add WARN_UNUSED_RESULT to make sure callers check
afakhry
2016/10/22 00:28:48
Done.
| |
| 154 if (pending_configuration_) { | |
| 155 base::RunLoop run_loop; | |
| 156 quit_closure_ = run_loop.QuitClosure(); | |
| 157 run_loop.Run(); | |
| 158 } | |
| 159 | |
| 160 return end_ - start_; | |
| 161 } | |
| 162 | |
| 163 const DisplayConfigurator::ConfigurationCallback& | |
| 164 on_configuration_callback() const { | |
| 165 return on_configured_callback_; | |
| 166 } | |
| 167 | |
| 168 CallbackResult callback_result() const { return callback_result_; } | |
| 169 | |
| 170 private: | |
| 171 void OnConfigured(bool status) { | |
| 172 callback_result_ = status ? CALLBACK_SUCCESS : CALLBACK_FAILURE; | |
| 173 | |
| 174 pending_configuration_ = false; | |
| 175 end_ = base::TimeTicks::Now(); | |
| 176 | |
| 177 if (!quit_closure_.is_null()) | |
| 178 base::ResetAndReturn(&quit_closure_).Run(); | |
| 179 } | |
| 180 | |
| 181 const DisplayConfigurator::ConfigurationCallback on_configured_callback_; | |
| 182 | |
| 183 base::TimeTicks start_; | |
|
Daniel Erat
2016/10/21 21:09:45
please add comments describing what all of these m
afakhry
2016/10/22 00:28:48
Done.
| |
| 184 base::TimeTicks end_; | |
| 185 base::Closure quit_closure_; | |
| 186 | |
| 187 CallbackResult callback_result_; | |
| 188 | |
| 189 bool pending_configuration_; | |
| 190 | |
| 191 DISALLOW_COPY_AND_ASSIGN(ConfigurationWaiter); | |
| 192 }; | |
| 193 | |
| 194 } // namespace | |
| 195 | |
| 122 class DisplayConfiguratorTest : public testing::Test { | 196 class DisplayConfiguratorTest : public testing::Test { |
| 123 public: | 197 public: |
| 124 enum CallbackResult { | |
| 125 CALLBACK_FAILURE, | |
| 126 CALLBACK_SUCCESS, | |
| 127 CALLBACK_NOT_CALLED, | |
| 128 }; | |
| 129 | |
| 130 DisplayConfiguratorTest() | 198 DisplayConfiguratorTest() |
| 131 : small_mode_(gfx::Size(1366, 768), false, 60.0f), | 199 : small_mode_(gfx::Size(1366, 768), false, 60.0f), |
| 132 big_mode_(gfx::Size(2560, 1600), false, 60.0f), | 200 big_mode_(gfx::Size(2560, 1600), false, 60.0f), |
| 133 observer_(&configurator_), | 201 observer_(&configurator_), |
| 134 test_api_(&configurator_), | 202 test_api_(&configurator_), |
| 135 enable_content_protection_status_(0), | 203 enable_content_protection_status_(0), |
| 136 enable_content_protection_call_count_(0), | 204 enable_content_protection_call_count_(0), |
| 137 query_content_protection_call_count_(0), | 205 query_content_protection_call_count_(0), |
| 138 callback_result_(CALLBACK_NOT_CALLED), | |
| 139 display_control_result_(CALLBACK_NOT_CALLED) {} | 206 display_control_result_(CALLBACK_NOT_CALLED) {} |
| 140 ~DisplayConfiguratorTest() override {} | 207 ~DisplayConfiguratorTest() override {} |
| 141 | 208 |
| 142 void SetUp() override { | 209 void SetUp() override { |
| 143 log_.reset(new ActionLogger()); | 210 log_.reset(new ActionLogger()); |
| 144 | 211 |
| 145 native_display_delegate_ = new TestNativeDisplayDelegate(log_.get()); | 212 native_display_delegate_ = new TestNativeDisplayDelegate(log_.get()); |
| 146 configurator_.SetDelegateForTesting( | 213 configurator_.SetDelegateForTesting( |
| 147 std::unique_ptr<NativeDisplayDelegate>(native_display_delegate_)); | 214 std::unique_ptr<NativeDisplayDelegate>(native_display_delegate_)); |
| 148 | 215 |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 177 o->set_current_mode(modes.back().get()); | 244 o->set_current_mode(modes.back().get()); |
| 178 o->set_native_mode(modes.back().get()); | 245 o->set_native_mode(modes.back().get()); |
| 179 o->set_modes(std::move(modes)); | 246 o->set_modes(std::move(modes)); |
| 180 o->set_type(DISPLAY_CONNECTION_TYPE_HDMI); | 247 o->set_type(DISPLAY_CONNECTION_TYPE_HDMI); |
| 181 o->set_is_aspect_preserving_scaling(true); | 248 o->set_is_aspect_preserving_scaling(true); |
| 182 o->set_display_id(789); | 249 o->set_display_id(789); |
| 183 | 250 |
| 184 UpdateOutputs(2, false); | 251 UpdateOutputs(2, false); |
| 185 } | 252 } |
| 186 | 253 |
| 187 void OnConfiguredCallback(bool status) { | |
| 188 callback_result_ = (status ? CALLBACK_SUCCESS : CALLBACK_FAILURE); | |
| 189 } | |
| 190 | |
| 191 void OnDisplayControlUpdated(bool status) { | 254 void OnDisplayControlUpdated(bool status) { |
| 192 display_control_result_ = (status ? CALLBACK_SUCCESS : CALLBACK_FAILURE); | 255 display_control_result_ = (status ? CALLBACK_SUCCESS : CALLBACK_FAILURE); |
| 193 } | 256 } |
| 194 | 257 |
| 195 void EnableContentProtectionCallback(bool status) { | 258 void EnableContentProtectionCallback(bool status) { |
| 196 enable_content_protection_status_ = status; | 259 enable_content_protection_status_ = status; |
| 197 enable_content_protection_call_count_++; | 260 enable_content_protection_call_count_++; |
| 198 } | 261 } |
| 199 | 262 |
| 200 void QueryContentProtectionCallback( | 263 void QueryContentProtectionCallback( |
| 201 const DisplayConfigurator::QueryProtectionResponse& response) { | 264 const DisplayConfigurator::QueryProtectionResponse& response) { |
| 202 query_content_protection_response_ = response; | 265 query_content_protection_response_ = response; |
| 203 query_content_protection_call_count_++; | 266 query_content_protection_call_count_++; |
| 204 } | 267 } |
| 205 | 268 |
| 206 // Predefined modes that can be used by outputs. | 269 // Predefined modes that can be used by outputs. |
| 207 const DisplayMode small_mode_; | 270 const DisplayMode small_mode_; |
| 208 const DisplayMode big_mode_; | 271 const DisplayMode big_mode_; |
| 209 | 272 |
| 210 protected: | 273 protected: |
| 274 // The delay less than which we expect the configuration to be finished. | |
| 275 static const int kMaxShortDelayMs = | |
|
Daniel Erat
2016/10/21 21:09:45
make both of these be base::TimeDeltas (possibly n
afakhry
2016/10/22 00:28:48
Great suggestion. Actually, they can even be const
| |
| 276 DisplayConfigurator::kConfigureDelayMs / 3; | |
| 277 | |
| 278 // The minimum configuration delay we expect when resuming while in 2+ display | |
| 279 // mode. | |
| 280 static const int kMinLongDelayMs = | |
| 281 DisplayConfigurator::kResumeConfigureMultiDisplayDelayMs; | |
| 282 | |
| 211 // Configures |native_display_delegate_| to return the first |num_outputs| | 283 // Configures |native_display_delegate_| to return the first |num_outputs| |
| 212 // entries from | 284 // entries from |
| 213 // |outputs_|. If |send_events| is true, also sends screen-change and | 285 // |outputs_|. If |send_events| is true, also sends screen-change and |
| 214 // output-change events to |configurator_| and triggers the configure | 286 // output-change events to |configurator_| and triggers the configure |
| 215 // timeout if one was scheduled. | 287 // timeout if one was scheduled. |
| 216 void UpdateOutputs(size_t num_outputs, bool send_events) { | 288 void UpdateOutputs(size_t num_outputs, bool send_events) { |
| 217 ASSERT_LE(num_outputs, arraysize(outputs_)); | 289 ASSERT_LE(num_outputs, arraysize(outputs_)); |
| 218 std::vector<DisplaySnapshot*> outputs; | 290 std::vector<DisplaySnapshot*> outputs; |
| 219 for (size_t i = 0; i < num_outputs; ++i) | 291 for (size_t i = 0; i < num_outputs; ++i) |
| 220 outputs.push_back(&outputs_[i]); | 292 outputs.push_back(&outputs_[i]); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 240 configurator_.ForceInitialConfigure(0); | 312 configurator_.ForceInitialConfigure(0); |
| 241 EXPECT_EQ(JoinActions(kInitXRandR, kGrab, | 313 EXPECT_EQ(JoinActions(kInitXRandR, kGrab, |
| 242 GetFramebufferAction(small_mode_.size(), &outputs_[0], | 314 GetFramebufferAction(small_mode_.size(), &outputs_[0], |
| 243 NULL).c_str(), | 315 NULL).c_str(), |
| 244 GetCrtcAction(outputs_[0], &small_mode_, | 316 GetCrtcAction(outputs_[0], &small_mode_, |
| 245 gfx::Point(0, 0)).c_str(), | 317 gfx::Point(0, 0)).c_str(), |
| 246 kForceDPMS, kUngrab, NULL), | 318 kForceDPMS, kUngrab, NULL), |
| 247 log_->GetActionsAndClear()); | 319 log_->GetActionsAndClear()); |
| 248 } | 320 } |
| 249 | 321 |
| 250 CallbackResult PopCallbackResult() { | 322 void ResumeDisplays( |
| 251 CallbackResult result = callback_result_; | 323 const DisplayConfigurator::ConfigurationCallback& callback) { |
| 252 callback_result_ = CALLBACK_NOT_CALLED; | 324 configurator_.ResumeDisplaysInternal(callback); |
| 253 return result; | |
| 254 } | 325 } |
| 255 | 326 |
| 256 CallbackResult PopDisplayControlResult() { | 327 CallbackResult PopDisplayControlResult() { |
| 257 CallbackResult result = display_control_result_; | 328 CallbackResult result = display_control_result_; |
| 258 display_control_result_ = CALLBACK_NOT_CALLED; | 329 display_control_result_ = CALLBACK_NOT_CALLED; |
| 259 return result; | 330 return result; |
| 260 } | 331 } |
| 261 | 332 |
| 262 base::MessageLoop message_loop_; | 333 base::MessageLoop message_loop_; |
| 263 TestStateController state_controller_; | 334 TestStateController state_controller_; |
| 264 TestMirroringController mirroring_controller_; | 335 TestMirroringController mirroring_controller_; |
| 265 DisplayConfigurator configurator_; | 336 DisplayConfigurator configurator_; |
| 266 TestObserver observer_; | 337 TestObserver observer_; |
| 267 std::unique_ptr<ActionLogger> log_; | 338 std::unique_ptr<ActionLogger> log_; |
| 268 TestNativeDisplayDelegate* native_display_delegate_; // not owned | 339 TestNativeDisplayDelegate* native_display_delegate_; // not owned |
| 269 DisplayConfigurator::TestApi test_api_; | 340 DisplayConfigurator::TestApi test_api_; |
| 270 | 341 |
| 271 bool enable_content_protection_status_; | 342 bool enable_content_protection_status_; |
| 272 int enable_content_protection_call_count_; | 343 int enable_content_protection_call_count_; |
| 273 DisplayConfigurator::QueryProtectionResponse | 344 DisplayConfigurator::QueryProtectionResponse |
| 274 query_content_protection_response_; | 345 query_content_protection_response_; |
| 275 int query_content_protection_call_count_; | 346 int query_content_protection_call_count_; |
| 276 | 347 |
| 277 TestDisplaySnapshot outputs_[3]; | 348 TestDisplaySnapshot outputs_[3]; |
| 278 | 349 |
| 279 CallbackResult callback_result_; | |
| 280 CallbackResult display_control_result_; | 350 CallbackResult display_control_result_; |
| 281 | 351 |
| 282 private: | 352 private: |
| 283 DISALLOW_COPY_AND_ASSIGN(DisplayConfiguratorTest); | 353 DISALLOW_COPY_AND_ASSIGN(DisplayConfiguratorTest); |
| 284 }; | 354 }; |
| 285 | 355 |
| 286 } // namespace | |
| 287 | |
| 288 TEST_F(DisplayConfiguratorTest, FindDisplayModeMatchingSize) { | 356 TEST_F(DisplayConfiguratorTest, FindDisplayModeMatchingSize) { |
| 289 std::vector<const DisplayMode*> modes; | 357 std::vector<const DisplayMode*> modes; |
| 290 | 358 |
| 291 // Fields are width, height, interlaced, refresh rate. | 359 // Fields are width, height, interlaced, refresh rate. |
| 292 modes.push_back(new DisplayMode(gfx::Size(1920, 1200), false, 60.0)); | 360 modes.push_back(new DisplayMode(gfx::Size(1920, 1200), false, 60.0)); |
| 293 DisplayMode* native_mode = | 361 DisplayMode* native_mode = |
| 294 new DisplayMode(gfx::Size(1920, 1200), false, 50.0); | 362 new DisplayMode(gfx::Size(1920, 1200), false, 50.0); |
| 295 modes.push_back(native_mode); | 363 modes.push_back(native_mode); |
| 296 // Different rates. | 364 // Different rates. |
| 297 modes.push_back(new DisplayMode(gfx::Size(1920, 1080), false, 30.0)); | 365 modes.push_back(new DisplayMode(gfx::Size(1920, 1080), false, 30.0)); |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 662 GetCrtcAction(outputs_[1], &small_mode_, gfx::Point(0, 0)).c_str(), | 730 GetCrtcAction(outputs_[1], &small_mode_, gfx::Point(0, 0)).c_str(), |
| 663 kUngrab, | 731 kUngrab, |
| 664 NULL), | 732 NULL), |
| 665 log_->GetActionsAndClear()); | 733 log_->GetActionsAndClear()); |
| 666 EXPECT_FALSE(mirroring_controller_.SoftwareMirroringEnabled()); | 734 EXPECT_FALSE(mirroring_controller_.SoftwareMirroringEnabled()); |
| 667 EXPECT_EQ(1, observer_.num_changes()); | 735 EXPECT_EQ(1, observer_.num_changes()); |
| 668 | 736 |
| 669 // Turning off the internal display should switch the external display to | 737 // Turning off the internal display should switch the external display to |
| 670 // its native mode. | 738 // its native mode. |
| 671 observer_.Reset(); | 739 observer_.Reset(); |
| 740 ConfigurationWaiter config_waiter; | |
| 672 configurator_.SetDisplayPower( | 741 configurator_.SetDisplayPower( |
| 673 chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, | 742 chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, |
| 674 DisplayConfigurator::kSetDisplayPowerNoFlags, | 743 DisplayConfigurator::kSetDisplayPowerNoFlags, |
| 675 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, | 744 config_waiter.on_configuration_callback()); |
| 676 base::Unretained(this))); | 745 base::TimeDelta delay = config_waiter.Wait(); |
| 677 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); | 746 EXPECT_LT(delay, base::TimeDelta::FromMilliseconds(kMaxShortDelayMs)); |
|
Daniel Erat
2016/10/21 21:09:45
how about inlining all of these?
EXPECT_LT(config
afakhry
2016/10/22 00:28:48
Done.
| |
| 747 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter.callback_result()); | |
| 678 EXPECT_EQ( | 748 EXPECT_EQ( |
| 679 JoinActions( | 749 JoinActions( |
| 680 kGrab, | 750 kGrab, |
| 681 GetFramebufferAction(big_mode_.size(), &outputs_[0], &outputs_[1]) | 751 GetFramebufferAction(big_mode_.size(), &outputs_[0], &outputs_[1]) |
| 682 .c_str(), | 752 .c_str(), |
| 683 GetCrtcAction(outputs_[0], NULL, gfx::Point(0, 0)).c_str(), | 753 GetCrtcAction(outputs_[0], NULL, gfx::Point(0, 0)).c_str(), |
| 684 GetCrtcAction(outputs_[1], &big_mode_, gfx::Point(0, 0)).c_str(), | 754 GetCrtcAction(outputs_[1], &big_mode_, gfx::Point(0, 0)).c_str(), |
| 685 kForceDPMS, | 755 kForceDPMS, |
| 686 kUngrab, | 756 kUngrab, |
| 687 NULL), | 757 NULL), |
| 688 log_->GetActionsAndClear()); | 758 log_->GetActionsAndClear()); |
| 689 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_SINGLE, configurator_.display_state()); | 759 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_SINGLE, configurator_.display_state()); |
| 690 EXPECT_EQ(1, observer_.num_changes()); | 760 EXPECT_EQ(1, observer_.num_changes()); |
| 691 | 761 |
| 692 // When all displays are turned off, the framebuffer should switch back | 762 // When all displays are turned off, the framebuffer should switch back |
| 693 // to the mirrored size. | 763 // to the mirrored size. |
| 694 observer_.Reset(); | 764 observer_.Reset(); |
| 765 config_waiter.Reset(); | |
| 695 configurator_.SetDisplayPower( | 766 configurator_.SetDisplayPower( |
| 696 chromeos::DISPLAY_POWER_ALL_OFF, | 767 chromeos::DISPLAY_POWER_ALL_OFF, |
| 697 DisplayConfigurator::kSetDisplayPowerNoFlags, | 768 DisplayConfigurator::kSetDisplayPowerNoFlags, |
| 698 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, | 769 config_waiter.on_configuration_callback()); |
| 699 base::Unretained(this))); | 770 delay = config_waiter.Wait(); |
| 700 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); | 771 EXPECT_LT(delay, base::TimeDelta::FromMilliseconds(kMaxShortDelayMs)); |
| 772 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter.callback_result()); | |
| 701 EXPECT_EQ( | 773 EXPECT_EQ( |
| 702 JoinActions(kGrab, | 774 JoinActions(kGrab, |
| 703 GetFramebufferAction( | 775 GetFramebufferAction( |
| 704 small_mode_.size(), &outputs_[0], &outputs_[1]).c_str(), | 776 small_mode_.size(), &outputs_[0], &outputs_[1]).c_str(), |
| 705 GetCrtcAction(outputs_[0], NULL, gfx::Point(0, 0)).c_str(), | 777 GetCrtcAction(outputs_[0], NULL, gfx::Point(0, 0)).c_str(), |
| 706 GetCrtcAction(outputs_[1], NULL, gfx::Point(0, 0)).c_str(), | 778 GetCrtcAction(outputs_[1], NULL, gfx::Point(0, 0)).c_str(), |
| 707 kUngrab, | 779 kUngrab, |
| 708 NULL), | 780 NULL), |
| 709 log_->GetActionsAndClear()); | 781 log_->GetActionsAndClear()); |
| 710 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_MIRROR, configurator_.display_state()); | 782 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_MIRROR, configurator_.display_state()); |
| 711 EXPECT_FALSE(mirroring_controller_.SoftwareMirroringEnabled()); | 783 EXPECT_FALSE(mirroring_controller_.SoftwareMirroringEnabled()); |
| 712 EXPECT_EQ(1, observer_.num_changes()); | 784 EXPECT_EQ(1, observer_.num_changes()); |
| 713 | 785 |
| 714 // Turn all displays on and check that mirroring is still used. | 786 // Turn all displays on and check that mirroring is still used. |
| 715 observer_.Reset(); | 787 observer_.Reset(); |
| 788 config_waiter.Reset(); | |
| 716 configurator_.SetDisplayPower( | 789 configurator_.SetDisplayPower( |
| 717 chromeos::DISPLAY_POWER_ALL_ON, | 790 chromeos::DISPLAY_POWER_ALL_ON, |
| 718 DisplayConfigurator::kSetDisplayPowerNoFlags, | 791 DisplayConfigurator::kSetDisplayPowerNoFlags, |
| 719 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, | 792 config_waiter.on_configuration_callback()); |
| 720 base::Unretained(this))); | 793 delay = config_waiter.Wait(); |
| 721 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); | 794 EXPECT_LT(delay, base::TimeDelta::FromMilliseconds(kMaxShortDelayMs)); |
| 795 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter.callback_result()); | |
| 722 EXPECT_EQ( | 796 EXPECT_EQ( |
| 723 JoinActions( | 797 JoinActions( |
| 724 kGrab, | 798 kGrab, |
| 725 GetFramebufferAction(small_mode_.size(), &outputs_[0], &outputs_[1]) | 799 GetFramebufferAction(small_mode_.size(), &outputs_[0], &outputs_[1]) |
| 726 .c_str(), | 800 .c_str(), |
| 727 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), | 801 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), |
| 728 GetCrtcAction(outputs_[1], &small_mode_, gfx::Point(0, 0)).c_str(), | 802 GetCrtcAction(outputs_[1], &small_mode_, gfx::Point(0, 0)).c_str(), |
| 729 kForceDPMS, | 803 kForceDPMS, |
| 730 kUngrab, | 804 kUngrab, |
| 731 NULL), | 805 NULL), |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 763 NULL), | 837 NULL), |
| 764 log_->GetActionsAndClear()); | 838 log_->GetActionsAndClear()); |
| 765 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED, | 839 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED, |
| 766 configurator_.display_state()); | 840 configurator_.display_state()); |
| 767 EXPECT_TRUE(mirroring_controller_.SoftwareMirroringEnabled()); | 841 EXPECT_TRUE(mirroring_controller_.SoftwareMirroringEnabled()); |
| 768 EXPECT_EQ(1, observer_.num_changes()); | 842 EXPECT_EQ(1, observer_.num_changes()); |
| 769 | 843 |
| 770 // Turning off the internal display should switch the external display to | 844 // Turning off the internal display should switch the external display to |
| 771 // its native mode. | 845 // its native mode. |
| 772 observer_.Reset(); | 846 observer_.Reset(); |
| 847 config_waiter.Reset(); | |
| 773 configurator_.SetDisplayPower( | 848 configurator_.SetDisplayPower( |
| 774 chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, | 849 chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, |
| 775 DisplayConfigurator::kSetDisplayPowerNoFlags, | 850 DisplayConfigurator::kSetDisplayPowerNoFlags, |
| 776 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, | 851 config_waiter.on_configuration_callback()); |
| 777 base::Unretained(this))); | 852 delay = config_waiter.Wait(); |
| 778 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); | 853 EXPECT_LT(delay, base::TimeDelta::FromMilliseconds(kMaxShortDelayMs)); |
| 854 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter.callback_result()); | |
| 779 EXPECT_EQ( | 855 EXPECT_EQ( |
| 780 JoinActions( | 856 JoinActions( |
| 781 kGrab, | 857 kGrab, |
| 782 GetFramebufferAction(big_mode_.size(), &outputs_[0], &outputs_[1]) | 858 GetFramebufferAction(big_mode_.size(), &outputs_[0], &outputs_[1]) |
| 783 .c_str(), | 859 .c_str(), |
| 784 GetCrtcAction(outputs_[0], NULL, gfx::Point(0, 0)).c_str(), | 860 GetCrtcAction(outputs_[0], NULL, gfx::Point(0, 0)).c_str(), |
| 785 GetCrtcAction(outputs_[1], &big_mode_, gfx::Point(0, 0)).c_str(), | 861 GetCrtcAction(outputs_[1], &big_mode_, gfx::Point(0, 0)).c_str(), |
| 786 kForceDPMS, | 862 kForceDPMS, |
| 787 kUngrab, | 863 kUngrab, |
| 788 NULL), | 864 NULL), |
| 789 log_->GetActionsAndClear()); | 865 log_->GetActionsAndClear()); |
| 790 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_SINGLE, configurator_.display_state()); | 866 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_SINGLE, configurator_.display_state()); |
| 791 EXPECT_FALSE(mirroring_controller_.SoftwareMirroringEnabled()); | 867 EXPECT_FALSE(mirroring_controller_.SoftwareMirroringEnabled()); |
| 792 EXPECT_EQ(1, observer_.num_changes()); | 868 EXPECT_EQ(1, observer_.num_changes()); |
| 793 | 869 |
| 794 // When all displays are turned off, the framebuffer should switch back | 870 // When all displays are turned off, the framebuffer should switch back |
| 795 // to the extended + software mirroring. | 871 // to the extended + software mirroring. |
| 796 observer_.Reset(); | 872 observer_.Reset(); |
| 873 config_waiter.Reset(); | |
| 797 configurator_.SetDisplayPower( | 874 configurator_.SetDisplayPower( |
| 798 chromeos::DISPLAY_POWER_ALL_OFF, | 875 chromeos::DISPLAY_POWER_ALL_OFF, |
| 799 DisplayConfigurator::kSetDisplayPowerNoFlags, | 876 DisplayConfigurator::kSetDisplayPowerNoFlags, |
| 800 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, | 877 config_waiter.on_configuration_callback()); |
| 801 base::Unretained(this))); | 878 delay = config_waiter.Wait(); |
| 802 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); | 879 EXPECT_LT(delay, base::TimeDelta::FromMilliseconds(kMaxShortDelayMs)); |
| 880 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter.callback_result()); | |
| 803 EXPECT_EQ( | 881 EXPECT_EQ( |
| 804 JoinActions( | 882 JoinActions( |
| 805 kGrab, | 883 kGrab, |
| 806 GetFramebufferAction(gfx::Size(big_mode_.size().width(), kDualHeight), | 884 GetFramebufferAction(gfx::Size(big_mode_.size().width(), kDualHeight), |
| 807 &outputs_[0], | 885 &outputs_[0], |
| 808 &outputs_[1]).c_str(), | 886 &outputs_[1]).c_str(), |
| 809 GetCrtcAction(outputs_[0], NULL, gfx::Point(0, 0)).c_str(), | 887 GetCrtcAction(outputs_[0], NULL, gfx::Point(0, 0)).c_str(), |
| 810 GetCrtcAction(outputs_[1], | 888 GetCrtcAction(outputs_[1], |
| 811 NULL, | 889 NULL, |
| 812 gfx::Point(0, | 890 gfx::Point(0, |
| 813 small_mode_.size().height() + | 891 small_mode_.size().height() + |
| 814 DisplayConfigurator::kVerticalGap)) | 892 DisplayConfigurator::kVerticalGap)) |
| 815 .c_str(), | 893 .c_str(), |
| 816 kUngrab, | 894 kUngrab, |
| 817 NULL), | 895 NULL), |
| 818 log_->GetActionsAndClear()); | 896 log_->GetActionsAndClear()); |
| 819 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED, | 897 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED, |
| 820 configurator_.display_state()); | 898 configurator_.display_state()); |
| 821 EXPECT_TRUE(mirroring_controller_.SoftwareMirroringEnabled()); | 899 EXPECT_TRUE(mirroring_controller_.SoftwareMirroringEnabled()); |
| 822 EXPECT_EQ(1, observer_.num_changes()); | 900 EXPECT_EQ(1, observer_.num_changes()); |
| 823 | 901 |
| 824 // Turn all displays on and check that mirroring is still used. | 902 // Turn all displays on and check that mirroring is still used. |
| 825 observer_.Reset(); | 903 observer_.Reset(); |
| 904 config_waiter.Reset(); | |
| 826 configurator_.SetDisplayPower( | 905 configurator_.SetDisplayPower( |
| 827 chromeos::DISPLAY_POWER_ALL_ON, | 906 chromeos::DISPLAY_POWER_ALL_ON, |
| 828 DisplayConfigurator::kSetDisplayPowerNoFlags, | 907 DisplayConfigurator::kSetDisplayPowerNoFlags, |
| 829 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, | 908 config_waiter.on_configuration_callback()); |
| 830 base::Unretained(this))); | 909 delay = config_waiter.Wait(); |
| 831 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); | 910 EXPECT_LT(delay, base::TimeDelta::FromMilliseconds(kMaxShortDelayMs)); |
| 911 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter.callback_result()); | |
| 832 EXPECT_EQ( | 912 EXPECT_EQ( |
| 833 JoinActions( | 913 JoinActions( |
| 834 kGrab, | 914 kGrab, |
| 835 GetFramebufferAction(gfx::Size(big_mode_.size().width(), kDualHeight), | 915 GetFramebufferAction(gfx::Size(big_mode_.size().width(), kDualHeight), |
| 836 &outputs_[0], | 916 &outputs_[0], |
| 837 &outputs_[1]).c_str(), | 917 &outputs_[1]).c_str(), |
| 838 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), | 918 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), |
| 839 GetCrtcAction(outputs_[1], | 919 GetCrtcAction(outputs_[1], |
| 840 &big_mode_, | 920 &big_mode_, |
| 841 gfx::Point(0, | 921 gfx::Point(0, |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 853 } | 933 } |
| 854 | 934 |
| 855 TEST_F(DisplayConfiguratorTest, SuspendAndResume) { | 935 TEST_F(DisplayConfiguratorTest, SuspendAndResume) { |
| 856 InitWithSingleOutput(); | 936 InitWithSingleOutput(); |
| 857 | 937 |
| 858 // No preparation is needed before suspending when the display is already | 938 // No preparation is needed before suspending when the display is already |
| 859 // on. The configurator should still reprobe on resume in case a display | 939 // on. The configurator should still reprobe on resume in case a display |
| 860 // was connected while suspended. | 940 // was connected while suspended. |
| 861 const gfx::Size framebuffer_size = configurator_.framebuffer_size(); | 941 const gfx::Size framebuffer_size = configurator_.framebuffer_size(); |
| 862 DCHECK(!framebuffer_size.IsEmpty()); | 942 DCHECK(!framebuffer_size.IsEmpty()); |
| 863 configurator_.SuspendDisplays(base::Bind( | 943 ConfigurationWaiter config_waiter; |
| 864 &DisplayConfiguratorTest::OnConfiguredCallback, base::Unretained(this))); | 944 configurator_.SuspendDisplays(config_waiter.on_configuration_callback()); |
| 865 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); | 945 base::TimeDelta delay = config_waiter.Wait(); |
| 946 EXPECT_LT(delay, base::TimeDelta::FromMilliseconds(kMaxShortDelayMs)); | |
| 947 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter.callback_result()); | |
| 866 EXPECT_EQ(framebuffer_size.ToString(), | 948 EXPECT_EQ(framebuffer_size.ToString(), |
| 867 configurator_.framebuffer_size().ToString()); | 949 configurator_.framebuffer_size().ToString()); |
| 868 EXPECT_EQ( | 950 EXPECT_EQ( |
| 869 JoinActions( | 951 JoinActions( |
| 870 kGrab, | 952 kGrab, |
| 871 GetFramebufferAction(small_mode_.size(), &outputs_[0], NULL).c_str(), | 953 GetFramebufferAction(small_mode_.size(), &outputs_[0], NULL).c_str(), |
| 872 GetCrtcAction(outputs_[0], NULL, gfx::Point(0, 0)).c_str(), | 954 GetCrtcAction(outputs_[0], NULL, gfx::Point(0, 0)).c_str(), |
| 873 kUngrab, | 955 kUngrab, |
| 874 kSync, | 956 kSync, |
| 875 NULL), | 957 NULL), |
| 876 log_->GetActionsAndClear()); | 958 log_->GetActionsAndClear()); |
| 877 configurator_.ResumeDisplays(); | 959 |
| 960 // No resume delay in single display mode. | |
| 961 config_waiter.Reset(); | |
| 962 ResumeDisplays(config_waiter.on_configuration_callback()); | |
| 963 delay = config_waiter.Wait(); | |
| 964 EXPECT_LT(delay, base::TimeDelta::FromMilliseconds(kMaxShortDelayMs)); | |
| 965 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter.callback_result()); | |
| 878 EXPECT_EQ( | 966 EXPECT_EQ( |
| 879 JoinActions( | 967 JoinActions( |
| 880 kGrab, | 968 kGrab, |
| 881 GetFramebufferAction(small_mode_.size(), &outputs_[0], NULL).c_str(), | 969 GetFramebufferAction(small_mode_.size(), &outputs_[0], NULL).c_str(), |
| 882 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), | 970 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), |
| 883 kForceDPMS, | 971 kForceDPMS, |
| 884 kUngrab, | 972 kUngrab, |
| 885 NULL), | 973 NULL), |
| 886 log_->GetActionsAndClear()); | 974 log_->GetActionsAndClear()); |
| 887 | 975 |
| 888 // Now turn the display off before suspending and check that the | 976 // Now turn the display off before suspending and check that the |
| 889 // configurator turns it back on and syncs with the server. | 977 // configurator turns it back on and syncs with the server. |
| 978 config_waiter.Reset(); | |
| 890 configurator_.SetDisplayPower( | 979 configurator_.SetDisplayPower( |
| 891 chromeos::DISPLAY_POWER_ALL_OFF, | 980 chromeos::DISPLAY_POWER_ALL_OFF, |
| 892 DisplayConfigurator::kSetDisplayPowerNoFlags, | 981 DisplayConfigurator::kSetDisplayPowerNoFlags, |
| 893 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, | 982 config_waiter.on_configuration_callback()); |
| 894 base::Unretained(this))); | 983 delay = config_waiter.Wait(); |
| 895 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); | 984 EXPECT_LT(delay, base::TimeDelta::FromMilliseconds(kMaxShortDelayMs)); |
| 985 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter.callback_result()); | |
| 896 EXPECT_EQ( | 986 EXPECT_EQ( |
| 897 JoinActions( | 987 JoinActions( |
| 898 kGrab, | 988 kGrab, |
| 899 GetFramebufferAction(small_mode_.size(), &outputs_[0], NULL).c_str(), | 989 GetFramebufferAction(small_mode_.size(), &outputs_[0], NULL).c_str(), |
| 900 GetCrtcAction(outputs_[0], NULL, gfx::Point(0, 0)).c_str(), | 990 GetCrtcAction(outputs_[0], NULL, gfx::Point(0, 0)).c_str(), |
| 901 kUngrab, | 991 kUngrab, |
| 902 NULL), | 992 NULL), |
| 903 log_->GetActionsAndClear()); | 993 log_->GetActionsAndClear()); |
| 904 | 994 |
| 905 configurator_.SuspendDisplays(base::Bind( | 995 config_waiter.Reset(); |
| 906 &DisplayConfiguratorTest::OnConfiguredCallback, base::Unretained(this))); | 996 configurator_.SuspendDisplays(config_waiter.on_configuration_callback()); |
| 907 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); | 997 delay = config_waiter.Wait(); |
| 998 EXPECT_LT(delay, base::TimeDelta::FromMilliseconds(kMaxShortDelayMs)); | |
| 999 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter.callback_result()); | |
| 908 EXPECT_EQ(kSync, log_->GetActionsAndClear()); | 1000 EXPECT_EQ(kSync, log_->GetActionsAndClear()); |
| 909 | 1001 |
| 910 configurator_.ResumeDisplays(); | 1002 config_waiter.Reset(); |
| 1003 ResumeDisplays(config_waiter.on_configuration_callback()); | |
| 1004 delay = config_waiter.Wait(); | |
| 1005 EXPECT_LT(delay, base::TimeDelta::FromMilliseconds(kMaxShortDelayMs)); | |
| 1006 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter.callback_result()); | |
| 911 EXPECT_EQ(kNoActions, log_->GetActionsAndClear()); | 1007 EXPECT_EQ(kNoActions, log_->GetActionsAndClear()); |
| 912 | 1008 |
| 1009 config_waiter.Reset(); | |
| 913 configurator_.SetDisplayPower( | 1010 configurator_.SetDisplayPower( |
| 914 chromeos::DISPLAY_POWER_ALL_ON, | 1011 chromeos::DISPLAY_POWER_ALL_ON, |
| 915 DisplayConfigurator::kSetDisplayPowerNoFlags, | 1012 DisplayConfigurator::kSetDisplayPowerNoFlags, |
| 916 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, | 1013 config_waiter.on_configuration_callback()); |
| 917 base::Unretained(this))); | 1014 delay = config_waiter.Wait(); |
| 1015 EXPECT_LT(delay, base::TimeDelta::FromMilliseconds(kMaxShortDelayMs)); | |
| 1016 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter.callback_result()); | |
| 918 EXPECT_EQ( | 1017 EXPECT_EQ( |
| 919 JoinActions( | 1018 JoinActions( |
| 920 kGrab, | 1019 kGrab, |
| 921 GetFramebufferAction(small_mode_.size(), &outputs_[0], NULL).c_str(), | 1020 GetFramebufferAction(small_mode_.size(), &outputs_[0], NULL).c_str(), |
| 922 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), | 1021 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), |
| 923 kForceDPMS, | 1022 kForceDPMS, |
| 924 kUngrab, | 1023 kUngrab, |
| 925 NULL), | 1024 NULL), |
| 926 log_->GetActionsAndClear()); | 1025 log_->GetActionsAndClear()); |
| 927 | 1026 |
| 928 state_controller_.set_state(MULTIPLE_DISPLAY_STATE_DUAL_MIRROR); | 1027 state_controller_.set_state(MULTIPLE_DISPLAY_STATE_DUAL_MIRROR); |
| 929 UpdateOutputs(2, true); | 1028 UpdateOutputs(2, true); |
| 930 EXPECT_EQ( | 1029 EXPECT_EQ( |
| 931 JoinActions( | 1030 JoinActions( |
| 932 kGrab, | 1031 kGrab, |
| 933 GetFramebufferAction(small_mode_.size(), &outputs_[0], &outputs_[1]) | 1032 GetFramebufferAction(small_mode_.size(), &outputs_[0], &outputs_[1]) |
| 934 .c_str(), | 1033 .c_str(), |
| 935 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), | 1034 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), |
| 936 GetCrtcAction(outputs_[1], &small_mode_, gfx::Point(0, 0)).c_str(), | 1035 GetCrtcAction(outputs_[1], &small_mode_, gfx::Point(0, 0)).c_str(), |
| 937 kUngrab, | 1036 kUngrab, |
| 938 NULL), | 1037 NULL), |
| 939 log_->GetActionsAndClear()); | 1038 log_->GetActionsAndClear()); |
| 940 | 1039 |
| 1040 config_waiter.Reset(); | |
| 941 configurator_.SetDisplayPower( | 1041 configurator_.SetDisplayPower( |
| 942 chromeos::DISPLAY_POWER_ALL_OFF, | 1042 chromeos::DISPLAY_POWER_ALL_OFF, |
| 943 DisplayConfigurator::kSetDisplayPowerNoFlags, | 1043 DisplayConfigurator::kSetDisplayPowerNoFlags, |
| 944 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, | 1044 config_waiter.on_configuration_callback()); |
| 945 base::Unretained(this))); | 1045 delay = config_waiter.Wait(); |
| 946 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); | 1046 EXPECT_LT(delay, base::TimeDelta::FromMilliseconds(kMaxShortDelayMs)); |
| 1047 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter.callback_result()); | |
| 1048 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_MIRROR, | |
| 1049 configurator_.display_state()); | |
| 947 EXPECT_EQ( | 1050 EXPECT_EQ( |
| 948 JoinActions( | 1051 JoinActions( |
| 949 kGrab, | 1052 kGrab, |
| 950 GetFramebufferAction(small_mode_.size(), &outputs_[0], &outputs_[1]) | 1053 GetFramebufferAction(small_mode_.size(), &outputs_[0], &outputs_[1]) |
| 951 .c_str(), | 1054 .c_str(), |
| 952 GetCrtcAction(outputs_[0], NULL, gfx::Point(0, 0)).c_str(), | 1055 GetCrtcAction(outputs_[0], NULL, gfx::Point(0, 0)).c_str(), |
| 953 GetCrtcAction(outputs_[1], NULL, gfx::Point(0, 0)).c_str(), | 1056 GetCrtcAction(outputs_[1], NULL, gfx::Point(0, 0)).c_str(), |
| 954 kUngrab, | 1057 kUngrab, |
| 955 NULL), | 1058 NULL), |
| 956 log_->GetActionsAndClear()); | 1059 log_->GetActionsAndClear()); |
| 957 | 1060 |
| 958 configurator_.SuspendDisplays(base::Bind( | 1061 // No delay in suspend. |
| 959 &DisplayConfiguratorTest::OnConfiguredCallback, base::Unretained(this))); | 1062 config_waiter.Reset(); |
| 960 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); | 1063 configurator_.SuspendDisplays(config_waiter.on_configuration_callback()); |
| 1064 delay = config_waiter.Wait(); | |
| 1065 EXPECT_LT(delay, base::TimeDelta::FromMilliseconds(kMaxShortDelayMs)); | |
| 1066 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter.callback_result()); | |
| 1067 EXPECT_EQ(chromeos::DISPLAY_POWER_ALL_OFF, | |
| 1068 configurator_.current_power_state()); | |
| 1069 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_MIRROR, | |
| 1070 configurator_.display_state()); | |
| 961 EXPECT_EQ(kSync, log_->GetActionsAndClear()); | 1071 EXPECT_EQ(kSync, log_->GetActionsAndClear()); |
| 962 | 1072 |
| 963 // If a display is disconnected while suspended, the configurator should | 1073 // If a display is disconnected while suspended, the configurator should |
| 964 // pick up the change and only turn on the internal display. | 1074 // pick up the change and only turn on the internal display. The should be |
| 1075 // a longer configuration delay when we set the displays back to on. | |
| 965 UpdateOutputs(1, false); | 1076 UpdateOutputs(1, false); |
| 966 configurator_.ResumeDisplays(); | 1077 config_waiter.Reset(); |
| 1078 ResumeDisplays(config_waiter.on_configuration_callback()); | |
| 1079 delay = config_waiter.Wait(); | |
| 1080 EXPECT_LT(delay, base::TimeDelta::FromMilliseconds(kMaxShortDelayMs)); | |
| 1081 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter.callback_result()); | |
| 967 EXPECT_EQ(kNoActions, log_->GetActionsAndClear()); | 1082 EXPECT_EQ(kNoActions, log_->GetActionsAndClear()); |
| 968 | 1083 |
| 1084 config_waiter.Reset(); | |
| 969 configurator_.SetDisplayPower( | 1085 configurator_.SetDisplayPower( |
| 970 chromeos::DISPLAY_POWER_ALL_ON, | 1086 chromeos::DISPLAY_POWER_ALL_ON, |
| 971 DisplayConfigurator::kSetDisplayPowerNoFlags, | 1087 DisplayConfigurator::kSetDisplayPowerNoFlags, |
| 972 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, | 1088 config_waiter.on_configuration_callback()); |
| 973 base::Unretained(this))); | 1089 delay = config_waiter.Wait(); |
| 1090 EXPECT_GE(delay, base::TimeDelta::FromMilliseconds(kMinLongDelayMs)); | |
| 1091 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter.callback_result()); | |
| 974 EXPECT_EQ( | 1092 EXPECT_EQ( |
| 975 JoinActions( | 1093 JoinActions( |
| 976 kGrab, | 1094 kGrab, |
| 977 GetFramebufferAction(small_mode_.size(), &outputs_[0], NULL).c_str(), | 1095 GetFramebufferAction(small_mode_.size(), &outputs_[0], NULL).c_str(), |
| 978 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), | 1096 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), |
| 979 kForceDPMS, | 1097 kForceDPMS, |
| 980 kUngrab, | 1098 kUngrab, |
| 981 NULL), | 1099 NULL), |
| 982 log_->GetActionsAndClear()); | 1100 log_->GetActionsAndClear()); |
| 983 } | 1101 } |
| 984 | 1102 |
| 985 TEST_F(DisplayConfiguratorTest, Headless) { | 1103 TEST_F(DisplayConfiguratorTest, Headless) { |
| 986 UpdateOutputs(0, false); | 1104 UpdateOutputs(0, false); |
| 987 EXPECT_EQ(kNoActions, log_->GetActionsAndClear()); | 1105 EXPECT_EQ(kNoActions, log_->GetActionsAndClear()); |
| 988 Init(false); | 1106 Init(false); |
| 989 EXPECT_EQ(kNoActions, log_->GetActionsAndClear()); | 1107 EXPECT_EQ(kNoActions, log_->GetActionsAndClear()); |
| 990 configurator_.ForceInitialConfigure(0); | 1108 configurator_.ForceInitialConfigure(0); |
| 991 EXPECT_EQ(JoinActions(kInitXRandR, kGrab, kForceDPMS, kUngrab, NULL), | 1109 EXPECT_EQ(JoinActions(kInitXRandR, kGrab, kForceDPMS, kUngrab, NULL), |
| 992 log_->GetActionsAndClear()); | 1110 log_->GetActionsAndClear()); |
| 993 | 1111 |
| 994 // Not much should happen when the display power state is changed while | 1112 // Not much should happen when the display power state is changed while |
| 995 // no displays are connected. | 1113 // no displays are connected. |
| 1114 ConfigurationWaiter config_waiter; | |
| 996 configurator_.SetDisplayPower( | 1115 configurator_.SetDisplayPower( |
| 997 chromeos::DISPLAY_POWER_ALL_OFF, | 1116 chromeos::DISPLAY_POWER_ALL_OFF, |
| 998 DisplayConfigurator::kSetDisplayPowerNoFlags, | 1117 DisplayConfigurator::kSetDisplayPowerNoFlags, |
| 999 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, | 1118 config_waiter.on_configuration_callback()); |
| 1000 base::Unretained(this))); | 1119 base::TimeDelta delay = config_waiter.Wait(); |
| 1001 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); | 1120 EXPECT_LT(delay, base::TimeDelta::FromMilliseconds(kMaxShortDelayMs)); |
| 1121 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter.callback_result()); | |
| 1002 EXPECT_EQ(JoinActions(kGrab, kUngrab, NULL), log_->GetActionsAndClear()); | 1122 EXPECT_EQ(JoinActions(kGrab, kUngrab, NULL), log_->GetActionsAndClear()); |
| 1123 config_waiter.Reset(); | |
| 1003 configurator_.SetDisplayPower( | 1124 configurator_.SetDisplayPower( |
| 1004 chromeos::DISPLAY_POWER_ALL_ON, | 1125 chromeos::DISPLAY_POWER_ALL_ON, |
| 1005 DisplayConfigurator::kSetDisplayPowerNoFlags, | 1126 DisplayConfigurator::kSetDisplayPowerNoFlags, |
| 1006 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, | 1127 config_waiter.on_configuration_callback()); |
| 1007 base::Unretained(this))); | 1128 delay = config_waiter.Wait(); |
| 1008 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); | 1129 EXPECT_LT(delay, base::TimeDelta::FromMilliseconds(kMaxShortDelayMs)); |
| 1130 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter.callback_result()); | |
| 1009 EXPECT_EQ(JoinActions(kGrab, kForceDPMS, kUngrab, NULL), | 1131 EXPECT_EQ(JoinActions(kGrab, kForceDPMS, kUngrab, NULL), |
| 1010 log_->GetActionsAndClear()); | 1132 log_->GetActionsAndClear()); |
| 1011 | 1133 |
| 1012 // Connect an external display and check that it's configured correctly. | 1134 // Connect an external display and check that it's configured correctly. |
| 1013 std::vector<std::unique_ptr<const DisplayMode>> modes; | 1135 std::vector<std::unique_ptr<const DisplayMode>> modes; |
| 1014 for (const std::unique_ptr<const DisplayMode>& mode : outputs_[1].modes()) { | 1136 for (const std::unique_ptr<const DisplayMode>& mode : outputs_[1].modes()) { |
| 1015 modes.push_back(mode->Clone()); | 1137 modes.push_back(mode->Clone()); |
| 1016 if (mode.get() == outputs_[1].current_mode()) | 1138 if (mode.get() == outputs_[1].current_mode()) |
| 1017 outputs_[0].set_current_mode(modes.back().get()); | 1139 outputs_[0].set_current_mode(modes.back().get()); |
| 1018 if (mode.get() == outputs_[1].native_mode()) | 1140 if (mode.get() == outputs_[1].native_mode()) |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1242 log_->GetActionsAndClear()); | 1364 log_->GetActionsAndClear()); |
| 1243 } | 1365 } |
| 1244 | 1366 |
| 1245 TEST_F(DisplayConfiguratorTest, DoNotConfigureWithSuspendedDisplays) { | 1367 TEST_F(DisplayConfiguratorTest, DoNotConfigureWithSuspendedDisplays) { |
| 1246 InitWithSingleOutput(); | 1368 InitWithSingleOutput(); |
| 1247 | 1369 |
| 1248 // The DisplayConfigurator may occasionally receive OnConfigurationChanged() | 1370 // The DisplayConfigurator may occasionally receive OnConfigurationChanged() |
| 1249 // after the displays have been suspended. This event should be ignored since | 1371 // after the displays have been suspended. This event should be ignored since |
| 1250 // the DisplayConfigurator will force a probe and reconfiguration of displays | 1372 // the DisplayConfigurator will force a probe and reconfiguration of displays |
| 1251 // at resume time. | 1373 // at resume time. |
| 1252 configurator_.SuspendDisplays(base::Bind( | 1374 ConfigurationWaiter config_waiter; |
| 1253 &DisplayConfiguratorTest::OnConfiguredCallback, base::Unretained(this))); | 1375 configurator_.SuspendDisplays(config_waiter.on_configuration_callback()); |
| 1254 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); | 1376 base::TimeDelta delay = config_waiter.Wait(); |
| 1377 EXPECT_LT(delay, base::TimeDelta::FromMilliseconds(kMaxShortDelayMs)); | |
| 1378 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter.callback_result()); | |
| 1255 EXPECT_EQ( | 1379 EXPECT_EQ( |
| 1256 JoinActions( | 1380 JoinActions( |
| 1257 kGrab, | 1381 kGrab, |
| 1258 GetFramebufferAction(small_mode_.size(), &outputs_[0], NULL).c_str(), | 1382 GetFramebufferAction(small_mode_.size(), &outputs_[0], NULL).c_str(), |
| 1259 GetCrtcAction(outputs_[0], NULL, gfx::Point(0, 0)).c_str(), | 1383 GetCrtcAction(outputs_[0], NULL, gfx::Point(0, 0)).c_str(), |
| 1260 kUngrab, | 1384 kUngrab, |
| 1261 kSync, | 1385 kSync, |
| 1262 NULL), | 1386 NULL), |
| 1263 log_->GetActionsAndClear()); | 1387 log_->GetActionsAndClear()); |
| 1264 | 1388 |
| 1265 // The configuration timer should not be started when the displays | 1389 // The configuration timer should not be started when the displays |
| 1266 // are suspended. | 1390 // are suspended. |
| 1267 configurator_.OnConfigurationChanged(); | 1391 configurator_.OnConfigurationChanged(); |
| 1268 EXPECT_FALSE(test_api_.TriggerConfigureTimeout()); | 1392 EXPECT_FALSE(test_api_.TriggerConfigureTimeout()); |
| 1269 EXPECT_EQ(kNoActions, log_->GetActionsAndClear()); | 1393 EXPECT_EQ(kNoActions, log_->GetActionsAndClear()); |
| 1270 | 1394 |
| 1271 // Calls to SetDisplayPower should do nothing if the power state doesn't | 1395 // Calls to SetDisplayPower should do nothing if the power state doesn't |
| 1272 // change. | 1396 // change. |
| 1397 config_waiter.Reset(); | |
| 1273 configurator_.SetDisplayPower( | 1398 configurator_.SetDisplayPower( |
| 1274 chromeos::DISPLAY_POWER_ALL_OFF, | 1399 chromeos::DISPLAY_POWER_ALL_OFF, |
| 1275 DisplayConfigurator::kSetDisplayPowerNoFlags, | 1400 DisplayConfigurator::kSetDisplayPowerNoFlags, |
| 1276 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, | 1401 config_waiter.on_configuration_callback()); |
| 1277 base::Unretained(this))); | 1402 delay = config_waiter.Wait(); |
| 1278 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); | 1403 EXPECT_LT(delay, base::TimeDelta::FromMilliseconds(kMaxShortDelayMs)); |
| 1404 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter.callback_result()); | |
| 1279 EXPECT_EQ(kNoActions, log_->GetActionsAndClear()); | 1405 EXPECT_EQ(kNoActions, log_->GetActionsAndClear()); |
| 1406 config_waiter.Reset(); | |
| 1280 configurator_.SetDisplayPower( | 1407 configurator_.SetDisplayPower( |
| 1281 chromeos::DISPLAY_POWER_ALL_ON, | 1408 chromeos::DISPLAY_POWER_ALL_ON, |
| 1282 DisplayConfigurator::kSetDisplayPowerNoFlags, | 1409 DisplayConfigurator::kSetDisplayPowerNoFlags, |
| 1283 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, | 1410 config_waiter.on_configuration_callback()); |
| 1284 base::Unretained(this))); | 1411 delay = config_waiter.Wait(); |
| 1285 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); | 1412 EXPECT_LT(delay, base::TimeDelta::FromMilliseconds(kMaxShortDelayMs)); |
| 1413 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter.callback_result()); | |
| 1286 EXPECT_EQ( | 1414 EXPECT_EQ( |
| 1287 JoinActions( | 1415 JoinActions( |
| 1288 kGrab, | 1416 kGrab, |
| 1289 GetFramebufferAction(small_mode_.size(), &outputs_[0], NULL).c_str(), | 1417 GetFramebufferAction(small_mode_.size(), &outputs_[0], NULL).c_str(), |
| 1290 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), | 1418 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), |
| 1291 kForceDPMS, | 1419 kForceDPMS, |
| 1292 kUngrab, | 1420 kUngrab, |
| 1293 NULL), | 1421 NULL), |
| 1294 log_->GetActionsAndClear()); | 1422 log_->GetActionsAndClear()); |
| 1295 | 1423 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1309 // The DisplayConfigurator should do nothing at resume time if there is no | 1437 // The DisplayConfigurator should do nothing at resume time if there is no |
| 1310 // state change. | 1438 // state change. |
| 1311 UpdateOutputs(1, false); | 1439 UpdateOutputs(1, false); |
| 1312 configurator_.ResumeDisplays(); | 1440 configurator_.ResumeDisplays(); |
| 1313 EXPECT_EQ(kNoActions, log_->GetActionsAndClear()); | 1441 EXPECT_EQ(kNoActions, log_->GetActionsAndClear()); |
| 1314 | 1442 |
| 1315 // If a configuration task is pending when the displays are suspended, that | 1443 // If a configuration task is pending when the displays are suspended, that |
| 1316 // task should not run either and the timer should be stopped. The displays | 1444 // task should not run either and the timer should be stopped. The displays |
| 1317 // should be turned off by suspend. | 1445 // should be turned off by suspend. |
| 1318 configurator_.OnConfigurationChanged(); | 1446 configurator_.OnConfigurationChanged(); |
| 1319 configurator_.SuspendDisplays(base::Bind( | 1447 config_waiter.Reset(); |
| 1320 &DisplayConfiguratorTest::OnConfiguredCallback, base::Unretained(this))); | 1448 configurator_.SuspendDisplays(config_waiter.on_configuration_callback()); |
| 1321 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); | 1449 delay = config_waiter.Wait(); |
| 1450 EXPECT_LT(delay, base::TimeDelta::FromMilliseconds(kMaxShortDelayMs)); | |
| 1451 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter.callback_result()); | |
| 1322 EXPECT_EQ( | 1452 EXPECT_EQ( |
| 1323 JoinActions( | 1453 JoinActions( |
| 1324 kGrab, | 1454 kGrab, |
| 1325 GetFramebufferAction(small_mode_.size(), &outputs_[0], NULL).c_str(), | 1455 GetFramebufferAction(small_mode_.size(), &outputs_[0], NULL).c_str(), |
| 1326 GetCrtcAction(outputs_[0], NULL, gfx::Point(0, 0)).c_str(), | 1456 GetCrtcAction(outputs_[0], NULL, gfx::Point(0, 0)).c_str(), |
| 1327 kUngrab, | 1457 kUngrab, |
| 1328 kSync, | 1458 kSync, |
| 1329 NULL), | 1459 NULL), |
| 1330 log_->GetActionsAndClear()); | 1460 log_->GetActionsAndClear()); |
| 1331 | 1461 |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1540 // so they can be reused later: http://crosbug.com/p/31571 | 1670 // so they can be reused later: http://crosbug.com/p/31571 |
| 1541 TEST_F(DisplayConfiguratorTest, SaveDisplayPowerStateOnConfigFailure) { | 1671 TEST_F(DisplayConfiguratorTest, SaveDisplayPowerStateOnConfigFailure) { |
| 1542 // Start out with two displays in extended mode. | 1672 // Start out with two displays in extended mode. |
| 1543 state_controller_.set_state(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED); | 1673 state_controller_.set_state(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED); |
| 1544 Init(false); | 1674 Init(false); |
| 1545 configurator_.ForceInitialConfigure(0); | 1675 configurator_.ForceInitialConfigure(0); |
| 1546 log_->GetActionsAndClear(); | 1676 log_->GetActionsAndClear(); |
| 1547 observer_.Reset(); | 1677 observer_.Reset(); |
| 1548 | 1678 |
| 1549 // Turn off the internal display, simulating docked mode. | 1679 // Turn off the internal display, simulating docked mode. |
| 1680 ConfigurationWaiter config_waiter; | |
| 1550 configurator_.SetDisplayPower( | 1681 configurator_.SetDisplayPower( |
| 1551 chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, | 1682 chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, |
| 1552 DisplayConfigurator::kSetDisplayPowerNoFlags, | 1683 DisplayConfigurator::kSetDisplayPowerNoFlags, |
| 1553 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, | 1684 config_waiter.on_configuration_callback()); |
| 1554 base::Unretained(this))); | 1685 base::TimeDelta delay = config_waiter.Wait(); |
| 1555 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); | 1686 EXPECT_LT(delay, base::TimeDelta::FromMilliseconds(kMaxShortDelayMs)); |
| 1687 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter.callback_result()); | |
| 1556 EXPECT_EQ(1, observer_.num_changes()); | 1688 EXPECT_EQ(1, observer_.num_changes()); |
| 1557 EXPECT_EQ(0, observer_.num_failures()); | 1689 EXPECT_EQ(0, observer_.num_failures()); |
| 1558 log_->GetActionsAndClear(); | 1690 log_->GetActionsAndClear(); |
| 1559 | 1691 |
| 1560 // Make all subsequent configuration requests fail and try to turn the | 1692 // Make all subsequent configuration requests fail and try to turn the |
| 1561 // internal display back on. | 1693 // internal display back on. |
| 1562 native_display_delegate_->set_max_configurable_pixels(1); | 1694 native_display_delegate_->set_max_configurable_pixels(1); |
| 1563 configurator_.SetDisplayPower( | 1695 configurator_.SetDisplayPower( |
| 1564 chromeos::DISPLAY_POWER_ALL_ON, | 1696 chromeos::DISPLAY_POWER_ALL_ON, |
| 1565 DisplayConfigurator::kSetDisplayPowerNoFlags, | 1697 DisplayConfigurator::kSetDisplayPowerNoFlags, |
| 1566 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, | 1698 config_waiter.on_configuration_callback()); |
| 1567 base::Unretained(this))); | 1699 delay = config_waiter.Wait(); |
| 1568 EXPECT_EQ(CALLBACK_FAILURE, PopCallbackResult()); | 1700 EXPECT_LT(delay, base::TimeDelta::FromMilliseconds(kMaxShortDelayMs)); |
| 1701 EXPECT_EQ(CALLBACK_FAILURE, config_waiter.callback_result()); | |
| 1569 EXPECT_EQ(1, observer_.num_changes()); | 1702 EXPECT_EQ(1, observer_.num_changes()); |
| 1570 EXPECT_EQ(1, observer_.num_failures()); | 1703 EXPECT_EQ(1, observer_.num_failures()); |
| 1571 log_->GetActionsAndClear(); | 1704 log_->GetActionsAndClear(); |
| 1572 | 1705 |
| 1573 // Simulate the external display getting disconnected and check that the | 1706 // Simulate the external display getting disconnected and check that the |
| 1574 // internal display is turned on (i.e. DISPLAY_POWER_ALL_ON is used) rather | 1707 // internal display is turned on (i.e. DISPLAY_POWER_ALL_ON is used) rather |
| 1575 // than the earlier DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON state. | 1708 // than the earlier DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON state. |
| 1576 native_display_delegate_->set_max_configurable_pixels(0); | 1709 native_display_delegate_->set_max_configurable_pixels(0); |
| 1577 UpdateOutputs(1, true); | 1710 UpdateOutputs(1, true); |
| 1578 EXPECT_EQ(JoinActions(kGrab, GetFramebufferAction(small_mode_.size(), | 1711 EXPECT_EQ(JoinActions(kGrab, GetFramebufferAction(small_mode_.size(), |
| 1579 &outputs_[0], NULL).c_str(), | 1712 &outputs_[0], NULL).c_str(), |
| 1580 GetCrtcAction(outputs_[0], &small_mode_, | 1713 GetCrtcAction(outputs_[0], &small_mode_, |
| 1581 gfx::Point(0, 0)).c_str(), | 1714 gfx::Point(0, 0)).c_str(), |
| 1582 kForceDPMS, kUngrab, NULL), | 1715 kForceDPMS, kUngrab, NULL), |
| 1583 log_->GetActionsAndClear()); | 1716 log_->GetActionsAndClear()); |
| 1584 } | 1717 } |
| 1585 | 1718 |
| 1586 // Tests that the SetDisplayPowerState() task posted by HandleResume() doesn't | 1719 // Tests that the SetDisplayPowerState() task posted by HandleResume() doesn't |
| 1587 // use a stale state if a new state is requested before it runs: | 1720 // use a stale state if a new state is requested before it runs: |
| 1588 // http://crosbug.com/p/32393 | 1721 // http://crosbug.com/p/32393 |
| 1589 TEST_F(DisplayConfiguratorTest, DontRestoreStalePowerStateAfterResume) { | 1722 TEST_F(DisplayConfiguratorTest, DontRestoreStalePowerStateAfterResume) { |
| 1590 // Start out with two displays in mirrored mode. | 1723 // Start out with two displays in mirrored mode. |
| 1591 state_controller_.set_state(MULTIPLE_DISPLAY_STATE_DUAL_MIRROR); | 1724 state_controller_.set_state(MULTIPLE_DISPLAY_STATE_DUAL_MIRROR); |
| 1592 Init(false); | 1725 Init(false); |
| 1593 configurator_.ForceInitialConfigure(0); | 1726 configurator_.ForceInitialConfigure(0); |
| 1594 log_->GetActionsAndClear(); | 1727 log_->GetActionsAndClear(); |
| 1595 observer_.Reset(); | 1728 observer_.Reset(); |
| 1596 | 1729 |
| 1597 // Turn off the internal display, simulating docked mode. | 1730 // Turn off the internal display, simulating docked mode. |
| 1731 ConfigurationWaiter config_waiter; | |
| 1598 configurator_.SetDisplayPower( | 1732 configurator_.SetDisplayPower( |
| 1599 chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, | 1733 chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, |
| 1600 DisplayConfigurator::kSetDisplayPowerNoFlags, | 1734 DisplayConfigurator::kSetDisplayPowerNoFlags, |
| 1601 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, | 1735 config_waiter.on_configuration_callback()); |
| 1602 base::Unretained(this))); | 1736 base::TimeDelta delay = config_waiter.Wait(); |
| 1603 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); | 1737 EXPECT_LT(delay, base::TimeDelta::FromMilliseconds(kMaxShortDelayMs)); |
| 1738 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter.callback_result()); | |
| 1604 EXPECT_EQ(1, observer_.num_changes()); | 1739 EXPECT_EQ(1, observer_.num_changes()); |
| 1605 EXPECT_EQ(0, observer_.num_failures()); | 1740 EXPECT_EQ(0, observer_.num_failures()); |
| 1606 EXPECT_EQ( | 1741 EXPECT_EQ( |
| 1607 JoinActions( | 1742 JoinActions( |
| 1608 kGrab, | 1743 kGrab, |
| 1609 GetFramebufferAction(big_mode_.size(), &outputs_[0], &outputs_[1]) | 1744 GetFramebufferAction(big_mode_.size(), &outputs_[0], &outputs_[1]) |
| 1610 .c_str(), | 1745 .c_str(), |
| 1611 GetCrtcAction(outputs_[0], NULL, gfx::Point(0, 0)).c_str(), | 1746 GetCrtcAction(outputs_[0], NULL, gfx::Point(0, 0)).c_str(), |
| 1612 GetCrtcAction(outputs_[1], &big_mode_, gfx::Point(0, 0)).c_str(), | 1747 GetCrtcAction(outputs_[1], &big_mode_, gfx::Point(0, 0)).c_str(), |
| 1613 kForceDPMS, | 1748 kForceDPMS, |
| 1614 kUngrab, | 1749 kUngrab, |
| 1615 NULL), | 1750 NULL), |
| 1616 log_->GetActionsAndClear()); | 1751 log_->GetActionsAndClear()); |
| 1617 | 1752 |
| 1618 // Suspend and resume the system. Resuming should restore the previous power | 1753 // Suspend and resume the system. Resuming should restore the previous power |
| 1619 // state and force a probe. Suspend should turn off the displays since an | 1754 // state and force a probe. Suspend should turn off the displays since an |
| 1620 // external monitor is connected. | 1755 // external monitor is connected. |
| 1621 configurator_.SuspendDisplays(base::Bind( | 1756 config_waiter.Reset(); |
| 1622 &DisplayConfiguratorTest::OnConfiguredCallback, base::Unretained(this))); | 1757 configurator_.SuspendDisplays(config_waiter.on_configuration_callback()); |
| 1623 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); | 1758 delay = config_waiter.Wait(); |
| 1759 EXPECT_LT(delay, base::TimeDelta::FromMilliseconds(kMaxShortDelayMs)); | |
| 1760 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter.callback_result()); | |
| 1624 EXPECT_EQ(2, observer_.num_changes()); | 1761 EXPECT_EQ(2, observer_.num_changes()); |
| 1625 EXPECT_EQ( | 1762 EXPECT_EQ( |
| 1626 JoinActions( | 1763 JoinActions( |
| 1627 kGrab, | 1764 kGrab, |
| 1628 GetFramebufferAction(small_mode_.size(), &outputs_[0], | 1765 GetFramebufferAction(small_mode_.size(), &outputs_[0], |
| 1629 &outputs_[1]).c_str(), | 1766 &outputs_[1]).c_str(), |
| 1630 GetCrtcAction(outputs_[0], NULL, gfx::Point(0, 0)).c_str(), | 1767 GetCrtcAction(outputs_[0], NULL, gfx::Point(0, 0)).c_str(), |
| 1631 GetCrtcAction(outputs_[1], NULL, gfx::Point(0, 0)).c_str(), | 1768 GetCrtcAction(outputs_[1], NULL, gfx::Point(0, 0)).c_str(), |
| 1632 kUngrab, | 1769 kUngrab, |
| 1633 kSync, | 1770 kSync, |
| 1634 NULL), | 1771 NULL), |
| 1635 log_->GetActionsAndClear()); | 1772 log_->GetActionsAndClear()); |
| 1636 | 1773 |
| 1637 // Before the task runs, exit docked mode. | 1774 // Before the task runs, exit docked mode. |
| 1775 config_waiter.Reset(); | |
| 1638 configurator_.SetDisplayPower( | 1776 configurator_.SetDisplayPower( |
| 1639 chromeos::DISPLAY_POWER_ALL_ON, | 1777 chromeos::DISPLAY_POWER_ALL_ON, |
| 1640 DisplayConfigurator::kSetDisplayPowerNoFlags, | 1778 DisplayConfigurator::kSetDisplayPowerNoFlags, |
| 1641 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, | 1779 config_waiter.on_configuration_callback()); |
| 1642 base::Unretained(this))); | 1780 delay = config_waiter.Wait(); |
| 1643 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); | 1781 EXPECT_LT(delay, base::TimeDelta::FromMilliseconds(kMaxShortDelayMs)); |
| 1782 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter.callback_result()); | |
| 1644 EXPECT_EQ(3, observer_.num_changes()); | 1783 EXPECT_EQ(3, observer_.num_changes()); |
| 1645 EXPECT_EQ(0, observer_.num_failures()); | 1784 EXPECT_EQ(0, observer_.num_failures()); |
| 1646 EXPECT_EQ( | 1785 EXPECT_EQ( |
| 1647 JoinActions( | 1786 JoinActions( |
| 1648 kGrab, | 1787 kGrab, |
| 1649 GetFramebufferAction(small_mode_.size(), &outputs_[0], &outputs_[1]) | 1788 GetFramebufferAction(small_mode_.size(), &outputs_[0], &outputs_[1]) |
| 1650 .c_str(), | 1789 .c_str(), |
| 1651 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), | 1790 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), |
| 1652 GetCrtcAction(outputs_[1], &small_mode_, gfx::Point(0, 0)).c_str(), | 1791 GetCrtcAction(outputs_[1], &small_mode_, gfx::Point(0, 0)).c_str(), |
| 1653 kForceDPMS, | 1792 kForceDPMS, |
| 1654 kUngrab, | 1793 kUngrab, |
| 1655 NULL), | 1794 NULL), |
| 1656 log_->GetActionsAndClear()); | 1795 log_->GetActionsAndClear()); |
| 1657 | 1796 |
| 1658 // Check that the display states are not changed after resuming. | 1797 // Check that the display states are not changed after resuming. |
| 1659 configurator_.ResumeDisplays(); | 1798 config_waiter.Reset(); |
| 1799 ResumeDisplays(config_waiter.on_configuration_callback()); | |
| 1800 delay = config_waiter.Wait(); | |
| 1801 EXPECT_LT(delay, base::TimeDelta::FromMilliseconds(kMaxShortDelayMs)); | |
| 1802 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter.callback_result()); | |
| 1803 EXPECT_EQ(chromeos::DISPLAY_POWER_ALL_ON, | |
| 1804 configurator_.current_power_state()); | |
| 1660 EXPECT_EQ(kNoActions, log_->GetActionsAndClear()); | 1805 EXPECT_EQ(kNoActions, log_->GetActionsAndClear()); |
| 1661 } | 1806 } |
| 1662 | 1807 |
| 1663 TEST_F(DisplayConfiguratorTest, ExternalControl) { | 1808 TEST_F(DisplayConfiguratorTest, ExternalControl) { |
| 1664 InitWithSingleOutput(); | 1809 InitWithSingleOutput(); |
| 1665 state_controller_.set_state(MULTIPLE_DISPLAY_STATE_SINGLE); | 1810 state_controller_.set_state(MULTIPLE_DISPLAY_STATE_SINGLE); |
| 1666 configurator_.RelinquishControl( | 1811 configurator_.RelinquishControl( |
| 1667 base::Bind(&DisplayConfiguratorTest::OnDisplayControlUpdated, | 1812 base::Bind(&DisplayConfiguratorTest::OnDisplayControlUpdated, |
| 1668 base::Unretained(this))); | 1813 base::Unretained(this))); |
| 1669 EXPECT_EQ(CALLBACK_SUCCESS, PopDisplayControlResult()); | 1814 EXPECT_EQ(CALLBACK_SUCCESS, PopDisplayControlResult()); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 1689 SetDisplayPowerWhilePendingConfigurationTaskRunning) { | 1834 SetDisplayPowerWhilePendingConfigurationTaskRunning) { |
| 1690 // Start out with two displays in extended mode. | 1835 // Start out with two displays in extended mode. |
| 1691 state_controller_.set_state(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED); | 1836 state_controller_.set_state(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED); |
| 1692 Init(false); | 1837 Init(false); |
| 1693 configurator_.ForceInitialConfigure(0); | 1838 configurator_.ForceInitialConfigure(0); |
| 1694 log_->GetActionsAndClear(); | 1839 log_->GetActionsAndClear(); |
| 1695 observer_.Reset(); | 1840 observer_.Reset(); |
| 1696 | 1841 |
| 1697 native_display_delegate_->set_run_async(true); | 1842 native_display_delegate_->set_run_async(true); |
| 1698 | 1843 |
| 1844 ConfigurationWaiter config_waiter; | |
| 1699 configurator_.SetDisplayPower( | 1845 configurator_.SetDisplayPower( |
| 1700 chromeos::DISPLAY_POWER_ALL_OFF, | 1846 chromeos::DISPLAY_POWER_ALL_OFF, |
| 1701 DisplayConfigurator::kSetDisplayPowerNoFlags, | 1847 DisplayConfigurator::kSetDisplayPowerNoFlags, |
| 1702 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, | 1848 config_waiter.on_configuration_callback()); |
| 1703 base::Unretained(this))); | |
| 1704 | 1849 |
| 1705 configurator_.SetDisplayPower( | 1850 configurator_.SetDisplayPower( |
| 1706 chromeos::DISPLAY_POWER_ALL_ON, | 1851 chromeos::DISPLAY_POWER_ALL_ON, |
| 1707 DisplayConfigurator::kSetDisplayPowerNoFlags, | 1852 DisplayConfigurator::kSetDisplayPowerNoFlags, |
| 1708 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, | 1853 config_waiter.on_configuration_callback()); |
| 1709 base::Unretained(this))); | |
| 1710 | 1854 |
| 1711 EXPECT_EQ(CALLBACK_NOT_CALLED, PopCallbackResult()); | 1855 EXPECT_EQ(CALLBACK_NOT_CALLED, config_waiter.callback_result()); |
| 1712 base::RunLoop().RunUntilIdle(); | 1856 base::TimeDelta delay = config_waiter.Wait(); |
| 1713 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); | 1857 EXPECT_LT(delay, base::TimeDelta::FromMilliseconds(kMaxShortDelayMs)); |
| 1858 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter.callback_result()); | |
| 1714 EXPECT_EQ(1, observer_.num_changes()); | 1859 EXPECT_EQ(1, observer_.num_changes()); |
| 1715 EXPECT_EQ(0, observer_.num_failures()); | 1860 EXPECT_EQ(0, observer_.num_failures()); |
| 1716 | 1861 |
| 1717 const int kDualHeight = small_mode_.size().height() + | 1862 const int kDualHeight = small_mode_.size().height() + |
| 1718 DisplayConfigurator::kVerticalGap + | 1863 DisplayConfigurator::kVerticalGap + |
| 1719 big_mode_.size().height(); | 1864 big_mode_.size().height(); |
| 1720 EXPECT_EQ( | 1865 EXPECT_EQ( |
| 1721 JoinActions( | 1866 JoinActions( |
| 1722 kGrab, | 1867 kGrab, |
| 1723 GetFramebufferAction(gfx::Size(big_mode_.size().width(), kDualHeight), | 1868 GetFramebufferAction(gfx::Size(big_mode_.size().width(), kDualHeight), |
| 1724 &outputs_[0], &outputs_[1]) | 1869 &outputs_[0], &outputs_[1]) |
| 1725 .c_str(), | 1870 .c_str(), |
| 1726 GetCrtcAction(outputs_[0], nullptr, gfx::Point(0, 0)).c_str(), | 1871 GetCrtcAction(outputs_[0], nullptr, gfx::Point(0, 0)).c_str(), |
| 1727 GetCrtcAction(outputs_[1], nullptr, | 1872 GetCrtcAction(outputs_[1], nullptr, |
| 1728 gfx::Point(0, small_mode_.size().height() + | 1873 gfx::Point(0, small_mode_.size().height() + |
| 1729 DisplayConfigurator::kVerticalGap)) | 1874 DisplayConfigurator::kVerticalGap)) |
| 1730 .c_str(), | 1875 .c_str(), |
| 1731 kUngrab, NULL), | 1876 kUngrab, NULL), |
| 1732 log_->GetActionsAndClear()); | 1877 log_->GetActionsAndClear()); |
| 1733 | 1878 |
| 1879 config_waiter.Reset(); | |
| 1734 EXPECT_TRUE(test_api_.TriggerConfigureTimeout()); | 1880 EXPECT_TRUE(test_api_.TriggerConfigureTimeout()); |
| 1735 base::RunLoop().RunUntilIdle(); | 1881 delay = config_waiter.Wait(); |
| 1736 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); | 1882 EXPECT_LT(delay, base::TimeDelta::FromMilliseconds(kMaxShortDelayMs)); |
| 1883 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter.callback_result()); | |
| 1737 EXPECT_EQ(2, observer_.num_changes()); | 1884 EXPECT_EQ(2, observer_.num_changes()); |
| 1738 EXPECT_EQ(0, observer_.num_failures()); | 1885 EXPECT_EQ(0, observer_.num_failures()); |
| 1739 | 1886 |
| 1740 EXPECT_EQ( | 1887 EXPECT_EQ( |
| 1741 JoinActions( | 1888 JoinActions( |
| 1742 kGrab, | 1889 kGrab, |
| 1743 GetFramebufferAction(gfx::Size(big_mode_.size().width(), kDualHeight), | 1890 GetFramebufferAction(gfx::Size(big_mode_.size().width(), kDualHeight), |
| 1744 &outputs_[0], &outputs_[1]) | 1891 &outputs_[0], &outputs_[1]) |
| 1745 .c_str(), | 1892 .c_str(), |
| 1746 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), | 1893 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1757 // Start out with two displays in extended mode. | 1904 // Start out with two displays in extended mode. |
| 1758 state_controller_.set_state(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED); | 1905 state_controller_.set_state(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED); |
| 1759 Init(false); | 1906 Init(false); |
| 1760 configurator_.ForceInitialConfigure(0); | 1907 configurator_.ForceInitialConfigure(0); |
| 1761 log_->GetActionsAndClear(); | 1908 log_->GetActionsAndClear(); |
| 1762 observer_.Reset(); | 1909 observer_.Reset(); |
| 1763 | 1910 |
| 1764 // Fail display configuration. | 1911 // Fail display configuration. |
| 1765 native_display_delegate_->set_max_configurable_pixels(-1); | 1912 native_display_delegate_->set_max_configurable_pixels(-1); |
| 1766 | 1913 |
| 1914 ConfigurationWaiter config_waiter; | |
| 1767 configurator_.SetDisplayPower( | 1915 configurator_.SetDisplayPower( |
| 1768 chromeos::DISPLAY_POWER_ALL_OFF, | 1916 chromeos::DISPLAY_POWER_ALL_OFF, |
| 1769 DisplayConfigurator::kSetDisplayPowerNoFlags, | 1917 DisplayConfigurator::kSetDisplayPowerNoFlags, |
| 1770 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, | 1918 config_waiter.on_configuration_callback()); |
| 1771 base::Unretained(this))); | 1919 base::TimeDelta delay = config_waiter.Wait(); |
| 1772 | 1920 EXPECT_LT(delay, base::TimeDelta::FromMilliseconds(kMaxShortDelayMs)); |
| 1773 EXPECT_EQ(CALLBACK_FAILURE, PopCallbackResult()); | 1921 EXPECT_EQ(CALLBACK_FAILURE, config_waiter.callback_result()); |
| 1774 EXPECT_EQ(0, observer_.num_changes()); | 1922 EXPECT_EQ(0, observer_.num_changes()); |
| 1775 EXPECT_EQ(1, observer_.num_failures()); | 1923 EXPECT_EQ(1, observer_.num_failures()); |
| 1776 | 1924 |
| 1777 const int kDualHeight = small_mode_.size().height() + | 1925 const int kDualHeight = small_mode_.size().height() + |
| 1778 DisplayConfigurator::kVerticalGap + | 1926 DisplayConfigurator::kVerticalGap + |
| 1779 big_mode_.size().height(); | 1927 big_mode_.size().height(); |
| 1780 | 1928 |
| 1781 EXPECT_EQ( | 1929 EXPECT_EQ( |
| 1782 JoinActions( | 1930 JoinActions( |
| 1783 kGrab, | 1931 kGrab, |
| 1784 GetFramebufferAction(gfx::Size(big_mode_.size().width(), kDualHeight), | 1932 GetFramebufferAction(gfx::Size(big_mode_.size().width(), kDualHeight), |
| 1785 &outputs_[0], &outputs_[1]) | 1933 &outputs_[0], &outputs_[1]) |
| 1786 .c_str(), | 1934 .c_str(), |
| 1787 GetCrtcAction(outputs_[0], nullptr, gfx::Point(0, 0)).c_str(), | 1935 GetCrtcAction(outputs_[0], nullptr, gfx::Point(0, 0)).c_str(), |
| 1788 GetCrtcAction(outputs_[1], nullptr, | 1936 GetCrtcAction(outputs_[1], nullptr, |
| 1789 gfx::Point(0, small_mode_.size().height() + | 1937 gfx::Point(0, small_mode_.size().height() + |
| 1790 DisplayConfigurator::kVerticalGap)) | 1938 DisplayConfigurator::kVerticalGap)) |
| 1791 .c_str(), | 1939 .c_str(), |
| 1792 kUngrab, NULL), | 1940 kUngrab, NULL), |
| 1793 log_->GetActionsAndClear()); | 1941 log_->GetActionsAndClear()); |
| 1794 | 1942 |
| 1795 // This configuration should trigger a display configuration since the | 1943 // This configuration should trigger a display configuration since the |
| 1796 // previous configuration failed. | 1944 // previous configuration failed. |
| 1945 config_waiter.Reset(); | |
| 1797 configurator_.SetDisplayPower( | 1946 configurator_.SetDisplayPower( |
| 1798 chromeos::DISPLAY_POWER_ALL_ON, | 1947 chromeos::DISPLAY_POWER_ALL_ON, |
| 1799 DisplayConfigurator::kSetDisplayPowerNoFlags, | 1948 DisplayConfigurator::kSetDisplayPowerNoFlags, |
| 1800 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, | 1949 config_waiter.on_configuration_callback()); |
| 1801 base::Unretained(this))); | 1950 delay = config_waiter.Wait(); |
| 1951 EXPECT_LT(delay, base::TimeDelta::FromMilliseconds(kMaxShortDelayMs)); | |
| 1802 | 1952 |
| 1803 EXPECT_EQ(0, observer_.num_changes()); | 1953 EXPECT_EQ(0, observer_.num_changes()); |
| 1804 EXPECT_EQ(2, observer_.num_failures()); | 1954 EXPECT_EQ(2, observer_.num_failures()); |
| 1805 EXPECT_EQ( | 1955 EXPECT_EQ( |
| 1806 JoinActions( | 1956 JoinActions( |
| 1807 kGrab, | 1957 kGrab, |
| 1808 GetFramebufferAction(gfx::Size(big_mode_.size().width(), kDualHeight), | 1958 GetFramebufferAction(gfx::Size(big_mode_.size().width(), kDualHeight), |
| 1809 &outputs_[0], &outputs_[1]) | 1959 &outputs_[0], &outputs_[1]) |
| 1810 .c_str(), | 1960 .c_str(), |
| 1811 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), | 1961 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1877 GetCrtcAction( | 2027 GetCrtcAction( |
| 1878 outputs_[2], &small_mode_, | 2028 outputs_[2], &small_mode_, |
| 1879 gfx::Point(0, small_mode_.size().height() + | 2029 gfx::Point(0, small_mode_.size().height() + |
| 1880 big_mode_.size().height() + | 2030 big_mode_.size().height() + |
| 1881 2 * DisplayConfigurator::kVerticalGap)) | 2031 2 * DisplayConfigurator::kVerticalGap)) |
| 1882 .c_str(), | 2032 .c_str(), |
| 1883 kUngrab, NULL), | 2033 kUngrab, NULL), |
| 1884 log_->GetActionsAndClear()); | 2034 log_->GetActionsAndClear()); |
| 1885 | 2035 |
| 1886 // Verify that turning the power off works. | 2036 // Verify that turning the power off works. |
| 2037 ConfigurationWaiter config_waiter; | |
| 1887 configurator_.SetDisplayPower( | 2038 configurator_.SetDisplayPower( |
| 1888 chromeos::DISPLAY_POWER_ALL_OFF, | 2039 chromeos::DISPLAY_POWER_ALL_OFF, |
| 1889 DisplayConfigurator::kSetDisplayPowerNoFlags, | 2040 DisplayConfigurator::kSetDisplayPowerNoFlags, |
| 1890 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, | 2041 config_waiter.on_configuration_callback()); |
| 1891 base::Unretained(this))); | 2042 base::TimeDelta delay = config_waiter.Wait(); |
| 1892 | 2043 EXPECT_LT(delay, base::TimeDelta::FromMilliseconds(kMaxShortDelayMs)); |
| 1893 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); | 2044 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter.callback_result()); |
| 1894 EXPECT_EQ( | 2045 EXPECT_EQ( |
| 1895 JoinActions( | 2046 JoinActions( |
| 1896 kGrab, GetFramebufferAction( | 2047 kGrab, GetFramebufferAction( |
| 1897 gfx::Size(big_mode_.size().width(), kTripleHeight), | 2048 gfx::Size(big_mode_.size().width(), kTripleHeight), |
| 1898 &outputs_[0], &outputs_[1]) | 2049 &outputs_[0], &outputs_[1]) |
| 1899 .c_str(), | 2050 .c_str(), |
| 1900 GetCrtcAction(outputs_[0], nullptr, gfx::Point(0, 0)).c_str(), | 2051 GetCrtcAction(outputs_[0], nullptr, gfx::Point(0, 0)).c_str(), |
| 1901 GetCrtcAction(outputs_[1], nullptr, | 2052 GetCrtcAction(outputs_[1], nullptr, |
| 1902 gfx::Point(0, small_mode_.size().height() + | 2053 gfx::Point(0, small_mode_.size().height() + |
| 1903 DisplayConfigurator::kVerticalGap)) | 2054 DisplayConfigurator::kVerticalGap)) |
| 1904 .c_str(), | 2055 .c_str(), |
| 1905 GetCrtcAction( | 2056 GetCrtcAction( |
| 1906 outputs_[2], nullptr, | 2057 outputs_[2], nullptr, |
| 1907 gfx::Point(0, small_mode_.size().height() + | 2058 gfx::Point(0, small_mode_.size().height() + |
| 1908 big_mode_.size().height() + | 2059 big_mode_.size().height() + |
| 1909 2 * DisplayConfigurator::kVerticalGap)) | 2060 2 * DisplayConfigurator::kVerticalGap)) |
| 1910 .c_str(), | 2061 .c_str(), |
| 1911 kUngrab, NULL), | 2062 kUngrab, NULL), |
| 1912 log_->GetActionsAndClear()); | 2063 log_->GetActionsAndClear()); |
| 1913 | 2064 |
| 2065 config_waiter.Reset(); | |
| 1914 configurator_.SetDisplayPower( | 2066 configurator_.SetDisplayPower( |
| 1915 chromeos::DISPLAY_POWER_ALL_ON, | 2067 chromeos::DISPLAY_POWER_ALL_ON, |
| 1916 DisplayConfigurator::kSetDisplayPowerNoFlags, | 2068 DisplayConfigurator::kSetDisplayPowerNoFlags, |
| 1917 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, | 2069 config_waiter.on_configuration_callback()); |
| 1918 base::Unretained(this))); | 2070 delay = config_waiter.Wait(); |
| 1919 | 2071 EXPECT_LT(delay, base::TimeDelta::FromMilliseconds(kMaxShortDelayMs)); |
| 1920 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); | 2072 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter.callback_result()); |
| 1921 EXPECT_EQ( | 2073 EXPECT_EQ( |
| 1922 JoinActions( | 2074 JoinActions( |
| 1923 kGrab, GetFramebufferAction( | 2075 kGrab, GetFramebufferAction( |
| 1924 gfx::Size(big_mode_.size().width(), kTripleHeight), | 2076 gfx::Size(big_mode_.size().width(), kTripleHeight), |
| 1925 &outputs_[0], &outputs_[1]) | 2077 &outputs_[0], &outputs_[1]) |
| 1926 .c_str(), | 2078 .c_str(), |
| 1927 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), | 2079 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), |
| 1928 GetCrtcAction(outputs_[1], &big_mode_, | 2080 GetCrtcAction(outputs_[1], &big_mode_, |
| 1929 gfx::Point(0, small_mode_.size().height() + | 2081 gfx::Point(0, small_mode_.size().height() + |
| 1930 DisplayConfigurator::kVerticalGap)) | 2082 DisplayConfigurator::kVerticalGap)) |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 1950 .c_str(), | 2102 .c_str(), |
| 1951 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), | 2103 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), |
| 1952 GetCrtcAction(outputs_[1], &big_mode_, | 2104 GetCrtcAction(outputs_[1], &big_mode_, |
| 1953 gfx::Point(0, small_mode_.size().height() + | 2105 gfx::Point(0, small_mode_.size().height() + |
| 1954 DisplayConfigurator::kVerticalGap)) | 2106 DisplayConfigurator::kVerticalGap)) |
| 1955 .c_str(), | 2107 .c_str(), |
| 1956 kUngrab, NULL), | 2108 kUngrab, NULL), |
| 1957 log_->GetActionsAndClear()); | 2109 log_->GetActionsAndClear()); |
| 1958 } | 2110 } |
| 1959 | 2111 |
| 2112 // Tests the suspend and resume behavior when in dual or multi display modes. | |
| 2113 TEST_F(DisplayConfiguratorTest, SuspendResumeWithMultipleDisplays) { | |
| 2114 InitWithSingleOutput(); | |
| 2115 state_controller_.set_state(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED); | |
| 2116 observer_.Reset(); | |
| 2117 UpdateOutputs(2, true); | |
| 2118 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED, | |
| 2119 configurator_.display_state()); | |
| 2120 EXPECT_FALSE(mirroring_controller_.SoftwareMirroringEnabled()); | |
| 2121 EXPECT_EQ(1, observer_.num_changes()); | |
| 2122 EXPECT_EQ(chromeos::DISPLAY_POWER_ALL_ON, | |
| 2123 configurator_.current_power_state()); | |
| 2124 | |
| 2125 // Suspending displays should result in an immediate configuration without | |
| 2126 // delays, even in dual display mode. | |
| 2127 ConfigurationWaiter config_waiter; | |
| 2128 configurator_.SuspendDisplays(config_waiter.on_configuration_callback()); | |
| 2129 base::TimeDelta delay = config_waiter.Wait(); | |
| 2130 EXPECT_LT(delay, base::TimeDelta::FromMilliseconds(kMaxShortDelayMs)); | |
| 2131 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter.callback_result()); | |
| 2132 EXPECT_EQ(chromeos::DISPLAY_POWER_ALL_OFF, | |
| 2133 configurator_.current_power_state()); | |
| 2134 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED, | |
| 2135 configurator_.display_state()); | |
| 2136 | |
| 2137 // Resuming from suspend with dual displays, should be done after a delay, and | |
| 2138 // after the configuration we should still expect to be in a dual display | |
| 2139 // mode. | |
| 2140 config_waiter.Reset(); | |
| 2141 ResumeDisplays(config_waiter.on_configuration_callback()); | |
| 2142 delay = config_waiter.Wait(); | |
| 2143 EXPECT_GE(delay, base::TimeDelta::FromMilliseconds(kMinLongDelayMs)); | |
| 2144 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter.callback_result()); | |
| 2145 EXPECT_EQ(chromeos::DISPLAY_POWER_ALL_ON, | |
| 2146 configurator_.current_power_state()); | |
| 2147 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED, | |
| 2148 configurator_.display_state()); | |
| 2149 | |
| 2150 // Suspend displays and disconnect one of them while in suspend. | |
| 2151 config_waiter.Reset(); | |
| 2152 configurator_.SuspendDisplays(config_waiter.on_configuration_callback()); | |
| 2153 delay = config_waiter.Wait(); | |
| 2154 EXPECT_LT(delay, base::TimeDelta::FromMilliseconds(kMaxShortDelayMs)); | |
| 2155 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter.callback_result()); | |
| 2156 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED, | |
| 2157 configurator_.display_state()); | |
| 2158 EXPECT_EQ(chromeos::DISPLAY_POWER_ALL_OFF, | |
| 2159 configurator_.current_power_state()); | |
| 2160 UpdateOutputs(1, false); | |
| 2161 | |
| 2162 // Now resume, and expect that we'll still have a long delay since we were in | |
| 2163 // dual mode before suspend. The configurator should pick up the change and | |
| 2164 // detect that we are in single display mode now. | |
| 2165 config_waiter.Reset(); | |
| 2166 ResumeDisplays(config_waiter.on_configuration_callback()); | |
| 2167 delay = config_waiter.Wait(); | |
| 2168 EXPECT_GE(delay, base::TimeDelta::FromMilliseconds(kMinLongDelayMs)); | |
| 2169 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter.callback_result()); | |
| 2170 EXPECT_EQ(chromeos::DISPLAY_POWER_ALL_ON, | |
| 2171 configurator_.current_power_state()); | |
| 2172 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_SINGLE, configurator_.display_state()); | |
| 2173 | |
| 2174 // Verify that the above is the exact same behavior for 3+ displays. | |
| 2175 UpdateOutputs(3, true); | |
| 2176 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_MULTI_EXTENDED, | |
| 2177 configurator_.display_state()); | |
| 2178 // Suspend. | |
| 2179 config_waiter.Reset(); | |
| 2180 configurator_.SuspendDisplays(config_waiter.on_configuration_callback()); | |
| 2181 delay = config_waiter.Wait(); | |
| 2182 EXPECT_LT(delay, base::TimeDelta::FromMilliseconds(kMaxShortDelayMs)); | |
| 2183 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter.callback_result()); | |
| 2184 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_MULTI_EXTENDED, | |
| 2185 configurator_.display_state()); | |
| 2186 EXPECT_EQ(chromeos::DISPLAY_POWER_ALL_OFF, | |
| 2187 configurator_.current_power_state()); | |
| 2188 | |
| 2189 // Resume and expect the correct delay. | |
| 2190 config_waiter.Reset(); | |
| 2191 ResumeDisplays(config_waiter.on_configuration_callback()); | |
| 2192 delay = config_waiter.Wait(); | |
| 2193 EXPECT_GE(delay, base::TimeDelta::FromMilliseconds(kMinLongDelayMs)); | |
| 2194 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter.callback_result()); | |
| 2195 EXPECT_EQ(chromeos::DISPLAY_POWER_ALL_ON, | |
| 2196 configurator_.current_power_state()); | |
| 2197 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_MULTI_EXTENDED, | |
| 2198 configurator_.display_state()); | |
| 2199 } | |
| 2200 | |
| 1960 } // namespace test | 2201 } // namespace test |
| 1961 } // namespace ui | 2202 } // namespace ui |
| OLD | NEW |