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

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: 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" 20 #include "remoting/protocol/authentication_method.h"
21 #include "remoting/protocol/chromium_port_allocator.h" 21 #include "remoting/protocol/chromium_port_allocator.h"
22 #include "remoting/protocol/host_stub.h" 22 #include "remoting/protocol/host_stub.h"
23 #include "remoting/protocol/libjingle_transport_factory.h" 23 #include "remoting/protocol/libjingle_transport_factory.h"
24 #include "remoting/protocol/negotiating_client_authenticator.h" 24 #include "remoting/protocol/negotiating_client_authenticator.h"
25 #include "remoting/protocol/network_settings.h" 25 #include "remoting/protocol/network_settings.h"
26 #include "remoting/protocol/session_config.h" 26 #include "remoting/protocol/session_config.h"
27 #include "remoting/protocol/third_party_client_authenticator.h" 27 #include "remoting/protocol/third_party_client_authenticator.h"
28 #include "remoting/signaling/xmpp_signal_strategy.h" 28 #include "remoting/signaling/xmpp_signal_strategy.h"
29 #include "remoting/test/host_info.h"
29 #include "remoting/test/remote_host_info_fetcher.h" 30 #include "remoting/test/remote_host_info_fetcher.h"
30 #include "remoting/test/test_video_renderer.h" 31 #include "remoting/test/test_video_renderer.h"
31 32
32 namespace { 33 namespace {
33 34
34 const char kAppRemotingCapabilities[] = 35 const char kAppRemotingCapabilities[] =
35 "rateLimitResizeRequests desktopShape sendInitialResolution googleDrive"; 36 "rateLimitResizeRequests desktopShape sendInitialResolution googleDrive";
37 const char kChromotingCapabilities[] = "";
joedow 2015/07/14 19:58:44 This isn't really providing any value. This proba
tonychun 2015/07/15 17:32:50 Done.
36 38
37 const char kXmppHostName[] = "talk.google.com"; 39 const char kXmppHostName[] = "talk.google.com";
38 const int kXmppPortNumber = 5222; 40 const int kXmppPortNumber = 5222;
39 41
40 // Used as the TokenFetcherCallback for App Remoting sessions. 42 // Used as the TokenFetcherCallback for App Remoting sessions.
41 void FetchThirdPartyToken( 43 void FetchThirdPartyToken(
42 const std::string& authorization_token, 44 const std::string& authorization_token,
43 const std::string& shared_secret, 45 const std::string& shared_secret,
44 const GURL& token_url, 46 const GURL& token_url,
45 const std::string& host_public_key, 47 const std::string& host_public_key,
46 const std::string& scope, 48 const std::string& scope,
47 base::WeakPtr<remoting::TokenFetcherProxy> token_fetcher_proxy) { 49 base::WeakPtr<remoting::TokenFetcherProxy> token_fetcher_proxy) {
48 VLOG(2) << "FetchThirdPartyToken(" 50 VLOG(2) << "FetchThirdPartyToken("
49 << "token_url: " << token_url << ", " 51 << "token_url: " << token_url << ", "
50 << "host_public_key: " << host_public_key << ", " 52 << "host_public_key: " << host_public_key << ", "
51 << "scope: " << scope << ") Called"; 53 << "scope: " << scope << ") Called";
52 54
53 if (token_fetcher_proxy) { 55 if (token_fetcher_proxy) {
54 token_fetcher_proxy->OnTokenFetched(authorization_token, shared_secret); 56 token_fetcher_proxy->OnTokenFetched(authorization_token, shared_secret);
55 token_fetcher_proxy.reset(); 57 token_fetcher_proxy.reset();
56 } else { 58 } else {
57 LOG(ERROR) << "Invalid token fetcher proxy passed in"; 59 LOG(ERROR) << "Invalid token fetcher proxy passed in";
58 } 60 }
59 } 61 }
60 62
63 void FetchSecret(
64 const std::string& client_secret,
65 bool pairing_supported,
66 bool pairing_expected,
67 const remoting::protocol::SecretFetchedCallback& secret_fetched_callback) {
68 secret_fetched_callback.Run(client_secret);
69
70 // TODO(TonyChun): Pairing currently not supported for testing.
joedow 2015/07/14 19:58:44 Why include this code? The condition below actual
tonychun 2015/07/15 17:32:50 Done.
71 if (pairing_supported == pairing_expected) {
72 VLOG(2) << "Pairing supported!";
73 } else {
74 VLOG(2) << "Pairing not supported!";
75 }
76 }
77
61 const char* ConnectionStateToFriendlyString( 78 const char* ConnectionStateToFriendlyString(
62 remoting::protocol::ConnectionToHost::State state) { 79 remoting::protocol::ConnectionToHost::State state) {
63 switch (state) { 80 switch (state) {
64 case remoting::protocol::ConnectionToHost::INITIALIZING: 81 case remoting::protocol::ConnectionToHost::INITIALIZING:
65 return "INITIALIZING"; 82 return "INITIALIZING";
66 83
67 case remoting::protocol::ConnectionToHost::CONNECTING: 84 case remoting::protocol::ConnectionToHost::CONNECTING:
68 return "CONNECTING"; 85 return "CONNECTING";
69 86
70 case remoting::protocol::ConnectionToHost::AUTHENTICATED: 87 case remoting::protocol::ConnectionToHost::AUTHENTICATED:
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 : video_renderer_(video_renderer.Pass()) { 156 : video_renderer_(video_renderer.Pass()) {
140 TestChromotingClient(); 157 TestChromotingClient();
141 } 158 }
142 159
143 TestChromotingClient::~TestChromotingClient() { 160 TestChromotingClient::~TestChromotingClient() {
144 // Ensure any connections are closed and the members are destroyed in the 161 // Ensure any connections are closed and the members are destroyed in the
145 // appropriate order. 162 // appropriate order.
146 EndConnection(); 163 EndConnection();
147 } 164 }
148 165
166 void TestChromotingClient::StartConnection(const std::string& user_name,
167 const std::string& access_token,
168 const std::string& client_pin,
169 const HostInfo& host_info) {
joedow 2015/07/14 19:58:44 There is a lot of duplication here, can you refact
tonychun 2015/07/15 17:32:50 Done.
170 DCHECK(!user_name.empty());
171 DCHECK(!access_token.empty());
172 DCHECK(host_info.IsReadyForConnection());
173
174 // Required to establish a connection to the host.
175 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop();
176
177 scoped_refptr<URLRequestContextGetter> request_context_getter;
178 request_context_getter = new URLRequestContextGetter(
179 base::ThreadTaskRunnerHandle::Get(), // network_runner
180 base::ThreadTaskRunnerHandle::Get()); // file_runner
181
182 client_context_.reset(new ClientContext(base::ThreadTaskRunnerHandle::Get()));
183
184 // Check to see if the user passed in a customized video renderer.
185 if (!video_renderer_) {
186 video_renderer_.reset(new TestVideoRenderer());
187 }
188
189 chromoting_client_.reset(new ChromotingClient(client_context_.get(),
190 this, // client_user_interface.
191 video_renderer_.get(),
192 nullptr)); // audio_player
193
194 if (test_connection_to_host_) {
195 chromoting_client_->SetConnectionToHostForTests(
196 test_connection_to_host_.Pass());
197 }
198
199 XmppSignalStrategy::XmppServerConfig xmpp_server_config;
200 xmpp_server_config.host = kXmppHostName;
201 xmpp_server_config.port = kXmppPortNumber;
202 xmpp_server_config.use_tls = true;
203 xmpp_server_config.username = user_name;
204 xmpp_server_config.auth_token = access_token;
205
206 // Set up the signal strategy. This must outlive the client object.
207 signal_strategy_.reset(
208 new XmppSignalStrategy(net::ClientSocketFactory::GetDefaultFactory(),
209 request_context_getter, xmpp_server_config));
210
211 protocol::NetworkSettings network_settings(
212 protocol::NetworkSettings::NAT_TRAVERSAL_FULL);
213
214 scoped_ptr<protocol::ChromiumPortAllocator> port_allocator(
215 protocol::ChromiumPortAllocator::Create(request_context_getter,
216 network_settings));
217
218 scoped_ptr<protocol::TransportFactory> transport_factory(
219 new protocol::LibjingleTransportFactory(
220 signal_strategy_.get(), port_allocator.Pass(), network_settings,
221 protocol::TransportRole::CLIENT));
222
223 // Note: Only remote hosts without third party authenication methods
224 // can connect for now.
225 std::vector<protocol::AuthenticationMethod> auth_methods;
226 auth_methods.push_back(protocol::AuthenticationMethod::Spake2Pair());
227 auth_methods.push_back(protocol::AuthenticationMethod::Spake2(
228 protocol::AuthenticationMethod::HMAC_SHA256));
229 auth_methods.push_back(protocol::AuthenticationMethod::Spake2(
230 protocol::AuthenticationMethod::NONE));
231
232 protocol::FetchSecretCallback fetch_secret_callback =
233 base::Bind(&FetchSecret, client_pin, true);
234 scoped_ptr<protocol::Authenticator> authenticator(
235 new protocol::NegotiatingClientAuthenticator(
236 std::string(), // client_pairing_id
237 std::string(), // shared_secret
238 host_info.host_id, // authentication_tag
239 fetch_secret_callback, nullptr, auth_methods));
240
241 chromoting_client_->Start(signal_strategy_.get(), authenticator.Pass(),
242 transport_factory.Pass(), host_info.host_jid,
243 kChromotingCapabilities);
244 }
245
149 void TestChromotingClient::StartConnection( 246 void TestChromotingClient::StartConnection(
150 const std::string& user_name, 247 const std::string& user_name,
151 const std::string& access_token, 248 const std::string& access_token,
152 const RemoteHostInfo& remote_host_info) { 249 const RemoteHostInfo& remote_host_info) {
153 DCHECK(!user_name.empty()); 250 DCHECK(!user_name.empty());
154 DCHECK(!access_token.empty()); 251 DCHECK(!access_token.empty());
155 DCHECK(remote_host_info.IsReadyForConnection()); 252 DCHECK(remote_host_info.IsReadyForConnection());
156 253
157 // Required to establish a connection to the host. 254 // Required to establish a connection to the host.
158 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); 255 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop();
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 VLOG(1) << "TestChromotingClient::InjectClipboardEvent() Called"; 439 VLOG(1) << "TestChromotingClient::InjectClipboardEvent() Called";
343 } 440 }
344 441
345 void TestChromotingClient::SetCursorShape( 442 void TestChromotingClient::SetCursorShape(
346 const protocol::CursorShapeInfo& cursor_shape) { 443 const protocol::CursorShapeInfo& cursor_shape) {
347 VLOG(1) << "TestChromotingClient::SetCursorShape() Called"; 444 VLOG(1) << "TestChromotingClient::SetCursorShape() Called";
348 } 445 }
349 446
350 } // namespace test 447 } // namespace test
351 } // namespace remoting 448 } // namespace remoting
OLDNEW
« remoting/test/test_chromoting_client.h ('K') | « remoting/test/test_chromoting_client.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698