OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/bind.h" |
| 6 #include "base/message_loop/message_loop.h" |
| 7 #include "base/run_loop.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "ui/display/chromeos/test/action_logger_util.h" |
| 10 #include "ui/display/chromeos/test/test_display_snapshot.h" |
| 11 #include "ui/display/chromeos/test/test_native_display_delegate.h" |
| 12 #include "ui/display/chromeos/update_display_configuration_task.h" |
| 13 |
| 14 namespace ui { |
| 15 namespace test { |
| 16 |
| 17 namespace { |
| 18 |
| 19 class TestDisplayLayoutManager |
| 20 : public DisplayConfigurator::DisplayLayoutManager { |
| 21 public: |
| 22 TestDisplayLayoutManager() |
| 23 : should_mirror_(true), |
| 24 display_state_(MULTIPLE_DISPLAY_STATE_INVALID), |
| 25 power_state_(chromeos::DISPLAY_POWER_ALL_ON) {} |
| 26 ~TestDisplayLayoutManager() override {} |
| 27 |
| 28 void set_should_mirror(bool should_mirror) { should_mirror_ = should_mirror; } |
| 29 |
| 30 void set_display_state(MultipleDisplayState state) { display_state_ = state; } |
| 31 |
| 32 void set_power_state(chromeos::DisplayPowerState state) { |
| 33 power_state_ = state; |
| 34 } |
| 35 |
| 36 // DisplayConfigurator::DisplayLayoutManager: |
| 37 DisplayConfigurator::SoftwareMirroringController* |
| 38 GetSoftwareMirroringController() const override { |
| 39 return nullptr; |
| 40 } |
| 41 |
| 42 DisplayConfigurator::StateController* GetStateController() const override { |
| 43 return nullptr; |
| 44 } |
| 45 |
| 46 MultipleDisplayState GetDisplayState() const override { |
| 47 return display_state_; |
| 48 } |
| 49 |
| 50 virtual chromeos::DisplayPowerState GetPowerState() const override { |
| 51 return power_state_; |
| 52 } |
| 53 |
| 54 virtual std::vector<DisplayConfigurator::DisplayState> ParseDisplays( |
| 55 const std::vector<DisplaySnapshot*>& displays) const override { |
| 56 std::vector<DisplayConfigurator::DisplayState> parsed_displays; |
| 57 for (DisplaySnapshot* display : displays) { |
| 58 DisplayConfigurator::DisplayState state; |
| 59 state.display = display; |
| 60 state.selected_mode = display->native_mode(); |
| 61 if (should_mirror_) |
| 62 state.mirror_mode = FindMirrorMode(displays); |
| 63 |
| 64 parsed_displays.push_back(state); |
| 65 } |
| 66 |
| 67 return parsed_displays; |
| 68 } |
| 69 |
| 70 virtual bool GetDisplayLayout( |
| 71 const std::vector<DisplayConfigurator::DisplayState>& displays, |
| 72 MultipleDisplayState new_display_state, |
| 73 chromeos::DisplayPowerState new_power_state, |
| 74 std::vector<DisplayConfigureRequest>* requests, |
| 75 gfx::Size* framebuffer_size) const override { |
| 76 gfx::Point origin; |
| 77 for (const DisplayConfigurator::DisplayState& state : displays) { |
| 78 const DisplayMode* mode = state.selected_mode; |
| 79 if (new_display_state == MULTIPLE_DISPLAY_STATE_DUAL_MIRROR) |
| 80 mode = state.mirror_mode; |
| 81 |
| 82 if (!mode) |
| 83 return false; |
| 84 |
| 85 if (new_power_state == chromeos::DISPLAY_POWER_ALL_ON) { |
| 86 requests->push_back( |
| 87 DisplayConfigureRequest(state.display, mode, origin)); |
| 88 } else { |
| 89 requests->push_back( |
| 90 DisplayConfigureRequest(state.display, nullptr, origin)); |
| 91 } |
| 92 |
| 93 if (new_display_state != MULTIPLE_DISPLAY_STATE_DUAL_MIRROR) { |
| 94 origin.Offset(0, state.selected_mode->size().height()); |
| 95 framebuffer_size->SetToMax(gfx::Size(mode->size().width(), origin.y())); |
| 96 } else { |
| 97 *framebuffer_size = mode->size(); |
| 98 } |
| 99 } |
| 100 |
| 101 return true; |
| 102 } |
| 103 |
| 104 private: |
| 105 const DisplayMode* FindMirrorMode( |
| 106 const std::vector<DisplaySnapshot*>& displays) const { |
| 107 const DisplayMode* mode = displays[0]->native_mode(); |
| 108 for (DisplaySnapshot* display : displays) { |
| 109 if (mode->size().GetArea() > display->native_mode()->size().GetArea()) |
| 110 mode = display->native_mode(); |
| 111 } |
| 112 |
| 113 return mode; |
| 114 } |
| 115 |
| 116 bool should_mirror_; |
| 117 |
| 118 MultipleDisplayState display_state_; |
| 119 |
| 120 chromeos::DisplayPowerState power_state_; |
| 121 |
| 122 DISALLOW_COPY_AND_ASSIGN(TestDisplayLayoutManager); |
| 123 }; |
| 124 |
| 125 class UpdateDisplayConfigurationTaskTest : public testing::Test { |
| 126 public: |
| 127 UpdateDisplayConfigurationTaskTest() |
| 128 : delegate_(&log_), |
| 129 small_mode_(gfx::Size(1366, 768), false, 60.0f), |
| 130 big_mode_(gfx::Size(2560, 1600), false, 60.0f), |
| 131 configured_(false), |
| 132 configuration_status_(false), |
| 133 display_state_(MULTIPLE_DISPLAY_STATE_INVALID), |
| 134 power_state_(chromeos::DISPLAY_POWER_ALL_ON) { |
| 135 std::vector<const DisplayMode*> modes; |
| 136 modes.push_back(&small_mode_); |
| 137 displays_[0].set_current_mode(&small_mode_); |
| 138 displays_[0].set_native_mode(&small_mode_); |
| 139 displays_[0].set_modes(modes); |
| 140 displays_[0].set_display_id(123); |
| 141 |
| 142 modes.push_back(&big_mode_); |
| 143 displays_[1].set_current_mode(&big_mode_); |
| 144 displays_[1].set_native_mode(&big_mode_); |
| 145 displays_[1].set_modes(modes); |
| 146 displays_[1].set_display_id(456); |
| 147 } |
| 148 ~UpdateDisplayConfigurationTaskTest() override {} |
| 149 |
| 150 void UpdateDisplays(size_t count) { |
| 151 std::vector<DisplaySnapshot*> displays; |
| 152 for (size_t i = 0; i < count; ++i) |
| 153 displays.push_back(&displays_[i]); |
| 154 |
| 155 delegate_.set_outputs(displays); |
| 156 } |
| 157 |
| 158 void ResponseCallback( |
| 159 bool success, |
| 160 const std::vector<DisplayConfigurator::DisplayState>& displays, |
| 161 const gfx::Size& framebuffer_size, |
| 162 MultipleDisplayState new_display_state, |
| 163 chromeos::DisplayPowerState new_power_state) { |
| 164 configured_ = true; |
| 165 configuration_status_ = success; |
| 166 display_states_ = displays; |
| 167 display_state_ = new_display_state; |
| 168 power_state_ = new_power_state; |
| 169 |
| 170 if (success) { |
| 171 layout_manager_.set_display_state(display_state_); |
| 172 layout_manager_.set_power_state(power_state_); |
| 173 } |
| 174 } |
| 175 |
| 176 protected: |
| 177 ActionLogger log_; |
| 178 TestNativeDisplayDelegate delegate_; |
| 179 TestDisplayLayoutManager layout_manager_; |
| 180 |
| 181 const DisplayMode small_mode_; |
| 182 const DisplayMode big_mode_; |
| 183 |
| 184 TestDisplaySnapshot displays_[2]; |
| 185 |
| 186 bool configured_; |
| 187 bool configuration_status_; |
| 188 std::vector<DisplayConfigurator::DisplayState> display_states_; |
| 189 MultipleDisplayState display_state_; |
| 190 chromeos::DisplayPowerState power_state_; |
| 191 |
| 192 private: |
| 193 DISALLOW_COPY_AND_ASSIGN(UpdateDisplayConfigurationTaskTest); |
| 194 }; |
| 195 |
| 196 } // namespace |
| 197 |
| 198 TEST_F(UpdateDisplayConfigurationTaskTest, HeadlessConfiguration) { |
| 199 { |
| 200 UpdateDisplayConfigurationTask task( |
| 201 &delegate_, &layout_manager_, MULTIPLE_DISPLAY_STATE_HEADLESS, |
| 202 chromeos::DISPLAY_POWER_ALL_ON, 0, 0, false, |
| 203 base::Bind(&UpdateDisplayConfigurationTaskTest::ResponseCallback, |
| 204 base::Unretained(this))); |
| 205 task.Run(); |
| 206 } |
| 207 |
| 208 EXPECT_TRUE(configured_); |
| 209 EXPECT_TRUE(configuration_status_); |
| 210 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_HEADLESS, display_state_); |
| 211 EXPECT_EQ(chromeos::DISPLAY_POWER_ALL_ON, power_state_); |
| 212 EXPECT_EQ(JoinActions(kGrab, kUngrab, NULL), log_.GetActionsAndClear()); |
| 213 } |
| 214 |
| 215 TEST_F(UpdateDisplayConfigurationTaskTest, SingleConfiguration) { |
| 216 UpdateDisplays(1); |
| 217 |
| 218 { |
| 219 UpdateDisplayConfigurationTask task( |
| 220 &delegate_, &layout_manager_, MULTIPLE_DISPLAY_STATE_SINGLE, |
| 221 chromeos::DISPLAY_POWER_ALL_ON, 0, 0, false, |
| 222 base::Bind(&UpdateDisplayConfigurationTaskTest::ResponseCallback, |
| 223 base::Unretained(this))); |
| 224 task.Run(); |
| 225 } |
| 226 |
| 227 EXPECT_TRUE(configured_); |
| 228 EXPECT_TRUE(configuration_status_); |
| 229 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_SINGLE, display_state_); |
| 230 EXPECT_EQ(chromeos::DISPLAY_POWER_ALL_ON, power_state_); |
| 231 EXPECT_EQ(JoinActions( |
| 232 kGrab, GetFramebufferAction(small_mode_.size(), &displays_[0], |
| 233 nullptr).c_str(), |
| 234 GetCrtcAction(displays_[0], &small_mode_, gfx::Point()).c_str(), |
| 235 kUngrab, NULL), |
| 236 log_.GetActionsAndClear()); |
| 237 } |
| 238 |
| 239 TEST_F(UpdateDisplayConfigurationTaskTest, ExtendedConfiguration) { |
| 240 UpdateDisplays(2); |
| 241 |
| 242 { |
| 243 UpdateDisplayConfigurationTask task( |
| 244 &delegate_, &layout_manager_, MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED, |
| 245 chromeos::DISPLAY_POWER_ALL_ON, 0, 0, false, |
| 246 base::Bind(&UpdateDisplayConfigurationTaskTest::ResponseCallback, |
| 247 base::Unretained(this))); |
| 248 task.Run(); |
| 249 } |
| 250 |
| 251 EXPECT_TRUE(configured_); |
| 252 EXPECT_TRUE(configuration_status_); |
| 253 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED, display_state_); |
| 254 EXPECT_EQ(chromeos::DISPLAY_POWER_ALL_ON, power_state_); |
| 255 EXPECT_EQ( |
| 256 JoinActions( |
| 257 kGrab, GetFramebufferAction(gfx::Size(big_mode_.size().width(), |
| 258 small_mode_.size().height() + |
| 259 big_mode_.size().height()), |
| 260 &displays_[0], &displays_[1]).c_str(), |
| 261 GetCrtcAction(displays_[0], &small_mode_, gfx::Point()).c_str(), |
| 262 GetCrtcAction(displays_[1], &big_mode_, |
| 263 gfx::Point(0, small_mode_.size().height())).c_str(), |
| 264 kUngrab, NULL), |
| 265 log_.GetActionsAndClear()); |
| 266 } |
| 267 |
| 268 TEST_F(UpdateDisplayConfigurationTaskTest, MirrorConfiguration) { |
| 269 UpdateDisplays(2); |
| 270 |
| 271 { |
| 272 UpdateDisplayConfigurationTask task( |
| 273 &delegate_, &layout_manager_, MULTIPLE_DISPLAY_STATE_DUAL_MIRROR, |
| 274 chromeos::DISPLAY_POWER_ALL_ON, 0, 0, false, |
| 275 base::Bind(&UpdateDisplayConfigurationTaskTest::ResponseCallback, |
| 276 base::Unretained(this))); |
| 277 task.Run(); |
| 278 } |
| 279 |
| 280 EXPECT_TRUE(configured_); |
| 281 EXPECT_TRUE(configuration_status_); |
| 282 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_MIRROR, display_state_); |
| 283 EXPECT_EQ(chromeos::DISPLAY_POWER_ALL_ON, power_state_); |
| 284 EXPECT_EQ(JoinActions( |
| 285 kGrab, GetFramebufferAction(small_mode_.size(), &displays_[0], |
| 286 &displays_[1]).c_str(), |
| 287 GetCrtcAction(displays_[0], &small_mode_, gfx::Point()).c_str(), |
| 288 GetCrtcAction(displays_[1], &small_mode_, gfx::Point()).c_str(), |
| 289 kUngrab, NULL), |
| 290 log_.GetActionsAndClear()); |
| 291 } |
| 292 |
| 293 TEST_F(UpdateDisplayConfigurationTaskTest, FailMirrorConfiguration) { |
| 294 layout_manager_.set_should_mirror(false); |
| 295 UpdateDisplays(2); |
| 296 |
| 297 { |
| 298 UpdateDisplayConfigurationTask task( |
| 299 &delegate_, &layout_manager_, MULTIPLE_DISPLAY_STATE_DUAL_MIRROR, |
| 300 chromeos::DISPLAY_POWER_ALL_ON, 0, 0, false, |
| 301 base::Bind(&UpdateDisplayConfigurationTaskTest::ResponseCallback, |
| 302 base::Unretained(this))); |
| 303 task.Run(); |
| 304 } |
| 305 |
| 306 EXPECT_TRUE(configured_); |
| 307 EXPECT_FALSE(configuration_status_); |
| 308 EXPECT_EQ(JoinActions(kGrab, kUngrab, NULL), log_.GetActionsAndClear()); |
| 309 } |
| 310 |
| 311 TEST_F(UpdateDisplayConfigurationTaskTest, FailExtendedConfiguration) { |
| 312 delegate_.set_max_configurable_pixels(1); |
| 313 UpdateDisplays(2); |
| 314 |
| 315 { |
| 316 UpdateDisplayConfigurationTask task( |
| 317 &delegate_, &layout_manager_, MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED, |
| 318 chromeos::DISPLAY_POWER_ALL_ON, 0, 0, false, |
| 319 base::Bind(&UpdateDisplayConfigurationTaskTest::ResponseCallback, |
| 320 base::Unretained(this))); |
| 321 task.Run(); |
| 322 } |
| 323 |
| 324 EXPECT_TRUE(configured_); |
| 325 EXPECT_FALSE(configuration_status_); |
| 326 EXPECT_EQ( |
| 327 JoinActions( |
| 328 kGrab, GetFramebufferAction(gfx::Size(big_mode_.size().width(), |
| 329 small_mode_.size().height() + |
| 330 big_mode_.size().height()), |
| 331 &displays_[0], &displays_[1]).c_str(), |
| 332 GetCrtcAction(displays_[0], &small_mode_, gfx::Point()).c_str(), |
| 333 GetCrtcAction(displays_[1], &big_mode_, |
| 334 gfx::Point(0, small_mode_.size().height())).c_str(), |
| 335 GetCrtcAction(displays_[1], &small_mode_, |
| 336 gfx::Point(0, small_mode_.size().height())).c_str(), |
| 337 kUngrab, NULL), |
| 338 log_.GetActionsAndClear()); |
| 339 } |
| 340 |
| 341 TEST_F(UpdateDisplayConfigurationTaskTest, SingleChangePowerConfiguration) { |
| 342 UpdateDisplays(1); |
| 343 |
| 344 { |
| 345 UpdateDisplayConfigurationTask task( |
| 346 &delegate_, &layout_manager_, MULTIPLE_DISPLAY_STATE_SINGLE, |
| 347 chromeos::DISPLAY_POWER_ALL_ON, 0, 0, false, |
| 348 base::Bind(&UpdateDisplayConfigurationTaskTest::ResponseCallback, |
| 349 base::Unretained(this))); |
| 350 task.Run(); |
| 351 } |
| 352 |
| 353 EXPECT_TRUE(configured_); |
| 354 EXPECT_TRUE(configuration_status_); |
| 355 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_SINGLE, display_state_); |
| 356 EXPECT_EQ(chromeos::DISPLAY_POWER_ALL_ON, power_state_); |
| 357 EXPECT_EQ(JoinActions( |
| 358 kGrab, GetFramebufferAction(small_mode_.size(), &displays_[0], |
| 359 nullptr).c_str(), |
| 360 GetCrtcAction(displays_[0], &small_mode_, gfx::Point()).c_str(), |
| 361 kUngrab, NULL), |
| 362 log_.GetActionsAndClear()); |
| 363 |
| 364 // Turn power off |
| 365 { |
| 366 UpdateDisplayConfigurationTask task( |
| 367 &delegate_, &layout_manager_, MULTIPLE_DISPLAY_STATE_SINGLE, |
| 368 chromeos::DISPLAY_POWER_ALL_OFF, 0, 0, false, |
| 369 base::Bind(&UpdateDisplayConfigurationTaskTest::ResponseCallback, |
| 370 base::Unretained(this))); |
| 371 task.Run(); |
| 372 } |
| 373 |
| 374 EXPECT_TRUE(configuration_status_); |
| 375 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_SINGLE, display_state_); |
| 376 EXPECT_EQ(chromeos::DISPLAY_POWER_ALL_OFF, power_state_); |
| 377 EXPECT_EQ( |
| 378 JoinActions(kGrab, GetFramebufferAction(small_mode_.size(), &displays_[0], |
| 379 nullptr).c_str(), |
| 380 GetCrtcAction(displays_[0], nullptr, gfx::Point()).c_str(), |
| 381 kUngrab, NULL), |
| 382 log_.GetActionsAndClear()); |
| 383 } |
| 384 |
| 385 } // namespace test |
| 386 } // namespace ui |
OLD | NEW |