OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "ui/display/chromeos/display_layout_manager.h" | 9 #include "ui/display/chromeos/display_layout_manager.h" |
10 #include "ui/display/chromeos/test/action_logger_util.h" | 10 #include "ui/display/chromeos/test/action_logger_util.h" |
11 #include "ui/display/chromeos/test/test_display_snapshot.h" | 11 #include "ui/display/chromeos/test/test_display_snapshot.h" |
12 #include "ui/display/chromeos/test/test_native_display_delegate.h" | 12 #include "ui/display/chromeos/test/test_native_display_delegate.h" |
13 #include "ui/display/chromeos/update_display_configuration_task.h" | 13 #include "ui/display/chromeos/update_display_configuration_task.h" |
14 | 14 |
15 namespace ui { | 15 namespace ui { |
16 namespace test { | 16 namespace test { |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 class TestSoftwareMirroringController | |
21 : public DisplayConfigurator::SoftwareMirroringController { | |
22 public: | |
23 TestSoftwareMirroringController() : is_enabled_(false) {} | |
24 ~TestSoftwareMirroringController() override {} | |
25 | |
26 // DisplayConfigurator::SoftwareMirroringController: | |
27 void SetSoftwareMirroring(bool enabled) override { is_enabled_ = enabled; } | |
28 bool SoftwareMirroringEnabled() const override { return is_enabled_; } | |
oshima
2015/05/19 16:42:28
optional: accessors/mutators are typically uses se
oshima
2015/05/19 16:42:54
Doh, s/uses//
dnicoara
2015/05/19 16:50:16
I know, but these are part of an interface, so the
oshima
2015/05/19 16:53:52
sorry I missed override.
| |
29 | |
30 private: | |
31 bool is_enabled_; | |
32 | |
33 DISALLOW_COPY_AND_ASSIGN(TestSoftwareMirroringController); | |
34 }; | |
35 | |
20 class TestDisplayLayoutManager : public DisplayLayoutManager { | 36 class TestDisplayLayoutManager : public DisplayLayoutManager { |
21 public: | 37 public: |
22 TestDisplayLayoutManager() | 38 TestDisplayLayoutManager() |
23 : should_mirror_(true), | 39 : should_mirror_(true), |
24 display_state_(MULTIPLE_DISPLAY_STATE_INVALID), | 40 display_state_(MULTIPLE_DISPLAY_STATE_INVALID), |
25 power_state_(chromeos::DISPLAY_POWER_ALL_ON) {} | 41 power_state_(chromeos::DISPLAY_POWER_ALL_ON) {} |
26 ~TestDisplayLayoutManager() override {} | 42 ~TestDisplayLayoutManager() override {} |
27 | 43 |
28 void set_should_mirror(bool should_mirror) { should_mirror_ = should_mirror; } | 44 void set_should_mirror(bool should_mirror) { should_mirror_ = should_mirror; } |
29 | 45 |
30 void set_display_state(MultipleDisplayState state) { display_state_ = state; } | 46 void set_display_state(MultipleDisplayState state) { display_state_ = state; } |
31 | 47 |
32 void set_power_state(chromeos::DisplayPowerState state) { | 48 void set_power_state(chromeos::DisplayPowerState state) { |
33 power_state_ = state; | 49 power_state_ = state; |
34 } | 50 } |
35 | 51 |
52 void set_software_mirroring_controller( | |
53 scoped_ptr<DisplayConfigurator::SoftwareMirroringController> | |
54 software_mirroring_controller) { | |
55 software_mirroring_controller_ = software_mirroring_controller.Pass(); | |
56 } | |
57 | |
36 // DisplayConfigurator::DisplayLayoutManager: | 58 // DisplayConfigurator::DisplayLayoutManager: |
37 DisplayConfigurator::SoftwareMirroringController* | 59 DisplayConfigurator::SoftwareMirroringController* |
38 GetSoftwareMirroringController() const override { | 60 GetSoftwareMirroringController() const override { |
39 return nullptr; | 61 return software_mirroring_controller_.get(); |
40 } | 62 } |
41 | 63 |
42 DisplayConfigurator::StateController* GetStateController() const override { | 64 DisplayConfigurator::StateController* GetStateController() const override { |
43 return nullptr; | 65 return nullptr; |
44 } | 66 } |
45 | 67 |
46 MultipleDisplayState GetDisplayState() const override { | 68 MultipleDisplayState GetDisplayState() const override { |
47 return display_state_; | 69 return display_state_; |
48 } | 70 } |
49 | 71 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
102 | 124 |
103 return mode; | 125 return mode; |
104 } | 126 } |
105 | 127 |
106 bool should_mirror_; | 128 bool should_mirror_; |
107 | 129 |
108 MultipleDisplayState display_state_; | 130 MultipleDisplayState display_state_; |
109 | 131 |
110 chromeos::DisplayPowerState power_state_; | 132 chromeos::DisplayPowerState power_state_; |
111 | 133 |
134 scoped_ptr<DisplayConfigurator::SoftwareMirroringController> | |
135 software_mirroring_controller_; | |
136 | |
112 DISALLOW_COPY_AND_ASSIGN(TestDisplayLayoutManager); | 137 DISALLOW_COPY_AND_ASSIGN(TestDisplayLayoutManager); |
113 }; | 138 }; |
114 | 139 |
115 class UpdateDisplayConfigurationTaskTest : public testing::Test { | 140 class UpdateDisplayConfigurationTaskTest : public testing::Test { |
116 public: | 141 public: |
117 UpdateDisplayConfigurationTaskTest() | 142 UpdateDisplayConfigurationTaskTest() |
118 : delegate_(&log_), | 143 : delegate_(&log_), |
119 small_mode_(gfx::Size(1366, 768), false, 60.0f), | 144 small_mode_(gfx::Size(1366, 768), false, 60.0f), |
120 big_mode_(gfx::Size(2560, 1600), false, 60.0f), | 145 big_mode_(gfx::Size(2560, 1600), false, 60.0f), |
121 configured_(false), | 146 configured_(false), |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
364 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_SINGLE, display_state_); | 389 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_SINGLE, display_state_); |
365 EXPECT_EQ(chromeos::DISPLAY_POWER_ALL_OFF, power_state_); | 390 EXPECT_EQ(chromeos::DISPLAY_POWER_ALL_OFF, power_state_); |
366 EXPECT_EQ( | 391 EXPECT_EQ( |
367 JoinActions(kGrab, GetFramebufferAction(small_mode_.size(), &displays_[0], | 392 JoinActions(kGrab, GetFramebufferAction(small_mode_.size(), &displays_[0], |
368 nullptr).c_str(), | 393 nullptr).c_str(), |
369 GetCrtcAction(displays_[0], nullptr, gfx::Point()).c_str(), | 394 GetCrtcAction(displays_[0], nullptr, gfx::Point()).c_str(), |
370 kUngrab, NULL), | 395 kUngrab, NULL), |
371 log_.GetActionsAndClear()); | 396 log_.GetActionsAndClear()); |
372 } | 397 } |
373 | 398 |
399 TEST_F(UpdateDisplayConfigurationTaskTest, NoopSoftwareMirrorConfiguration) { | |
400 layout_manager_.set_should_mirror(false); | |
401 layout_manager_.set_software_mirroring_controller( | |
402 make_scoped_ptr(new TestSoftwareMirroringController())); | |
403 UpdateDisplays(2); | |
404 | |
405 { | |
406 UpdateDisplayConfigurationTask task( | |
407 &delegate_, &layout_manager_, MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED, | |
408 chromeos::DISPLAY_POWER_ALL_ON, 0, 0, false, | |
409 base::Bind(&UpdateDisplayConfigurationTaskTest::ResponseCallback, | |
410 base::Unretained(this))); | |
411 task.Run(); | |
412 } | |
413 | |
414 log_.GetActionsAndClear(); | |
415 | |
416 { | |
417 UpdateDisplayConfigurationTask task( | |
418 &delegate_, &layout_manager_, MULTIPLE_DISPLAY_STATE_DUAL_MIRROR, | |
419 chromeos::DISPLAY_POWER_ALL_ON, 0, 0, false, | |
420 base::Bind(&UpdateDisplayConfigurationTaskTest::ResponseCallback, | |
421 base::Unretained(this))); | |
422 task.Run(); | |
423 } | |
424 | |
425 EXPECT_TRUE(configuration_status_); | |
426 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED, display_state_); | |
427 EXPECT_TRUE(layout_manager_.GetSoftwareMirroringController() | |
428 ->SoftwareMirroringEnabled()); | |
429 EXPECT_EQ(JoinActions(kGrab, kUngrab, NULL), log_.GetActionsAndClear()); | |
430 } | |
431 | |
432 TEST_F(UpdateDisplayConfigurationTaskTest, | |
433 ForceConfigurationWhileGoingToSoftwareMirror) { | |
434 layout_manager_.set_should_mirror(false); | |
435 layout_manager_.set_software_mirroring_controller( | |
436 make_scoped_ptr(new TestSoftwareMirroringController())); | |
437 UpdateDisplays(2); | |
438 | |
439 { | |
440 UpdateDisplayConfigurationTask task( | |
441 &delegate_, &layout_manager_, MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED, | |
442 chromeos::DISPLAY_POWER_ALL_ON, 0, 0, false, | |
443 base::Bind(&UpdateDisplayConfigurationTaskTest::ResponseCallback, | |
444 base::Unretained(this))); | |
445 task.Run(); | |
446 } | |
447 | |
448 log_.GetActionsAndClear(); | |
449 | |
450 { | |
451 UpdateDisplayConfigurationTask task( | |
452 &delegate_, &layout_manager_, MULTIPLE_DISPLAY_STATE_DUAL_MIRROR, | |
453 chromeos::DISPLAY_POWER_ALL_ON, 0, 0, true /* force_configure */, | |
454 base::Bind(&UpdateDisplayConfigurationTaskTest::ResponseCallback, | |
455 base::Unretained(this))); | |
456 task.Run(); | |
457 } | |
458 | |
459 EXPECT_TRUE(configuration_status_); | |
460 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED, display_state_); | |
461 EXPECT_TRUE(layout_manager_.GetSoftwareMirroringController() | |
462 ->SoftwareMirroringEnabled()); | |
463 EXPECT_EQ( | |
464 JoinActions( | |
465 kGrab, GetFramebufferAction(gfx::Size(big_mode_.size().width(), | |
466 small_mode_.size().height() + | |
467 big_mode_.size().height()), | |
468 &displays_[0], &displays_[1]).c_str(), | |
469 GetCrtcAction(displays_[0], &small_mode_, gfx::Point()).c_str(), | |
470 GetCrtcAction(displays_[1], &big_mode_, | |
471 gfx::Point(0, small_mode_.size().height())).c_str(), | |
472 kUngrab, NULL), | |
473 log_.GetActionsAndClear()); | |
474 } | |
475 | |
374 } // namespace test | 476 } // namespace test |
375 } // namespace ui | 477 } // namespace ui |
OLD | NEW |