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