Chromium Code Reviews| 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/strings/string_split.h" | |
| 11 #include "base/thread_task_runner_handle.h" | 12 #include "base/thread_task_runner_handle.h" |
| 12 #include "jingle/glue/thread_wrapper.h" | 13 #include "jingle/glue/thread_wrapper.h" |
| 13 #include "net/base/request_priority.h" | 14 #include "net/base/request_priority.h" |
| 14 #include "net/socket/client_socket_factory.h" | 15 #include "net/socket/client_socket_factory.h" |
| 15 #include "remoting/base/url_request_context_getter.h" | 16 #include "remoting/base/url_request_context_getter.h" |
| 16 #include "remoting/client/audio_player.h" | 17 #include "remoting/client/audio_player.h" |
| 17 #include "remoting/client/chromoting_client.h" | 18 #include "remoting/client/chromoting_client.h" |
| 18 #include "remoting/client/client_context.h" | 19 #include "remoting/client/client_context.h" |
| 19 #include "remoting/client/token_fetcher_proxy.h" | 20 #include "remoting/client/token_fetcher_proxy.h" |
| 20 #include "remoting/protocol/authentication_method.h" | 21 #include "remoting/protocol/authentication_method.h" |
| 21 #include "remoting/protocol/chromium_port_allocator.h" | 22 #include "remoting/protocol/chromium_port_allocator.h" |
| 22 #include "remoting/protocol/host_stub.h" | 23 #include "remoting/protocol/host_stub.h" |
| 23 #include "remoting/protocol/libjingle_transport_factory.h" | 24 #include "remoting/protocol/libjingle_transport_factory.h" |
| 24 #include "remoting/protocol/negotiating_client_authenticator.h" | 25 #include "remoting/protocol/negotiating_client_authenticator.h" |
| 25 #include "remoting/protocol/network_settings.h" | 26 #include "remoting/protocol/network_settings.h" |
| 26 #include "remoting/protocol/session_config.h" | 27 #include "remoting/protocol/session_config.h" |
| 27 #include "remoting/protocol/third_party_client_authenticator.h" | 28 #include "remoting/protocol/third_party_client_authenticator.h" |
| 28 #include "remoting/signaling/xmpp_signal_strategy.h" | 29 #include "remoting/signaling/xmpp_signal_strategy.h" |
| 29 #include "remoting/test/remote_host_info_fetcher.h" | 30 #include "remoting/test/remote_host_info_fetcher.h" |
|
joedow
2015/07/16 03:23:19
This header seems like it is not needed
tonychun
2015/07/16 23:12:08
Done.
| |
| 30 #include "remoting/test/test_video_renderer.h" | 31 #include "remoting/test/test_video_renderer.h" |
| 31 | 32 |
| 32 namespace { | 33 namespace { |
| 33 | |
| 34 const char kAppRemotingCapabilities[] = | |
| 35 "rateLimitResizeRequests desktopShape sendInitialResolution googleDrive"; | |
| 36 | |
| 37 const char kXmppHostName[] = "talk.google.com"; | 34 const char kXmppHostName[] = "talk.google.com"; |
| 38 const int kXmppPortNumber = 5222; | 35 const int kXmppPortNumber = 5222; |
| 39 | 36 |
| 40 // Used as the TokenFetcherCallback for App Remoting sessions. | 37 // Used as the TokenFetcherCallback for App Remoting sessions. |
| 41 void FetchThirdPartyToken( | 38 void FetchThirdPartyToken( |
| 42 const std::string& authorization_token, | 39 const std::string& authorization_token, |
| 43 const std::string& shared_secret, | 40 const std::string& shared_secret, |
| 44 const GURL& token_url, | 41 const GURL& token_url, |
| 45 const std::string& host_public_key, | 42 const std::string& host_public_key, |
| 46 const std::string& scope, | 43 const std::string& scope, |
| 47 base::WeakPtr<remoting::TokenFetcherProxy> token_fetcher_proxy) { | 44 base::WeakPtr<remoting::TokenFetcherProxy> token_fetcher_proxy) { |
| 48 VLOG(2) << "FetchThirdPartyToken(" | 45 VLOG(2) << "FetchThirdPartyToken(" |
| 49 << "token_url: " << token_url << ", " | 46 << "token_url: " << token_url << ", " |
| 50 << "host_public_key: " << host_public_key << ", " | 47 << "host_public_key: " << host_public_key << ", " |
| 51 << "scope: " << scope << ") Called"; | 48 << "scope: " << scope << ") Called"; |
| 52 | 49 |
| 53 if (token_fetcher_proxy) { | 50 if (token_fetcher_proxy) { |
| 54 token_fetcher_proxy->OnTokenFetched(authorization_token, shared_secret); | 51 token_fetcher_proxy->OnTokenFetched(authorization_token, shared_secret); |
| 55 token_fetcher_proxy.reset(); | 52 token_fetcher_proxy.reset(); |
| 56 } else { | 53 } else { |
| 57 LOG(ERROR) << "Invalid token fetcher proxy passed in"; | 54 LOG(ERROR) << "Invalid token fetcher proxy passed in"; |
| 58 } | 55 } |
| 59 } | 56 } |
| 60 | 57 |
| 58 void FetchSecret( | |
| 59 const std::string& client_secret, | |
| 60 bool pairing_supported, | |
|
joedow
2015/07/16 03:23:19
is pairing_supported needed? You bind true to it
tonychun
2015/07/16 23:12:08
Removed the unused parameter.
| |
| 61 bool pairing_expected, | |
| 62 const remoting::protocol::SecretFetchedCallback& secret_fetched_callback) { | |
| 63 secret_fetched_callback.Run(client_secret); | |
| 64 } | |
| 65 | |
| 61 const char* ConnectionStateToFriendlyString( | 66 const char* ConnectionStateToFriendlyString( |
| 62 remoting::protocol::ConnectionToHost::State state) { | 67 remoting::protocol::ConnectionToHost::State state) { |
| 63 switch (state) { | 68 switch (state) { |
| 64 case remoting::protocol::ConnectionToHost::INITIALIZING: | 69 case remoting::protocol::ConnectionToHost::INITIALIZING: |
| 65 return "INITIALIZING"; | 70 return "INITIALIZING"; |
| 66 | 71 |
| 67 case remoting::protocol::ConnectionToHost::CONNECTING: | 72 case remoting::protocol::ConnectionToHost::CONNECTING: |
| 68 return "CONNECTING"; | 73 return "CONNECTING"; |
| 69 | 74 |
| 70 case remoting::protocol::ConnectionToHost::AUTHENTICATED: | 75 case remoting::protocol::ConnectionToHost::AUTHENTICATED: |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 TestChromotingClient(); | 145 TestChromotingClient(); |
| 141 } | 146 } |
| 142 | 147 |
| 143 TestChromotingClient::~TestChromotingClient() { | 148 TestChromotingClient::~TestChromotingClient() { |
| 144 // Ensure any connections are closed and the members are destroyed in the | 149 // Ensure any connections are closed and the members are destroyed in the |
| 145 // appropriate order. | 150 // appropriate order. |
| 146 EndConnection(); | 151 EndConnection(); |
| 147 } | 152 } |
| 148 | 153 |
| 149 void TestChromotingClient::StartConnection( | 154 void TestChromotingClient::StartConnection( |
| 150 const std::string& user_name, | 155 const ConnectionInfo& connection_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. | 156 // Required to establish a connection to the host. |
| 158 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); | 157 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); |
| 159 | 158 |
| 160 scoped_refptr<URLRequestContextGetter> request_context_getter; | 159 scoped_refptr<URLRequestContextGetter> request_context_getter; |
| 161 request_context_getter = new URLRequestContextGetter( | 160 request_context_getter = new URLRequestContextGetter( |
| 162 base::ThreadTaskRunnerHandle::Get(), // network_runner | 161 base::ThreadTaskRunnerHandle::Get(), // network_runner |
| 163 base::ThreadTaskRunnerHandle::Get()); // file_runner | 162 base::ThreadTaskRunnerHandle::Get()); // file_runner |
| 164 | 163 |
| 165 client_context_.reset(new ClientContext(base::ThreadTaskRunnerHandle::Get())); | 164 client_context_.reset(new ClientContext(base::ThreadTaskRunnerHandle::Get())); |
| 166 | 165 |
| 167 // Check to see if the user passed in a customized video renderer. | 166 // Check to see if the user passed in a customized video renderer. |
| 168 if (!video_renderer_) { | 167 if (!video_renderer_) { |
| 169 video_renderer_.reset(new TestVideoRenderer()); | 168 video_renderer_.reset(new TestVideoRenderer()); |
| 170 } | 169 } |
| 171 | 170 |
| 172 chromoting_client_.reset(new ChromotingClient(client_context_.get(), | 171 chromoting_client_.reset(new ChromotingClient(client_context_.get(), |
| 173 this, // client_user_interface. | 172 this, // client_user_interface. |
| 174 video_renderer_.get(), | 173 video_renderer_.get(), |
| 175 nullptr)); // audio_player | 174 nullptr)); // audio_player |
| 176 | 175 |
| 177 if (test_connection_to_host_) { | 176 if (test_connection_to_host_) { |
| 178 chromoting_client_->SetConnectionToHostForTests( | 177 chromoting_client_->SetConnectionToHostForTests( |
| 179 test_connection_to_host_.Pass()); | 178 test_connection_to_host_.Pass()); |
| 180 } | 179 } |
| 181 | 180 |
| 182 XmppSignalStrategy::XmppServerConfig xmpp_server_config; | 181 XmppSignalStrategy::XmppServerConfig xmpp_server_config; |
| 183 xmpp_server_config.host = kXmppHostName; | 182 xmpp_server_config.host = kXmppHostName; |
| 184 xmpp_server_config.port = kXmppPortNumber; | 183 xmpp_server_config.port = kXmppPortNumber; |
| 185 xmpp_server_config.use_tls = true; | 184 xmpp_server_config.use_tls = true; |
| 186 xmpp_server_config.username = user_name; | 185 xmpp_server_config.username = connection_info.user_name; |
| 187 xmpp_server_config.auth_token = access_token; | 186 xmpp_server_config.auth_token = connection_info.access_token; |
| 188 | 187 |
| 189 // Set up the signal strategy. This must outlive the client object. | 188 // Set up the signal strategy. This must outlive the client object. |
| 190 signal_strategy_.reset( | 189 signal_strategy_.reset( |
| 191 new XmppSignalStrategy(net::ClientSocketFactory::GetDefaultFactory(), | 190 new XmppSignalStrategy(net::ClientSocketFactory::GetDefaultFactory(), |
| 192 request_context_getter, xmpp_server_config)); | 191 request_context_getter, xmpp_server_config)); |
| 193 | 192 |
| 194 protocol::NetworkSettings network_settings( | 193 protocol::NetworkSettings network_settings( |
| 195 protocol::NetworkSettings::NAT_TRAVERSAL_FULL); | 194 protocol::NetworkSettings::NAT_TRAVERSAL_FULL); |
| 196 | 195 |
| 197 scoped_ptr<protocol::ChromiumPortAllocator> port_allocator( | 196 scoped_ptr<protocol::ChromiumPortAllocator> port_allocator( |
| 198 protocol::ChromiumPortAllocator::Create(request_context_getter, | 197 protocol::ChromiumPortAllocator::Create(request_context_getter, |
| 199 network_settings)); | 198 network_settings)); |
| 200 | 199 |
| 201 scoped_ptr<protocol::TransportFactory> transport_factory( | 200 scoped_ptr<protocol::TransportFactory> transport_factory( |
| 202 new protocol::LibjingleTransportFactory( | 201 new protocol::LibjingleTransportFactory( |
| 203 signal_strategy_.get(), port_allocator.Pass(), network_settings, | 202 signal_strategy_.get(), port_allocator.Pass(), network_settings, |
| 204 protocol::TransportRole::CLIENT)); | 203 protocol::TransportRole::CLIENT)); |
| 205 | 204 |
| 206 scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher> | 205 scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher> |
| 207 token_fetcher(new TokenFetcherProxy( | 206 token_fetcher(new TokenFetcherProxy( |
| 208 base::Bind(&FetchThirdPartyToken, remote_host_info.authorization_code, | 207 base::Bind(&FetchThirdPartyToken, |
| 209 remote_host_info.shared_secret), | 208 connection_info.authorization_code, |
|
joedow
2015/07/16 03:23:19
indentation seems off here, either 4 spaces or lin
tonychun
2015/07/16 23:12:08
Done.
| |
| 210 "FAKE_HOST_PUBLIC_KEY")); | 209 connection_info.shared_secret), |
| 210 connection_info.public_key)); | |
| 211 | 211 |
| 212 // Parse |auth_methods_str| for authentication methods. | |
|
joedow
2015/07/16 03:23:19
Why build this here? This feels like something th
tonychun
2015/07/16 23:12:08
Done.
| |
| 213 std::vector<std::string> parts; | |
| 214 base::SplitString(connection_info.auth_methods_str, ',', &parts); | |
| 212 std::vector<protocol::AuthenticationMethod> auth_methods; | 215 std::vector<protocol::AuthenticationMethod> auth_methods; |
| 213 auth_methods.push_back(protocol::AuthenticationMethod::ThirdParty()); | 216 for (std::string part : parts) { |
| 217 protocol::AuthenticationMethod auth_method = | |
| 218 protocol::AuthenticationMethod::FromString(part); | |
| 219 if (auth_method.is_valid()) { | |
| 220 auth_methods.push_back(auth_method); | |
| 221 } | |
| 222 } | |
| 214 | 223 |
| 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; | 224 protocol::FetchSecretCallback fetch_secret_callback; |
| 225 if (!connection_info.pin.empty()) { | |
| 226 fetch_secret_callback = base::Bind(&FetchSecret, connection_info.pin, true); | |
| 227 } | |
| 218 scoped_ptr<protocol::Authenticator> authenticator( | 228 scoped_ptr<protocol::Authenticator> authenticator( |
| 219 new protocol::NegotiatingClientAuthenticator( | 229 new protocol::NegotiatingClientAuthenticator( |
| 220 std::string(), // client_pairing_id | 230 std::string(), // client_pairing_id |
| 221 std::string(), // shared_secret | 231 std::string(), // shared_secret |
|
joedow
2015/07/16 03:23:19
you can pass the connection_info members for pairi
tonychun
2015/07/16 23:12:08
I've added a new member in ConnectionSetupInfo (ne
| |
| 222 std::string(), // authentication_tag | 232 connection_info.host_id, // authentication_tag |
| 223 fetch_secret_callback, token_fetcher.Pass(), auth_methods)); | 233 fetch_secret_callback, token_fetcher.Pass(), auth_methods)); |
| 224 | 234 |
| 225 chromoting_client_->Start(signal_strategy_.get(), authenticator.Pass(), | 235 chromoting_client_->Start(signal_strategy_.get(), authenticator.Pass(), |
| 226 transport_factory.Pass(), remote_host_info.host_jid, | 236 transport_factory.Pass(), connection_info.host_jid, |
| 227 kAppRemotingCapabilities); | 237 connection_info.capabilities); |
| 228 } | 238 } |
| 229 | 239 |
| 230 void TestChromotingClient::EndConnection() { | 240 void TestChromotingClient::EndConnection() { |
| 231 // Clearing out the client will close the connection. | 241 // Clearing out the client will close the connection. |
| 232 chromoting_client_.reset(); | 242 chromoting_client_.reset(); |
| 233 | 243 |
| 234 // The signal strategy object must outlive the client so destroy it next. | 244 // The signal strategy object must outlive the client so destroy it next. |
| 235 signal_strategy_.reset(); | 245 signal_strategy_.reset(); |
| 236 | 246 |
| 237 // The connection state will be updated when the chromoting client was | 247 // 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"; | 352 VLOG(1) << "TestChromotingClient::InjectClipboardEvent() Called"; |
| 343 } | 353 } |
| 344 | 354 |
| 345 void TestChromotingClient::SetCursorShape( | 355 void TestChromotingClient::SetCursorShape( |
| 346 const protocol::CursorShapeInfo& cursor_shape) { | 356 const protocol::CursorShapeInfo& cursor_shape) { |
| 347 VLOG(1) << "TestChromotingClient::SetCursorShape() Called"; | 357 VLOG(1) << "TestChromotingClient::SetCursorShape() Called"; |
| 348 } | 358 } |
| 349 | 359 |
| 350 } // namespace test | 360 } // namespace test |
| 351 } // namespace remoting | 361 } // namespace remoting |
| OLD | NEW |