PermissionRequestCreatorApiary: switch from deprecated "namespace" to "eventType"
[chromium-blink-merge.git] / ash / display / projecting_observer_chromeos_unittest.cc
blob06eb7986fb1a6af8690b44adde3567d933df5da4
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_power_manager_client.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/display/chromeos/test/test_display_snapshot.h"
12 namespace ash {
13 namespace {
15 ui::TestDisplaySnapshot* CreateInternalSnapshot() {
16 ui::TestDisplaySnapshot* output = new ui::TestDisplaySnapshot();
17 output->set_type(ui::DISPLAY_CONNECTION_TYPE_INTERNAL);
18 return output;
21 ui::TestDisplaySnapshot* CreateVGASnapshot() {
22 ui::TestDisplaySnapshot* output = new ui::TestDisplaySnapshot();
23 output->set_type(ui::DISPLAY_CONNECTION_TYPE_VGA);
24 return output;
27 class ProjectingObserverTest : public testing::Test {
28 public:
29 ProjectingObserverTest() : observer_(&fake_power_client_) {}
31 ~ProjectingObserverTest() override {}
33 protected:
34 chromeos::FakePowerManagerClient fake_power_client_;
35 ProjectingObserver observer_;
37 private:
38 DISALLOW_COPY_AND_ASSIGN(ProjectingObserverTest);
41 } // namespace
43 TEST_F(ProjectingObserverTest, CheckNoDisplay) {
44 ScopedVector<ui::DisplaySnapshot> displays;
45 observer_.OnDisplayModeChanged(displays.get());
47 EXPECT_EQ(1, fake_power_client_.num_set_is_projecting_calls());
48 EXPECT_FALSE(fake_power_client_.is_projecting());
51 TEST_F(ProjectingObserverTest, CheckWithoutInternalDisplay) {
52 ScopedVector<ui::DisplaySnapshot> displays;
53 displays.push_back(CreateVGASnapshot());
54 observer_.OnDisplayModeChanged(displays.get());
56 EXPECT_EQ(1, fake_power_client_.num_set_is_projecting_calls());
57 EXPECT_FALSE(fake_power_client_.is_projecting());
60 TEST_F(ProjectingObserverTest, CheckWithInternalDisplay) {
61 ScopedVector<ui::DisplaySnapshot> displays;
62 displays.push_back(CreateInternalSnapshot());
63 observer_.OnDisplayModeChanged(displays.get());
65 EXPECT_EQ(1, fake_power_client_.num_set_is_projecting_calls());
66 EXPECT_FALSE(fake_power_client_.is_projecting());
69 TEST_F(ProjectingObserverTest, CheckWithTwoVGADisplays) {
70 ScopedVector<ui::DisplaySnapshot> displays;
71 displays.push_back(CreateVGASnapshot());
72 displays.push_back(CreateVGASnapshot());
73 observer_.OnDisplayModeChanged(displays.get());
75 EXPECT_EQ(1, fake_power_client_.num_set_is_projecting_calls());
76 // We need at least 1 internal display to set projecting to on.
77 EXPECT_FALSE(fake_power_client_.is_projecting());
80 TEST_F(ProjectingObserverTest, CheckWithInternalAndVGADisplays) {
81 ScopedVector<ui::DisplaySnapshot> displays;
82 displays.push_back(CreateInternalSnapshot());
83 displays.push_back(CreateVGASnapshot());
84 observer_.OnDisplayModeChanged(displays.get());
86 EXPECT_EQ(1, fake_power_client_.num_set_is_projecting_calls());
87 EXPECT_TRUE(fake_power_client_.is_projecting());
90 TEST_F(ProjectingObserverTest, CheckWithVGADisplayAndOneCastingSession) {
91 ScopedVector<ui::DisplaySnapshot> displays;
92 displays.push_back(CreateVGASnapshot());
93 observer_.OnDisplayModeChanged(displays.get());
95 observer_.OnCastingSessionStartedOrStopped(true);
97 EXPECT_EQ(2, fake_power_client_.num_set_is_projecting_calls());
98 // Need at least one internal display to set projecting state to |true|.
99 EXPECT_FALSE(fake_power_client_.is_projecting());
102 TEST_F(ProjectingObserverTest, CheckWithInternalDisplayAndOneCastingSession) {
103 ScopedVector<ui::DisplaySnapshot> displays;
104 displays.push_back(CreateInternalSnapshot());
105 observer_.OnDisplayModeChanged(displays.get());
107 observer_.OnCastingSessionStartedOrStopped(true);
109 EXPECT_EQ(2, fake_power_client_.num_set_is_projecting_calls());
110 EXPECT_TRUE(fake_power_client_.is_projecting());
113 TEST_F(ProjectingObserverTest, CheckProjectingAfterClosingACastingSession) {
114 ScopedVector<ui::DisplaySnapshot> displays;
115 displays.push_back(CreateInternalSnapshot());
116 observer_.OnDisplayModeChanged(displays.get());
118 observer_.OnCastingSessionStartedOrStopped(true);
119 observer_.OnCastingSessionStartedOrStopped(true);
121 EXPECT_EQ(3, fake_power_client_.num_set_is_projecting_calls());
122 EXPECT_TRUE(fake_power_client_.is_projecting());
124 observer_.OnCastingSessionStartedOrStopped(false);
126 EXPECT_EQ(4, fake_power_client_.num_set_is_projecting_calls());
127 EXPECT_TRUE(fake_power_client_.is_projecting());
130 TEST_F(ProjectingObserverTest,
131 CheckStopProjectingAfterClosingAllCastingSessions) {
132 ScopedVector<ui::DisplaySnapshot> displays;
133 displays.push_back(CreateInternalSnapshot());
134 observer_.OnDisplayModeChanged(displays.get());
136 observer_.OnCastingSessionStartedOrStopped(true);
137 observer_.OnCastingSessionStartedOrStopped(false);
139 EXPECT_EQ(3, fake_power_client_.num_set_is_projecting_calls());
140 EXPECT_FALSE(fake_power_client_.is_projecting());
143 TEST_F(ProjectingObserverTest,
144 CheckStopProjectingAfterDisconnectingSecondOutput) {
145 ScopedVector<ui::DisplaySnapshot> displays;
146 displays.push_back(CreateInternalSnapshot());
147 displays.push_back(CreateVGASnapshot());
148 observer_.OnDisplayModeChanged(displays.get());
150 // Remove VGA output.
151 displays.erase(displays.begin() + 1);
152 observer_.OnDisplayModeChanged(displays.get());
154 EXPECT_EQ(2, fake_power_client_.num_set_is_projecting_calls());
155 EXPECT_FALSE(fake_power_client_.is_projecting());
158 } // namespace ash