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

Side by Side Diff: remoting/test/test_chromoting_client.cc

Issue 1237093004: Support for connecting to localhost on the chromoting test driver. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Edited merge errors, comments, and optimized code. Created 5 years, 5 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/test/test_chromoting_client.h" 5 #include "remoting/test/test_chromoting_client.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/thread_task_runner_handle.h" 11 #include "base/thread_task_runner_handle.h"
12 #include "jingle/glue/thread_wrapper.h" 12 #include "jingle/glue/thread_wrapper.h"
13 #include "net/base/request_priority.h" 13 #include "net/base/request_priority.h"
14 #include "net/socket/client_socket_factory.h" 14 #include "net/socket/client_socket_factory.h"
15 #include "remoting/base/url_request_context_getter.h" 15 #include "remoting/base/url_request_context_getter.h"
16 #include "remoting/client/audio_player.h" 16 #include "remoting/client/audio_player.h"
17 #include "remoting/client/chromoting_client.h" 17 #include "remoting/client/chromoting_client.h"
18 #include "remoting/client/client_context.h" 18 #include "remoting/client/client_context.h"
19 #include "remoting/client/token_fetcher_proxy.h" 19 #include "remoting/client/token_fetcher_proxy.h"
20 #include "remoting/protocol/authentication_method.h"
21 #include "remoting/protocol/chromium_port_allocator.h" 20 #include "remoting/protocol/chromium_port_allocator.h"
22 #include "remoting/protocol/host_stub.h" 21 #include "remoting/protocol/host_stub.h"
23 #include "remoting/protocol/libjingle_transport_factory.h" 22 #include "remoting/protocol/libjingle_transport_factory.h"
24 #include "remoting/protocol/negotiating_client_authenticator.h" 23 #include "remoting/protocol/negotiating_client_authenticator.h"
25 #include "remoting/protocol/network_settings.h" 24 #include "remoting/protocol/network_settings.h"
26 #include "remoting/protocol/session_config.h" 25 #include "remoting/protocol/session_config.h"
27 #include "remoting/protocol/third_party_client_authenticator.h" 26 #include "remoting/protocol/third_party_client_authenticator.h"
28 #include "remoting/signaling/xmpp_signal_strategy.h" 27 #include "remoting/signaling/xmpp_signal_strategy.h"
29 #include "remoting/test/remote_host_info_fetcher.h"
30 #include "remoting/test/test_video_renderer.h" 28 #include "remoting/test/test_video_renderer.h"
31 29
32 namespace { 30 namespace {
33
34 const char kAppRemotingCapabilities[] =
35 "rateLimitResizeRequests desktopShape sendInitialResolution googleDrive";
36
37 const char kXmppHostName[] = "talk.google.com"; 31 const char kXmppHostName[] = "talk.google.com";
38 const int kXmppPortNumber = 5222; 32 const int kXmppPortNumber = 5222;
39 33
40 // Used as the TokenFetcherCallback for App Remoting sessions. 34 // Used as the TokenFetcherCallback for App Remoting sessions.
41 void FetchThirdPartyToken( 35 void FetchThirdPartyToken(
42 const std::string& authorization_token, 36 const std::string& authorization_token,
43 const std::string& shared_secret, 37 const std::string& shared_secret,
44 const GURL& token_url, 38 const GURL& token_url,
45 const std::string& host_public_key, 39 const std::string& host_public_key,
46 const std::string& scope, 40 const std::string& scope,
47 base::WeakPtr<remoting::TokenFetcherProxy> token_fetcher_proxy) { 41 base::WeakPtr<remoting::TokenFetcherProxy> token_fetcher_proxy) {
48 VLOG(2) << "FetchThirdPartyToken(" 42 VLOG(2) << "FetchThirdPartyToken("
49 << "token_url: " << token_url << ", " 43 << "token_url: " << token_url << ", "
50 << "host_public_key: " << host_public_key << ", " 44 << "host_public_key: " << host_public_key << ", "
51 << "scope: " << scope << ") Called"; 45 << "scope: " << scope << ") Called";
52 46
53 if (token_fetcher_proxy) { 47 if (token_fetcher_proxy) {
54 token_fetcher_proxy->OnTokenFetched(authorization_token, shared_secret); 48 token_fetcher_proxy->OnTokenFetched(authorization_token, shared_secret);
55 token_fetcher_proxy.reset(); 49 token_fetcher_proxy.reset();
56 } else { 50 } else {
57 LOG(ERROR) << "Invalid token fetcher proxy passed in"; 51 LOG(ERROR) << "Invalid token fetcher proxy passed in";
58 } 52 }
59 } 53 }
60 54
55 void FetchSecret(
56 const std::string& client_secret,
57 bool pairing_expected,
58 const remoting::protocol::SecretFetchedCallback& secret_fetched_callback) {
59 secret_fetched_callback.Run(client_secret);
60 }
61
61 const char* ConnectionStateToFriendlyString( 62 const char* ConnectionStateToFriendlyString(
62 remoting::protocol::ConnectionToHost::State state) { 63 remoting::protocol::ConnectionToHost::State state) {
63 switch (state) { 64 switch (state) {
64 case remoting::protocol::ConnectionToHost::INITIALIZING: 65 case remoting::protocol::ConnectionToHost::INITIALIZING:
65 return "INITIALIZING"; 66 return "INITIALIZING";
66 67
67 case remoting::protocol::ConnectionToHost::CONNECTING: 68 case remoting::protocol::ConnectionToHost::CONNECTING:
68 return "CONNECTING"; 69 return "CONNECTING";
69 70
70 case remoting::protocol::ConnectionToHost::AUTHENTICATED: 71 case remoting::protocol::ConnectionToHost::AUTHENTICATED:
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 TestChromotingClient(); 141 TestChromotingClient();
141 } 142 }
142 143
143 TestChromotingClient::~TestChromotingClient() { 144 TestChromotingClient::~TestChromotingClient() {
144 // Ensure any connections are closed and the members are destroyed in the 145 // Ensure any connections are closed and the members are destroyed in the
145 // appropriate order. 146 // appropriate order.
146 EndConnection(); 147 EndConnection();
147 } 148 }
148 149
149 void TestChromotingClient::StartConnection( 150 void TestChromotingClient::StartConnection(
150 const std::string& user_name, 151 const ConnectionSetupInfo& connection_setup_info) {
151 const std::string& access_token,
152 const RemoteHostInfo& remote_host_info) {
153 DCHECK(!user_name.empty());
154 DCHECK(!access_token.empty());
155 DCHECK(remote_host_info.IsReadyForConnection());
156
157 // Required to establish a connection to the host. 152 // Required to establish a connection to the host.
158 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); 153 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop();
159 154
160 scoped_refptr<URLRequestContextGetter> request_context_getter; 155 scoped_refptr<URLRequestContextGetter> request_context_getter;
161 request_context_getter = new URLRequestContextGetter( 156 request_context_getter = new URLRequestContextGetter(
162 base::ThreadTaskRunnerHandle::Get(), // network_runner 157 base::ThreadTaskRunnerHandle::Get(), // network_runner
163 base::ThreadTaskRunnerHandle::Get()); // file_runner 158 base::ThreadTaskRunnerHandle::Get()); // file_runner
164 159
165 client_context_.reset(new ClientContext(base::ThreadTaskRunnerHandle::Get())); 160 client_context_.reset(new ClientContext(base::ThreadTaskRunnerHandle::Get()));
166 161
167 // Check to see if the user passed in a customized video renderer. 162 // Check to see if the user passed in a customized video renderer.
168 if (!video_renderer_) { 163 if (!video_renderer_) {
169 video_renderer_.reset(new TestVideoRenderer()); 164 video_renderer_.reset(new TestVideoRenderer());
170 } 165 }
171 166
172 chromoting_client_.reset(new ChromotingClient(client_context_.get(), 167 chromoting_client_.reset(new ChromotingClient(client_context_.get(),
173 this, // client_user_interface. 168 this, // client_user_interface.
174 video_renderer_.get(), 169 video_renderer_.get(),
175 nullptr)); // audio_player 170 nullptr)); // audio_player
176 171
177 if (test_connection_to_host_) { 172 if (test_connection_to_host_) {
178 chromoting_client_->SetConnectionToHostForTests( 173 chromoting_client_->SetConnectionToHostForTests(
179 test_connection_to_host_.Pass()); 174 test_connection_to_host_.Pass());
180 } 175 }
181 176
182 XmppSignalStrategy::XmppServerConfig xmpp_server_config; 177 XmppSignalStrategy::XmppServerConfig xmpp_server_config;
183 xmpp_server_config.host = kXmppHostName; 178 xmpp_server_config.host = kXmppHostName;
184 xmpp_server_config.port = kXmppPortNumber; 179 xmpp_server_config.port = kXmppPortNumber;
185 xmpp_server_config.use_tls = true; 180 xmpp_server_config.use_tls = true;
186 xmpp_server_config.username = user_name; 181 xmpp_server_config.username = connection_setup_info.user_name;
187 xmpp_server_config.auth_token = access_token; 182 xmpp_server_config.auth_token = connection_setup_info.access_token;
188 183
189 // Set up the signal strategy. This must outlive the client object. 184 // Set up the signal strategy. This must outlive the client object.
190 signal_strategy_.reset( 185 signal_strategy_.reset(
191 new XmppSignalStrategy(net::ClientSocketFactory::GetDefaultFactory(), 186 new XmppSignalStrategy(net::ClientSocketFactory::GetDefaultFactory(),
192 request_context_getter, xmpp_server_config)); 187 request_context_getter, xmpp_server_config));
193 188
194 protocol::NetworkSettings network_settings( 189 protocol::NetworkSettings network_settings(
195 protocol::NetworkSettings::NAT_TRAVERSAL_FULL); 190 protocol::NetworkSettings::NAT_TRAVERSAL_FULL);
196 191
197 scoped_ptr<protocol::ChromiumPortAllocator> port_allocator( 192 scoped_ptr<protocol::ChromiumPortAllocator> port_allocator(
198 protocol::ChromiumPortAllocator::Create(request_context_getter, 193 protocol::ChromiumPortAllocator::Create(request_context_getter,
199 network_settings)); 194 network_settings));
200 195
201 scoped_ptr<protocol::TransportFactory> transport_factory( 196 scoped_ptr<protocol::TransportFactory> transport_factory(
202 new protocol::LibjingleTransportFactory( 197 new protocol::LibjingleTransportFactory(
203 signal_strategy_.get(), port_allocator.Pass(), network_settings, 198 signal_strategy_.get(), port_allocator.Pass(), network_settings,
204 protocol::TransportRole::CLIENT)); 199 protocol::TransportRole::CLIENT));
205 200
206 scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher> 201 scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher>
207 token_fetcher(new TokenFetcherProxy( 202 token_fetcher(new TokenFetcherProxy(
208 base::Bind(&FetchThirdPartyToken, remote_host_info.authorization_code, 203 base::Bind(&FetchThirdPartyToken,
209 remote_host_info.shared_secret), 204 connection_setup_info.authorization_code,
210 "FAKE_HOST_PUBLIC_KEY")); 205 connection_setup_info.shared_secret),
206 connection_setup_info.public_key));
211 207
212 std::vector<protocol::AuthenticationMethod> auth_methods;
213 auth_methods.push_back(protocol::AuthenticationMethod::ThirdParty());
214
215 // FetchSecretCallback is used for PIN based auth which we aren't using so we
216 // can pass a null callback here.
217 protocol::FetchSecretCallback fetch_secret_callback; 208 protocol::FetchSecretCallback fetch_secret_callback;
209 if (!connection_setup_info.pin.empty()) {
210 fetch_secret_callback = base::Bind(&FetchSecret, connection_setup_info.pin);
211 }
joedow 2015/07/17 23:26:30 add newline here please
tonychun 2015/07/20 14:29:17 Done.
218 scoped_ptr<protocol::Authenticator> authenticator( 212 scoped_ptr<protocol::Authenticator> authenticator(
219 new protocol::NegotiatingClientAuthenticator( 213 new protocol::NegotiatingClientAuthenticator(
220 std::string(), // client_pairing_id 214 connection_setup_info.pairing_id,
221 std::string(), // shared_secret 215 connection_setup_info.shared_secret,
222 std::string(), // authentication_tag 216 connection_setup_info.host_id,
223 fetch_secret_callback, token_fetcher.Pass(), auth_methods)); 217 fetch_secret_callback,
218 token_fetcher.Pass(),
219 connection_setup_info.auth_methods));
224 220
225 chromoting_client_->Start(signal_strategy_.get(), authenticator.Pass(), 221 chromoting_client_->Start(
226 transport_factory.Pass(), remote_host_info.host_jid, 222 signal_strategy_.get(), authenticator.Pass(), transport_factory.Pass(),
227 kAppRemotingCapabilities); 223 connection_setup_info.host_jid, connection_setup_info.capabilities);
228 } 224 }
229 225
230 void TestChromotingClient::EndConnection() { 226 void TestChromotingClient::EndConnection() {
231 // Clearing out the client will close the connection. 227 // Clearing out the client will close the connection.
232 chromoting_client_.reset(); 228 chromoting_client_.reset();
233 229
234 // The signal strategy object must outlive the client so destroy it next. 230 // The signal strategy object must outlive the client so destroy it next.
235 signal_strategy_.reset(); 231 signal_strategy_.reset();
236 232
237 // The connection state will be updated when the chromoting client was 233 // The connection state will be updated when the chromoting client was
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 VLOG(1) << "TestChromotingClient::InjectClipboardEvent() Called"; 338 VLOG(1) << "TestChromotingClient::InjectClipboardEvent() Called";
343 } 339 }
344 340
345 void TestChromotingClient::SetCursorShape( 341 void TestChromotingClient::SetCursorShape(
346 const protocol::CursorShapeInfo& cursor_shape) { 342 const protocol::CursorShapeInfo& cursor_shape) {
347 VLOG(1) << "TestChromotingClient::SetCursorShape() Called"; 343 VLOG(1) << "TestChromotingClient::SetCursorShape() Called";
348 } 344 }
349 345
350 } // namespace test 346 } // namespace test
351 } // namespace remoting 347 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698