Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(251)

Side by Side Diff: ash/display/projecting_observer_chromeos_unittest.cc

Issue 187073002: Refactoring display configuration state to allow generic state objects (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 chromeos::OutputConfigurator::OutputSnapshot CreateInternalSnapshot() { 19 ui::TestDisplaySnapshot* CreateInternalSnapshot() {
18 chromeos::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 chromeos::OutputConfigurator::OutputSnapshot CreateVGASnapshot() { 25 ui::TestDisplaySnapshot* CreateVGASnapshot() {
24 chromeos::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 std::vector<chromeos::OutputConfigurator::InternalDisplayState> CreateOutputs(
32 const ScopedVector<ui::TestDisplaySnapshot>& displays) {
33 std::vector<chromeos::OutputConfigurator::InternalDisplayState> outputs;
34 for (size_t i = 0; i < displays.size(); ++i) {
35 chromeos::OutputConfigurator::InternalDisplayState 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<chromeos::OutputConfigurator::OutputSnapshot> outputs; 71 ScopedVector<ui::TestDisplaySnapshot> displays;
72 std::vector<chromeos::OutputConfigurator::InternalDisplayState> outputs =
73 CreateOutputs(displays);
58 observer_->OnDisplayModeChanged(outputs); 74 observer_->OnDisplayModeChanged(outputs);
59 75
60 EXPECT_EQ(1, fake_power_client_->num_set_is_projecting_calls()); 76 EXPECT_EQ(1, fake_power_client_->num_set_is_projecting_calls());
61 EXPECT_FALSE(fake_power_client_->is_projecting()); 77 EXPECT_FALSE(fake_power_client_->is_projecting());
62 } 78 }
63 79
64 TEST_F(ProjectingObserverTest, CheckWithoutInternalDisplay) { 80 TEST_F(ProjectingObserverTest, CheckWithoutInternalDisplay) {
65 std::vector<chromeos::OutputConfigurator::OutputSnapshot> outputs; 81 ScopedVector<ui::TestDisplaySnapshot> displays;
66 outputs.push_back(CreateVGASnapshot()); 82 displays.push_back(CreateVGASnapshot());
83 std::vector<chromeos::OutputConfigurator::InternalDisplayState> outputs =
84 CreateOutputs(displays);
67 observer_->OnDisplayModeChanged(outputs); 85 observer_->OnDisplayModeChanged(outputs);
68 86
69 EXPECT_EQ(1, fake_power_client_->num_set_is_projecting_calls()); 87 EXPECT_EQ(1, fake_power_client_->num_set_is_projecting_calls());
70 EXPECT_FALSE(fake_power_client_->is_projecting()); 88 EXPECT_FALSE(fake_power_client_->is_projecting());
71 } 89 }
72 90
73 TEST_F(ProjectingObserverTest, CheckWithInternalDisplay) { 91 TEST_F(ProjectingObserverTest, CheckWithInternalDisplay) {
74 std::vector<chromeos::OutputConfigurator::OutputSnapshot> outputs; 92 ScopedVector<ui::TestDisplaySnapshot> displays;
75 outputs.push_back(CreateInternalSnapshot()); 93 displays.push_back(CreateInternalSnapshot());
94 std::vector<chromeos::OutputConfigurator::InternalDisplayState> outputs =
95 CreateOutputs(displays);
76 observer_->OnDisplayModeChanged(outputs); 96 observer_->OnDisplayModeChanged(outputs);
77 97
78 EXPECT_EQ(1, fake_power_client_->num_set_is_projecting_calls()); 98 EXPECT_EQ(1, fake_power_client_->num_set_is_projecting_calls());
79 EXPECT_FALSE(fake_power_client_->is_projecting()); 99 EXPECT_FALSE(fake_power_client_->is_projecting());
80 } 100 }
81 101
82 TEST_F(ProjectingObserverTest, CheckWithTwoVGADisplays) { 102 TEST_F(ProjectingObserverTest, CheckWithTwoVGADisplays) {
83 std::vector<chromeos::OutputConfigurator::OutputSnapshot> outputs; 103 ScopedVector<ui::TestDisplaySnapshot> displays;
84 outputs.push_back(CreateVGASnapshot()); 104 displays.push_back(CreateVGASnapshot());
85 outputs.push_back(CreateVGASnapshot()); 105 displays.push_back(CreateVGASnapshot());
106 std::vector<chromeos::OutputConfigurator::InternalDisplayState> outputs =
107 CreateOutputs(displays);
86 observer_->OnDisplayModeChanged(outputs); 108 observer_->OnDisplayModeChanged(outputs);
87 109
88 EXPECT_EQ(1, fake_power_client_->num_set_is_projecting_calls()); 110 EXPECT_EQ(1, fake_power_client_->num_set_is_projecting_calls());
89 // We need at least 1 internal display to set projecting to on. 111 // We need at least 1 internal display to set projecting to on.
90 EXPECT_FALSE(fake_power_client_->is_projecting()); 112 EXPECT_FALSE(fake_power_client_->is_projecting());
91 } 113 }
92 114
93 TEST_F(ProjectingObserverTest, CheckWithInternalAndVGADisplays) { 115 TEST_F(ProjectingObserverTest, CheckWithInternalAndVGADisplays) {
94 std::vector<chromeos::OutputConfigurator::OutputSnapshot> outputs; 116 ScopedVector<ui::TestDisplaySnapshot> displays;
95 outputs.push_back(CreateInternalSnapshot()); 117 displays.push_back(CreateInternalSnapshot());
96 outputs.push_back(CreateVGASnapshot()); 118 displays.push_back(CreateVGASnapshot());
119 std::vector<chromeos::OutputConfigurator::InternalDisplayState> outputs =
120 CreateOutputs(displays);
97 observer_->OnDisplayModeChanged(outputs); 121 observer_->OnDisplayModeChanged(outputs);
98 122
99 EXPECT_EQ(1, fake_power_client_->num_set_is_projecting_calls()); 123 EXPECT_EQ(1, fake_power_client_->num_set_is_projecting_calls());
100 EXPECT_TRUE(fake_power_client_->is_projecting()); 124 EXPECT_TRUE(fake_power_client_->is_projecting());
101 } 125 }
102 126
103 TEST_F(ProjectingObserverTest, CheckWithVGADisplayAndOneCastingSession) { 127 TEST_F(ProjectingObserverTest, CheckWithVGADisplayAndOneCastingSession) {
104 std::vector<chromeos::OutputConfigurator::OutputSnapshot> outputs; 128 ScopedVector<ui::TestDisplaySnapshot> displays;
105 outputs.push_back(CreateVGASnapshot()); 129 displays.push_back(CreateVGASnapshot());
130 std::vector<chromeos::OutputConfigurator::InternalDisplayState> outputs =
131 CreateOutputs(displays);
106 observer_->OnDisplayModeChanged(outputs); 132 observer_->OnDisplayModeChanged(outputs);
107 133
108 observer_->OnCastingSessionStartedOrStopped(true); 134 observer_->OnCastingSessionStartedOrStopped(true);
109 135
110 EXPECT_EQ(2, fake_power_client_->num_set_is_projecting_calls()); 136 EXPECT_EQ(2, fake_power_client_->num_set_is_projecting_calls());
111 // Need at least one internal display to set projecting state to |true|. 137 // Need at least one internal display to set projecting state to |true|.
112 EXPECT_FALSE(fake_power_client_->is_projecting()); 138 EXPECT_FALSE(fake_power_client_->is_projecting());
113 } 139 }
114 140
115 TEST_F(ProjectingObserverTest, CheckWithInternalDisplayAndOneCastingSession) { 141 TEST_F(ProjectingObserverTest, CheckWithInternalDisplayAndOneCastingSession) {
116 std::vector<chromeos::OutputConfigurator::OutputSnapshot> outputs; 142 ScopedVector<ui::TestDisplaySnapshot> displays;
117 outputs.push_back(CreateInternalSnapshot()); 143 displays.push_back(CreateInternalSnapshot());
144 std::vector<chromeos::OutputConfigurator::InternalDisplayState> outputs =
145 CreateOutputs(displays);
118 observer_->OnDisplayModeChanged(outputs); 146 observer_->OnDisplayModeChanged(outputs);
119 147
120 observer_->OnCastingSessionStartedOrStopped(true); 148 observer_->OnCastingSessionStartedOrStopped(true);
121 149
122 EXPECT_EQ(2, fake_power_client_->num_set_is_projecting_calls()); 150 EXPECT_EQ(2, fake_power_client_->num_set_is_projecting_calls());
123 EXPECT_TRUE(fake_power_client_->is_projecting()); 151 EXPECT_TRUE(fake_power_client_->is_projecting());
124 } 152 }
125 153
126 TEST_F(ProjectingObserverTest, CheckProjectingAfterClosingACastingSession) { 154 TEST_F(ProjectingObserverTest, CheckProjectingAfterClosingACastingSession) {
127 std::vector<chromeos::OutputConfigurator::OutputSnapshot> outputs; 155 ScopedVector<ui::TestDisplaySnapshot> displays;
128 outputs.push_back(CreateInternalSnapshot()); 156 displays.push_back(CreateInternalSnapshot());
157 std::vector<chromeos::OutputConfigurator::InternalDisplayState> outputs =
158 CreateOutputs(displays);
129 observer_->OnDisplayModeChanged(outputs); 159 observer_->OnDisplayModeChanged(outputs);
130 160
131 observer_->OnCastingSessionStartedOrStopped(true); 161 observer_->OnCastingSessionStartedOrStopped(true);
132 observer_->OnCastingSessionStartedOrStopped(true); 162 observer_->OnCastingSessionStartedOrStopped(true);
133 163
134 EXPECT_EQ(3, fake_power_client_->num_set_is_projecting_calls()); 164 EXPECT_EQ(3, fake_power_client_->num_set_is_projecting_calls());
135 EXPECT_TRUE(fake_power_client_->is_projecting()); 165 EXPECT_TRUE(fake_power_client_->is_projecting());
136 166
137 observer_->OnCastingSessionStartedOrStopped(false); 167 observer_->OnCastingSessionStartedOrStopped(false);
138 168
139 EXPECT_EQ(4, fake_power_client_->num_set_is_projecting_calls()); 169 EXPECT_EQ(4, fake_power_client_->num_set_is_projecting_calls());
140 EXPECT_TRUE(fake_power_client_->is_projecting()); 170 EXPECT_TRUE(fake_power_client_->is_projecting());
141 } 171 }
142 172
143 TEST_F(ProjectingObserverTest, 173 TEST_F(ProjectingObserverTest,
144 CheckStopProjectingAfterClosingAllCastingSessions) { 174 CheckStopProjectingAfterClosingAllCastingSessions) {
145 std::vector<chromeos::OutputConfigurator::OutputSnapshot> outputs; 175 ScopedVector<ui::TestDisplaySnapshot> displays;
146 outputs.push_back(CreateInternalSnapshot()); 176 displays.push_back(CreateInternalSnapshot());
177 std::vector<chromeos::OutputConfigurator::InternalDisplayState> outputs =
178 CreateOutputs(displays);
147 observer_->OnDisplayModeChanged(outputs); 179 observer_->OnDisplayModeChanged(outputs);
148 180
149 observer_->OnCastingSessionStartedOrStopped(true); 181 observer_->OnCastingSessionStartedOrStopped(true);
150 observer_->OnCastingSessionStartedOrStopped(false); 182 observer_->OnCastingSessionStartedOrStopped(false);
151 183
152 EXPECT_EQ(3, fake_power_client_->num_set_is_projecting_calls()); 184 EXPECT_EQ(3, fake_power_client_->num_set_is_projecting_calls());
153 EXPECT_FALSE(fake_power_client_->is_projecting()); 185 EXPECT_FALSE(fake_power_client_->is_projecting());
154 } 186 }
155 187
156 TEST_F(ProjectingObserverTest, 188 TEST_F(ProjectingObserverTest,
157 CheckStopProjectingAfterDisconnectingSecondOutput) { 189 CheckStopProjectingAfterDisconnectingSecondOutput) {
158 std::vector<chromeos::OutputConfigurator::OutputSnapshot> outputs; 190 ScopedVector<ui::TestDisplaySnapshot> displays;
159 outputs.push_back(CreateInternalSnapshot()); 191 displays.push_back(CreateInternalSnapshot());
160 outputs.push_back(CreateVGASnapshot()); 192 displays.push_back(CreateVGASnapshot());
193 std::vector<chromeos::OutputConfigurator::InternalDisplayState> outputs =
194 CreateOutputs(displays);
161 observer_->OnDisplayModeChanged(outputs); 195 observer_->OnDisplayModeChanged(outputs);
162 196
163 // Remove VGA output. 197 // Remove VGA output.
164 outputs.erase(outputs.begin() + 1); 198 outputs.erase(outputs.begin() + 1);
165 observer_->OnDisplayModeChanged(outputs); 199 observer_->OnDisplayModeChanged(outputs);
166 200
167 EXPECT_EQ(2, fake_power_client_->num_set_is_projecting_calls()); 201 EXPECT_EQ(2, fake_power_client_->num_set_is_projecting_calls());
168 EXPECT_FALSE(fake_power_client_->is_projecting()); 202 EXPECT_FALSE(fake_power_client_->is_projecting());
169 } 203 }
170 204
171 } // namespace internal 205 } // namespace internal
172 206
173 } // namespace ash 207 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698