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

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

Issue 1357973002: Removing Test and Staging environments from App Remoting Test Driver tool. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing unittest Created 5 years, 2 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/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 "net/url_request/test_url_fetcher_factory.h" 10 #include "net/url_request/test_url_fetcher_factory.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 12
13 namespace { 13 namespace {
14 const char kTestApplicationId[] = "klasdfjlkasdfjklasjfdkljsadf"; 14 const char kTestApplicationId[] = "klasdfjlkasdfjklasjfdkljsadf";
15 const char kTestApplicationId2[] = "klasdfjlkasdfjklasjfdkljsadf2";
15 const char kAccessTokenValue[] = "test_access_token_value"; 16 const char kAccessTokenValue[] = "test_access_token_value";
16 const char kRemoteHostInfoReadyResponse[] = 17 const char kRemoteHostInfoReadyResponse[] =
17 "{" 18 "{"
18 " \"status\": \"done\"," 19 " \"status\": \"done\","
19 " \"host\": {" 20 " \"host\": {"
20 " \"kind\": \"test_kind\"," 21 " \"kind\": \"test_kind\","
21 " \"applicationId\": \"klasdfjlkasdfjklasjfdkljsadf\"," 22 " \"applicationId\": \"klasdfjlkasdfjklasjfdkljsadf\","
22 " \"hostId\": \"test_host_id\"" 23 " \"hostId\": \"test_host_id\""
23 " }," 24 " },"
24 " \"hostJid\": \"test_host_jid\"," 25 " \"hostJid\": \"test_host_jid\","
25 " \"authorizationCode\": \"test_authorization_code\"," 26 " \"authorizationCode\": \"test_authorization_code\","
26 " \"sharedSecret\": \"test_shared_secret\"" 27 " \"sharedSecret\": \"test_shared_secret\""
27 "}"; 28 "}";
29 const char kRemoteHostInfoReadyResponse2[] =
30 "{"
31 " \"status\": \"done\","
32 " \"host\": {"
33 " \"kind\": \"test_kind\","
34 " \"applicationId\": \"klasdfjlkasdfjklasjfdkljsadf2\","
35 " \"hostId\": \"test_host_id\""
36 " },"
37 " \"hostJid\": \"test_host_jid\","
38 " \"authorizationCode\": \"test_authorization_code\","
39 " \"sharedSecret\": \"test_shared_secret\""
40 "}";
28 const char kRemoteHostInfoPendingResponse[] = 41 const char kRemoteHostInfoPendingResponse[] =
29 "{" 42 "{"
30 " \"status\": \"pending\"" 43 " \"status\": \"pending\""
31 "}"; 44 "}";
32 const char kRemoteHostInfoEmptyResponse[] = "{}"; 45 const char kRemoteHostInfoEmptyResponse[] = "{}";
33 } // namespace 46 } // namespace
34 47
35 namespace remoting { 48 namespace remoting {
36 namespace test { 49 namespace test {
37 50
(...skipping 19 matching lines...) Expand all
57 // Sets the HTTP status and data returned for a specified URL. 70 // Sets the HTTP status and data returned for a specified URL.
58 void SetFakeResponse(const GURL& url, 71 void SetFakeResponse(const GURL& url,
59 const std::string& data, 72 const std::string& data,
60 net::HttpStatusCode code, 73 net::HttpStatusCode code,
61 net::URLRequestStatus::Status status); 74 net::URLRequestStatus::Status status);
62 75
63 // Used for result verification. 76 // Used for result verification.
64 RemoteHostInfo remote_host_info_; 77 RemoteHostInfo remote_host_info_;
65 78
66 std::string dev_service_environment_url_; 79 std::string dev_service_environment_url_;
67 std::string test_service_environment_url_; 80 std::string dev_service_environment_url_2_;
68 std::string staging_service_environment_url_;
69 81
70 private: 82 private:
71 net::FakeURLFetcherFactory url_fetcher_factory_; 83 net::FakeURLFetcherFactory url_fetcher_factory_;
72 scoped_ptr<base::MessageLoopForIO> message_loop_; 84 scoped_ptr<base::MessageLoopForIO> message_loop_;
73 85
74 DISALLOW_COPY_AND_ASSIGN(RemoteHostInfoFetcherTest); 86 DISALLOW_COPY_AND_ASSIGN(RemoteHostInfoFetcherTest);
75 }; 87 };
76 88
77 void RemoteHostInfoFetcherTest::OnRemoteHostInfoRetrieved( 89 void RemoteHostInfoFetcherTest::OnRemoteHostInfoRetrieved(
78 base::Closure done_closure, 90 base::Closure done_closure,
79 const RemoteHostInfo& retrieved_remote_host_info) { 91 const RemoteHostInfo& retrieved_remote_host_info) {
80 remote_host_info_ = retrieved_remote_host_info; 92 remote_host_info_ = retrieved_remote_host_info;
81 93
82 done_closure.Run(); 94 done_closure.Run();
83 } 95 }
84 96
85 void RemoteHostInfoFetcherTest::SetUp() { 97 void RemoteHostInfoFetcherTest::SetUp() {
86 DCHECK(!message_loop_); 98 DCHECK(!message_loop_);
87 message_loop_.reset(new base::MessageLoopForIO); 99 message_loop_.reset(new base::MessageLoopForIO);
88 100
89 dev_service_environment_url_ = 101 dev_service_environment_url_ =
90 GetRunApplicationUrl(kTestApplicationId, kDeveloperEnvironment); 102 GetRunApplicationUrl(kTestApplicationId, kDeveloperEnvironment);
91 SetFakeResponse(GURL(dev_service_environment_url_), 103 SetFakeResponse(GURL(dev_service_environment_url_),
92 kRemoteHostInfoEmptyResponse, net::HTTP_NOT_FOUND, 104 kRemoteHostInfoEmptyResponse, net::HTTP_NOT_FOUND,
93 net::URLRequestStatus::FAILED); 105 net::URLRequestStatus::FAILED);
94 106
95 test_service_environment_url_ = 107 dev_service_environment_url_2_ =
96 GetRunApplicationUrl(kTestApplicationId, kTestingEnvironment); 108 GetRunApplicationUrl(kTestApplicationId2, kDeveloperEnvironment);
97 SetFakeResponse(GURL(test_service_environment_url_), 109 SetFakeResponse(GURL(dev_service_environment_url_2_),
98 kRemoteHostInfoEmptyResponse, net::HTTP_NOT_FOUND,
99 net::URLRequestStatus::FAILED);
100
101 staging_service_environment_url_ =
102 GetRunApplicationUrl(kTestApplicationId, kStagingEnvironment);
103 SetFakeResponse(GURL(staging_service_environment_url_),
104 kRemoteHostInfoEmptyResponse, net::HTTP_NOT_FOUND, 110 kRemoteHostInfoEmptyResponse, net::HTTP_NOT_FOUND,
105 net::URLRequestStatus::FAILED); 111 net::URLRequestStatus::FAILED);
106 } 112 }
107 113
108 void RemoteHostInfoFetcherTest::SetFakeResponse( 114 void RemoteHostInfoFetcherTest::SetFakeResponse(
109 const GURL& url, 115 const GURL& url,
110 const std::string& data, 116 const std::string& data,
111 net::HttpStatusCode code, 117 net::HttpStatusCode code,
112 net::URLRequestStatus::Status status) { 118 net::URLRequestStatus::Status status) {
113 url_fetcher_factory_.SetFakeResponse(url, data, code, status); 119 url_fetcher_factory_.SetFakeResponse(url, data, code, status);
(...skipping 18 matching lines...) Expand all
132 138
133 EXPECT_TRUE(request_started); 139 EXPECT_TRUE(request_started);
134 EXPECT_TRUE(remote_host_info_.IsReadyForConnection()); 140 EXPECT_TRUE(remote_host_info_.IsReadyForConnection());
135 EXPECT_EQ(remote_host_info_.application_id.compare(kTestApplicationId), 0); 141 EXPECT_EQ(remote_host_info_.application_id.compare(kTestApplicationId), 0);
136 EXPECT_TRUE(!remote_host_info_.host_id.empty()); 142 EXPECT_TRUE(!remote_host_info_.host_id.empty());
137 EXPECT_TRUE(!remote_host_info_.host_jid.empty()); 143 EXPECT_TRUE(!remote_host_info_.host_jid.empty());
138 EXPECT_TRUE(!remote_host_info_.authorization_code.empty()); 144 EXPECT_TRUE(!remote_host_info_.authorization_code.empty());
139 EXPECT_TRUE(!remote_host_info_.shared_secret.empty()); 145 EXPECT_TRUE(!remote_host_info_.shared_secret.empty());
140 } 146 }
141 147
142 TEST_F(RemoteHostInfoFetcherTest, RetrieveRemoteHostInfoFromTest) {
143 SetFakeResponse(GURL(test_service_environment_url_),
144 kRemoteHostInfoReadyResponse, net::HTTP_OK,
145 net::URLRequestStatus::SUCCESS);
146
147 base::RunLoop run_loop;
148 RemoteHostInfoCallback remote_host_info_callback =
149 base::Bind(&RemoteHostInfoFetcherTest::OnRemoteHostInfoRetrieved,
150 base::Unretained(this), run_loop.QuitClosure());
151
152 RemoteHostInfoFetcher remote_host_info_fetcher;
153 bool request_started = remote_host_info_fetcher.RetrieveRemoteHostInfo(
154 kTestApplicationId, kAccessTokenValue, kTestingEnvironment,
155 remote_host_info_callback);
156
157 run_loop.Run();
158
159 EXPECT_TRUE(request_started);
160 EXPECT_TRUE(remote_host_info_.IsReadyForConnection());
161 EXPECT_EQ(remote_host_info_.application_id.compare(kTestApplicationId), 0);
162 EXPECT_TRUE(!remote_host_info_.host_id.empty());
163 EXPECT_TRUE(!remote_host_info_.host_jid.empty());
164 EXPECT_TRUE(!remote_host_info_.authorization_code.empty());
165 EXPECT_TRUE(!remote_host_info_.shared_secret.empty());
166 }
167
168 TEST_F(RemoteHostInfoFetcherTest, RetrieveRemoteHostInfoFromStaging) {
169 SetFakeResponse(GURL(staging_service_environment_url_),
170 kRemoteHostInfoReadyResponse, net::HTTP_OK,
171 net::URLRequestStatus::SUCCESS);
172
173 base::RunLoop run_loop;
174 RemoteHostInfoCallback remote_host_info_callback =
175 base::Bind(&RemoteHostInfoFetcherTest::OnRemoteHostInfoRetrieved,
176 base::Unretained(this), run_loop.QuitClosure());
177
178 RemoteHostInfoFetcher remote_host_info_fetcher;
179 bool request_started = remote_host_info_fetcher.RetrieveRemoteHostInfo(
180 kTestApplicationId, kAccessTokenValue, kStagingEnvironment,
181 remote_host_info_callback);
182
183 run_loop.Run();
184
185 EXPECT_TRUE(request_started);
186 EXPECT_TRUE(remote_host_info_.IsReadyForConnection());
187 EXPECT_EQ(remote_host_info_.application_id.compare(kTestApplicationId), 0);
188 EXPECT_TRUE(!remote_host_info_.host_id.empty());
189 EXPECT_TRUE(!remote_host_info_.host_jid.empty());
190 EXPECT_TRUE(!remote_host_info_.authorization_code.empty());
191 EXPECT_TRUE(!remote_host_info_.shared_secret.empty());
192 }
193
194 TEST_F(RemoteHostInfoFetcherTest, RetrieveRemoteHostInfoInvalidEnvironment) { 148 TEST_F(RemoteHostInfoFetcherTest, RetrieveRemoteHostInfoInvalidEnvironment) {
195 base::RunLoop run_loop; 149 base::RunLoop run_loop;
196 RemoteHostInfoCallback remote_host_info_callback = 150 RemoteHostInfoCallback remote_host_info_callback =
197 base::Bind(&RemoteHostInfoFetcherTest::OnRemoteHostInfoRetrieved, 151 base::Bind(&RemoteHostInfoFetcherTest::OnRemoteHostInfoRetrieved,
198 base::Unretained(this), run_loop.QuitClosure()); 152 base::Unretained(this), run_loop.QuitClosure());
199 153
200 RemoteHostInfoFetcher remote_host_info_fetcher; 154 RemoteHostInfoFetcher remote_host_info_fetcher;
201 bool request_started = remote_host_info_fetcher.RetrieveRemoteHostInfo( 155 bool request_started = remote_host_info_fetcher.RetrieveRemoteHostInfo(
202 kTestApplicationId, kAccessTokenValue, kUnknownEnvironment, 156 kTestApplicationId, kAccessTokenValue, kUnknownEnvironment,
203 remote_host_info_callback); 157 remote_host_info_callback);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 dev_run_loop.Run(); 261 dev_run_loop.Run();
308 262
309 EXPECT_TRUE(dev_request_started); 263 EXPECT_TRUE(dev_request_started);
310 EXPECT_TRUE(remote_host_info_.IsReadyForConnection()); 264 EXPECT_TRUE(remote_host_info_.IsReadyForConnection());
311 EXPECT_EQ(remote_host_info_.application_id.compare(kTestApplicationId), 0); 265 EXPECT_EQ(remote_host_info_.application_id.compare(kTestApplicationId), 0);
312 EXPECT_TRUE(!remote_host_info_.host_id.empty()); 266 EXPECT_TRUE(!remote_host_info_.host_id.empty());
313 EXPECT_TRUE(!remote_host_info_.host_jid.empty()); 267 EXPECT_TRUE(!remote_host_info_.host_jid.empty());
314 EXPECT_TRUE(!remote_host_info_.authorization_code.empty()); 268 EXPECT_TRUE(!remote_host_info_.authorization_code.empty());
315 EXPECT_TRUE(!remote_host_info_.shared_secret.empty()); 269 EXPECT_TRUE(!remote_host_info_.shared_secret.empty());
316 270
317 // Next, we will fetch info from the test service environment. 271 // Next, we will fetch a different application info block from the dev
318 SetFakeResponse(GURL(test_service_environment_url_), 272 // service environment.
319 kRemoteHostInfoReadyResponse, net::HTTP_OK, 273 SetFakeResponse(GURL(dev_service_environment_url_2_),
274 kRemoteHostInfoReadyResponse2, net::HTTP_OK,
320 net::URLRequestStatus::SUCCESS); 275 net::URLRequestStatus::SUCCESS);
321 276
322 base::RunLoop test_run_loop; 277 base::RunLoop test_run_loop;
323 RemoteHostInfoCallback test_remote_host_info_callback = 278 RemoteHostInfoCallback test_remote_host_info_callback =
324 base::Bind(&RemoteHostInfoFetcherTest::OnRemoteHostInfoRetrieved, 279 base::Bind(&RemoteHostInfoFetcherTest::OnRemoteHostInfoRetrieved,
325 base::Unretained(this), test_run_loop.QuitClosure()); 280 base::Unretained(this), test_run_loop.QuitClosure());
326 281
327 // Reset the state of our internal |remote_host_info_| object. 282 // Reset the state of our internal |remote_host_info_| object.
328 remote_host_info_ = RemoteHostInfo(); 283 remote_host_info_ = RemoteHostInfo();
329 EXPECT_FALSE(remote_host_info_.IsReadyForConnection()); 284 EXPECT_FALSE(remote_host_info_.IsReadyForConnection());
330 285
331 bool test_request_started = remote_host_info_fetcher.RetrieveRemoteHostInfo( 286 bool test_request_started = remote_host_info_fetcher.RetrieveRemoteHostInfo(
332 kTestApplicationId, kAccessTokenValue, kTestingEnvironment, 287 kTestApplicationId2, kAccessTokenValue, kDeveloperEnvironment,
333 test_remote_host_info_callback); 288 test_remote_host_info_callback);
334 289
335 test_run_loop.Run(); 290 test_run_loop.Run();
336 291
337 EXPECT_TRUE(test_request_started); 292 EXPECT_TRUE(test_request_started);
338 EXPECT_TRUE(remote_host_info_.IsReadyForConnection()); 293 EXPECT_TRUE(remote_host_info_.IsReadyForConnection());
339 EXPECT_EQ(remote_host_info_.application_id.compare(kTestApplicationId), 0); 294 EXPECT_EQ(remote_host_info_.application_id.compare(kTestApplicationId2), 0);
340 EXPECT_TRUE(!remote_host_info_.host_id.empty()); 295 EXPECT_TRUE(!remote_host_info_.host_id.empty());
341 EXPECT_TRUE(!remote_host_info_.host_jid.empty()); 296 EXPECT_TRUE(!remote_host_info_.host_jid.empty());
342 EXPECT_TRUE(!remote_host_info_.authorization_code.empty()); 297 EXPECT_TRUE(!remote_host_info_.authorization_code.empty());
343 EXPECT_TRUE(!remote_host_info_.shared_secret.empty()); 298 EXPECT_TRUE(!remote_host_info_.shared_secret.empty());
344 } 299 }
345 300
346 } // namespace test 301 } // namespace test
347 } // namespace remoting 302 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/test/app_remoting_test_driver.cc ('k') | testing/chromoting/app_remoting_integration_tests.isolate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698