OLD | NEW |
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" | 28 #include "remoting/test/connection_setup_info.h" |
30 #include "remoting/test/test_video_renderer.h" | 29 #include "remoting/test/test_video_renderer.h" |
31 | 30 |
32 namespace { | 31 namespace { |
33 | |
34 const char kAppRemotingCapabilities[] = | |
35 "rateLimitResizeRequests desktopShape sendInitialResolution googleDrive"; | |
36 | |
37 const char kXmppHostName[] = "talk.google.com"; | 32 const char kXmppHostName[] = "talk.google.com"; |
38 const int kXmppPortNumber = 5222; | 33 const int kXmppPortNumber = 5222; |
39 | 34 |
40 // Used as the TokenFetcherCallback for App Remoting sessions. | 35 // Used as the TokenFetcherCallback for App Remoting sessions. |
41 void FetchThirdPartyToken( | 36 void FetchThirdPartyToken( |
42 const std::string& authorization_token, | 37 const std::string& authorization_token, |
43 const std::string& shared_secret, | 38 const std::string& shared_secret, |
44 const GURL& token_url, | 39 const GURL& token_url, |
45 const std::string& host_public_key, | 40 const std::string& host_public_key, |
46 const std::string& scope, | 41 const std::string& scope, |
47 base::WeakPtr<remoting::TokenFetcherProxy> token_fetcher_proxy) { | 42 base::WeakPtr<remoting::TokenFetcherProxy> token_fetcher_proxy) { |
48 VLOG(2) << "FetchThirdPartyToken(" | 43 VLOG(2) << "FetchThirdPartyToken(" |
49 << "token_url: " << token_url << ", " | 44 << "token_url: " << token_url << ", " |
50 << "host_public_key: " << host_public_key << ", " | 45 << "host_public_key: " << host_public_key << ", " |
51 << "scope: " << scope << ") Called"; | 46 << "scope: " << scope << ") Called"; |
52 | 47 |
53 if (token_fetcher_proxy) { | 48 if (token_fetcher_proxy) { |
54 token_fetcher_proxy->OnTokenFetched(authorization_token, shared_secret); | 49 token_fetcher_proxy->OnTokenFetched(authorization_token, shared_secret); |
55 token_fetcher_proxy.reset(); | 50 token_fetcher_proxy.reset(); |
56 } else { | 51 } else { |
57 LOG(ERROR) << "Invalid token fetcher proxy passed in"; | 52 LOG(ERROR) << "Invalid token fetcher proxy passed in"; |
58 } | 53 } |
59 } | 54 } |
60 | 55 |
| 56 void FetchSecret( |
| 57 const std::string& client_secret, |
| 58 bool pairing_expected, |
| 59 const remoting::protocol::SecretFetchedCallback& secret_fetched_callback) { |
| 60 secret_fetched_callback.Run(client_secret); |
| 61 } |
| 62 |
61 const char* ConnectionStateToFriendlyString( | 63 const char* ConnectionStateToFriendlyString( |
62 remoting::protocol::ConnectionToHost::State state) { | 64 remoting::protocol::ConnectionToHost::State state) { |
63 switch (state) { | 65 switch (state) { |
64 case remoting::protocol::ConnectionToHost::INITIALIZING: | 66 case remoting::protocol::ConnectionToHost::INITIALIZING: |
65 return "INITIALIZING"; | 67 return "INITIALIZING"; |
66 | 68 |
67 case remoting::protocol::ConnectionToHost::CONNECTING: | 69 case remoting::protocol::ConnectionToHost::CONNECTING: |
68 return "CONNECTING"; | 70 return "CONNECTING"; |
69 | 71 |
70 case remoting::protocol::ConnectionToHost::AUTHENTICATED: | 72 case remoting::protocol::ConnectionToHost::AUTHENTICATED: |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 TestChromotingClient(); | 142 TestChromotingClient(); |
141 } | 143 } |
142 | 144 |
143 TestChromotingClient::~TestChromotingClient() { | 145 TestChromotingClient::~TestChromotingClient() { |
144 // Ensure any connections are closed and the members are destroyed in the | 146 // Ensure any connections are closed and the members are destroyed in the |
145 // appropriate order. | 147 // appropriate order. |
146 EndConnection(); | 148 EndConnection(); |
147 } | 149 } |
148 | 150 |
149 void TestChromotingClient::StartConnection( | 151 void TestChromotingClient::StartConnection( |
150 const std::string& user_name, | 152 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. | 153 // Required to establish a connection to the host. |
158 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); | 154 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); |
159 | 155 |
160 scoped_refptr<URLRequestContextGetter> request_context_getter; | 156 scoped_refptr<URLRequestContextGetter> request_context_getter; |
161 request_context_getter = new URLRequestContextGetter( | 157 request_context_getter = new URLRequestContextGetter( |
162 base::ThreadTaskRunnerHandle::Get(), // network_runner | 158 base::ThreadTaskRunnerHandle::Get(), // network_runner |
163 base::ThreadTaskRunnerHandle::Get()); // file_runner | 159 base::ThreadTaskRunnerHandle::Get()); // file_runner |
164 | 160 |
165 client_context_.reset(new ClientContext(base::ThreadTaskRunnerHandle::Get())); | 161 client_context_.reset(new ClientContext(base::ThreadTaskRunnerHandle::Get())); |
166 | 162 |
167 // Check to see if the user passed in a customized video renderer. | 163 // Check to see if the user passed in a customized video renderer. |
168 if (!video_renderer_) { | 164 if (!video_renderer_) { |
169 video_renderer_.reset(new TestVideoRenderer()); | 165 video_renderer_.reset(new TestVideoRenderer()); |
170 } | 166 } |
171 | 167 |
172 chromoting_client_.reset(new ChromotingClient(client_context_.get(), | 168 chromoting_client_.reset(new ChromotingClient(client_context_.get(), |
173 this, // client_user_interface. | 169 this, // client_user_interface. |
174 video_renderer_.get(), | 170 video_renderer_.get(), |
175 nullptr)); // audio_player | 171 nullptr)); // audio_player |
176 | 172 |
177 if (test_connection_to_host_) { | 173 if (test_connection_to_host_) { |
178 chromoting_client_->SetConnectionToHostForTests( | 174 chromoting_client_->SetConnectionToHostForTests( |
179 test_connection_to_host_.Pass()); | 175 test_connection_to_host_.Pass()); |
180 } | 176 } |
181 | 177 |
182 XmppSignalStrategy::XmppServerConfig xmpp_server_config; | 178 XmppSignalStrategy::XmppServerConfig xmpp_server_config; |
183 xmpp_server_config.host = kXmppHostName; | 179 xmpp_server_config.host = kXmppHostName; |
184 xmpp_server_config.port = kXmppPortNumber; | 180 xmpp_server_config.port = kXmppPortNumber; |
185 xmpp_server_config.use_tls = true; | 181 xmpp_server_config.use_tls = true; |
186 xmpp_server_config.username = user_name; | 182 xmpp_server_config.username = connection_setup_info.user_name; |
187 xmpp_server_config.auth_token = access_token; | 183 xmpp_server_config.auth_token = connection_setup_info.access_token; |
188 | 184 |
189 // Set up the signal strategy. This must outlive the client object. | 185 // Set up the signal strategy. This must outlive the client object. |
190 signal_strategy_.reset( | 186 signal_strategy_.reset( |
191 new XmppSignalStrategy(net::ClientSocketFactory::GetDefaultFactory(), | 187 new XmppSignalStrategy(net::ClientSocketFactory::GetDefaultFactory(), |
192 request_context_getter, xmpp_server_config)); | 188 request_context_getter, xmpp_server_config)); |
193 | 189 |
194 protocol::NetworkSettings network_settings( | 190 protocol::NetworkSettings network_settings( |
195 protocol::NetworkSettings::NAT_TRAVERSAL_FULL); | 191 protocol::NetworkSettings::NAT_TRAVERSAL_FULL); |
196 | 192 |
197 scoped_ptr<protocol::ChromiumPortAllocator> port_allocator( | 193 scoped_ptr<protocol::ChromiumPortAllocator> port_allocator( |
198 protocol::ChromiumPortAllocator::Create(request_context_getter, | 194 protocol::ChromiumPortAllocator::Create(request_context_getter, |
199 network_settings)); | 195 network_settings)); |
200 | 196 |
201 scoped_ptr<protocol::TransportFactory> transport_factory( | 197 scoped_ptr<protocol::TransportFactory> transport_factory( |
202 new protocol::LibjingleTransportFactory( | 198 new protocol::LibjingleTransportFactory( |
203 signal_strategy_.get(), port_allocator.Pass(), network_settings, | 199 signal_strategy_.get(), port_allocator.Pass(), network_settings, |
204 protocol::TransportRole::CLIENT)); | 200 protocol::TransportRole::CLIENT)); |
205 | 201 |
206 scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher> | 202 scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher> |
207 token_fetcher(new TokenFetcherProxy( | 203 token_fetcher(new TokenFetcherProxy( |
208 base::Bind(&FetchThirdPartyToken, remote_host_info.authorization_code, | 204 base::Bind(&FetchThirdPartyToken, |
209 remote_host_info.shared_secret), | 205 connection_setup_info.authorization_code, |
210 "FAKE_HOST_PUBLIC_KEY")); | 206 connection_setup_info.shared_secret), |
| 207 connection_setup_info.public_key)); |
211 | 208 |
212 std::vector<protocol::AuthenticationMethod> auth_methods; | 209 protocol::FetchSecretCallback fetch_secret_callback; |
213 auth_methods.push_back(protocol::AuthenticationMethod::ThirdParty()); | 210 if (!connection_setup_info.pin.empty()) { |
| 211 fetch_secret_callback = base::Bind(&FetchSecret, connection_setup_info.pin); |
| 212 } |
214 | 213 |
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; | |
218 scoped_ptr<protocol::Authenticator> authenticator( | 214 scoped_ptr<protocol::Authenticator> authenticator( |
219 new protocol::NegotiatingClientAuthenticator( | 215 new protocol::NegotiatingClientAuthenticator( |
220 std::string(), // client_pairing_id | 216 connection_setup_info.pairing_id, |
221 std::string(), // shared_secret | 217 connection_setup_info.shared_secret, |
222 std::string(), // authentication_tag | 218 connection_setup_info.host_id, |
223 fetch_secret_callback, token_fetcher.Pass(), auth_methods)); | 219 fetch_secret_callback, |
| 220 token_fetcher.Pass(), |
| 221 connection_setup_info.auth_methods)); |
224 | 222 |
225 chromoting_client_->Start(signal_strategy_.get(), authenticator.Pass(), | 223 chromoting_client_->Start( |
226 transport_factory.Pass(), remote_host_info.host_jid, | 224 signal_strategy_.get(), authenticator.Pass(), transport_factory.Pass(), |
227 kAppRemotingCapabilities); | 225 connection_setup_info.host_jid, connection_setup_info.capabilities); |
228 } | 226 } |
229 | 227 |
230 void TestChromotingClient::EndConnection() { | 228 void TestChromotingClient::EndConnection() { |
231 // Clearing out the client will close the connection. | 229 // Clearing out the client will close the connection. |
232 chromoting_client_.reset(); | 230 chromoting_client_.reset(); |
233 | 231 |
234 // The signal strategy object must outlive the client so destroy it next. | 232 // The signal strategy object must outlive the client so destroy it next. |
235 signal_strategy_.reset(); | 233 signal_strategy_.reset(); |
236 | 234 |
237 // The connection state will be updated when the chromoting client was | 235 // The connection state will be updated when the chromoting client was |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 VLOG(1) << "TestChromotingClient::InjectClipboardEvent() Called"; | 340 VLOG(1) << "TestChromotingClient::InjectClipboardEvent() Called"; |
343 } | 341 } |
344 | 342 |
345 void TestChromotingClient::SetCursorShape( | 343 void TestChromotingClient::SetCursorShape( |
346 const protocol::CursorShapeInfo& cursor_shape) { | 344 const protocol::CursorShapeInfo& cursor_shape) { |
347 VLOG(1) << "TestChromotingClient::SetCursorShape() Called"; | 345 VLOG(1) << "TestChromotingClient::SetCursorShape() Called"; |
348 } | 346 } |
349 | 347 |
350 } // namespace test | 348 } // namespace test |
351 } // namespace remoting | 349 } // namespace remoting |
OLD | NEW |