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