| 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/remote_host_info_fetcher.h" | 5 #include "remoting/test/remote_host_info_fetcher.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 namespace remoting { | 36 namespace remoting { |
| 37 namespace test { | 37 namespace test { |
| 38 | 38 |
| 39 // Provides base functionality for the RemoteHostInfoFetcher Tests below. The | 39 // Provides base functionality for the RemoteHostInfoFetcher Tests below. The |
| 40 // FakeURLFetcherFactory allows us to override the response data and payload for | 40 // FakeURLFetcherFactory allows us to override the response data and payload for |
| 41 // specified URLs. We use this to stub out network calls made by the | 41 // specified URLs. We use this to stub out network calls made by the |
| 42 // RemoteHostInfoFetcher. This fixture also creates an IO MessageLoop, if | 42 // RemoteHostInfoFetcher. This fixture also creates an IO MessageLoop, if |
| 43 // necessary, for use by the RemoteHostInfoFetcher. | 43 // necessary, for use by the RemoteHostInfoFetcher. |
| 44 class RemoteHostInfoFetcherTest : public ::testing::Test { | 44 class RemoteHostInfoFetcherTest : public ::testing::Test { |
| 45 public: | 45 public: |
| 46 RemoteHostInfoFetcherTest() : | 46 RemoteHostInfoFetcherTest() : url_fetcher_factory_(nullptr) {} |
| 47 url_fetcher_factory_(nullptr) {} | |
| 48 ~RemoteHostInfoFetcherTest() override {} | 47 ~RemoteHostInfoFetcherTest() override {} |
| 49 | 48 |
| 50 // Used as a RemoteHostInfoCallback for testing. | 49 // Used as a RemoteHostInfoCallback for testing. |
| 51 void OnRemoteHostInfoRetrieved( | 50 void OnRemoteHostInfoRetrieved( |
| 52 base::Closure done_closure, | 51 base::Closure done_closure, |
| 53 const RemoteHostInfo& retrieved_remote_host_info); | 52 const RemoteHostInfo& retrieved_remote_host_info); |
| 54 | 53 |
| 55 protected: | 54 protected: |
| 56 // testing::Test interface. | 55 // testing::Test interface. |
| 57 void SetUp() override; | 56 void SetUp() override; |
| 58 | 57 |
| 59 // Sets the HTTP status and data returned for a specified URL. | 58 // Sets the HTTP status and data returned for a specified URL. |
| 60 void SetFakeResponse( | 59 void SetFakeResponse(const GURL& url, |
| 61 const GURL& url, | 60 const std::string& data, |
| 62 const std::string& data, | 61 net::HttpStatusCode code, |
| 63 net::HttpStatusCode code, | 62 net::URLRequestStatus::Status status); |
| 64 net::URLRequestStatus::Status status); | |
| 65 | 63 |
| 66 // Used for result verification. | 64 // Used for result verification. |
| 67 RemoteHostInfo remote_host_info_; | 65 RemoteHostInfo remote_host_info_; |
| 68 | 66 |
| 69 protected: | 67 protected: |
| 70 std::string dev_service_environment_url_; | 68 std::string dev_service_environment_url_; |
| 71 std::string test_service_environment_url_; | 69 std::string test_service_environment_url_; |
| 72 | 70 |
| 73 private: | 71 private: |
| 74 net::FakeURLFetcherFactory url_fetcher_factory_; | 72 net::FakeURLFetcherFactory url_fetcher_factory_; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 85 done_closure.Run(); | 83 done_closure.Run(); |
| 86 } | 84 } |
| 87 | 85 |
| 88 void RemoteHostInfoFetcherTest::SetUp() { | 86 void RemoteHostInfoFetcherTest::SetUp() { |
| 89 if (!base::MessageLoop::current()) { | 87 if (!base::MessageLoop::current()) { |
| 90 // Create a temporary message loop if the current thread does not already | 88 // Create a temporary message loop if the current thread does not already |
| 91 // have one so we can use its task runner to create a request object. | 89 // have one so we can use its task runner to create a request object. |
| 92 message_loop_.reset(new base::MessageLoopForIO); | 90 message_loop_.reset(new base::MessageLoopForIO); |
| 93 } | 91 } |
| 94 | 92 |
| 95 dev_service_environment_url_ = base::StringPrintf( | 93 dev_service_environment_url_ = |
| 96 kDevServiceEnvironmentUrlFormat, | 94 base::StringPrintf(kDevServiceEnvironmentUrlFormat, kTestApplicationId); |
| 97 kTestApplicationId); | |
| 98 | 95 |
| 99 test_service_environment_url_ = base::StringPrintf( | 96 test_service_environment_url_ = |
| 100 kTestServiceEnvironmentUrlFormat, | 97 base::StringPrintf(kTestServiceEnvironmentUrlFormat, kTestApplicationId); |
| 101 kTestApplicationId); | |
| 102 } | 98 } |
| 103 | 99 |
| 104 void RemoteHostInfoFetcherTest::SetFakeResponse( | 100 void RemoteHostInfoFetcherTest::SetFakeResponse( |
| 105 const GURL& url, | 101 const GURL& url, |
| 106 const std::string& data, | 102 const std::string& data, |
| 107 net::HttpStatusCode code, | 103 net::HttpStatusCode code, |
| 108 net::URLRequestStatus::Status status) { | 104 net::URLRequestStatus::Status status) { |
| 109 url_fetcher_factory_.SetFakeResponse(url, data, code, status); | 105 url_fetcher_factory_.SetFakeResponse(url, data, code, status); |
| 110 } | 106 } |
| 111 | 107 |
| 112 TEST_F(RemoteHostInfoFetcherTest, RetrieveRemoteHostInfoFromDev) { | 108 TEST_F(RemoteHostInfoFetcherTest, RetrieveRemoteHostInfoFromDev) { |
| 113 SetFakeResponse( | 109 SetFakeResponse(GURL(dev_service_environment_url_), |
| 114 GURL(dev_service_environment_url_), | 110 kRemoteHostInfoReadyResponse, net::HTTP_OK, |
| 115 kRemoteHostInfoReadyResponse, | 111 net::URLRequestStatus::SUCCESS); |
| 116 net::HTTP_OK, | |
| 117 net::URLRequestStatus::SUCCESS); | |
| 118 | 112 |
| 119 SetFakeResponse( | 113 SetFakeResponse(GURL(test_service_environment_url_), |
| 120 GURL(test_service_environment_url_), | 114 kRemoteHostInfoEmptyResponse, net::HTTP_NOT_FOUND, |
| 121 kRemoteHostInfoEmptyResponse, | 115 net::URLRequestStatus::FAILED); |
| 122 net::HTTP_NOT_FOUND, | |
| 123 net::URLRequestStatus::FAILED); | |
| 124 | 116 |
| 125 base::RunLoop run_loop; | 117 base::RunLoop run_loop; |
| 126 RemoteHostInfoCallback remote_host_info_callback = | 118 RemoteHostInfoCallback remote_host_info_callback = |
| 127 base::Bind(&RemoteHostInfoFetcherTest::OnRemoteHostInfoRetrieved, | 119 base::Bind(&RemoteHostInfoFetcherTest::OnRemoteHostInfoRetrieved, |
| 128 base::Unretained(this), | 120 base::Unretained(this), run_loop.QuitClosure()); |
| 129 run_loop.QuitClosure()); | |
| 130 | 121 |
| 131 RemoteHostInfoFetcher remote_host_info_fetcher; | 122 RemoteHostInfoFetcher remote_host_info_fetcher; |
| 132 bool request_started = remote_host_info_fetcher.RetrieveRemoteHostInfo( | 123 bool request_started = remote_host_info_fetcher.RetrieveRemoteHostInfo( |
| 133 kTestApplicationId, | 124 kTestApplicationId, kAccessTokenValue, kDeveloperEnvironment, |
| 134 kAccessTokenValue, | |
| 135 kDeveloperEnvironment, | |
| 136 remote_host_info_callback); | 125 remote_host_info_callback); |
| 137 | 126 |
| 138 run_loop.Run(); | 127 run_loop.Run(); |
| 139 | 128 |
| 140 EXPECT_TRUE(request_started); | 129 EXPECT_TRUE(request_started); |
| 141 EXPECT_TRUE(remote_host_info_.IsReadyForConnection()); | 130 EXPECT_TRUE(remote_host_info_.IsReadyForConnection()); |
| 142 EXPECT_EQ(remote_host_info_.application_id.compare(kTestApplicationId), 0); | 131 EXPECT_EQ(remote_host_info_.application_id.compare(kTestApplicationId), 0); |
| 143 EXPECT_TRUE(!remote_host_info_.host_id.empty()); | 132 EXPECT_TRUE(!remote_host_info_.host_id.empty()); |
| 144 EXPECT_TRUE(!remote_host_info_.host_jid.empty()); | 133 EXPECT_TRUE(!remote_host_info_.host_jid.empty()); |
| 145 EXPECT_TRUE(!remote_host_info_.authorization_code.empty()); | 134 EXPECT_TRUE(!remote_host_info_.authorization_code.empty()); |
| 146 EXPECT_TRUE(!remote_host_info_.shared_secret.empty()); | 135 EXPECT_TRUE(!remote_host_info_.shared_secret.empty()); |
| 147 } | 136 } |
| 148 | 137 |
| 149 TEST_F(RemoteHostInfoFetcherTest, RetrieveRemoteHostInfoFromTest) { | 138 TEST_F(RemoteHostInfoFetcherTest, RetrieveRemoteHostInfoFromTest) { |
| 150 SetFakeResponse( | 139 SetFakeResponse(GURL(test_service_environment_url_), |
| 151 GURL(test_service_environment_url_), | 140 kRemoteHostInfoReadyResponse, net::HTTP_OK, |
| 152 kRemoteHostInfoReadyResponse, | 141 net::URLRequestStatus::SUCCESS); |
| 153 net::HTTP_OK, | |
| 154 net::URLRequestStatus::SUCCESS); | |
| 155 | 142 |
| 156 SetFakeResponse( | 143 SetFakeResponse(GURL(dev_service_environment_url_), |
| 157 GURL(dev_service_environment_url_), | 144 kRemoteHostInfoEmptyResponse, net::HTTP_NOT_FOUND, |
| 158 kRemoteHostInfoEmptyResponse, | 145 net::URLRequestStatus::FAILED); |
| 159 net::HTTP_NOT_FOUND, | |
| 160 net::URLRequestStatus::FAILED); | |
| 161 | 146 |
| 162 base::RunLoop run_loop; | 147 base::RunLoop run_loop; |
| 163 RemoteHostInfoCallback remote_host_info_callback = | 148 RemoteHostInfoCallback remote_host_info_callback = |
| 164 base::Bind(&RemoteHostInfoFetcherTest::OnRemoteHostInfoRetrieved, | 149 base::Bind(&RemoteHostInfoFetcherTest::OnRemoteHostInfoRetrieved, |
| 165 base::Unretained(this), | 150 base::Unretained(this), run_loop.QuitClosure()); |
| 166 run_loop.QuitClosure()); | |
| 167 | 151 |
| 168 RemoteHostInfoFetcher remote_host_info_fetcher; | 152 RemoteHostInfoFetcher remote_host_info_fetcher; |
| 169 bool request_started = remote_host_info_fetcher.RetrieveRemoteHostInfo( | 153 bool request_started = remote_host_info_fetcher.RetrieveRemoteHostInfo( |
| 170 kTestApplicationId, | 154 kTestApplicationId, kAccessTokenValue, kTestingEnvironment, |
| 171 kAccessTokenValue, | |
| 172 kTestingEnvironment, | |
| 173 remote_host_info_callback); | 155 remote_host_info_callback); |
| 174 | 156 |
| 175 run_loop.Run(); | 157 run_loop.Run(); |
| 176 | 158 |
| 177 EXPECT_TRUE(request_started); | 159 EXPECT_TRUE(request_started); |
| 178 EXPECT_TRUE(remote_host_info_.IsReadyForConnection()); | 160 EXPECT_TRUE(remote_host_info_.IsReadyForConnection()); |
| 179 EXPECT_EQ(remote_host_info_.application_id.compare(kTestApplicationId), 0); | 161 EXPECT_EQ(remote_host_info_.application_id.compare(kTestApplicationId), 0); |
| 180 EXPECT_TRUE(!remote_host_info_.host_id.empty()); | 162 EXPECT_TRUE(!remote_host_info_.host_id.empty()); |
| 181 EXPECT_TRUE(!remote_host_info_.host_jid.empty()); | 163 EXPECT_TRUE(!remote_host_info_.host_jid.empty()); |
| 182 EXPECT_TRUE(!remote_host_info_.authorization_code.empty()); | 164 EXPECT_TRUE(!remote_host_info_.authorization_code.empty()); |
| 183 EXPECT_TRUE(!remote_host_info_.shared_secret.empty()); | 165 EXPECT_TRUE(!remote_host_info_.shared_secret.empty()); |
| 184 } | 166 } |
| 185 | 167 |
| 186 TEST_F(RemoteHostInfoFetcherTest, RetrieveRemoteHostInfoInvalidEnvironment) { | 168 TEST_F(RemoteHostInfoFetcherTest, RetrieveRemoteHostInfoInvalidEnvironment) { |
| 187 base::RunLoop run_loop; | 169 base::RunLoop run_loop; |
| 188 RemoteHostInfoCallback remote_host_info_callback = | 170 RemoteHostInfoCallback remote_host_info_callback = |
| 189 base::Bind(&RemoteHostInfoFetcherTest::OnRemoteHostInfoRetrieved, | 171 base::Bind(&RemoteHostInfoFetcherTest::OnRemoteHostInfoRetrieved, |
| 190 base::Unretained(this), | 172 base::Unretained(this), run_loop.QuitClosure()); |
| 191 run_loop.QuitClosure()); | |
| 192 | 173 |
| 193 RemoteHostInfoFetcher remote_host_info_fetcher; | 174 RemoteHostInfoFetcher remote_host_info_fetcher; |
| 194 bool request_started = remote_host_info_fetcher.RetrieveRemoteHostInfo( | 175 bool request_started = remote_host_info_fetcher.RetrieveRemoteHostInfo( |
| 195 kTestApplicationId, | 176 kTestApplicationId, kAccessTokenValue, kUnknownEnvironment, |
| 196 kAccessTokenValue, | |
| 197 kUnknownEnvironment, | |
| 198 remote_host_info_callback); | 177 remote_host_info_callback); |
| 199 | 178 |
| 200 EXPECT_FALSE(request_started); | 179 EXPECT_FALSE(request_started); |
| 201 } | 180 } |
| 202 | 181 |
| 203 TEST_F(RemoteHostInfoFetcherTest, RetrieveRemoteHostInfoNetworkError) { | 182 TEST_F(RemoteHostInfoFetcherTest, RetrieveRemoteHostInfoNetworkError) { |
| 204 SetFakeResponse( | 183 SetFakeResponse(GURL(dev_service_environment_url_), |
| 205 GURL(dev_service_environment_url_), | 184 kRemoteHostInfoReadyResponse, net::HTTP_NOT_FOUND, |
| 206 kRemoteHostInfoReadyResponse, | 185 net::URLRequestStatus::FAILED); |
| 207 net::HTTP_NOT_FOUND, | |
| 208 net::URLRequestStatus::FAILED); | |
| 209 | 186 |
| 210 base::RunLoop run_loop; | 187 base::RunLoop run_loop; |
| 211 RemoteHostInfoCallback remote_host_info_callback = | 188 RemoteHostInfoCallback remote_host_info_callback = |
| 212 base::Bind(&RemoteHostInfoFetcherTest::OnRemoteHostInfoRetrieved, | 189 base::Bind(&RemoteHostInfoFetcherTest::OnRemoteHostInfoRetrieved, |
| 213 base::Unretained(this), | 190 base::Unretained(this), run_loop.QuitClosure()); |
| 214 run_loop.QuitClosure()); | |
| 215 | 191 |
| 216 RemoteHostInfoFetcher remote_host_info_fetcher; | 192 RemoteHostInfoFetcher remote_host_info_fetcher; |
| 217 bool request_started = remote_host_info_fetcher.RetrieveRemoteHostInfo( | 193 bool request_started = remote_host_info_fetcher.RetrieveRemoteHostInfo( |
| 218 kTestApplicationId, | 194 kTestApplicationId, kAccessTokenValue, kDeveloperEnvironment, |
| 219 kAccessTokenValue, | |
| 220 kDeveloperEnvironment, | |
| 221 remote_host_info_callback); | 195 remote_host_info_callback); |
| 222 | 196 |
| 223 run_loop.Run(); | 197 run_loop.Run(); |
| 224 | 198 |
| 225 EXPECT_TRUE(request_started); | 199 EXPECT_TRUE(request_started); |
| 226 EXPECT_FALSE(remote_host_info_.IsReadyForConnection()); | 200 EXPECT_FALSE(remote_host_info_.IsReadyForConnection()); |
| 227 | 201 |
| 228 // If there was a network error retrieving the remote host info, then none of | 202 // If there was a network error retrieving the remote host info, then none of |
| 229 // the connection details should be populated. | 203 // the connection details should be populated. |
| 230 EXPECT_TRUE(remote_host_info_.application_id.empty()); | 204 EXPECT_TRUE(remote_host_info_.application_id.empty()); |
| 231 EXPECT_TRUE(remote_host_info_.host_id.empty()); | 205 EXPECT_TRUE(remote_host_info_.host_id.empty()); |
| 232 EXPECT_TRUE(remote_host_info_.host_jid.empty()); | 206 EXPECT_TRUE(remote_host_info_.host_jid.empty()); |
| 233 EXPECT_TRUE(remote_host_info_.authorization_code.empty()); | 207 EXPECT_TRUE(remote_host_info_.authorization_code.empty()); |
| 234 EXPECT_TRUE(remote_host_info_.shared_secret.empty()); | 208 EXPECT_TRUE(remote_host_info_.shared_secret.empty()); |
| 235 } | 209 } |
| 236 | 210 |
| 237 TEST_F(RemoteHostInfoFetcherTest, RetrieveRemoteHostInfoPendingResponse) { | 211 TEST_F(RemoteHostInfoFetcherTest, RetrieveRemoteHostInfoPendingResponse) { |
| 238 SetFakeResponse( | 212 SetFakeResponse(GURL(dev_service_environment_url_), |
| 239 GURL(dev_service_environment_url_), | 213 kRemoteHostInfoPendingResponse, net::HTTP_OK, |
| 240 kRemoteHostInfoPendingResponse, | 214 net::URLRequestStatus::SUCCESS); |
| 241 net::HTTP_OK, | |
| 242 net::URLRequestStatus::SUCCESS); | |
| 243 | 215 |
| 244 base::RunLoop run_loop; | 216 base::RunLoop run_loop; |
| 245 RemoteHostInfoCallback remote_host_info_callback = | 217 RemoteHostInfoCallback remote_host_info_callback = |
| 246 base::Bind(&RemoteHostInfoFetcherTest::OnRemoteHostInfoRetrieved, | 218 base::Bind(&RemoteHostInfoFetcherTest::OnRemoteHostInfoRetrieved, |
| 247 base::Unretained(this), | 219 base::Unretained(this), run_loop.QuitClosure()); |
| 248 run_loop.QuitClosure()); | |
| 249 | 220 |
| 250 RemoteHostInfoFetcher remote_host_info_fetcher; | 221 RemoteHostInfoFetcher remote_host_info_fetcher; |
| 251 bool request_started = remote_host_info_fetcher.RetrieveRemoteHostInfo( | 222 bool request_started = remote_host_info_fetcher.RetrieveRemoteHostInfo( |
| 252 kTestApplicationId, | 223 kTestApplicationId, kAccessTokenValue, kDeveloperEnvironment, |
| 253 kAccessTokenValue, | |
| 254 kDeveloperEnvironment, | |
| 255 remote_host_info_callback); | 224 remote_host_info_callback); |
| 256 | 225 |
| 257 run_loop.Run(); | 226 run_loop.Run(); |
| 258 | 227 |
| 259 EXPECT_TRUE(request_started); | 228 EXPECT_TRUE(request_started); |
| 260 EXPECT_FALSE(remote_host_info_.IsReadyForConnection()); | 229 EXPECT_FALSE(remote_host_info_.IsReadyForConnection()); |
| 261 | 230 |
| 262 // If the remote host request is pending, then none of the connection details | 231 // If the remote host request is pending, then none of the connection details |
| 263 // should be populated. | 232 // should be populated. |
| 264 EXPECT_TRUE(remote_host_info_.application_id.empty()); | 233 EXPECT_TRUE(remote_host_info_.application_id.empty()); |
| 265 EXPECT_TRUE(remote_host_info_.host_id.empty()); | 234 EXPECT_TRUE(remote_host_info_.host_id.empty()); |
| 266 EXPECT_TRUE(remote_host_info_.host_jid.empty()); | 235 EXPECT_TRUE(remote_host_info_.host_jid.empty()); |
| 267 EXPECT_TRUE(remote_host_info_.authorization_code.empty()); | 236 EXPECT_TRUE(remote_host_info_.authorization_code.empty()); |
| 268 EXPECT_TRUE(remote_host_info_.shared_secret.empty()); | 237 EXPECT_TRUE(remote_host_info_.shared_secret.empty()); |
| 269 } | 238 } |
| 270 | 239 |
| 271 TEST_F(RemoteHostInfoFetcherTest, RetrieveRemoteHostInfoEmptyResponse) { | 240 TEST_F(RemoteHostInfoFetcherTest, RetrieveRemoteHostInfoEmptyResponse) { |
| 272 SetFakeResponse( | 241 SetFakeResponse(GURL(dev_service_environment_url_), |
| 273 GURL(dev_service_environment_url_), | 242 kRemoteHostInfoEmptyResponse, net::HTTP_OK, |
| 274 kRemoteHostInfoEmptyResponse, | 243 net::URLRequestStatus::SUCCESS); |
| 275 net::HTTP_OK, | |
| 276 net::URLRequestStatus::SUCCESS); | |
| 277 | 244 |
| 278 base::RunLoop run_loop; | 245 base::RunLoop run_loop; |
| 279 RemoteHostInfoCallback remote_host_info_callback = | 246 RemoteHostInfoCallback remote_host_info_callback = |
| 280 base::Bind(&RemoteHostInfoFetcherTest::OnRemoteHostInfoRetrieved, | 247 base::Bind(&RemoteHostInfoFetcherTest::OnRemoteHostInfoRetrieved, |
| 281 base::Unretained(this), | 248 base::Unretained(this), run_loop.QuitClosure()); |
| 282 run_loop.QuitClosure()); | |
| 283 | 249 |
| 284 RemoteHostInfoFetcher remote_host_info_fetcher; | 250 RemoteHostInfoFetcher remote_host_info_fetcher; |
| 285 bool request_started = remote_host_info_fetcher.RetrieveRemoteHostInfo( | 251 bool request_started = remote_host_info_fetcher.RetrieveRemoteHostInfo( |
| 286 kTestApplicationId, | 252 kTestApplicationId, kAccessTokenValue, kDeveloperEnvironment, |
| 287 kAccessTokenValue, | |
| 288 kDeveloperEnvironment, | |
| 289 remote_host_info_callback); | 253 remote_host_info_callback); |
| 290 | 254 |
| 291 run_loop.Run(); | 255 run_loop.Run(); |
| 292 | 256 |
| 293 EXPECT_TRUE(request_started); | 257 EXPECT_TRUE(request_started); |
| 294 EXPECT_FALSE(remote_host_info_.IsReadyForConnection()); | 258 EXPECT_FALSE(remote_host_info_.IsReadyForConnection()); |
| 295 | 259 |
| 296 // If we received an empty response, then none of the connection details | 260 // If we received an empty response, then none of the connection details |
| 297 // should be populated. | 261 // should be populated. |
| 298 EXPECT_TRUE(remote_host_info_.application_id.empty()); | 262 EXPECT_TRUE(remote_host_info_.application_id.empty()); |
| 299 EXPECT_TRUE(remote_host_info_.host_id.empty()); | 263 EXPECT_TRUE(remote_host_info_.host_id.empty()); |
| 300 EXPECT_TRUE(remote_host_info_.host_jid.empty()); | 264 EXPECT_TRUE(remote_host_info_.host_jid.empty()); |
| 301 EXPECT_TRUE(remote_host_info_.authorization_code.empty()); | 265 EXPECT_TRUE(remote_host_info_.authorization_code.empty()); |
| 302 EXPECT_TRUE(remote_host_info_.shared_secret.empty()); | 266 EXPECT_TRUE(remote_host_info_.shared_secret.empty()); |
| 303 } | 267 } |
| 304 | 268 |
| 305 TEST_F(RemoteHostInfoFetcherTest, MultipleRetrieveRemoteHostInfoRequests) { | 269 TEST_F(RemoteHostInfoFetcherTest, MultipleRetrieveRemoteHostInfoRequests) { |
| 306 // First, we will fetch info from the development service environment. | 270 // First, we will fetch info from the development service environment. |
| 307 SetFakeResponse( | 271 SetFakeResponse(GURL(dev_service_environment_url_), |
| 308 GURL(dev_service_environment_url_), | 272 kRemoteHostInfoReadyResponse, net::HTTP_OK, |
| 309 kRemoteHostInfoReadyResponse, | 273 net::URLRequestStatus::SUCCESS); |
| 310 net::HTTP_OK, | |
| 311 net::URLRequestStatus::SUCCESS); | |
| 312 | 274 |
| 313 SetFakeResponse( | 275 SetFakeResponse(GURL(test_service_environment_url_), |
| 314 GURL(test_service_environment_url_), | 276 kRemoteHostInfoEmptyResponse, net::HTTP_NOT_FOUND, |
| 315 kRemoteHostInfoEmptyResponse, | 277 net::URLRequestStatus::FAILED); |
| 316 net::HTTP_NOT_FOUND, | |
| 317 net::URLRequestStatus::FAILED); | |
| 318 | 278 |
| 319 base::RunLoop dev_run_loop; | 279 base::RunLoop dev_run_loop; |
| 320 RemoteHostInfoCallback dev_remote_host_info_callback = | 280 RemoteHostInfoCallback dev_remote_host_info_callback = |
| 321 base::Bind(&RemoteHostInfoFetcherTest::OnRemoteHostInfoRetrieved, | 281 base::Bind(&RemoteHostInfoFetcherTest::OnRemoteHostInfoRetrieved, |
| 322 base::Unretained(this), | 282 base::Unretained(this), dev_run_loop.QuitClosure()); |
| 323 dev_run_loop.QuitClosure()); | |
| 324 | 283 |
| 325 RemoteHostInfoFetcher remote_host_info_fetcher; | 284 RemoteHostInfoFetcher remote_host_info_fetcher; |
| 326 bool dev_request_started = remote_host_info_fetcher.RetrieveRemoteHostInfo( | 285 bool dev_request_started = remote_host_info_fetcher.RetrieveRemoteHostInfo( |
| 327 kTestApplicationId, | 286 kTestApplicationId, kAccessTokenValue, kDeveloperEnvironment, |
| 328 kAccessTokenValue, | |
| 329 kDeveloperEnvironment, | |
| 330 dev_remote_host_info_callback); | 287 dev_remote_host_info_callback); |
| 331 | 288 |
| 332 dev_run_loop.Run(); | 289 dev_run_loop.Run(); |
| 333 | 290 |
| 334 EXPECT_TRUE(dev_request_started); | 291 EXPECT_TRUE(dev_request_started); |
| 335 EXPECT_TRUE(remote_host_info_.IsReadyForConnection()); | 292 EXPECT_TRUE(remote_host_info_.IsReadyForConnection()); |
| 336 EXPECT_EQ(remote_host_info_.application_id.compare(kTestApplicationId), 0); | 293 EXPECT_EQ(remote_host_info_.application_id.compare(kTestApplicationId), 0); |
| 337 EXPECT_TRUE(!remote_host_info_.host_id.empty()); | 294 EXPECT_TRUE(!remote_host_info_.host_id.empty()); |
| 338 EXPECT_TRUE(!remote_host_info_.host_jid.empty()); | 295 EXPECT_TRUE(!remote_host_info_.host_jid.empty()); |
| 339 EXPECT_TRUE(!remote_host_info_.authorization_code.empty()); | 296 EXPECT_TRUE(!remote_host_info_.authorization_code.empty()); |
| 340 EXPECT_TRUE(!remote_host_info_.shared_secret.empty()); | 297 EXPECT_TRUE(!remote_host_info_.shared_secret.empty()); |
| 341 | 298 |
| 342 // Next, we will fetch info from the test service environment. | 299 // Next, we will fetch info from the test service environment. |
| 343 SetFakeResponse( | 300 SetFakeResponse(GURL(test_service_environment_url_), |
| 344 GURL(test_service_environment_url_), | 301 kRemoteHostInfoReadyResponse, net::HTTP_OK, |
| 345 kRemoteHostInfoReadyResponse, | 302 net::URLRequestStatus::SUCCESS); |
| 346 net::HTTP_OK, | |
| 347 net::URLRequestStatus::SUCCESS); | |
| 348 | 303 |
| 349 SetFakeResponse( | 304 SetFakeResponse(GURL(dev_service_environment_url_), |
| 350 GURL(dev_service_environment_url_), | 305 kRemoteHostInfoEmptyResponse, net::HTTP_NOT_FOUND, |
| 351 kRemoteHostInfoEmptyResponse, | 306 net::URLRequestStatus::FAILED); |
| 352 net::HTTP_NOT_FOUND, | |
| 353 net::URLRequestStatus::FAILED); | |
| 354 | 307 |
| 355 base::RunLoop test_run_loop; | 308 base::RunLoop test_run_loop; |
| 356 RemoteHostInfoCallback test_remote_host_info_callback = | 309 RemoteHostInfoCallback test_remote_host_info_callback = |
| 357 base::Bind(&RemoteHostInfoFetcherTest::OnRemoteHostInfoRetrieved, | 310 base::Bind(&RemoteHostInfoFetcherTest::OnRemoteHostInfoRetrieved, |
| 358 base::Unretained(this), | 311 base::Unretained(this), test_run_loop.QuitClosure()); |
| 359 test_run_loop.QuitClosure()); | |
| 360 | 312 |
| 361 // Reset the state of our internal |remote_host_info_| object. | 313 // Reset the state of our internal |remote_host_info_| object. |
| 362 remote_host_info_ = RemoteHostInfo(); | 314 remote_host_info_ = RemoteHostInfo(); |
| 363 EXPECT_FALSE(remote_host_info_.IsReadyForConnection()); | 315 EXPECT_FALSE(remote_host_info_.IsReadyForConnection()); |
| 364 | 316 |
| 365 bool test_request_started = remote_host_info_fetcher.RetrieveRemoteHostInfo( | 317 bool test_request_started = remote_host_info_fetcher.RetrieveRemoteHostInfo( |
| 366 kTestApplicationId, | 318 kTestApplicationId, kAccessTokenValue, kTestingEnvironment, |
| 367 kAccessTokenValue, | |
| 368 kTestingEnvironment, | |
| 369 test_remote_host_info_callback); | 319 test_remote_host_info_callback); |
| 370 | 320 |
| 371 test_run_loop.Run(); | 321 test_run_loop.Run(); |
| 372 | 322 |
| 373 EXPECT_TRUE(test_request_started); | 323 EXPECT_TRUE(test_request_started); |
| 374 EXPECT_TRUE(remote_host_info_.IsReadyForConnection()); | 324 EXPECT_TRUE(remote_host_info_.IsReadyForConnection()); |
| 375 EXPECT_EQ(remote_host_info_.application_id.compare(kTestApplicationId), 0); | 325 EXPECT_EQ(remote_host_info_.application_id.compare(kTestApplicationId), 0); |
| 376 EXPECT_TRUE(!remote_host_info_.host_id.empty()); | 326 EXPECT_TRUE(!remote_host_info_.host_id.empty()); |
| 377 EXPECT_TRUE(!remote_host_info_.host_jid.empty()); | 327 EXPECT_TRUE(!remote_host_info_.host_jid.empty()); |
| 378 EXPECT_TRUE(!remote_host_info_.authorization_code.empty()); | 328 EXPECT_TRUE(!remote_host_info_.authorization_code.empty()); |
| 379 EXPECT_TRUE(!remote_host_info_.shared_secret.empty()); | 329 EXPECT_TRUE(!remote_host_info_.shared_secret.empty()); |
| 380 } | 330 } |
| 381 | 331 |
| 382 } // namespace test | 332 } // namespace test |
| 383 } // namespace remoting | 333 } // namespace remoting |
| OLD | NEW |