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