Enable maximize mode when keyboard is open past 180 degrees.
[chromium-blink-merge.git] / ash / display / projecting_observer_chromeos_unittest.cc
bloba6c1d2053e2dcdee8100c12d7daf8daf76d8fa58
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.
5 #include "ash/display/projecting_observer_chromeos.h"
7 #include "base/memory/scoped_vector.h"
8 #include "chromeos/dbus/fake_dbus_thread_manager.h"
9 #include "chromeos/dbus/fake_power_manager_client.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "ui/display/chromeos/test/test_display_snapshot.h"
13 namespace ash {
14 namespace {
16 ui::TestDisplaySnapshot* CreateInternalSnapshot() {
17 ui::TestDisplaySnapshot* output = new ui::TestDisplaySnapshot();
18 output->set_type(ui::OUTPUT_TYPE_INTERNAL);
19 return output;
22 ui::TestDisplaySnapshot* CreateVGASnapshot() {
23 ui::TestDisplaySnapshot* output = new ui::TestDisplaySnapshot();
24 output->set_type(ui::OUTPUT_TYPE_VGA);
25 return output;
28 ui::OutputConfigurator::DisplayStateList CreateOutputs(
29 const ScopedVector<ui::TestDisplaySnapshot>& displays) {
30 ui::OutputConfigurator::DisplayStateList outputs;
31 for (size_t i = 0; i < displays.size(); ++i) {
32 ui::OutputConfigurator::DisplayState state;
33 state.display = displays[i];
34 outputs.push_back(state);
37 return outputs;
40 class ProjectingObserverTest : public testing::Test {
41 public:
42 ProjectingObserverTest() : observer_(new ProjectingObserver()) {
43 chromeos::FakeDBusThreadManager* dbus_manager =
44 new chromeos::FakeDBusThreadManager();
45 fake_power_client_ = new chromeos::FakePowerManagerClient();
47 dbus_manager->SetPowerManagerClient(
48 scoped_ptr<chromeos::PowerManagerClient>(fake_power_client_));
50 // Takes ownership of |dbus_manager|.
51 chromeos::DBusThreadManager::InitializeForTesting(dbus_manager);
54 virtual ~ProjectingObserverTest() {
55 chromeos::DBusThreadManager::Shutdown();
58 protected:
59 scoped_ptr<ProjectingObserver> observer_;
60 chromeos::FakePowerManagerClient* fake_power_client_; // Not owned.
62 DISALLOW_COPY_AND_ASSIGN(ProjectingObserverTest);
65 } // namespace
67 TEST_F(ProjectingObserverTest, CheckNoDisplay) {
68 ScopedVector<ui::TestDisplaySnapshot> displays;
69 ui::OutputConfigurator::DisplayStateList outputs = CreateOutputs(displays);
70 observer_->OnDisplayModeChanged(outputs);
72 EXPECT_EQ(1, fake_power_client_->num_set_is_projecting_calls());
73 EXPECT_FALSE(fake_power_client_->is_projecting());
76 TEST_F(ProjectingObserverTest, CheckWithoutInternalDisplay) {
77 ScopedVector<ui::TestDisplaySnapshot> displays;
78 displays.push_back(CreateVGASnapshot());
79 ui::OutputConfigurator::DisplayStateList outputs = CreateOutputs(displays);
80 observer_->OnDisplayModeChanged(outputs);
82 EXPECT_EQ(1, fake_power_client_->num_set_is_projecting_calls());
83 EXPECT_FALSE(fake_power_client_->is_projecting());
86 TEST_F(ProjectingObserverTest, CheckWithInternalDisplay) {
87 ScopedVector<ui::TestDisplaySnapshot> displays;
88 displays.push_back(CreateInternalSnapshot());
89 ui::OutputConfigurator::DisplayStateList outputs = CreateOutputs(displays);
90 observer_->OnDisplayModeChanged(outputs);
92 EXPECT_EQ(1, fake_power_client_->num_set_is_projecting_calls());
93 EXPECT_FALSE(fake_power_client_->is_projecting());
96 TEST_F(ProjectingObserverTest, CheckWithTwoVGADisplays) {
97 ScopedVector<ui::TestDisplaySnapshot> displays;
98 displays.push_back(CreateVGASnapshot());
99 displays.push_back(CreateVGASnapshot());
100 ui::OutputConfigurator::DisplayStateList outputs = CreateOutputs(displays);
101 observer_->OnDisplayModeChanged(outputs);
103 EXPECT_EQ(1, fake_power_client_->num_set_is_projecting_calls());
104 // We need at least 1 internal display to set projecting to on.
105 EXPECT_FALSE(fake_power_client_->is_projecting());
108 TEST_F(ProjectingObserverTest, CheckWithInternalAndVGADisplays) {
109 ScopedVector<ui::TestDisplaySnapshot> displays;
110 displays.push_back(CreateInternalSnapshot());
111 displays.push_back(CreateVGASnapshot());
112 ui::OutputConfigurator::DisplayStateList outputs = CreateOutputs(displays);
113 observer_->OnDisplayModeChanged(outputs);
115 EXPECT_EQ(1, fake_power_client_->num_set_is_projecting_calls());
116 EXPECT_TRUE(fake_power_client_->is_projecting());
119 TEST_F(ProjectingObserverTest, CheckWithVGADisplayAndOneCastingSession) {
120 ScopedVector<ui::TestDisplaySnapshot> displays;
121 displays.push_back(CreateVGASnapshot());
122 ui::OutputConfigurator::DisplayStateList outputs = CreateOutputs(displays);
123 observer_->OnDisplayModeChanged(outputs);
125 observer_->OnCastingSessionStartedOrStopped(true);
127 EXPECT_EQ(2, fake_power_client_->num_set_is_projecting_calls());
128 // Need at least one internal display to set projecting state to |true|.
129 EXPECT_FALSE(fake_power_client_->is_projecting());
132 TEST_F(ProjectingObserverTest, CheckWithInternalDisplayAndOneCastingSession) {
133 ScopedVector<ui::TestDisplaySnapshot> displays;
134 displays.push_back(CreateInternalSnapshot());
135 ui::OutputConfigurator::DisplayStateList outputs = CreateOutputs(displays);
136 observer_->OnDisplayModeChanged(outputs);
138 observer_->OnCastingSessionStartedOrStopped(true);
140 EXPECT_EQ(2, fake_power_client_->num_set_is_projecting_calls());
141 EXPECT_TRUE(fake_power_client_->is_projecting());
144 TEST_F(ProjectingObserverTest, CheckProjectingAfterClosingACastingSession) {
145 ScopedVector<ui::TestDisplaySnapshot> displays;
146 displays.push_back(CreateInternalSnapshot());
147 ui::OutputConfigurator::DisplayStateList outputs = CreateOutputs(displays);
148 observer_->OnDisplayModeChanged(outputs);
150 observer_->OnCastingSessionStartedOrStopped(true);
151 observer_->OnCastingSessionStartedOrStopped(true);
153 EXPECT_EQ(3, fake_power_client_->num_set_is_projecting_calls());
154 EXPECT_TRUE(fake_power_client_->is_projecting());
156 observer_->OnCastingSessionStartedOrStopped(false);
158 EXPECT_EQ(4, fake_power_client_->num_set_is_projecting_calls());
159 EXPECT_TRUE(fake_power_client_->is_projecting());
162 TEST_F(ProjectingObserverTest,
163 CheckStopProjectingAfterClosingAllCastingSessions) {
164 ScopedVector<ui::TestDisplaySnapshot> displays;
165 displays.push_back(CreateInternalSnapshot());
166 ui::OutputConfigurator::DisplayStateList outputs = CreateOutputs(displays);
167 observer_->OnDisplayModeChanged(outputs);
169 observer_->OnCastingSessionStartedOrStopped(true);
170 observer_->OnCastingSessionStartedOrStopped(false);
172 EXPECT_EQ(3, fake_power_client_->num_set_is_projecting_calls());
173 EXPECT_FALSE(fake_power_client_->is_projecting());
176 TEST_F(ProjectingObserverTest,
177 CheckStopProjectingAfterDisconnectingSecondOutput) {
178 ScopedVector<ui::TestDisplaySnapshot> displays;
179 displays.push_back(CreateInternalSnapshot());
180 displays.push_back(CreateVGASnapshot());
181 ui::OutputConfigurator::DisplayStateList outputs = CreateOutputs(displays);
182 observer_->OnDisplayModeChanged(outputs);
184 // Remove VGA output.
185 outputs.erase(outputs.begin() + 1);
186 observer_->OnDisplayModeChanged(outputs);
188 EXPECT_EQ(2, fake_power_client_->num_set_is_projecting_calls());
189 EXPECT_FALSE(fake_power_client_->is_projecting());
192 } // namespace ash