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

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: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View 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"
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 o->set_modes(std::move(modes)); 180 o->set_modes(std::move(modes));
180 o->set_type(DISPLAY_CONNECTION_TYPE_HDMI); 181 o->set_type(DISPLAY_CONNECTION_TYPE_HDMI);
181 o->set_is_aspect_preserving_scaling(true); 182 o->set_is_aspect_preserving_scaling(true);
182 o->set_display_id(789); 183 o->set_display_id(789);
183 184
184 UpdateOutputs(2, false); 185 UpdateOutputs(2, false);
185 } 186 }
186 187
187 void OnConfiguredCallback(bool status) { 188 void OnConfiguredCallback(bool status) {
188 callback_result_ = (status ? CALLBACK_SUCCESS : CALLBACK_FAILURE); 189 callback_result_ = (status ? CALLBACK_SUCCESS : CALLBACK_FAILURE);
190
191 if (!quit_closure_.is_null())
192 base::ResetAndReturn(&quit_closure_).Run();
193
194 configuration_done_ = true;
189 } 195 }
190 196
191 void OnDisplayControlUpdated(bool status) { 197 void OnDisplayControlUpdated(bool status) {
192 display_control_result_ = (status ? CALLBACK_SUCCESS : CALLBACK_FAILURE); 198 display_control_result_ = (status ? CALLBACK_SUCCESS : CALLBACK_FAILURE);
193 } 199 }
194 200
195 void EnableContentProtectionCallback(bool status) { 201 void EnableContentProtectionCallback(bool status) {
196 enable_content_protection_status_ = status; 202 enable_content_protection_status_ = status;
197 enable_content_protection_call_count_++; 203 enable_content_protection_call_count_++;
198 } 204 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 NULL).c_str(), 249 NULL).c_str(),
244 GetCrtcAction(outputs_[0], &small_mode_, 250 GetCrtcAction(outputs_[0], &small_mode_,
245 gfx::Point(0, 0)).c_str(), 251 gfx::Point(0, 0)).c_str(),
246 kForceDPMS, kUngrab, NULL), 252 kForceDPMS, kUngrab, NULL),
247 log_->GetActionsAndClear()); 253 log_->GetActionsAndClear());
248 } 254 }
249 255
250 CallbackResult PopCallbackResult() { 256 CallbackResult PopCallbackResult() {
251 CallbackResult result = callback_result_; 257 CallbackResult result = callback_result_;
252 callback_result_ = CALLBACK_NOT_CALLED; 258 callback_result_ = CALLBACK_NOT_CALLED;
259 configuration_done_ = false;
253 return result; 260 return result;
254 } 261 }
255 262
256 CallbackResult PopDisplayControlResult() { 263 CallbackResult PopDisplayControlResult() {
257 CallbackResult result = display_control_result_; 264 CallbackResult result = display_control_result_;
258 display_control_result_ = CALLBACK_NOT_CALLED; 265 display_control_result_ = CALLBACK_NOT_CALLED;
266 configuration_done_ = false;
259 return result; 267 return result;
260 } 268 }
261 269
270 void WaitForConfiguration() {
Daniel Erat 2016/10/19 16:57:56 how about making this take an expected_duration pa
afakhry 2016/10/21 20:03:03 I think the best approach is to encapsulate the wa
271 if (!configuration_done_) {
272 base::RunLoop run_loop;
273 quit_closure_ = run_loop.QuitClosure();
274 run_loop.Run();
275 }
276 configuration_done_ = false;
277 }
278
262 base::MessageLoop message_loop_; 279 base::MessageLoop message_loop_;
280 base::Closure quit_closure_;
263 TestStateController state_controller_; 281 TestStateController state_controller_;
264 TestMirroringController mirroring_controller_; 282 TestMirroringController mirroring_controller_;
265 DisplayConfigurator configurator_; 283 DisplayConfigurator configurator_;
266 TestObserver observer_; 284 TestObserver observer_;
267 std::unique_ptr<ActionLogger> log_; 285 std::unique_ptr<ActionLogger> log_;
268 TestNativeDisplayDelegate* native_display_delegate_; // not owned 286 TestNativeDisplayDelegate* native_display_delegate_; // not owned
269 DisplayConfigurator::TestApi test_api_; 287 DisplayConfigurator::TestApi test_api_;
270 288
271 bool enable_content_protection_status_; 289 bool enable_content_protection_status_;
272 int enable_content_protection_call_count_; 290 int enable_content_protection_call_count_;
273 DisplayConfigurator::QueryProtectionResponse 291 DisplayConfigurator::QueryProtectionResponse
274 query_content_protection_response_; 292 query_content_protection_response_;
275 int query_content_protection_call_count_; 293 int query_content_protection_call_count_;
276 294
277 TestDisplaySnapshot outputs_[3]; 295 TestDisplaySnapshot outputs_[3];
278 296
279 CallbackResult callback_result_; 297 CallbackResult callback_result_;
280 CallbackResult display_control_result_; 298 CallbackResult display_control_result_;
281 299
300 bool configuration_done_ = false;
Daniel Erat 2016/10/18 22:17:41 please add a comment describing when this is true
301
282 private: 302 private:
283 DISALLOW_COPY_AND_ASSIGN(DisplayConfiguratorTest); 303 DISALLOW_COPY_AND_ASSIGN(DisplayConfiguratorTest);
284 }; 304 };
285 305
286 } // namespace 306 } // namespace
287 307
288 TEST_F(DisplayConfiguratorTest, FindDisplayModeMatchingSize) { 308 TEST_F(DisplayConfiguratorTest, FindDisplayModeMatchingSize) {
289 std::vector<const DisplayMode*> modes; 309 std::vector<const DisplayMode*> modes;
290 310
291 // Fields are width, height, interlaced, refresh rate. 311 // Fields are width, height, interlaced, refresh rate.
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 EXPECT_FALSE(mirroring_controller_.SoftwareMirroringEnabled()); 731 EXPECT_FALSE(mirroring_controller_.SoftwareMirroringEnabled());
712 EXPECT_EQ(1, observer_.num_changes()); 732 EXPECT_EQ(1, observer_.num_changes());
713 733
714 // Turn all displays on and check that mirroring is still used. 734 // Turn all displays on and check that mirroring is still used.
715 observer_.Reset(); 735 observer_.Reset();
716 configurator_.SetDisplayPower( 736 configurator_.SetDisplayPower(
717 chromeos::DISPLAY_POWER_ALL_ON, 737 chromeos::DISPLAY_POWER_ALL_ON,
718 DisplayConfigurator::kSetDisplayPowerNoFlags, 738 DisplayConfigurator::kSetDisplayPowerNoFlags,
719 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, 739 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback,
720 base::Unretained(this))); 740 base::Unretained(this)));
741 WaitForConfiguration();
721 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); 742 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult());
722 EXPECT_EQ( 743 EXPECT_EQ(
723 JoinActions( 744 JoinActions(
724 kGrab, 745 kGrab,
725 GetFramebufferAction(small_mode_.size(), &outputs_[0], &outputs_[1]) 746 GetFramebufferAction(small_mode_.size(), &outputs_[0], &outputs_[1])
726 .c_str(), 747 .c_str(),
727 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), 748 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(),
728 GetCrtcAction(outputs_[1], &small_mode_, gfx::Point(0, 0)).c_str(), 749 GetCrtcAction(outputs_[1], &small_mode_, gfx::Point(0, 0)).c_str(),
729 kForceDPMS, 750 kForceDPMS,
730 kUngrab, 751 kUngrab,
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 EXPECT_TRUE(mirroring_controller_.SoftwareMirroringEnabled()); 842 EXPECT_TRUE(mirroring_controller_.SoftwareMirroringEnabled());
822 EXPECT_EQ(1, observer_.num_changes()); 843 EXPECT_EQ(1, observer_.num_changes());
823 844
824 // Turn all displays on and check that mirroring is still used. 845 // Turn all displays on and check that mirroring is still used.
825 observer_.Reset(); 846 observer_.Reset();
826 configurator_.SetDisplayPower( 847 configurator_.SetDisplayPower(
827 chromeos::DISPLAY_POWER_ALL_ON, 848 chromeos::DISPLAY_POWER_ALL_ON,
828 DisplayConfigurator::kSetDisplayPowerNoFlags, 849 DisplayConfigurator::kSetDisplayPowerNoFlags,
829 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, 850 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback,
830 base::Unretained(this))); 851 base::Unretained(this)));
852 WaitForConfiguration();
831 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); 853 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult());
832 EXPECT_EQ( 854 EXPECT_EQ(
833 JoinActions( 855 JoinActions(
834 kGrab, 856 kGrab,
835 GetFramebufferAction(gfx::Size(big_mode_.size().width(), kDualHeight), 857 GetFramebufferAction(gfx::Size(big_mode_.size().width(), kDualHeight),
836 &outputs_[0], 858 &outputs_[0],
837 &outputs_[1]).c_str(), 859 &outputs_[1]).c_str(),
838 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), 860 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(),
839 GetCrtcAction(outputs_[1], 861 GetCrtcAction(outputs_[1],
840 &big_mode_, 862 &big_mode_,
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 // pick up the change and only turn on the internal display. 986 // pick up the change and only turn on the internal display.
965 UpdateOutputs(1, false); 987 UpdateOutputs(1, false);
966 configurator_.ResumeDisplays(); 988 configurator_.ResumeDisplays();
967 EXPECT_EQ(kNoActions, log_->GetActionsAndClear()); 989 EXPECT_EQ(kNoActions, log_->GetActionsAndClear());
968 990
969 configurator_.SetDisplayPower( 991 configurator_.SetDisplayPower(
970 chromeos::DISPLAY_POWER_ALL_ON, 992 chromeos::DISPLAY_POWER_ALL_ON,
971 DisplayConfigurator::kSetDisplayPowerNoFlags, 993 DisplayConfigurator::kSetDisplayPowerNoFlags,
972 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, 994 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback,
973 base::Unretained(this))); 995 base::Unretained(this)));
996 WaitForConfiguration();
974 EXPECT_EQ( 997 EXPECT_EQ(
975 JoinActions( 998 JoinActions(
976 kGrab, 999 kGrab,
977 GetFramebufferAction(small_mode_.size(), &outputs_[0], NULL).c_str(), 1000 GetFramebufferAction(small_mode_.size(), &outputs_[0], NULL).c_str(),
978 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), 1001 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(),
979 kForceDPMS, 1002 kForceDPMS,
980 kUngrab, 1003 kUngrab,
981 NULL), 1004 NULL),
982 log_->GetActionsAndClear()); 1005 log_->GetActionsAndClear());
983 } 1006 }
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after
1633 kSync, 1656 kSync,
1634 NULL), 1657 NULL),
1635 log_->GetActionsAndClear()); 1658 log_->GetActionsAndClear());
1636 1659
1637 // Before the task runs, exit docked mode. 1660 // Before the task runs, exit docked mode.
1638 configurator_.SetDisplayPower( 1661 configurator_.SetDisplayPower(
1639 chromeos::DISPLAY_POWER_ALL_ON, 1662 chromeos::DISPLAY_POWER_ALL_ON,
1640 DisplayConfigurator::kSetDisplayPowerNoFlags, 1663 DisplayConfigurator::kSetDisplayPowerNoFlags,
1641 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, 1664 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback,
1642 base::Unretained(this))); 1665 base::Unretained(this)));
1666 WaitForConfiguration();
1643 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); 1667 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult());
1644 EXPECT_EQ(3, observer_.num_changes()); 1668 EXPECT_EQ(3, observer_.num_changes());
1645 EXPECT_EQ(0, observer_.num_failures()); 1669 EXPECT_EQ(0, observer_.num_failures());
1646 EXPECT_EQ( 1670 EXPECT_EQ(
1647 JoinActions( 1671 JoinActions(
1648 kGrab, 1672 kGrab,
1649 GetFramebufferAction(small_mode_.size(), &outputs_[0], &outputs_[1]) 1673 GetFramebufferAction(small_mode_.size(), &outputs_[0], &outputs_[1])
1650 .c_str(), 1674 .c_str(),
1651 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), 1675 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(),
1652 GetCrtcAction(outputs_[1], &small_mode_, gfx::Point(0, 0)).c_str(), 1676 GetCrtcAction(outputs_[1], &small_mode_, gfx::Point(0, 0)).c_str(),
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
1909 2 * DisplayConfigurator::kVerticalGap)) 1933 2 * DisplayConfigurator::kVerticalGap))
1910 .c_str(), 1934 .c_str(),
1911 kUngrab, NULL), 1935 kUngrab, NULL),
1912 log_->GetActionsAndClear()); 1936 log_->GetActionsAndClear());
1913 1937
1914 configurator_.SetDisplayPower( 1938 configurator_.SetDisplayPower(
1915 chromeos::DISPLAY_POWER_ALL_ON, 1939 chromeos::DISPLAY_POWER_ALL_ON,
1916 DisplayConfigurator::kSetDisplayPowerNoFlags, 1940 DisplayConfigurator::kSetDisplayPowerNoFlags,
1917 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, 1941 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback,
1918 base::Unretained(this))); 1942 base::Unretained(this)));
1943 WaitForConfiguration();
1919 1944
1920 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); 1945 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult());
1921 EXPECT_EQ( 1946 EXPECT_EQ(
1922 JoinActions( 1947 JoinActions(
1923 kGrab, GetFramebufferAction( 1948 kGrab, GetFramebufferAction(
1924 gfx::Size(big_mode_.size().width(), kTripleHeight), 1949 gfx::Size(big_mode_.size().width(), kTripleHeight),
1925 &outputs_[0], &outputs_[1]) 1950 &outputs_[0], &outputs_[1])
1926 .c_str(), 1951 .c_str(),
1927 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), 1952 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(),
1928 GetCrtcAction(outputs_[1], &big_mode_, 1953 GetCrtcAction(outputs_[1], &big_mode_,
(...skipping 20 matching lines...) Expand all
1949 &outputs_[0], &outputs_[1]) 1974 &outputs_[0], &outputs_[1])
1950 .c_str(), 1975 .c_str(),
1951 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), 1976 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(),
1952 GetCrtcAction(outputs_[1], &big_mode_, 1977 GetCrtcAction(outputs_[1], &big_mode_,
1953 gfx::Point(0, small_mode_.size().height() + 1978 gfx::Point(0, small_mode_.size().height() +
1954 DisplayConfigurator::kVerticalGap)) 1979 DisplayConfigurator::kVerticalGap))
1955 .c_str(), 1980 .c_str(),
1956 kUngrab, NULL), 1981 kUngrab, NULL),
1957 log_->GetActionsAndClear()); 1982 log_->GetActionsAndClear());
1958 } 1983 }
1959 1984
Daniel Erat 2016/10/18 22:17:41 please add a new test that verifies that the code
afakhry 2016/10/21 20:03:03 Done.
1960 } // namespace test 1985 } // namespace test
1961 } // namespace ui 1986 } // 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