| 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 "ash/display/projecting_observer_chromeos.h" | 5 #include "ash/display/projecting_observer_chromeos.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_vector.h" |
| 7 #include "chromeos/dbus/fake_dbus_thread_manager.h" | 8 #include "chromeos/dbus/fake_dbus_thread_manager.h" |
| 8 #include "chromeos/dbus/fake_power_manager_client.h" | 9 #include "chromeos/dbus/fake_power_manager_client.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "ui/display/chromeos/test/test_display_snapshot.h" |
| 10 | 12 |
| 11 namespace ash { | 13 namespace ash { |
| 12 | 14 |
| 13 namespace internal { | 15 namespace internal { |
| 14 | 16 |
| 15 namespace { | 17 namespace { |
| 16 | 18 |
| 17 ui::OutputConfigurator::OutputSnapshot CreateInternalSnapshot() { | 19 ui::TestDisplaySnapshot* CreateInternalSnapshot() { |
| 18 ui::OutputConfigurator::OutputSnapshot output; | 20 ui::TestDisplaySnapshot* output = new ui::TestDisplaySnapshot(); |
| 19 output.type = ui::OUTPUT_TYPE_INTERNAL; | 21 output->set_type(ui::OUTPUT_TYPE_INTERNAL); |
| 20 return output; | 22 return output; |
| 21 } | 23 } |
| 22 | 24 |
| 23 ui::OutputConfigurator::OutputSnapshot CreateVGASnapshot() { | 25 ui::TestDisplaySnapshot* CreateVGASnapshot() { |
| 24 ui::OutputConfigurator::OutputSnapshot output; | 26 ui::TestDisplaySnapshot* output = new ui::TestDisplaySnapshot(); |
| 25 output.type = ui::OUTPUT_TYPE_VGA; | 27 output->set_type(ui::OUTPUT_TYPE_VGA); |
| 26 return output; | 28 return output; |
| 27 } | 29 } |
| 28 | 30 |
| 31 ui::OutputConfigurator::DisplayStateList CreateOutputs( |
| 32 const ScopedVector<ui::TestDisplaySnapshot>& displays) { |
| 33 ui::OutputConfigurator::DisplayStateList outputs; |
| 34 for (size_t i = 0; i < displays.size(); ++i) { |
| 35 ui::OutputConfigurator::DisplayState state; |
| 36 state.display = displays[i]; |
| 37 outputs.push_back(state); |
| 38 } |
| 39 |
| 40 return outputs; |
| 41 } |
| 42 |
| 29 class ProjectingObserverTest : public testing::Test { | 43 class ProjectingObserverTest : public testing::Test { |
| 30 public: | 44 public: |
| 31 ProjectingObserverTest() : observer_(new ProjectingObserver()) { | 45 ProjectingObserverTest() : observer_(new ProjectingObserver()) { |
| 32 chromeos::FakeDBusThreadManager* dbus_manager = | 46 chromeos::FakeDBusThreadManager* dbus_manager = |
| 33 new chromeos::FakeDBusThreadManager(); | 47 new chromeos::FakeDBusThreadManager(); |
| 34 fake_power_client_ = new chromeos::FakePowerManagerClient(); | 48 fake_power_client_ = new chromeos::FakePowerManagerClient(); |
| 35 | 49 |
| 36 dbus_manager->SetPowerManagerClient( | 50 dbus_manager->SetPowerManagerClient( |
| 37 scoped_ptr<chromeos::PowerManagerClient>(fake_power_client_)); | 51 scoped_ptr<chromeos::PowerManagerClient>(fake_power_client_)); |
| 38 | 52 |
| 39 // Takes ownership of |dbus_manager|. | 53 // Takes ownership of |dbus_manager|. |
| 40 chromeos::DBusThreadManager::InitializeForTesting(dbus_manager); | 54 chromeos::DBusThreadManager::InitializeForTesting(dbus_manager); |
| 41 } | 55 } |
| 42 | 56 |
| 43 virtual ~ProjectingObserverTest() { | 57 virtual ~ProjectingObserverTest() { |
| 44 chromeos::DBusThreadManager::Shutdown(); | 58 chromeos::DBusThreadManager::Shutdown(); |
| 45 } | 59 } |
| 46 | 60 |
| 47 protected: | 61 protected: |
| 48 scoped_ptr<ProjectingObserver> observer_; | 62 scoped_ptr<ProjectingObserver> observer_; |
| 49 chromeos::FakePowerManagerClient* fake_power_client_; // Not owned. | 63 chromeos::FakePowerManagerClient* fake_power_client_; // Not owned. |
| 50 | 64 |
| 51 DISALLOW_COPY_AND_ASSIGN(ProjectingObserverTest); | 65 DISALLOW_COPY_AND_ASSIGN(ProjectingObserverTest); |
| 52 }; | 66 }; |
| 53 | 67 |
| 54 } // namespace | 68 } // namespace |
| 55 | 69 |
| 56 TEST_F(ProjectingObserverTest, CheckNoDisplay) { | 70 TEST_F(ProjectingObserverTest, CheckNoDisplay) { |
| 57 std::vector<ui::OutputConfigurator::OutputSnapshot> outputs; | 71 ScopedVector<ui::TestDisplaySnapshot> displays; |
| 72 ui::OutputConfigurator::DisplayStateList outputs = CreateOutputs(displays); |
| 58 observer_->OnDisplayModeChanged(outputs); | 73 observer_->OnDisplayModeChanged(outputs); |
| 59 | 74 |
| 60 EXPECT_EQ(1, fake_power_client_->num_set_is_projecting_calls()); | 75 EXPECT_EQ(1, fake_power_client_->num_set_is_projecting_calls()); |
| 61 EXPECT_FALSE(fake_power_client_->is_projecting()); | 76 EXPECT_FALSE(fake_power_client_->is_projecting()); |
| 62 } | 77 } |
| 63 | 78 |
| 64 TEST_F(ProjectingObserverTest, CheckWithoutInternalDisplay) { | 79 TEST_F(ProjectingObserverTest, CheckWithoutInternalDisplay) { |
| 65 std::vector<ui::OutputConfigurator::OutputSnapshot> outputs; | 80 ScopedVector<ui::TestDisplaySnapshot> displays; |
| 66 outputs.push_back(CreateVGASnapshot()); | 81 displays.push_back(CreateVGASnapshot()); |
| 82 ui::OutputConfigurator::DisplayStateList outputs = CreateOutputs(displays); |
| 67 observer_->OnDisplayModeChanged(outputs); | 83 observer_->OnDisplayModeChanged(outputs); |
| 68 | 84 |
| 69 EXPECT_EQ(1, fake_power_client_->num_set_is_projecting_calls()); | 85 EXPECT_EQ(1, fake_power_client_->num_set_is_projecting_calls()); |
| 70 EXPECT_FALSE(fake_power_client_->is_projecting()); | 86 EXPECT_FALSE(fake_power_client_->is_projecting()); |
| 71 } | 87 } |
| 72 | 88 |
| 73 TEST_F(ProjectingObserverTest, CheckWithInternalDisplay) { | 89 TEST_F(ProjectingObserverTest, CheckWithInternalDisplay) { |
| 74 std::vector<ui::OutputConfigurator::OutputSnapshot> outputs; | 90 ScopedVector<ui::TestDisplaySnapshot> displays; |
| 75 outputs.push_back(CreateInternalSnapshot()); | 91 displays.push_back(CreateInternalSnapshot()); |
| 92 ui::OutputConfigurator::DisplayStateList outputs = CreateOutputs(displays); |
| 76 observer_->OnDisplayModeChanged(outputs); | 93 observer_->OnDisplayModeChanged(outputs); |
| 77 | 94 |
| 78 EXPECT_EQ(1, fake_power_client_->num_set_is_projecting_calls()); | 95 EXPECT_EQ(1, fake_power_client_->num_set_is_projecting_calls()); |
| 79 EXPECT_FALSE(fake_power_client_->is_projecting()); | 96 EXPECT_FALSE(fake_power_client_->is_projecting()); |
| 80 } | 97 } |
| 81 | 98 |
| 82 TEST_F(ProjectingObserverTest, CheckWithTwoVGADisplays) { | 99 TEST_F(ProjectingObserverTest, CheckWithTwoVGADisplays) { |
| 83 std::vector<ui::OutputConfigurator::OutputSnapshot> outputs; | 100 ScopedVector<ui::TestDisplaySnapshot> displays; |
| 84 outputs.push_back(CreateVGASnapshot()); | 101 displays.push_back(CreateVGASnapshot()); |
| 85 outputs.push_back(CreateVGASnapshot()); | 102 displays.push_back(CreateVGASnapshot()); |
| 103 ui::OutputConfigurator::DisplayStateList outputs = CreateOutputs(displays); |
| 86 observer_->OnDisplayModeChanged(outputs); | 104 observer_->OnDisplayModeChanged(outputs); |
| 87 | 105 |
| 88 EXPECT_EQ(1, fake_power_client_->num_set_is_projecting_calls()); | 106 EXPECT_EQ(1, fake_power_client_->num_set_is_projecting_calls()); |
| 89 // We need at least 1 internal display to set projecting to on. | 107 // We need at least 1 internal display to set projecting to on. |
| 90 EXPECT_FALSE(fake_power_client_->is_projecting()); | 108 EXPECT_FALSE(fake_power_client_->is_projecting()); |
| 91 } | 109 } |
| 92 | 110 |
| 93 TEST_F(ProjectingObserverTest, CheckWithInternalAndVGADisplays) { | 111 TEST_F(ProjectingObserverTest, CheckWithInternalAndVGADisplays) { |
| 94 std::vector<ui::OutputConfigurator::OutputSnapshot> outputs; | 112 ScopedVector<ui::TestDisplaySnapshot> displays; |
| 95 outputs.push_back(CreateInternalSnapshot()); | 113 displays.push_back(CreateInternalSnapshot()); |
| 96 outputs.push_back(CreateVGASnapshot()); | 114 displays.push_back(CreateVGASnapshot()); |
| 115 ui::OutputConfigurator::DisplayStateList outputs = CreateOutputs(displays); |
| 97 observer_->OnDisplayModeChanged(outputs); | 116 observer_->OnDisplayModeChanged(outputs); |
| 98 | 117 |
| 99 EXPECT_EQ(1, fake_power_client_->num_set_is_projecting_calls()); | 118 EXPECT_EQ(1, fake_power_client_->num_set_is_projecting_calls()); |
| 100 EXPECT_TRUE(fake_power_client_->is_projecting()); | 119 EXPECT_TRUE(fake_power_client_->is_projecting()); |
| 101 } | 120 } |
| 102 | 121 |
| 103 TEST_F(ProjectingObserverTest, CheckWithVGADisplayAndOneCastingSession) { | 122 TEST_F(ProjectingObserverTest, CheckWithVGADisplayAndOneCastingSession) { |
| 104 std::vector<ui::OutputConfigurator::OutputSnapshot> outputs; | 123 ScopedVector<ui::TestDisplaySnapshot> displays; |
| 105 outputs.push_back(CreateVGASnapshot()); | 124 displays.push_back(CreateVGASnapshot()); |
| 125 ui::OutputConfigurator::DisplayStateList outputs = CreateOutputs(displays); |
| 106 observer_->OnDisplayModeChanged(outputs); | 126 observer_->OnDisplayModeChanged(outputs); |
| 107 | 127 |
| 108 observer_->OnCastingSessionStartedOrStopped(true); | 128 observer_->OnCastingSessionStartedOrStopped(true); |
| 109 | 129 |
| 110 EXPECT_EQ(2, fake_power_client_->num_set_is_projecting_calls()); | 130 EXPECT_EQ(2, fake_power_client_->num_set_is_projecting_calls()); |
| 111 // Need at least one internal display to set projecting state to |true|. | 131 // Need at least one internal display to set projecting state to |true|. |
| 112 EXPECT_FALSE(fake_power_client_->is_projecting()); | 132 EXPECT_FALSE(fake_power_client_->is_projecting()); |
| 113 } | 133 } |
| 114 | 134 |
| 115 TEST_F(ProjectingObserverTest, CheckWithInternalDisplayAndOneCastingSession) { | 135 TEST_F(ProjectingObserverTest, CheckWithInternalDisplayAndOneCastingSession) { |
| 116 std::vector<ui::OutputConfigurator::OutputSnapshot> outputs; | 136 ScopedVector<ui::TestDisplaySnapshot> displays; |
| 117 outputs.push_back(CreateInternalSnapshot()); | 137 displays.push_back(CreateInternalSnapshot()); |
| 138 ui::OutputConfigurator::DisplayStateList outputs = CreateOutputs(displays); |
| 118 observer_->OnDisplayModeChanged(outputs); | 139 observer_->OnDisplayModeChanged(outputs); |
| 119 | 140 |
| 120 observer_->OnCastingSessionStartedOrStopped(true); | 141 observer_->OnCastingSessionStartedOrStopped(true); |
| 121 | 142 |
| 122 EXPECT_EQ(2, fake_power_client_->num_set_is_projecting_calls()); | 143 EXPECT_EQ(2, fake_power_client_->num_set_is_projecting_calls()); |
| 123 EXPECT_TRUE(fake_power_client_->is_projecting()); | 144 EXPECT_TRUE(fake_power_client_->is_projecting()); |
| 124 } | 145 } |
| 125 | 146 |
| 126 TEST_F(ProjectingObserverTest, CheckProjectingAfterClosingACastingSession) { | 147 TEST_F(ProjectingObserverTest, CheckProjectingAfterClosingACastingSession) { |
| 127 std::vector<ui::OutputConfigurator::OutputSnapshot> outputs; | 148 ScopedVector<ui::TestDisplaySnapshot> displays; |
| 128 outputs.push_back(CreateInternalSnapshot()); | 149 displays.push_back(CreateInternalSnapshot()); |
| 150 ui::OutputConfigurator::DisplayStateList outputs = CreateOutputs(displays); |
| 129 observer_->OnDisplayModeChanged(outputs); | 151 observer_->OnDisplayModeChanged(outputs); |
| 130 | 152 |
| 131 observer_->OnCastingSessionStartedOrStopped(true); | 153 observer_->OnCastingSessionStartedOrStopped(true); |
| 132 observer_->OnCastingSessionStartedOrStopped(true); | 154 observer_->OnCastingSessionStartedOrStopped(true); |
| 133 | 155 |
| 134 EXPECT_EQ(3, fake_power_client_->num_set_is_projecting_calls()); | 156 EXPECT_EQ(3, fake_power_client_->num_set_is_projecting_calls()); |
| 135 EXPECT_TRUE(fake_power_client_->is_projecting()); | 157 EXPECT_TRUE(fake_power_client_->is_projecting()); |
| 136 | 158 |
| 137 observer_->OnCastingSessionStartedOrStopped(false); | 159 observer_->OnCastingSessionStartedOrStopped(false); |
| 138 | 160 |
| 139 EXPECT_EQ(4, fake_power_client_->num_set_is_projecting_calls()); | 161 EXPECT_EQ(4, fake_power_client_->num_set_is_projecting_calls()); |
| 140 EXPECT_TRUE(fake_power_client_->is_projecting()); | 162 EXPECT_TRUE(fake_power_client_->is_projecting()); |
| 141 } | 163 } |
| 142 | 164 |
| 143 TEST_F(ProjectingObserverTest, | 165 TEST_F(ProjectingObserverTest, |
| 144 CheckStopProjectingAfterClosingAllCastingSessions) { | 166 CheckStopProjectingAfterClosingAllCastingSessions) { |
| 145 std::vector<ui::OutputConfigurator::OutputSnapshot> outputs; | 167 ScopedVector<ui::TestDisplaySnapshot> displays; |
| 146 outputs.push_back(CreateInternalSnapshot()); | 168 displays.push_back(CreateInternalSnapshot()); |
| 169 ui::OutputConfigurator::DisplayStateList outputs = CreateOutputs(displays); |
| 147 observer_->OnDisplayModeChanged(outputs); | 170 observer_->OnDisplayModeChanged(outputs); |
| 148 | 171 |
| 149 observer_->OnCastingSessionStartedOrStopped(true); | 172 observer_->OnCastingSessionStartedOrStopped(true); |
| 150 observer_->OnCastingSessionStartedOrStopped(false); | 173 observer_->OnCastingSessionStartedOrStopped(false); |
| 151 | 174 |
| 152 EXPECT_EQ(3, fake_power_client_->num_set_is_projecting_calls()); | 175 EXPECT_EQ(3, fake_power_client_->num_set_is_projecting_calls()); |
| 153 EXPECT_FALSE(fake_power_client_->is_projecting()); | 176 EXPECT_FALSE(fake_power_client_->is_projecting()); |
| 154 } | 177 } |
| 155 | 178 |
| 156 TEST_F(ProjectingObserverTest, | 179 TEST_F(ProjectingObserverTest, |
| 157 CheckStopProjectingAfterDisconnectingSecondOutput) { | 180 CheckStopProjectingAfterDisconnectingSecondOutput) { |
| 158 std::vector<ui::OutputConfigurator::OutputSnapshot> outputs; | 181 ScopedVector<ui::TestDisplaySnapshot> displays; |
| 159 outputs.push_back(CreateInternalSnapshot()); | 182 displays.push_back(CreateInternalSnapshot()); |
| 160 outputs.push_back(CreateVGASnapshot()); | 183 displays.push_back(CreateVGASnapshot()); |
| 184 ui::OutputConfigurator::DisplayStateList outputs = CreateOutputs(displays); |
| 161 observer_->OnDisplayModeChanged(outputs); | 185 observer_->OnDisplayModeChanged(outputs); |
| 162 | 186 |
| 163 // Remove VGA output. | 187 // Remove VGA output. |
| 164 outputs.erase(outputs.begin() + 1); | 188 outputs.erase(outputs.begin() + 1); |
| 165 observer_->OnDisplayModeChanged(outputs); | 189 observer_->OnDisplayModeChanged(outputs); |
| 166 | 190 |
| 167 EXPECT_EQ(2, fake_power_client_->num_set_is_projecting_calls()); | 191 EXPECT_EQ(2, fake_power_client_->num_set_is_projecting_calls()); |
| 168 EXPECT_FALSE(fake_power_client_->is_projecting()); | 192 EXPECT_FALSE(fake_power_client_->is_projecting()); |
| 169 } | 193 } |
| 170 | 194 |
| 171 } // namespace internal | 195 } // namespace internal |
| 172 | 196 |
| 173 } // namespace ash | 197 } // namespace ash |
| OLD | NEW |