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

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: Painful Rebase 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_native_display_delegate.h" 18 #include "ui/display/chromeos/test/test_native_display_delegate.h"
18 #include "ui/display/fake_display_snapshot.h" 19 #include "ui/display/fake_display_snapshot.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
26 int64_t kDisplayIds[3] = {123, 456, 789}; 27 int64_t kDisplayIds[3] = {123, 456, 789};
27 28
28 std::unique_ptr<ui::DisplayMode> MakeDisplayMode(int width, 29 std::unique_ptr<ui::DisplayMode> MakeDisplayMode(int width,
29 int height, 30 int height,
30 bool is_interlaced, 31 bool is_interlaced,
31 float refresh_rate) { 32 float refresh_rate) {
32 return base::MakeUnique<ui::DisplayMode>(gfx::Size(width, height), 33 return base::MakeUnique<ui::DisplayMode>(gfx::Size(width, height),
33 is_interlaced, refresh_rate); 34 is_interlaced, refresh_rate);
34 } 35 }
35 36
37 enum CallbackResult {
Daniel Erat 2016/10/25 16:05:33 i don't understand what you're verifying by checki
afakhry 2016/10/25 20:14:11 ResumeDisplays() can result in a delayed configura
Daniel Erat 2016/10/26 15:50:00 thanks for the detailed explanation! i understand
38 CALLBACK_FAILURE,
39 CALLBACK_SUCCESS,
40 CALLBACK_NOT_CALLED,
41 };
42
43 // The delay less than which we expect the configuration to be finished.
44 constexpr base::TimeDelta kMaxShortDelayMs = base::TimeDelta::FromMilliseconds(
45 DisplayConfigurator::kConfigureDelayMs / 3);
46
47 // The minimum configuration delay we expect when resuming while in 2+ display
48 // mode.
49 constexpr base::TimeDelta kMinLongDelayMs = base::TimeDelta::FromMilliseconds(
50 DisplayConfigurator::kResumeConfigureMultiDisplayDelayMs);
51
36 class TestObserver : public DisplayConfigurator::Observer { 52 class TestObserver : public DisplayConfigurator::Observer {
37 public: 53 public:
38 explicit TestObserver(DisplayConfigurator* configurator) 54 explicit TestObserver(DisplayConfigurator* configurator)
39 : configurator_(configurator) { 55 : configurator_(configurator) {
40 Reset(); 56 Reset();
41 configurator_->AddObserver(this); 57 configurator_->AddObserver(this);
42 } 58 }
43 ~TestObserver() override { configurator_->RemoveObserver(this); } 59 ~TestObserver() override { configurator_->RemoveObserver(this); }
44 60
45 int num_changes() const { return num_changes_; } 61 int num_changes() const { return num_changes_; }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 bool SoftwareMirroringEnabled() const override { 138 bool SoftwareMirroringEnabled() const override {
123 return software_mirroring_enabled_; 139 return software_mirroring_enabled_;
124 } 140 }
125 141
126 private: 142 private:
127 bool software_mirroring_enabled_; 143 bool software_mirroring_enabled_;
128 144
129 DISALLOW_COPY_AND_ASSIGN(TestMirroringController); 145 DISALLOW_COPY_AND_ASSIGN(TestMirroringController);
130 }; 146 };
131 147
148 // Abstracts waiting for the display configuration to be completed and getting
149 // the time it took to complete.
150 class ConfigurationWaiter {
151 public:
152 ConfigurationWaiter(DisplayConfigurator::TestApi* test_api)
153 : on_configured_callback_(base::Bind(&ConfigurationWaiter::OnConfigured,
154 base::Unretained(this))),
155 test_api_(test_api),
156 callback_result_(CALLBACK_NOT_CALLED),
157 pending_configuration_(true) {}
158
159 ~ConfigurationWaiter() = default;
160
161 void Reset() {
162 callback_result_ = CALLBACK_NOT_CALLED;
163 pending_configuration_ = true;
164 }
165
166 // Simulates Waiting for the configuration to complete by manually triggering
Daniel Erat 2016/10/25 16:05:32 nit: s/Waiting/waiting/
afakhry 2016/10/25 20:14:11 Done.
167 // the configuration timer and returns how long it was supposed to take for
168 // timer task to complete.
169 base::TimeDelta Wait() WARN_UNUSED_RESULT {
170 base::RunLoop().RunUntilIdle();
171 if (!pending_configuration_)
172 return base::TimeDelta();
173
174 const base::TimeDelta delay = test_api_->GetConfigureDelay();
175 if (!test_api_->TriggerConfigureTimeout())
176 return base::TimeDelta::Max();
177
178 return delay;
179 }
180
181 const DisplayConfigurator::ConfigurationCallback& on_configuration_callback()
182 const {
183 return on_configured_callback_;
184 }
185
186 CallbackResult callback_result() const { return callback_result_; }
187
188 private:
189 void OnConfigured(bool status) {
190 callback_result_ = status ? CALLBACK_SUCCESS : CALLBACK_FAILURE;
191
192 pending_configuration_ = false;
193 }
194
195 // The callback that should be used with the DisplayConfigurator calls to be
196 // invoked with the display configuration is done. It will always execute this
197 // waiter's OnConfigured().
198 const DisplayConfigurator::ConfigurationCallback on_configured_callback_;
199
200 DisplayConfigurator::TestApi* test_api_; // Not owned.
201
202 // The status of the display configuration.
203 CallbackResult callback_result_;
204
205 // True if we are expecting a display configuration completion, false if the
206 // configuration has already been completed.
207 bool pending_configuration_;
208
209 DISALLOW_COPY_AND_ASSIGN(ConfigurationWaiter);
210 };
211
132 class DisplayConfiguratorTest : public testing::Test { 212 class DisplayConfiguratorTest : public testing::Test {
133 public: 213 public:
134 enum CallbackResult {
135 CALLBACK_FAILURE,
136 CALLBACK_SUCCESS,
137 CALLBACK_NOT_CALLED,
138 };
139
140 DisplayConfiguratorTest() 214 DisplayConfiguratorTest()
141 : small_mode_(gfx::Size(1366, 768), false, 60.0f), 215 : small_mode_(gfx::Size(1366, 768), false, 60.0f),
142 big_mode_(gfx::Size(2560, 1600), false, 60.0f), 216 big_mode_(gfx::Size(2560, 1600), false, 60.0f),
143 observer_(&configurator_), 217 observer_(&configurator_),
144 test_api_(&configurator_), 218 test_api_(&configurator_),
219 config_waiter_(&test_api_),
145 enable_content_protection_status_(0), 220 enable_content_protection_status_(0),
146 enable_content_protection_call_count_(0), 221 enable_content_protection_call_count_(0),
147 query_content_protection_call_count_(0), 222 query_content_protection_call_count_(0),
148 callback_result_(CALLBACK_NOT_CALLED),
149 display_control_result_(CALLBACK_NOT_CALLED) {} 223 display_control_result_(CALLBACK_NOT_CALLED) {}
150 ~DisplayConfiguratorTest() override {} 224 ~DisplayConfiguratorTest() override {}
151 225
152 void SetUp() override { 226 void SetUp() override {
153 log_.reset(new ActionLogger()); 227 log_.reset(new ActionLogger());
154 228
155 native_display_delegate_ = new TestNativeDisplayDelegate(log_.get()); 229 native_display_delegate_ = new TestNativeDisplayDelegate(log_.get());
156 configurator_.SetDelegateForTesting( 230 configurator_.SetDelegateForTesting(
157 std::unique_ptr<NativeDisplayDelegate>(native_display_delegate_)); 231 std::unique_ptr<NativeDisplayDelegate>(native_display_delegate_));
158 232
(...skipping 21 matching lines...) Expand all
180 .SetId(kDisplayIds[2]) 254 .SetId(kDisplayIds[2])
181 .SetNativeMode(small_mode_.Clone()) 255 .SetNativeMode(small_mode_.Clone())
182 .SetCurrentMode(small_mode_.Clone()) 256 .SetCurrentMode(small_mode_.Clone())
183 .SetType(DISPLAY_CONNECTION_TYPE_HDMI) 257 .SetType(DISPLAY_CONNECTION_TYPE_HDMI)
184 .SetIsAspectPerservingScaling(true) 258 .SetIsAspectPerservingScaling(true)
185 .Build(); 259 .Build();
186 260
187 UpdateOutputs(2, false); 261 UpdateOutputs(2, false);
188 } 262 }
189 263
190 void OnConfiguredCallback(bool status) {
191 callback_result_ = (status ? CALLBACK_SUCCESS : CALLBACK_FAILURE);
192 }
193
194 void OnDisplayControlUpdated(bool status) { 264 void OnDisplayControlUpdated(bool status) {
195 display_control_result_ = (status ? CALLBACK_SUCCESS : CALLBACK_FAILURE); 265 display_control_result_ = (status ? CALLBACK_SUCCESS : CALLBACK_FAILURE);
196 } 266 }
197 267
198 void EnableContentProtectionCallback(bool status) { 268 void EnableContentProtectionCallback(bool status) {
199 enable_content_protection_status_ = status; 269 enable_content_protection_status_ = status;
200 enable_content_protection_call_count_++; 270 enable_content_protection_call_count_++;
201 } 271 }
202 272
203 void QueryContentProtectionCallback( 273 void QueryContentProtectionCallback(
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 EXPECT_EQ( 314 EXPECT_EQ(
245 JoinActions( 315 JoinActions(
246 kInitXRandR, kGrab, 316 kInitXRandR, kGrab,
247 GetFramebufferAction(small_mode_.size(), outputs_[0].get(), nullptr) 317 GetFramebufferAction(small_mode_.size(), outputs_[0].get(), nullptr)
248 .c_str(), 318 .c_str(),
249 GetCrtcAction(*outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), 319 GetCrtcAction(*outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(),
250 kForceDPMS, kUngrab, nullptr), 320 kForceDPMS, kUngrab, nullptr),
251 log_->GetActionsAndClear()); 321 log_->GetActionsAndClear());
252 } 322 }
253 323
254 CallbackResult PopCallbackResult() {
255 CallbackResult result = callback_result_;
256 callback_result_ = CALLBACK_NOT_CALLED;
257 return result;
258 }
259
260 CallbackResult PopDisplayControlResult() { 324 CallbackResult PopDisplayControlResult() {
261 CallbackResult result = display_control_result_; 325 CallbackResult result = display_control_result_;
262 display_control_result_ = CALLBACK_NOT_CALLED; 326 display_control_result_ = CALLBACK_NOT_CALLED;
263 return result; 327 return result;
264 } 328 }
265 329
266 base::MessageLoop message_loop_; 330 base::MessageLoop message_loop_;
267 TestStateController state_controller_; 331 TestStateController state_controller_;
268 TestMirroringController mirroring_controller_; 332 TestMirroringController mirroring_controller_;
269 DisplayConfigurator configurator_; 333 DisplayConfigurator configurator_;
270 TestObserver observer_; 334 TestObserver observer_;
271 std::unique_ptr<ActionLogger> log_; 335 std::unique_ptr<ActionLogger> log_;
272 TestNativeDisplayDelegate* native_display_delegate_; // not owned 336 TestNativeDisplayDelegate* native_display_delegate_; // not owned
273 DisplayConfigurator::TestApi test_api_; 337 DisplayConfigurator::TestApi test_api_;
274 338 ConfigurationWaiter config_waiter_;
275 bool enable_content_protection_status_; 339 bool enable_content_protection_status_;
276 int enable_content_protection_call_count_; 340 int enable_content_protection_call_count_;
277 DisplayConfigurator::QueryProtectionResponse 341 DisplayConfigurator::QueryProtectionResponse
278 query_content_protection_response_; 342 query_content_protection_response_;
279 int query_content_protection_call_count_; 343 int query_content_protection_call_count_;
280 344
281 std::unique_ptr<DisplaySnapshot> outputs_[3]; 345 std::unique_ptr<DisplaySnapshot> outputs_[3];
282 346
283 CallbackResult callback_result_;
284 CallbackResult display_control_result_; 347 CallbackResult display_control_result_;
285 348
286 private: 349 private:
287 DISALLOW_COPY_AND_ASSIGN(DisplayConfiguratorTest); 350 DISALLOW_COPY_AND_ASSIGN(DisplayConfiguratorTest);
288 }; 351 };
289 352
290 } // namespace 353 } // namespace
291 354
292 TEST_F(DisplayConfiguratorTest, FindDisplayModeMatchingSize) { 355 TEST_F(DisplayConfiguratorTest, FindDisplayModeMatchingSize) {
293 std::unique_ptr<ui::DisplaySnapshot> output = 356 std::unique_ptr<ui::DisplaySnapshot> output =
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 GetCrtcAction(*outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), 713 GetCrtcAction(*outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(),
651 GetCrtcAction(*outputs_[1], &small_mode_, gfx::Point(0, 0)).c_str(), 714 GetCrtcAction(*outputs_[1], &small_mode_, gfx::Point(0, 0)).c_str(),
652 kUngrab, nullptr), 715 kUngrab, nullptr),
653 log_->GetActionsAndClear()); 716 log_->GetActionsAndClear());
654 EXPECT_FALSE(mirroring_controller_.SoftwareMirroringEnabled()); 717 EXPECT_FALSE(mirroring_controller_.SoftwareMirroringEnabled());
655 EXPECT_EQ(1, observer_.num_changes()); 718 EXPECT_EQ(1, observer_.num_changes());
656 719
657 // Turning off the internal display should switch the external display to 720 // Turning off the internal display should switch the external display to
658 // its native mode. 721 // its native mode.
659 observer_.Reset(); 722 observer_.Reset();
723 config_waiter_.Reset();
660 configurator_.SetDisplayPower( 724 configurator_.SetDisplayPower(
661 chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, 725 chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON,
662 DisplayConfigurator::kSetDisplayPowerNoFlags, 726 DisplayConfigurator::kSetDisplayPowerNoFlags,
663 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, 727 config_waiter_.on_configuration_callback());
664 base::Unretained(this))); 728 EXPECT_LT(config_waiter_.Wait(), kMaxShortDelayMs);
665 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); 729 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter_.callback_result());
666 EXPECT_EQ( 730 EXPECT_EQ(
667 JoinActions( 731 JoinActions(
668 kGrab, GetFramebufferAction(big_mode_.size(), outputs_[0].get(), 732 kGrab, GetFramebufferAction(big_mode_.size(), outputs_[0].get(),
669 outputs_[1].get()) 733 outputs_[1].get())
670 .c_str(), 734 .c_str(),
671 GetCrtcAction(*outputs_[0], nullptr, gfx::Point(0, 0)).c_str(), 735 GetCrtcAction(*outputs_[0], nullptr, gfx::Point(0, 0)).c_str(),
672 GetCrtcAction(*outputs_[1], &big_mode_, gfx::Point(0, 0)).c_str(), 736 GetCrtcAction(*outputs_[1], &big_mode_, gfx::Point(0, 0)).c_str(),
673 kForceDPMS, kUngrab, nullptr), 737 kForceDPMS, kUngrab, nullptr),
674 log_->GetActionsAndClear()); 738 log_->GetActionsAndClear());
675 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_SINGLE, configurator_.display_state()); 739 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_SINGLE, configurator_.display_state());
676 EXPECT_EQ(1, observer_.num_changes()); 740 EXPECT_EQ(1, observer_.num_changes());
677 741
678 // When all displays are turned off, the framebuffer should switch back 742 // When all displays are turned off, the framebuffer should switch back
679 // to the mirrored size. 743 // to the mirrored size.
680 observer_.Reset(); 744 observer_.Reset();
681 configurator_.SetDisplayPower( 745 config_waiter_.Reset();
682 chromeos::DISPLAY_POWER_ALL_OFF, 746 configurator_.SetDisplayPower(chromeos::DISPLAY_POWER_ALL_OFF,
683 DisplayConfigurator::kSetDisplayPowerNoFlags, 747 DisplayConfigurator::kSetDisplayPowerNoFlags,
684 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, 748 config_waiter_.on_configuration_callback());
685 base::Unretained(this))); 749 EXPECT_LT(config_waiter_.Wait(), kMaxShortDelayMs);
686 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); 750 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter_.callback_result());
687 EXPECT_EQ( 751 EXPECT_EQ(
688 JoinActions( 752 JoinActions(
689 kGrab, GetFramebufferAction(small_mode_.size(), outputs_[0].get(), 753 kGrab, GetFramebufferAction(small_mode_.size(), outputs_[0].get(),
690 outputs_[1].get()) 754 outputs_[1].get())
691 .c_str(), 755 .c_str(),
692 GetCrtcAction(*outputs_[0], nullptr, gfx::Point(0, 0)).c_str(), 756 GetCrtcAction(*outputs_[0], nullptr, gfx::Point(0, 0)).c_str(),
693 GetCrtcAction(*outputs_[1], nullptr, gfx::Point(0, 0)).c_str(), 757 GetCrtcAction(*outputs_[1], nullptr, gfx::Point(0, 0)).c_str(),
694 kUngrab, nullptr), 758 kUngrab, nullptr),
695 log_->GetActionsAndClear()); 759 log_->GetActionsAndClear());
696 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_MIRROR, configurator_.display_state()); 760 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_MIRROR, configurator_.display_state());
697 EXPECT_FALSE(mirroring_controller_.SoftwareMirroringEnabled()); 761 EXPECT_FALSE(mirroring_controller_.SoftwareMirroringEnabled());
698 EXPECT_EQ(1, observer_.num_changes()); 762 EXPECT_EQ(1, observer_.num_changes());
699 763
700 // Turn all displays on and check that mirroring is still used. 764 // Turn all displays on and check that mirroring is still used.
701 observer_.Reset(); 765 observer_.Reset();
702 configurator_.SetDisplayPower( 766 config_waiter_.Reset();
703 chromeos::DISPLAY_POWER_ALL_ON, 767 configurator_.SetDisplayPower(chromeos::DISPLAY_POWER_ALL_ON,
704 DisplayConfigurator::kSetDisplayPowerNoFlags, 768 DisplayConfigurator::kSetDisplayPowerNoFlags,
705 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, 769 config_waiter_.on_configuration_callback());
706 base::Unretained(this))); 770 EXPECT_LT(config_waiter_.Wait(), kMaxShortDelayMs);
707 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); 771 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter_.callback_result());
708 EXPECT_EQ( 772 EXPECT_EQ(
709 JoinActions( 773 JoinActions(
710 kGrab, GetFramebufferAction(small_mode_.size(), outputs_[0].get(), 774 kGrab, GetFramebufferAction(small_mode_.size(), outputs_[0].get(),
711 outputs_[1].get()) 775 outputs_[1].get())
712 .c_str(), 776 .c_str(),
713 GetCrtcAction(*outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), 777 GetCrtcAction(*outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(),
714 GetCrtcAction(*outputs_[1], &small_mode_, gfx::Point(0, 0)).c_str(), 778 GetCrtcAction(*outputs_[1], &small_mode_, gfx::Point(0, 0)).c_str(),
715 kForceDPMS, kUngrab, nullptr), 779 kForceDPMS, kUngrab, nullptr),
716 log_->GetActionsAndClear()); 780 log_->GetActionsAndClear());
717 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_MIRROR, configurator_.display_state()); 781 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_MIRROR, configurator_.display_state());
(...skipping 29 matching lines...) Expand all
747 kUngrab, nullptr), 811 kUngrab, nullptr),
748 log_->GetActionsAndClear()); 812 log_->GetActionsAndClear());
749 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED, 813 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED,
750 configurator_.display_state()); 814 configurator_.display_state());
751 EXPECT_TRUE(mirroring_controller_.SoftwareMirroringEnabled()); 815 EXPECT_TRUE(mirroring_controller_.SoftwareMirroringEnabled());
752 EXPECT_EQ(1, observer_.num_changes()); 816 EXPECT_EQ(1, observer_.num_changes());
753 817
754 // Turning off the internal display should switch the external display to 818 // Turning off the internal display should switch the external display to
755 // its native mode. 819 // its native mode.
756 observer_.Reset(); 820 observer_.Reset();
821 config_waiter_.Reset();
757 configurator_.SetDisplayPower( 822 configurator_.SetDisplayPower(
758 chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, 823 chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON,
759 DisplayConfigurator::kSetDisplayPowerNoFlags, 824 DisplayConfigurator::kSetDisplayPowerNoFlags,
760 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, 825 config_waiter_.on_configuration_callback());
761 base::Unretained(this))); 826 EXPECT_LT(config_waiter_.Wait(), kMaxShortDelayMs);
762 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); 827 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter_.callback_result());
763 EXPECT_EQ( 828 EXPECT_EQ(
764 JoinActions( 829 JoinActions(
765 kGrab, GetFramebufferAction(big_mode_.size(), outputs_[0].get(), 830 kGrab, GetFramebufferAction(big_mode_.size(), outputs_[0].get(),
766 outputs_[1].get()) 831 outputs_[1].get())
767 .c_str(), 832 .c_str(),
768 GetCrtcAction(*outputs_[0], nullptr, gfx::Point(0, 0)).c_str(), 833 GetCrtcAction(*outputs_[0], nullptr, gfx::Point(0, 0)).c_str(),
769 GetCrtcAction(*outputs_[1], &big_mode_, gfx::Point(0, 0)).c_str(), 834 GetCrtcAction(*outputs_[1], &big_mode_, gfx::Point(0, 0)).c_str(),
770 kForceDPMS, kUngrab, nullptr), 835 kForceDPMS, kUngrab, nullptr),
771 log_->GetActionsAndClear()); 836 log_->GetActionsAndClear());
772 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_SINGLE, configurator_.display_state()); 837 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_SINGLE, configurator_.display_state());
773 EXPECT_FALSE(mirroring_controller_.SoftwareMirroringEnabled()); 838 EXPECT_FALSE(mirroring_controller_.SoftwareMirroringEnabled());
774 EXPECT_EQ(1, observer_.num_changes()); 839 EXPECT_EQ(1, observer_.num_changes());
775 840
776 // When all displays are turned off, the framebuffer should switch back 841 // When all displays are turned off, the framebuffer should switch back
777 // to the extended + software mirroring. 842 // to the extended + software mirroring.
778 observer_.Reset(); 843 observer_.Reset();
779 configurator_.SetDisplayPower( 844 config_waiter_.Reset();
780 chromeos::DISPLAY_POWER_ALL_OFF, 845 configurator_.SetDisplayPower(chromeos::DISPLAY_POWER_ALL_OFF,
781 DisplayConfigurator::kSetDisplayPowerNoFlags, 846 DisplayConfigurator::kSetDisplayPowerNoFlags,
782 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, 847 config_waiter_.on_configuration_callback());
783 base::Unretained(this))); 848 EXPECT_LT(config_waiter_.Wait(), kMaxShortDelayMs);
784 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); 849 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter_.callback_result());
785 EXPECT_EQ( 850 EXPECT_EQ(
786 JoinActions( 851 JoinActions(
787 kGrab, 852 kGrab,
788 GetFramebufferAction(gfx::Size(big_mode_.size().width(), kDualHeight), 853 GetFramebufferAction(gfx::Size(big_mode_.size().width(), kDualHeight),
789 outputs_[0].get(), outputs_[1].get()) 854 outputs_[0].get(), outputs_[1].get())
790 .c_str(), 855 .c_str(),
791 GetCrtcAction(*outputs_[0], nullptr, gfx::Point(0, 0)).c_str(), 856 GetCrtcAction(*outputs_[0], nullptr, gfx::Point(0, 0)).c_str(),
792 GetCrtcAction(*outputs_[1], nullptr, 857 GetCrtcAction(*outputs_[1], nullptr,
793 gfx::Point(0, small_mode_.size().height() + 858 gfx::Point(0, small_mode_.size().height() +
794 DisplayConfigurator::kVerticalGap)) 859 DisplayConfigurator::kVerticalGap))
795 .c_str(), 860 .c_str(),
796 kUngrab, nullptr), 861 kUngrab, nullptr),
797 log_->GetActionsAndClear()); 862 log_->GetActionsAndClear());
798 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED, 863 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED,
799 configurator_.display_state()); 864 configurator_.display_state());
800 EXPECT_TRUE(mirroring_controller_.SoftwareMirroringEnabled()); 865 EXPECT_TRUE(mirroring_controller_.SoftwareMirroringEnabled());
801 EXPECT_EQ(1, observer_.num_changes()); 866 EXPECT_EQ(1, observer_.num_changes());
802 867
803 // Turn all displays on and check that mirroring is still used. 868 // Turn all displays on and check that mirroring is still used.
804 observer_.Reset(); 869 observer_.Reset();
805 configurator_.SetDisplayPower( 870 config_waiter_.Reset();
806 chromeos::DISPLAY_POWER_ALL_ON, 871 configurator_.SetDisplayPower(chromeos::DISPLAY_POWER_ALL_ON,
807 DisplayConfigurator::kSetDisplayPowerNoFlags, 872 DisplayConfigurator::kSetDisplayPowerNoFlags,
808 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, 873 config_waiter_.on_configuration_callback());
809 base::Unretained(this))); 874 EXPECT_LT(config_waiter_.Wait(), kMaxShortDelayMs);
810 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); 875 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter_.callback_result());
811 EXPECT_EQ( 876 EXPECT_EQ(
812 JoinActions( 877 JoinActions(
813 kGrab, 878 kGrab,
814 GetFramebufferAction(gfx::Size(big_mode_.size().width(), kDualHeight), 879 GetFramebufferAction(gfx::Size(big_mode_.size().width(), kDualHeight),
815 outputs_[0].get(), outputs_[1].get()) 880 outputs_[0].get(), outputs_[1].get())
816 .c_str(), 881 .c_str(),
817 GetCrtcAction(*outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), 882 GetCrtcAction(*outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(),
818 GetCrtcAction(*outputs_[1], &big_mode_, 883 GetCrtcAction(*outputs_[1], &big_mode_,
819 gfx::Point(0, small_mode_.size().height() + 884 gfx::Point(0, small_mode_.size().height() +
820 DisplayConfigurator::kVerticalGap)) 885 DisplayConfigurator::kVerticalGap))
821 .c_str(), 886 .c_str(),
822 kForceDPMS, kUngrab, nullptr), 887 kForceDPMS, kUngrab, nullptr),
823 log_->GetActionsAndClear()); 888 log_->GetActionsAndClear());
824 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED, 889 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED,
825 configurator_.display_state()); 890 configurator_.display_state());
826 EXPECT_TRUE(mirroring_controller_.SoftwareMirroringEnabled()); 891 EXPECT_TRUE(mirroring_controller_.SoftwareMirroringEnabled());
827 EXPECT_EQ(1, observer_.num_changes()); 892 EXPECT_EQ(1, observer_.num_changes());
828 } 893 }
829 894
830 TEST_F(DisplayConfiguratorTest, SuspendAndResume) { 895 TEST_F(DisplayConfiguratorTest, SuspendAndResume) {
831 InitWithSingleOutput(); 896 InitWithSingleOutput();
832 897
833 // No preparation is needed before suspending when the display is already 898 // No preparation is needed before suspending when the display is already
834 // on. The configurator should still reprobe on resume in case a display 899 // on. The configurator should still reprobe on resume in case a display
835 // was connected while suspended. 900 // was connected while suspended.
836 const gfx::Size framebuffer_size = configurator_.framebuffer_size(); 901 const gfx::Size framebuffer_size = configurator_.framebuffer_size();
837 DCHECK(!framebuffer_size.IsEmpty()); 902 DCHECK(!framebuffer_size.IsEmpty());
838 configurator_.SuspendDisplays(base::Bind( 903 config_waiter_.Reset();
839 &DisplayConfiguratorTest::OnConfiguredCallback, base::Unretained(this))); 904 configurator_.SuspendDisplays(config_waiter_.on_configuration_callback());
840 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); 905 EXPECT_LT(config_waiter_.Wait(), kMaxShortDelayMs);
906 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter_.callback_result());
841 EXPECT_EQ(framebuffer_size.ToString(), 907 EXPECT_EQ(framebuffer_size.ToString(),
842 configurator_.framebuffer_size().ToString()); 908 configurator_.framebuffer_size().ToString());
843 EXPECT_EQ(JoinActions( 909 EXPECT_EQ(JoinActions(
844 kGrab, GetFramebufferAction(small_mode_.size(), 910 kGrab, GetFramebufferAction(small_mode_.size(),
845 outputs_[0].get(), nullptr) 911 outputs_[0].get(), nullptr)
846 .c_str(), 912 .c_str(),
847 GetCrtcAction(*outputs_[0], nullptr, gfx::Point(0, 0)).c_str(), 913 GetCrtcAction(*outputs_[0], nullptr, gfx::Point(0, 0)).c_str(),
848 kUngrab, kSync, nullptr), 914 kUngrab, kSync, nullptr),
849 log_->GetActionsAndClear()); 915 log_->GetActionsAndClear());
850 configurator_.ResumeDisplays(); 916
917 // No resume delay in single display mode.
918 config_waiter_.Reset();
919 configurator_.ResumeDisplays(config_waiter_.on_configuration_callback());
920 EXPECT_LT(config_waiter_.Wait(), kMaxShortDelayMs);
921 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter_.callback_result());
851 EXPECT_EQ( 922 EXPECT_EQ(
852 JoinActions( 923 JoinActions(
853 kGrab, 924 kGrab,
854 GetFramebufferAction(small_mode_.size(), outputs_[0].get(), nullptr) 925 GetFramebufferAction(small_mode_.size(), outputs_[0].get(), nullptr)
855 .c_str(), 926 .c_str(),
856 GetCrtcAction(*outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), 927 GetCrtcAction(*outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(),
857 kForceDPMS, kUngrab, nullptr), 928 kForceDPMS, kUngrab, nullptr),
858 log_->GetActionsAndClear()); 929 log_->GetActionsAndClear());
859 930
860 // Now turn the display off before suspending and check that the 931 // Now turn the display off before suspending and check that the
861 // configurator turns it back on and syncs with the server. 932 // configurator turns it back on and syncs with the server.
862 configurator_.SetDisplayPower( 933 config_waiter_.Reset();
863 chromeos::DISPLAY_POWER_ALL_OFF, 934 configurator_.SetDisplayPower(chromeos::DISPLAY_POWER_ALL_OFF,
864 DisplayConfigurator::kSetDisplayPowerNoFlags, 935 DisplayConfigurator::kSetDisplayPowerNoFlags,
865 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, 936 config_waiter_.on_configuration_callback());
866 base::Unretained(this))); 937 EXPECT_LT(config_waiter_.Wait(), kMaxShortDelayMs);
867 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); 938 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter_.callback_result());
868 EXPECT_EQ(JoinActions( 939 EXPECT_EQ(JoinActions(
869 kGrab, GetFramebufferAction(small_mode_.size(), 940 kGrab, GetFramebufferAction(small_mode_.size(),
870 outputs_[0].get(), nullptr) 941 outputs_[0].get(), nullptr)
871 .c_str(), 942 .c_str(),
872 GetCrtcAction(*outputs_[0], nullptr, gfx::Point(0, 0)).c_str(), 943 GetCrtcAction(*outputs_[0], nullptr, gfx::Point(0, 0)).c_str(),
873 kUngrab, nullptr), 944 kUngrab, nullptr),
874 log_->GetActionsAndClear()); 945 log_->GetActionsAndClear());
875 946
876 configurator_.SuspendDisplays(base::Bind( 947 config_waiter_.Reset();
877 &DisplayConfiguratorTest::OnConfiguredCallback, base::Unretained(this))); 948 configurator_.SuspendDisplays(config_waiter_.on_configuration_callback());
878 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); 949 EXPECT_LT(config_waiter_.Wait(), kMaxShortDelayMs);
950 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter_.callback_result());
879 EXPECT_EQ(kSync, log_->GetActionsAndClear()); 951 EXPECT_EQ(kSync, log_->GetActionsAndClear());
880 952
881 configurator_.ResumeDisplays(); 953 config_waiter_.Reset();
954 configurator_.ResumeDisplays(config_waiter_.on_configuration_callback());
955 EXPECT_LT(config_waiter_.Wait(), kMaxShortDelayMs);
956 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter_.callback_result());
882 EXPECT_EQ(kNoActions, log_->GetActionsAndClear()); 957 EXPECT_EQ(kNoActions, log_->GetActionsAndClear());
883 958
884 configurator_.SetDisplayPower( 959 config_waiter_.Reset();
885 chromeos::DISPLAY_POWER_ALL_ON, 960 configurator_.SetDisplayPower(chromeos::DISPLAY_POWER_ALL_ON,
886 DisplayConfigurator::kSetDisplayPowerNoFlags, 961 DisplayConfigurator::kSetDisplayPowerNoFlags,
887 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, 962 config_waiter_.on_configuration_callback());
888 base::Unretained(this))); 963 EXPECT_LT(config_waiter_.Wait(), kMaxShortDelayMs);
964 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter_.callback_result());
889 EXPECT_EQ( 965 EXPECT_EQ(
890 JoinActions( 966 JoinActions(
891 kGrab, 967 kGrab,
892 GetFramebufferAction(small_mode_.size(), outputs_[0].get(), nullptr) 968 GetFramebufferAction(small_mode_.size(), outputs_[0].get(), nullptr)
893 .c_str(), 969 .c_str(),
894 GetCrtcAction(*outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), 970 GetCrtcAction(*outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(),
895 kForceDPMS, kUngrab, nullptr), 971 kForceDPMS, kUngrab, nullptr),
896 log_->GetActionsAndClear()); 972 log_->GetActionsAndClear());
897 973
898 state_controller_.set_state(MULTIPLE_DISPLAY_STATE_DUAL_MIRROR); 974 state_controller_.set_state(MULTIPLE_DISPLAY_STATE_DUAL_MIRROR);
899 UpdateOutputs(2, true); 975 UpdateOutputs(2, true);
900 EXPECT_EQ( 976 EXPECT_EQ(
901 JoinActions( 977 JoinActions(
902 kGrab, GetFramebufferAction(small_mode_.size(), outputs_[0].get(), 978 kGrab, GetFramebufferAction(small_mode_.size(), outputs_[0].get(),
903 outputs_[1].get()) 979 outputs_[1].get())
904 .c_str(), 980 .c_str(),
905 GetCrtcAction(*outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), 981 GetCrtcAction(*outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(),
906 GetCrtcAction(*outputs_[1], &small_mode_, gfx::Point(0, 0)).c_str(), 982 GetCrtcAction(*outputs_[1], &small_mode_, gfx::Point(0, 0)).c_str(),
907 kUngrab, nullptr), 983 kUngrab, nullptr),
908 log_->GetActionsAndClear()); 984 log_->GetActionsAndClear());
909 985
910 configurator_.SetDisplayPower( 986 config_waiter_.Reset();
911 chromeos::DISPLAY_POWER_ALL_OFF, 987 configurator_.SetDisplayPower(chromeos::DISPLAY_POWER_ALL_OFF,
912 DisplayConfigurator::kSetDisplayPowerNoFlags, 988 DisplayConfigurator::kSetDisplayPowerNoFlags,
913 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, 989 config_waiter_.on_configuration_callback());
914 base::Unretained(this))); 990 EXPECT_LT(config_waiter_.Wait(), kMaxShortDelayMs);
915 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); 991 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter_.callback_result());
992 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_MIRROR, configurator_.display_state());
916 EXPECT_EQ( 993 EXPECT_EQ(
917 JoinActions( 994 JoinActions(
918 kGrab, GetFramebufferAction(small_mode_.size(), outputs_[0].get(), 995 kGrab, GetFramebufferAction(small_mode_.size(), outputs_[0].get(),
919 outputs_[1].get()) 996 outputs_[1].get())
920 .c_str(), 997 .c_str(),
921 GetCrtcAction(*outputs_[0], nullptr, gfx::Point(0, 0)).c_str(), 998 GetCrtcAction(*outputs_[0], nullptr, gfx::Point(0, 0)).c_str(),
922 GetCrtcAction(*outputs_[1], nullptr, gfx::Point(0, 0)).c_str(), 999 GetCrtcAction(*outputs_[1], nullptr, gfx::Point(0, 0)).c_str(),
923 kUngrab, nullptr), 1000 kUngrab, nullptr),
924 log_->GetActionsAndClear()); 1001 log_->GetActionsAndClear());
925 1002
926 configurator_.SuspendDisplays(base::Bind( 1003 // No delay in suspend.
927 &DisplayConfiguratorTest::OnConfiguredCallback, base::Unretained(this))); 1004 config_waiter_.Reset();
928 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); 1005 configurator_.SuspendDisplays(config_waiter_.on_configuration_callback());
1006 EXPECT_LT(config_waiter_.Wait(), kMaxShortDelayMs);
1007 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter_.callback_result());
1008 EXPECT_EQ(chromeos::DISPLAY_POWER_ALL_OFF,
1009 configurator_.current_power_state());
1010 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_MIRROR, configurator_.display_state());
929 EXPECT_EQ(kSync, log_->GetActionsAndClear()); 1011 EXPECT_EQ(kSync, log_->GetActionsAndClear());
930 1012
931 // If a display is disconnected while suspended, the configurator should 1013 // If a display is disconnected while suspended, the configurator should
932 // pick up the change and only turn on the internal display. 1014 // pick up the change and only turn on the internal display. The should be
1015 // a longer configuration delay when we set the displays back to on.
933 UpdateOutputs(1, false); 1016 UpdateOutputs(1, false);
934 configurator_.ResumeDisplays(); 1017 config_waiter_.Reset();
1018 configurator_.ResumeDisplays(config_waiter_.on_configuration_callback());
1019 EXPECT_LT(config_waiter_.Wait(), kMaxShortDelayMs);
1020 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter_.callback_result());
935 EXPECT_EQ(kNoActions, log_->GetActionsAndClear()); 1021 EXPECT_EQ(kNoActions, log_->GetActionsAndClear());
936 1022
937 configurator_.SetDisplayPower( 1023 config_waiter_.Reset();
938 chromeos::DISPLAY_POWER_ALL_ON, 1024 configurator_.SetDisplayPower(chromeos::DISPLAY_POWER_ALL_ON,
939 DisplayConfigurator::kSetDisplayPowerNoFlags, 1025 DisplayConfigurator::kSetDisplayPowerNoFlags,
940 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, 1026 config_waiter_.on_configuration_callback());
941 base::Unretained(this))); 1027 EXPECT_GE(config_waiter_.Wait(), kMinLongDelayMs);
1028 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter_.callback_result());
942 EXPECT_EQ( 1029 EXPECT_EQ(
943 JoinActions( 1030 JoinActions(
944 kGrab, 1031 kGrab,
945 GetFramebufferAction(small_mode_.size(), outputs_[0].get(), nullptr) 1032 GetFramebufferAction(small_mode_.size(), outputs_[0].get(), nullptr)
946 .c_str(), 1033 .c_str(),
947 GetCrtcAction(*outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), 1034 GetCrtcAction(*outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(),
948 kForceDPMS, kUngrab, nullptr), 1035 kForceDPMS, kUngrab, nullptr),
949 log_->GetActionsAndClear()); 1036 log_->GetActionsAndClear());
950 } 1037 }
951 1038
952 TEST_F(DisplayConfiguratorTest, Headless) { 1039 TEST_F(DisplayConfiguratorTest, Headless) {
953 UpdateOutputs(0, false); 1040 UpdateOutputs(0, false);
954 EXPECT_EQ(kNoActions, log_->GetActionsAndClear()); 1041 EXPECT_EQ(kNoActions, log_->GetActionsAndClear());
955 Init(false); 1042 Init(false);
956 EXPECT_EQ(kNoActions, log_->GetActionsAndClear()); 1043 EXPECT_EQ(kNoActions, log_->GetActionsAndClear());
957 configurator_.ForceInitialConfigure(0); 1044 configurator_.ForceInitialConfigure(0);
958 EXPECT_EQ(JoinActions(kInitXRandR, kGrab, kForceDPMS, kUngrab, nullptr), 1045 EXPECT_EQ(JoinActions(kInitXRandR, kGrab, kForceDPMS, kUngrab, nullptr),
959 log_->GetActionsAndClear()); 1046 log_->GetActionsAndClear());
960 1047
961 // Not much should happen when the display power state is changed while 1048 // Not much should happen when the display power state is changed while
962 // no displays are connected. 1049 // no displays are connected.
963 configurator_.SetDisplayPower( 1050 config_waiter_.Reset();
964 chromeos::DISPLAY_POWER_ALL_OFF, 1051 configurator_.SetDisplayPower(chromeos::DISPLAY_POWER_ALL_OFF,
965 DisplayConfigurator::kSetDisplayPowerNoFlags, 1052 DisplayConfigurator::kSetDisplayPowerNoFlags,
966 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, 1053 config_waiter_.on_configuration_callback());
967 base::Unretained(this))); 1054 EXPECT_LT(config_waiter_.Wait(), kMaxShortDelayMs);
968 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); 1055 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter_.callback_result());
969 EXPECT_EQ(JoinActions(kGrab, kUngrab, nullptr), log_->GetActionsAndClear()); 1056 EXPECT_EQ(JoinActions(kGrab, kUngrab, nullptr), log_->GetActionsAndClear());
970 configurator_.SetDisplayPower( 1057 config_waiter_.Reset();
971 chromeos::DISPLAY_POWER_ALL_ON, 1058 configurator_.SetDisplayPower(chromeos::DISPLAY_POWER_ALL_ON,
972 DisplayConfigurator::kSetDisplayPowerNoFlags, 1059 DisplayConfigurator::kSetDisplayPowerNoFlags,
973 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, 1060 config_waiter_.on_configuration_callback());
974 base::Unretained(this))); 1061 EXPECT_LT(config_waiter_.Wait(), kMaxShortDelayMs);
975 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); 1062 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter_.callback_result());
976 EXPECT_EQ(JoinActions(kGrab, kForceDPMS, kUngrab, nullptr), 1063 EXPECT_EQ(JoinActions(kGrab, kForceDPMS, kUngrab, nullptr),
977 log_->GetActionsAndClear()); 1064 log_->GetActionsAndClear());
978 1065
979 // Connect an external display and check that it's configured correctly. 1066 // Connect an external display and check that it's configured correctly.
980 outputs_[0] = display::FakeDisplaySnapshot::Builder() 1067 outputs_[0] = display::FakeDisplaySnapshot::Builder()
981 .SetId(kDisplayIds[0]) 1068 .SetId(kDisplayIds[0])
982 .SetNativeMode(big_mode_.Clone()) 1069 .SetNativeMode(big_mode_.Clone())
983 .SetCurrentMode(big_mode_.Clone()) 1070 .SetCurrentMode(big_mode_.Clone())
984 .AddMode(small_mode_.Clone()) 1071 .AddMode(small_mode_.Clone())
985 .SetType(DISPLAY_CONNECTION_TYPE_INTERNAL) 1072 .SetType(DISPLAY_CONNECTION_TYPE_INTERNAL)
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
1209 log_->GetActionsAndClear()); 1296 log_->GetActionsAndClear());
1210 } 1297 }
1211 1298
1212 TEST_F(DisplayConfiguratorTest, DoNotConfigureWithSuspendedDisplays) { 1299 TEST_F(DisplayConfiguratorTest, DoNotConfigureWithSuspendedDisplays) {
1213 InitWithSingleOutput(); 1300 InitWithSingleOutput();
1214 1301
1215 // The DisplayConfigurator may occasionally receive OnConfigurationChanged() 1302 // The DisplayConfigurator may occasionally receive OnConfigurationChanged()
1216 // after the displays have been suspended. This event should be ignored since 1303 // after the displays have been suspended. This event should be ignored since
1217 // the DisplayConfigurator will force a probe and reconfiguration of displays 1304 // the DisplayConfigurator will force a probe and reconfiguration of displays
1218 // at resume time. 1305 // at resume time.
1219 configurator_.SuspendDisplays(base::Bind( 1306 config_waiter_.Reset();
1220 &DisplayConfiguratorTest::OnConfiguredCallback, base::Unretained(this))); 1307 configurator_.SuspendDisplays(config_waiter_.on_configuration_callback());
1221 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); 1308 EXPECT_LT(config_waiter_.Wait(), kMaxShortDelayMs);
1309 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter_.callback_result());
1222 EXPECT_EQ(JoinActions( 1310 EXPECT_EQ(JoinActions(
1223 kGrab, GetFramebufferAction(small_mode_.size(), 1311 kGrab, GetFramebufferAction(small_mode_.size(),
1224 outputs_[0].get(), nullptr) 1312 outputs_[0].get(), nullptr)
1225 .c_str(), 1313 .c_str(),
1226 GetCrtcAction(*outputs_[0], nullptr, gfx::Point(0, 0)).c_str(), 1314 GetCrtcAction(*outputs_[0], nullptr, gfx::Point(0, 0)).c_str(),
1227 kUngrab, kSync, nullptr), 1315 kUngrab, kSync, nullptr),
1228 log_->GetActionsAndClear()); 1316 log_->GetActionsAndClear());
1229 1317
1230 // The configuration timer should not be started when the displays 1318 // The configuration timer should not be started when the displays
1231 // are suspended. 1319 // are suspended.
1232 configurator_.OnConfigurationChanged(); 1320 configurator_.OnConfigurationChanged();
1233 EXPECT_FALSE(test_api_.TriggerConfigureTimeout()); 1321 EXPECT_FALSE(test_api_.TriggerConfigureTimeout());
1234 EXPECT_EQ(kNoActions, log_->GetActionsAndClear()); 1322 EXPECT_EQ(kNoActions, log_->GetActionsAndClear());
1235 1323
1236 // Calls to SetDisplayPower should do nothing if the power state doesn't 1324 // Calls to SetDisplayPower should do nothing if the power state doesn't
1237 // change. 1325 // change.
1238 configurator_.SetDisplayPower( 1326 config_waiter_.Reset();
1239 chromeos::DISPLAY_POWER_ALL_OFF, 1327 configurator_.SetDisplayPower(chromeos::DISPLAY_POWER_ALL_OFF,
1240 DisplayConfigurator::kSetDisplayPowerNoFlags, 1328 DisplayConfigurator::kSetDisplayPowerNoFlags,
1241 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, 1329 config_waiter_.on_configuration_callback());
1242 base::Unretained(this))); 1330 EXPECT_LT(config_waiter_.Wait(), kMaxShortDelayMs);
1243 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); 1331 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter_.callback_result());
1244 EXPECT_EQ(kNoActions, log_->GetActionsAndClear()); 1332 EXPECT_EQ(kNoActions, log_->GetActionsAndClear());
1245 configurator_.SetDisplayPower( 1333 config_waiter_.Reset();
1246 chromeos::DISPLAY_POWER_ALL_ON, 1334 configurator_.SetDisplayPower(chromeos::DISPLAY_POWER_ALL_ON,
1247 DisplayConfigurator::kSetDisplayPowerNoFlags, 1335 DisplayConfigurator::kSetDisplayPowerNoFlags,
1248 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, 1336 config_waiter_.on_configuration_callback());
1249 base::Unretained(this))); 1337 EXPECT_LT(config_waiter_.Wait(), kMaxShortDelayMs);
1250 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); 1338 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter_.callback_result());
1251 EXPECT_EQ( 1339 EXPECT_EQ(
1252 JoinActions( 1340 JoinActions(
1253 kGrab, 1341 kGrab,
1254 GetFramebufferAction(small_mode_.size(), outputs_[0].get(), nullptr) 1342 GetFramebufferAction(small_mode_.size(), outputs_[0].get(), nullptr)
1255 .c_str(), 1343 .c_str(),
1256 GetCrtcAction(*outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), 1344 GetCrtcAction(*outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(),
1257 kForceDPMS, kUngrab, nullptr), 1345 kForceDPMS, kUngrab, nullptr),
1258 log_->GetActionsAndClear()); 1346 log_->GetActionsAndClear());
1259 1347
1260 UpdateOutputs(2, false); 1348 UpdateOutputs(2, false);
1261 configurator_.SetDisplayMode(MULTIPLE_DISPLAY_STATE_DUAL_MIRROR); 1349 configurator_.SetDisplayMode(MULTIPLE_DISPLAY_STATE_DUAL_MIRROR);
1262 EXPECT_EQ( 1350 EXPECT_EQ(
1263 JoinActions( 1351 JoinActions(
1264 kGrab, GetFramebufferAction(small_mode_.size(), outputs_[0].get(), 1352 kGrab, GetFramebufferAction(small_mode_.size(), outputs_[0].get(),
1265 outputs_[1].get()) 1353 outputs_[1].get())
1266 .c_str(), 1354 .c_str(),
1267 GetCrtcAction(*outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), 1355 GetCrtcAction(*outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(),
1268 GetCrtcAction(*outputs_[1], &small_mode_, gfx::Point(0, 0)).c_str(), 1356 GetCrtcAction(*outputs_[1], &small_mode_, gfx::Point(0, 0)).c_str(),
1269 kUngrab, nullptr), 1357 kUngrab, nullptr),
1270 log_->GetActionsAndClear()); 1358 log_->GetActionsAndClear());
1271 1359
1272 // The DisplayConfigurator should do nothing at resume time if there is no 1360 // The DisplayConfigurator should do nothing at resume time if there is no
1273 // state change. 1361 // state change.
1362 config_waiter_.Reset();
1274 UpdateOutputs(1, false); 1363 UpdateOutputs(1, false);
1275 configurator_.ResumeDisplays(); 1364 configurator_.ResumeDisplays(config_waiter_.on_configuration_callback());
1365 EXPECT_LT(config_waiter_.Wait(), kMaxShortDelayMs);
1366 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter_.callback_result());
1276 EXPECT_EQ(kNoActions, log_->GetActionsAndClear()); 1367 EXPECT_EQ(kNoActions, log_->GetActionsAndClear());
1277 1368
1278 // If a configuration task is pending when the displays are suspended, that 1369 // If a configuration task is pending when the displays are suspended, that
1279 // task should not run either and the timer should be stopped. The displays 1370 // task should not run either and the timer should be stopped. The displays
1280 // should be turned off by suspend. 1371 // should be turned off by suspend.
1281 configurator_.OnConfigurationChanged(); 1372 configurator_.OnConfigurationChanged();
1282 configurator_.SuspendDisplays(base::Bind( 1373 config_waiter_.Reset();
1283 &DisplayConfiguratorTest::OnConfiguredCallback, base::Unretained(this))); 1374 configurator_.SuspendDisplays(config_waiter_.on_configuration_callback());
1284 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); 1375 EXPECT_LT(config_waiter_.Wait(), kMaxShortDelayMs);
1376 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter_.callback_result());
1285 EXPECT_EQ(JoinActions( 1377 EXPECT_EQ(JoinActions(
1286 kGrab, GetFramebufferAction(small_mode_.size(), 1378 kGrab, GetFramebufferAction(small_mode_.size(),
1287 outputs_[0].get(), nullptr) 1379 outputs_[0].get(), nullptr)
1288 .c_str(), 1380 .c_str(),
1289 GetCrtcAction(*outputs_[0], nullptr, gfx::Point(0, 0)).c_str(), 1381 GetCrtcAction(*outputs_[0], nullptr, gfx::Point(0, 0)).c_str(),
1290 kUngrab, kSync, nullptr), 1382 kUngrab, kSync, nullptr),
1291 log_->GetActionsAndClear()); 1383 log_->GetActionsAndClear());
1292
1293 EXPECT_FALSE(test_api_.TriggerConfigureTimeout()); 1384 EXPECT_FALSE(test_api_.TriggerConfigureTimeout());
1294 EXPECT_EQ(kNoActions, log_->GetActionsAndClear()); 1385 EXPECT_EQ(kNoActions, log_->GetActionsAndClear());
1295 1386
1296 configurator_.ResumeDisplays(); 1387 config_waiter_.Reset();
1388 configurator_.ResumeDisplays(config_waiter_.on_configuration_callback());
1389 EXPECT_LT(config_waiter_.Wait(), kMaxShortDelayMs);
1390 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter_.callback_result());
1297 EXPECT_EQ( 1391 EXPECT_EQ(
1298 JoinActions( 1392 JoinActions(
1299 kGrab, 1393 kGrab,
1300 GetFramebufferAction(small_mode_.size(), outputs_[0].get(), nullptr) 1394 GetFramebufferAction(small_mode_.size(), outputs_[0].get(), nullptr)
1301 .c_str(), 1395 .c_str(),
1302 GetCrtcAction(*outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), 1396 GetCrtcAction(*outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(),
1303 kForceDPMS, kUngrab, nullptr), 1397 kForceDPMS, kUngrab, nullptr),
1304 log_->GetActionsAndClear()); 1398 log_->GetActionsAndClear());
1305 } 1399 }
1306 1400
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
1520 state_controller_.set_state(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED); 1614 state_controller_.set_state(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED);
1521 Init(false); 1615 Init(false);
1522 configurator_.ForceInitialConfigure(0); 1616 configurator_.ForceInitialConfigure(0);
1523 log_->GetActionsAndClear(); 1617 log_->GetActionsAndClear();
1524 observer_.Reset(); 1618 observer_.Reset();
1525 1619
1526 // Turn off the internal display, simulating docked mode. 1620 // Turn off the internal display, simulating docked mode.
1527 configurator_.SetDisplayPower( 1621 configurator_.SetDisplayPower(
1528 chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, 1622 chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON,
1529 DisplayConfigurator::kSetDisplayPowerNoFlags, 1623 DisplayConfigurator::kSetDisplayPowerNoFlags,
1530 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, 1624 config_waiter_.on_configuration_callback());
1531 base::Unretained(this))); 1625 EXPECT_LT(config_waiter_.Wait(), kMaxShortDelayMs);
1532 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); 1626 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter_.callback_result());
1533 EXPECT_EQ(1, observer_.num_changes()); 1627 EXPECT_EQ(1, observer_.num_changes());
1534 EXPECT_EQ(0, observer_.num_failures()); 1628 EXPECT_EQ(0, observer_.num_failures());
1535 log_->GetActionsAndClear(); 1629 log_->GetActionsAndClear();
1536 1630
1537 // Make all subsequent configuration requests fail and try to turn the 1631 // Make all subsequent configuration requests fail and try to turn the
1538 // internal display back on. 1632 // internal display back on.
1539 native_display_delegate_->set_max_configurable_pixels(1); 1633 native_display_delegate_->set_max_configurable_pixels(1);
1540 configurator_.SetDisplayPower( 1634 configurator_.SetDisplayPower(chromeos::DISPLAY_POWER_ALL_ON,
1541 chromeos::DISPLAY_POWER_ALL_ON, 1635 DisplayConfigurator::kSetDisplayPowerNoFlags,
1542 DisplayConfigurator::kSetDisplayPowerNoFlags, 1636 config_waiter_.on_configuration_callback());
1543 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, 1637 EXPECT_LT(config_waiter_.Wait(), kMaxShortDelayMs);
1544 base::Unretained(this))); 1638 EXPECT_EQ(CALLBACK_FAILURE, config_waiter_.callback_result());
1545 EXPECT_EQ(CALLBACK_FAILURE, PopCallbackResult());
1546 EXPECT_EQ(1, observer_.num_changes()); 1639 EXPECT_EQ(1, observer_.num_changes());
1547 EXPECT_EQ(1, observer_.num_failures()); 1640 EXPECT_EQ(1, observer_.num_failures());
1548 log_->GetActionsAndClear(); 1641 log_->GetActionsAndClear();
1549 1642
1550 // Simulate the external display getting disconnected and check that the 1643 // Simulate the external display getting disconnected and check that the
1551 // internal display is turned on (i.e. DISPLAY_POWER_ALL_ON is used) rather 1644 // internal display is turned on (i.e. DISPLAY_POWER_ALL_ON is used) rather
1552 // than the earlier DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON state. 1645 // than the earlier DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON state.
1553 native_display_delegate_->set_max_configurable_pixels(0); 1646 native_display_delegate_->set_max_configurable_pixels(0);
1554 UpdateOutputs(1, true); 1647 UpdateOutputs(1, true);
1555 EXPECT_EQ( 1648 EXPECT_EQ(
(...skipping 14 matching lines...) Expand all
1570 state_controller_.set_state(MULTIPLE_DISPLAY_STATE_DUAL_MIRROR); 1663 state_controller_.set_state(MULTIPLE_DISPLAY_STATE_DUAL_MIRROR);
1571 Init(false); 1664 Init(false);
1572 configurator_.ForceInitialConfigure(0); 1665 configurator_.ForceInitialConfigure(0);
1573 log_->GetActionsAndClear(); 1666 log_->GetActionsAndClear();
1574 observer_.Reset(); 1667 observer_.Reset();
1575 1668
1576 // Turn off the internal display, simulating docked mode. 1669 // Turn off the internal display, simulating docked mode.
1577 configurator_.SetDisplayPower( 1670 configurator_.SetDisplayPower(
1578 chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, 1671 chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON,
1579 DisplayConfigurator::kSetDisplayPowerNoFlags, 1672 DisplayConfigurator::kSetDisplayPowerNoFlags,
1580 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, 1673 config_waiter_.on_configuration_callback());
1581 base::Unretained(this))); 1674 EXPECT_LT(config_waiter_.Wait(), kMaxShortDelayMs);
1582 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); 1675 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter_.callback_result());
1583 EXPECT_EQ(1, observer_.num_changes()); 1676 EXPECT_EQ(1, observer_.num_changes());
1584 EXPECT_EQ(0, observer_.num_failures()); 1677 EXPECT_EQ(0, observer_.num_failures());
1585 EXPECT_EQ( 1678 EXPECT_EQ(
1586 JoinActions( 1679 JoinActions(
1587 kGrab, GetFramebufferAction(big_mode_.size(), outputs_[0].get(), 1680 kGrab, GetFramebufferAction(big_mode_.size(), outputs_[0].get(),
1588 outputs_[1].get()) 1681 outputs_[1].get())
1589 .c_str(), 1682 .c_str(),
1590 GetCrtcAction(*outputs_[0], nullptr, gfx::Point(0, 0)).c_str(), 1683 GetCrtcAction(*outputs_[0], nullptr, gfx::Point(0, 0)).c_str(),
1591 GetCrtcAction(*outputs_[1], &big_mode_, gfx::Point(0, 0)).c_str(), 1684 GetCrtcAction(*outputs_[1], &big_mode_, gfx::Point(0, 0)).c_str(),
1592 kForceDPMS, kUngrab, nullptr), 1685 kForceDPMS, kUngrab, nullptr),
1593 log_->GetActionsAndClear()); 1686 log_->GetActionsAndClear());
1594 1687
1595 // Suspend and resume the system. Resuming should restore the previous power 1688 // Suspend and resume the system. Resuming should restore the previous power
1596 // state and force a probe. Suspend should turn off the displays since an 1689 // state and force a probe. Suspend should turn off the displays since an
1597 // external monitor is connected. 1690 // external monitor is connected.
1598 configurator_.SuspendDisplays(base::Bind( 1691 config_waiter_.Reset();
1599 &DisplayConfiguratorTest::OnConfiguredCallback, base::Unretained(this))); 1692 configurator_.SuspendDisplays(config_waiter_.on_configuration_callback());
1600 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); 1693 EXPECT_LT(config_waiter_.Wait(), kMaxShortDelayMs);
1694 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter_.callback_result());
1601 EXPECT_EQ(2, observer_.num_changes()); 1695 EXPECT_EQ(2, observer_.num_changes());
1602 EXPECT_EQ( 1696 EXPECT_EQ(
1603 JoinActions( 1697 JoinActions(
1604 kGrab, GetFramebufferAction(small_mode_.size(), outputs_[0].get(), 1698 kGrab, GetFramebufferAction(small_mode_.size(), outputs_[0].get(),
1605 outputs_[1].get()) 1699 outputs_[1].get())
1606 .c_str(), 1700 .c_str(),
1607 GetCrtcAction(*outputs_[0], nullptr, gfx::Point(0, 0)).c_str(), 1701 GetCrtcAction(*outputs_[0], nullptr, gfx::Point(0, 0)).c_str(),
1608 GetCrtcAction(*outputs_[1], nullptr, gfx::Point(0, 0)).c_str(), 1702 GetCrtcAction(*outputs_[1], nullptr, gfx::Point(0, 0)).c_str(),
1609 kUngrab, kSync, nullptr), 1703 kUngrab, kSync, nullptr),
1610 log_->GetActionsAndClear()); 1704 log_->GetActionsAndClear());
1611 1705
1612 // Before the task runs, exit docked mode. 1706 // Before the task runs, exit docked mode.
1613 configurator_.SetDisplayPower( 1707 config_waiter_.Reset();
1614 chromeos::DISPLAY_POWER_ALL_ON, 1708 configurator_.SetDisplayPower(chromeos::DISPLAY_POWER_ALL_ON,
1615 DisplayConfigurator::kSetDisplayPowerNoFlags, 1709 DisplayConfigurator::kSetDisplayPowerNoFlags,
1616 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, 1710 config_waiter_.on_configuration_callback());
1617 base::Unretained(this))); 1711 EXPECT_LT(config_waiter_.Wait(), kMaxShortDelayMs);
1618 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); 1712 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter_.callback_result());
1619 EXPECT_EQ(3, observer_.num_changes()); 1713 EXPECT_EQ(3, observer_.num_changes());
1620 EXPECT_EQ(0, observer_.num_failures()); 1714 EXPECT_EQ(0, observer_.num_failures());
1621 EXPECT_EQ( 1715 EXPECT_EQ(
1622 JoinActions( 1716 JoinActions(
1623 kGrab, GetFramebufferAction(small_mode_.size(), outputs_[0].get(), 1717 kGrab, GetFramebufferAction(small_mode_.size(), outputs_[0].get(),
1624 outputs_[1].get()) 1718 outputs_[1].get())
1625 .c_str(), 1719 .c_str(),
1626 GetCrtcAction(*outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), 1720 GetCrtcAction(*outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(),
1627 GetCrtcAction(*outputs_[1], &small_mode_, gfx::Point(0, 0)).c_str(), 1721 GetCrtcAction(*outputs_[1], &small_mode_, gfx::Point(0, 0)).c_str(),
1628 kForceDPMS, kUngrab, nullptr), 1722 kForceDPMS, kUngrab, nullptr),
1629 log_->GetActionsAndClear()); 1723 log_->GetActionsAndClear());
1630 1724
1631 // Check that the display states are not changed after resuming. 1725 // Check that the display states are not changed after resuming.
1632 configurator_.ResumeDisplays(); 1726 config_waiter_.Reset();
1727 configurator_.ResumeDisplays(config_waiter_.on_configuration_callback());
1728 EXPECT_LT(config_waiter_.Wait(), kMaxShortDelayMs);
1729 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter_.callback_result());
1730 EXPECT_EQ(chromeos::DISPLAY_POWER_ALL_ON,
1731 configurator_.current_power_state());
1633 EXPECT_EQ(kNoActions, log_->GetActionsAndClear()); 1732 EXPECT_EQ(kNoActions, log_->GetActionsAndClear());
1634 } 1733 }
1635 1734
1636 TEST_F(DisplayConfiguratorTest, ExternalControl) { 1735 TEST_F(DisplayConfiguratorTest, ExternalControl) {
1637 InitWithSingleOutput(); 1736 InitWithSingleOutput();
1638 state_controller_.set_state(MULTIPLE_DISPLAY_STATE_SINGLE); 1737 state_controller_.set_state(MULTIPLE_DISPLAY_STATE_SINGLE);
1639 configurator_.RelinquishControl( 1738 configurator_.RelinquishControl(
1640 base::Bind(&DisplayConfiguratorTest::OnDisplayControlUpdated, 1739 base::Bind(&DisplayConfiguratorTest::OnDisplayControlUpdated,
1641 base::Unretained(this))); 1740 base::Unretained(this)));
1642 EXPECT_EQ(CALLBACK_SUCCESS, PopDisplayControlResult()); 1741 EXPECT_EQ(CALLBACK_SUCCESS, PopDisplayControlResult());
(...skipping 17 matching lines...) Expand all
1660 SetDisplayPowerWhilePendingConfigurationTaskRunning) { 1759 SetDisplayPowerWhilePendingConfigurationTaskRunning) {
1661 // Start out with two displays in extended mode. 1760 // Start out with two displays in extended mode.
1662 state_controller_.set_state(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED); 1761 state_controller_.set_state(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED);
1663 Init(false); 1762 Init(false);
1664 configurator_.ForceInitialConfigure(0); 1763 configurator_.ForceInitialConfigure(0);
1665 log_->GetActionsAndClear(); 1764 log_->GetActionsAndClear();
1666 observer_.Reset(); 1765 observer_.Reset();
1667 1766
1668 native_display_delegate_->set_run_async(true); 1767 native_display_delegate_->set_run_async(true);
1669 1768
1670 configurator_.SetDisplayPower( 1769 config_waiter_.Reset();
1671 chromeos::DISPLAY_POWER_ALL_OFF, 1770 configurator_.SetDisplayPower(chromeos::DISPLAY_POWER_ALL_OFF,
1672 DisplayConfigurator::kSetDisplayPowerNoFlags, 1771 DisplayConfigurator::kSetDisplayPowerNoFlags,
1673 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, 1772 config_waiter_.on_configuration_callback());
1674 base::Unretained(this)));
1675 1773
1676 configurator_.SetDisplayPower( 1774 configurator_.SetDisplayPower(chromeos::DISPLAY_POWER_ALL_ON,
1677 chromeos::DISPLAY_POWER_ALL_ON, 1775 DisplayConfigurator::kSetDisplayPowerNoFlags,
1678 DisplayConfigurator::kSetDisplayPowerNoFlags, 1776 config_waiter_.on_configuration_callback());
1679 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback,
1680 base::Unretained(this)));
1681 1777
1682 EXPECT_EQ(CALLBACK_NOT_CALLED, PopCallbackResult()); 1778 EXPECT_EQ(CALLBACK_NOT_CALLED, config_waiter_.callback_result());
1683 base::RunLoop().RunUntilIdle(); 1779 EXPECT_LT(config_waiter_.Wait(), kMaxShortDelayMs);
1684 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); 1780 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter_.callback_result());
1685 EXPECT_EQ(1, observer_.num_changes()); 1781 EXPECT_EQ(1, observer_.num_changes());
1686 EXPECT_EQ(0, observer_.num_failures()); 1782 EXPECT_EQ(0, observer_.num_failures());
1687 1783
1688 const int kDualHeight = small_mode_.size().height() + 1784 const int kDualHeight = small_mode_.size().height() +
1689 DisplayConfigurator::kVerticalGap + 1785 DisplayConfigurator::kVerticalGap +
1690 big_mode_.size().height(); 1786 big_mode_.size().height();
1691 EXPECT_EQ( 1787 EXPECT_EQ(
1692 JoinActions( 1788 JoinActions(
1693 kGrab, 1789 kGrab,
1694 GetFramebufferAction(gfx::Size(big_mode_.size().width(), kDualHeight), 1790 GetFramebufferAction(gfx::Size(big_mode_.size().width(), kDualHeight),
1695 outputs_[0].get(), outputs_[1].get()) 1791 outputs_[0].get(), outputs_[1].get())
1696 .c_str(), 1792 .c_str(),
1697 GetCrtcAction(*outputs_[0], nullptr, gfx::Point(0, 0)).c_str(), 1793 GetCrtcAction(*outputs_[0], nullptr, gfx::Point(0, 0)).c_str(),
1698 GetCrtcAction(*outputs_[1], nullptr, 1794 GetCrtcAction(*outputs_[1], nullptr,
1699 gfx::Point(0, small_mode_.size().height() + 1795 gfx::Point(0, small_mode_.size().height() +
1700 DisplayConfigurator::kVerticalGap)) 1796 DisplayConfigurator::kVerticalGap))
1701 .c_str(), 1797 .c_str(),
1702 kUngrab, nullptr), 1798 kUngrab, nullptr),
1703 log_->GetActionsAndClear()); 1799 log_->GetActionsAndClear());
1704 1800
1801 config_waiter_.Reset();
1705 EXPECT_TRUE(test_api_.TriggerConfigureTimeout()); 1802 EXPECT_TRUE(test_api_.TriggerConfigureTimeout());
1706 base::RunLoop().RunUntilIdle(); 1803 EXPECT_LT(config_waiter_.Wait(), kMaxShortDelayMs);
1707 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); 1804 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter_.callback_result());
1708 EXPECT_EQ(2, observer_.num_changes()); 1805 EXPECT_EQ(2, observer_.num_changes());
1709 EXPECT_EQ(0, observer_.num_failures()); 1806 EXPECT_EQ(0, observer_.num_failures());
1710 1807
1711 EXPECT_EQ( 1808 EXPECT_EQ(
1712 JoinActions( 1809 JoinActions(
1713 kGrab, 1810 kGrab,
1714 GetFramebufferAction(gfx::Size(big_mode_.size().width(), kDualHeight), 1811 GetFramebufferAction(gfx::Size(big_mode_.size().width(), kDualHeight),
1715 outputs_[0].get(), outputs_[1].get()) 1812 outputs_[0].get(), outputs_[1].get())
1716 .c_str(), 1813 .c_str(),
1717 GetCrtcAction(*outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), 1814 GetCrtcAction(*outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(),
(...skipping 10 matching lines...) Expand all
1728 // Start out with two displays in extended mode. 1825 // Start out with two displays in extended mode.
1729 state_controller_.set_state(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED); 1826 state_controller_.set_state(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED);
1730 Init(false); 1827 Init(false);
1731 configurator_.ForceInitialConfigure(0); 1828 configurator_.ForceInitialConfigure(0);
1732 log_->GetActionsAndClear(); 1829 log_->GetActionsAndClear();
1733 observer_.Reset(); 1830 observer_.Reset();
1734 1831
1735 // Fail display configuration. 1832 // Fail display configuration.
1736 native_display_delegate_->set_max_configurable_pixels(-1); 1833 native_display_delegate_->set_max_configurable_pixels(-1);
1737 1834
1738 configurator_.SetDisplayPower( 1835 config_waiter_.Reset();
1739 chromeos::DISPLAY_POWER_ALL_OFF, 1836 configurator_.SetDisplayPower(chromeos::DISPLAY_POWER_ALL_OFF,
1740 DisplayConfigurator::kSetDisplayPowerNoFlags, 1837 DisplayConfigurator::kSetDisplayPowerNoFlags,
1741 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, 1838 config_waiter_.on_configuration_callback());
1742 base::Unretained(this))); 1839 EXPECT_LT(config_waiter_.Wait(), kMaxShortDelayMs);
1743 1840 EXPECT_EQ(CALLBACK_FAILURE, config_waiter_.callback_result());
1744 EXPECT_EQ(CALLBACK_FAILURE, PopCallbackResult());
1745 EXPECT_EQ(0, observer_.num_changes()); 1841 EXPECT_EQ(0, observer_.num_changes());
1746 EXPECT_EQ(1, observer_.num_failures()); 1842 EXPECT_EQ(1, observer_.num_failures());
1747 1843
1748 const int kDualHeight = small_mode_.size().height() + 1844 const int kDualHeight = small_mode_.size().height() +
1749 DisplayConfigurator::kVerticalGap + 1845 DisplayConfigurator::kVerticalGap +
1750 big_mode_.size().height(); 1846 big_mode_.size().height();
1751 1847
1752 EXPECT_EQ( 1848 EXPECT_EQ(
1753 JoinActions( 1849 JoinActions(
1754 kGrab, 1850 kGrab,
1755 GetFramebufferAction(gfx::Size(big_mode_.size().width(), kDualHeight), 1851 GetFramebufferAction(gfx::Size(big_mode_.size().width(), kDualHeight),
1756 outputs_[0].get(), outputs_[1].get()) 1852 outputs_[0].get(), outputs_[1].get())
1757 .c_str(), 1853 .c_str(),
1758 GetCrtcAction(*outputs_[0], nullptr, gfx::Point(0, 0)).c_str(), 1854 GetCrtcAction(*outputs_[0], nullptr, gfx::Point(0, 0)).c_str(),
1759 GetCrtcAction(*outputs_[1], nullptr, 1855 GetCrtcAction(*outputs_[1], nullptr,
1760 gfx::Point(0, small_mode_.size().height() + 1856 gfx::Point(0, small_mode_.size().height() +
1761 DisplayConfigurator::kVerticalGap)) 1857 DisplayConfigurator::kVerticalGap))
1762 .c_str(), 1858 .c_str(),
1763 kUngrab, nullptr), 1859 kUngrab, nullptr),
1764 log_->GetActionsAndClear()); 1860 log_->GetActionsAndClear());
1765 1861
1766 // This configuration should trigger a display configuration since the 1862 // This configuration should trigger a display configuration since the
1767 // previous configuration failed. 1863 // previous configuration failed.
1768 configurator_.SetDisplayPower( 1864 config_waiter_.Reset();
1769 chromeos::DISPLAY_POWER_ALL_ON, 1865 configurator_.SetDisplayPower(chromeos::DISPLAY_POWER_ALL_ON,
1770 DisplayConfigurator::kSetDisplayPowerNoFlags, 1866 DisplayConfigurator::kSetDisplayPowerNoFlags,
1771 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, 1867 config_waiter_.on_configuration_callback());
1772 base::Unretained(this))); 1868 EXPECT_LT(config_waiter_.Wait(), kMaxShortDelayMs);
1773 1869
1774 EXPECT_EQ(0, observer_.num_changes()); 1870 EXPECT_EQ(0, observer_.num_changes());
1775 EXPECT_EQ(2, observer_.num_failures()); 1871 EXPECT_EQ(2, observer_.num_failures());
1776 EXPECT_EQ( 1872 EXPECT_EQ(
1777 JoinActions( 1873 JoinActions(
1778 kGrab, 1874 kGrab,
1779 GetFramebufferAction(gfx::Size(big_mode_.size().width(), kDualHeight), 1875 GetFramebufferAction(gfx::Size(big_mode_.size().width(), kDualHeight),
1780 outputs_[0].get(), outputs_[1].get()) 1876 outputs_[0].get(), outputs_[1].get())
1781 .c_str(), 1877 .c_str(),
1782 GetCrtcAction(*outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), 1878 GetCrtcAction(*outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(),
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1848 GetCrtcAction( 1944 GetCrtcAction(
1849 *outputs_[2], &small_mode_, 1945 *outputs_[2], &small_mode_,
1850 gfx::Point(0, small_mode_.size().height() + 1946 gfx::Point(0, small_mode_.size().height() +
1851 big_mode_.size().height() + 1947 big_mode_.size().height() +
1852 2 * DisplayConfigurator::kVerticalGap)) 1948 2 * DisplayConfigurator::kVerticalGap))
1853 .c_str(), 1949 .c_str(),
1854 kUngrab, nullptr), 1950 kUngrab, nullptr),
1855 log_->GetActionsAndClear()); 1951 log_->GetActionsAndClear());
1856 1952
1857 // Verify that turning the power off works. 1953 // Verify that turning the power off works.
1858 configurator_.SetDisplayPower( 1954 config_waiter_.Reset();
1859 chromeos::DISPLAY_POWER_ALL_OFF, 1955 configurator_.SetDisplayPower(chromeos::DISPLAY_POWER_ALL_OFF,
1860 DisplayConfigurator::kSetDisplayPowerNoFlags, 1956 DisplayConfigurator::kSetDisplayPowerNoFlags,
1861 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, 1957 config_waiter_.on_configuration_callback());
1862 base::Unretained(this))); 1958 EXPECT_LT(config_waiter_.Wait(), kMaxShortDelayMs);
1863 1959 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter_.callback_result());
1864 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult());
1865 EXPECT_EQ( 1960 EXPECT_EQ(
1866 JoinActions( 1961 JoinActions(
1867 kGrab, GetFramebufferAction( 1962 kGrab, GetFramebufferAction(
1868 gfx::Size(big_mode_.size().width(), kTripleHeight), 1963 gfx::Size(big_mode_.size().width(), kTripleHeight),
1869 outputs_[0].get(), outputs_[1].get()) 1964 outputs_[0].get(), outputs_[1].get())
1870 .c_str(), 1965 .c_str(),
1871 GetCrtcAction(*outputs_[0], nullptr, gfx::Point(0, 0)).c_str(), 1966 GetCrtcAction(*outputs_[0], nullptr, gfx::Point(0, 0)).c_str(),
1872 GetCrtcAction(*outputs_[1], nullptr, 1967 GetCrtcAction(*outputs_[1], nullptr,
1873 gfx::Point(0, small_mode_.size().height() + 1968 gfx::Point(0, small_mode_.size().height() +
1874 DisplayConfigurator::kVerticalGap)) 1969 DisplayConfigurator::kVerticalGap))
1875 .c_str(), 1970 .c_str(),
1876 GetCrtcAction( 1971 GetCrtcAction(
1877 *outputs_[2], nullptr, 1972 *outputs_[2], nullptr,
1878 gfx::Point(0, small_mode_.size().height() + 1973 gfx::Point(0, small_mode_.size().height() +
1879 big_mode_.size().height() + 1974 big_mode_.size().height() +
1880 2 * DisplayConfigurator::kVerticalGap)) 1975 2 * DisplayConfigurator::kVerticalGap))
1881 .c_str(), 1976 .c_str(),
1882 kUngrab, nullptr), 1977 kUngrab, nullptr),
1883 log_->GetActionsAndClear()); 1978 log_->GetActionsAndClear());
1884 1979
1885 configurator_.SetDisplayPower( 1980 config_waiter_.Reset();
1886 chromeos::DISPLAY_POWER_ALL_ON, 1981 configurator_.SetDisplayPower(chromeos::DISPLAY_POWER_ALL_ON,
1887 DisplayConfigurator::kSetDisplayPowerNoFlags, 1982 DisplayConfigurator::kSetDisplayPowerNoFlags,
1888 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, 1983 config_waiter_.on_configuration_callback());
1889 base::Unretained(this))); 1984 EXPECT_LT(config_waiter_.Wait(), kMaxShortDelayMs);
1890 1985 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter_.callback_result());
1891 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult());
1892 EXPECT_EQ( 1986 EXPECT_EQ(
1893 JoinActions( 1987 JoinActions(
1894 kGrab, GetFramebufferAction( 1988 kGrab, GetFramebufferAction(
1895 gfx::Size(big_mode_.size().width(), kTripleHeight), 1989 gfx::Size(big_mode_.size().width(), kTripleHeight),
1896 outputs_[0].get(), outputs_[1].get()) 1990 outputs_[0].get(), outputs_[1].get())
1897 .c_str(), 1991 .c_str(),
1898 GetCrtcAction(*outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), 1992 GetCrtcAction(*outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(),
1899 GetCrtcAction(*outputs_[1], &big_mode_, 1993 GetCrtcAction(*outputs_[1], &big_mode_,
1900 gfx::Point(0, small_mode_.size().height() + 1994 gfx::Point(0, small_mode_.size().height() +
1901 DisplayConfigurator::kVerticalGap)) 1995 DisplayConfigurator::kVerticalGap))
(...skipping 19 matching lines...) Expand all
1921 .c_str(), 2015 .c_str(),
1922 GetCrtcAction(*outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), 2016 GetCrtcAction(*outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(),
1923 GetCrtcAction(*outputs_[1], &big_mode_, 2017 GetCrtcAction(*outputs_[1], &big_mode_,
1924 gfx::Point(0, small_mode_.size().height() + 2018 gfx::Point(0, small_mode_.size().height() +
1925 DisplayConfigurator::kVerticalGap)) 2019 DisplayConfigurator::kVerticalGap))
1926 .c_str(), 2020 .c_str(),
1927 kUngrab, nullptr), 2021 kUngrab, nullptr),
1928 log_->GetActionsAndClear()); 2022 log_->GetActionsAndClear());
1929 } 2023 }
1930 2024
2025 // Tests the suspend and resume behavior when in dual or multi display modes.
2026 TEST_F(DisplayConfiguratorTest, SuspendResumeWithMultipleDisplays) {
2027 InitWithSingleOutput();
2028 state_controller_.set_state(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED);
2029 observer_.Reset();
2030 UpdateOutputs(2, true);
2031 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED,
2032 configurator_.display_state());
2033 EXPECT_FALSE(mirroring_controller_.SoftwareMirroringEnabled());
2034 EXPECT_EQ(1, observer_.num_changes());
2035 EXPECT_EQ(chromeos::DISPLAY_POWER_ALL_ON,
2036 configurator_.current_power_state());
2037
2038 // Suspending displays should result in an immediate configuration without
2039 // delays, even in dual display mode.
2040 config_waiter_.Reset();
2041 configurator_.SuspendDisplays(config_waiter_.on_configuration_callback());
2042 EXPECT_LT(config_waiter_.Wait(), kMaxShortDelayMs);
2043 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter_.callback_result());
2044 EXPECT_EQ(chromeos::DISPLAY_POWER_ALL_OFF,
2045 configurator_.current_power_state());
2046 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED,
2047 configurator_.display_state());
2048
2049 // Resuming from suspend with dual displays, should be done after a delay, and
2050 // after the configuration we should still expect to be in a dual display
2051 // mode.
2052 config_waiter_.Reset();
2053 configurator_.ResumeDisplays(config_waiter_.on_configuration_callback());
2054 EXPECT_GE(test_api_.GetConfigureDelay(), kMinLongDelayMs);
Daniel Erat 2016/10/25 16:05:32 you should use EXPECT_EQ rather than EXPECT_GE for
afakhry 2016/10/25 20:14:11 Done.
2055 EXPECT_TRUE(test_api_.TriggerConfigureTimeout());
2056 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter_.callback_result());
2057 EXPECT_EQ(chromeos::DISPLAY_POWER_ALL_ON,
2058 configurator_.current_power_state());
2059 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED,
2060 configurator_.display_state());
2061
2062 // Suspend displays and disconnect one of them while in suspend.
2063 config_waiter_.Reset();
2064 configurator_.SuspendDisplays(config_waiter_.on_configuration_callback());
2065 EXPECT_LT(config_waiter_.Wait(), kMaxShortDelayMs);
2066 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter_.callback_result());
2067 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED,
2068 configurator_.display_state());
2069 EXPECT_EQ(chromeos::DISPLAY_POWER_ALL_OFF,
2070 configurator_.current_power_state());
2071 UpdateOutputs(1, false);
2072
2073 // Now resume, and expect that we'll still have a long delay since we were in
2074 // dual mode before suspend. The configurator should pick up the change and
2075 // detect that we are in single display mode now.
2076 config_waiter_.Reset();
2077 configurator_.ResumeDisplays(config_waiter_.on_configuration_callback());
2078 EXPECT_GE(config_waiter_.Wait(), kMinLongDelayMs);
2079 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter_.callback_result());
2080 EXPECT_EQ(chromeos::DISPLAY_POWER_ALL_ON,
2081 configurator_.current_power_state());
2082 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_SINGLE, configurator_.display_state());
2083
2084 // Verify that the above is the exact same behavior for 3+ displays.
2085 UpdateOutputs(3, true);
2086 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_MULTI_EXTENDED,
2087 configurator_.display_state());
2088 // Suspend.
2089 config_waiter_.Reset();
2090 configurator_.SuspendDisplays(config_waiter_.on_configuration_callback());
2091 EXPECT_LT(config_waiter_.Wait(), kMaxShortDelayMs);
2092 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter_.callback_result());
2093 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_MULTI_EXTENDED,
2094 configurator_.display_state());
2095 EXPECT_EQ(chromeos::DISPLAY_POWER_ALL_OFF,
2096 configurator_.current_power_state());
2097
2098 // Resume and expect the correct delay.
2099 config_waiter_.Reset();
2100 configurator_.ResumeDisplays(config_waiter_.on_configuration_callback());
2101 EXPECT_GE(config_waiter_.Wait(), kMinLongDelayMs);
2102 EXPECT_EQ(CALLBACK_SUCCESS, config_waiter_.callback_result());
2103 EXPECT_EQ(chromeos::DISPLAY_POWER_ALL_ON,
2104 configurator_.current_power_state());
2105 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_MULTI_EXTENDED,
2106 configurator_.display_state());
2107 }
2108
1931 } // namespace test 2109 } // namespace test
1932 } // namespace ui 2110 } // 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