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

Side by Side Diff: remoting/host/chromoting_host_unittest.cc

Issue 2080723008: [Chromoting] Use device::PowerSaveBlocker to block screen saver (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Resolve review comments Created 4 years, 6 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "remoting/host/chromoting_host.h" 5 #include "remoting/host/chromoting_host.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 using testing::SaveArg; 51 using testing::SaveArg;
52 using testing::Sequence; 52 using testing::Sequence;
53 53
54 namespace remoting { 54 namespace remoting {
55 55
56 class ChromotingHostTest : public testing::Test { 56 class ChromotingHostTest : public testing::Test {
57 public: 57 public:
58 ChromotingHostTest() {} 58 ChromotingHostTest() {}
59 59
60 void SetUp() override { 60 void SetUp() override {
61 task_runner_ = new AutoThreadTaskRunner(message_loop_.task_runner(),
62 base::Bind(&base::DoNothing));
63
64 desktop_environment_factory_.reset(new FakeDesktopEnvironmentFactory()); 61 desktop_environment_factory_.reset(new FakeDesktopEnvironmentFactory());
65 session_manager_ = new protocol::MockSessionManager(); 62 session_manager_ = new protocol::MockSessionManager();
63 context_ = ChromotingHostContext::CreateForTest(
64 new AutoThreadTaskRunner(message_loop_.task_runner(),
65 base::Bind(&base::DoNothing)));
66 66
67 host_.reset(new ChromotingHost( 67 host_.reset(new ChromotingHost(
68 desktop_environment_factory_.get(), base::WrapUnique(session_manager_), 68 desktop_environment_factory_.get(), base::WrapUnique(session_manager_),
69 protocol::TransportContext::ForTests(protocol::TransportRole::SERVER), 69 protocol::TransportContext::ForTests(protocol::TransportRole::SERVER),
70 task_runner_, // Audio 70 *context_));
71 task_runner_)); // Video encode
72 host_->AddStatusObserver(&host_status_observer_); 71 host_->AddStatusObserver(&host_status_observer_);
73 72
74 xmpp_login_ = "host@domain"; 73 xmpp_login_ = "host@domain";
75 session1_ = new MockSession(); 74 session1_ = new MockSession();
76 session2_ = new MockSession(); 75 session2_ = new MockSession();
77 session_unowned1_.reset(new MockSession()); 76 session_unowned1_.reset(new MockSession());
78 session_unowned2_.reset(new MockSession()); 77 session_unowned2_.reset(new MockSession());
79 session_config1_ = SessionConfig::ForTest(); 78 session_config1_ = SessionConfig::ForTest();
80 session_jid1_ = "user@domain/rest-of-jid"; 79 session_jid1_ = "user@domain/rest-of-jid";
81 session_config2_ = SessionConfig::ForTest(); 80 session_config2_ = SessionConfig::ForTest();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 connection2_ = owned_connection2_.get(); 117 connection2_ = owned_connection2_.get();
119 connection2_->set_client_stub(&client_stub2_); 118 connection2_->set_client_stub(&client_stub2_);
120 } 119 }
121 120
122 // Helper method to pretend a client is connected to ChromotingHost. 121 // Helper method to pretend a client is connected to ChromotingHost.
123 void SimulateClientConnection(int connection_index, bool authenticate, 122 void SimulateClientConnection(int connection_index, bool authenticate,
124 bool reject) { 123 bool reject) {
125 std::unique_ptr<protocol::ConnectionToClient> connection = std::move( 124 std::unique_ptr<protocol::ConnectionToClient> connection = std::move(
126 (connection_index == 0) ? owned_connection1_ : owned_connection2_); 125 (connection_index == 0) ? owned_connection1_ : owned_connection2_);
127 protocol::ConnectionToClient* connection_ptr = connection.get(); 126 protocol::ConnectionToClient* connection_ptr = connection.get();
128 std::unique_ptr<ClientSession> client(new ClientSession( 127 std::unique_ptr<ClientSession> client(new ClientSession(*context_,
129 host_.get(), task_runner_ /* audio_task_runner */, 128 host_.get(), std::move(connection), desktop_environment_factory_.get(),
130 std::move(connection), desktop_environment_factory_.get(),
131 base::TimeDelta(), nullptr, std::vector<HostExtension*>())); 129 base::TimeDelta(), nullptr, std::vector<HostExtension*>()));
132 ClientSession* client_ptr = client.get(); 130 ClientSession* client_ptr = client.get();
133 131
134 connection_ptr->set_host_stub(client.get()); 132 connection_ptr->set_host_stub(client.get());
135 get_client(connection_index) = client_ptr; 133 get_client(connection_index) = client_ptr;
136 134
137 // |host| is responsible for deleting |client| from now on. 135 // |host| is responsible for deleting |client| from now on.
138 host_->clients_.push_back(client.release()); 136 host_->clients_.push_back(client.release());
139 137
140 if (authenticate) { 138 if (authenticate) {
141 client_ptr->OnConnectionAuthenticated(connection_ptr); 139 client_ptr->OnConnectionAuthenticated(connection_ptr);
142 if (!reject) 140 if (!reject)
143 client_ptr->OnConnectionChannelsConnected(connection_ptr); 141 client_ptr->OnConnectionChannelsConnected(connection_ptr);
144 } else { 142 } else {
145 client_ptr->OnConnectionClosed(connection_ptr, 143 client_ptr->OnConnectionClosed(connection_ptr,
146 protocol::AUTHENTICATION_FAILED); 144 protocol::AUTHENTICATION_FAILED);
147 } 145 }
148 } 146 }
149 147
150 void TearDown() override { 148 void TearDown() override {
151 if (host_) 149 if (host_)
152 ShutdownHost(); 150 ShutdownHost();
153 task_runner_ = nullptr; 151 context_ = nullptr;
154 152
155 message_loop_.RunUntilIdle(); 153 message_loop_.RunUntilIdle();
156 } 154 }
157 155
158 void DisconnectAllClients() { 156 void DisconnectAllClients() {
159 host_->DisconnectAllClients(); 157 host_->DisconnectAllClients();
160 } 158 }
161 159
162 void NotifyConnectionClosed1() { 160 void NotifyConnectionClosed1() {
163 if (session_unowned1_event_handler_) { 161 if (session_unowned1_event_handler_) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 // Expect that a client is disconnected. The given action will be done after 196 // Expect that a client is disconnected. The given action will be done after
199 // the status observer is notified that the session has finished. 197 // the status observer is notified that the session has finished.
200 Expectation ExpectClientDisconnected(int connection_index) { 198 Expectation ExpectClientDisconnected(int connection_index) {
201 return EXPECT_CALL(host_status_observer_, 199 return EXPECT_CALL(host_status_observer_,
202 OnClientDisconnected(get_session_jid(connection_index))) 200 OnClientDisconnected(get_session_jid(connection_index)))
203 .RetiresOnSaturation(); 201 .RetiresOnSaturation();
204 } 202 }
205 203
206 protected: 204 protected:
207 base::MessageLoop message_loop_; 205 base::MessageLoop message_loop_;
208 scoped_refptr<AutoThreadTaskRunner> task_runner_; 206 std::unique_ptr<ChromotingHostContext> context_;
209 MockConnectionToClientEventHandler handler_; 207 MockConnectionToClientEventHandler handler_;
210 std::unique_ptr<FakeDesktopEnvironmentFactory> desktop_environment_factory_; 208 std::unique_ptr<FakeDesktopEnvironmentFactory> desktop_environment_factory_;
211 MockHostStatusObserver host_status_observer_; 209 MockHostStatusObserver host_status_observer_;
212 std::unique_ptr<ChromotingHost> host_; 210 std::unique_ptr<ChromotingHost> host_;
213 protocol::MockSessionManager* session_manager_; 211 protocol::MockSessionManager* session_manager_;
214 std::string xmpp_login_; 212 std::string xmpp_login_;
215 protocol::FakeConnectionToClient* connection1_; 213 protocol::FakeConnectionToClient* connection1_;
216 std::unique_ptr<protocol::FakeConnectionToClient> owned_connection1_; 214 std::unique_ptr<protocol::FakeConnectionToClient> owned_connection1_;
217 ClientSession* client1_; 215 ClientSession* client1_;
218 std::string session_jid1_; 216 std::string session_jid1_;
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 388
391 ExpectClientConnected(0); 389 ExpectClientConnected(0);
392 SimulateClientConnection(0, true, false); 390 SimulateClientConnection(0, true, false);
393 391
394 ExpectClientDisconnected(0); 392 ExpectClientDisconnected(0);
395 DisconnectAllClients(); 393 DisconnectAllClients();
396 testing::Mock::VerifyAndClearExpectations(&host_status_observer_); 394 testing::Mock::VerifyAndClearExpectations(&host_status_observer_);
397 } 395 }
398 396
399 } // namespace remoting 397 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698