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

Side by Side Diff: ui/display/chromeos/display_configurator_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698