Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // A complete set of unit tests for GaiaAuthFetcher. | 5 // A complete set of unit tests for GaiaAuthFetcher. |
| 6 // Originally ported from GoogleAuthenticator tests. | 6 // Originally ported from GoogleAuthenticator tests. |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| 11 #include "base/memory/ref_counted.h" | |
| 11 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 12 #include "base/values.h" | 13 #include "base/values.h" |
| 13 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 14 #include "google_apis/gaia/gaia_auth_consumer.h" | 15 #include "google_apis/gaia/gaia_auth_consumer.h" |
| 15 #include "google_apis/gaia/gaia_auth_fetcher.h" | 16 #include "google_apis/gaia/gaia_auth_fetcher.h" |
| 16 #include "google_apis/gaia/gaia_urls.h" | 17 #include "google_apis/gaia/gaia_urls.h" |
| 17 #include "google_apis/gaia/google_service_auth_error.h" | 18 #include "google_apis/gaia/google_service_auth_error.h" |
| 18 #include "google_apis/gaia/mock_url_fetcher_factory.h" | 19 #include "google_apis/gaia/mock_url_fetcher_factory.h" |
| 19 #include "google_apis/google_api_keys.h" | 20 #include "google_apis/google_api_keys.h" |
| 20 #include "net/base/load_flags.h" | 21 #include "net/base/load_flags.h" |
| 21 #include "net/base/net_errors.h" | 22 #include "net/base/net_errors.h" |
| 23 #include "net/http/http_response_headers.h" | |
| 22 #include "net/http/http_status_code.h" | 24 #include "net/http/http_status_code.h" |
| 23 #include "net/url_request/test_url_fetcher_factory.h" | 25 #include "net/url_request/test_url_fetcher_factory.h" |
| 24 #include "net/url_request/url_fetcher_delegate.h" | 26 #include "net/url_request/url_fetcher_delegate.h" |
| 25 #include "net/url_request/url_request_status.h" | 27 #include "net/url_request/url_request_status.h" |
| 26 #include "net/url_request/url_request_test_util.h" | 28 #include "net/url_request/url_request_test_util.h" |
| 27 #include "testing/gmock/include/gmock/gmock.h" | 29 #include "testing/gmock/include/gmock/gmock.h" |
| 28 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 29 #include "url/gurl.h" | 31 #include "url/gurl.h" |
| 30 | 32 |
| 31 using ::testing::Invoke; | 33 using ::testing::Invoke; |
| 32 using ::testing::_; | 34 using ::testing::_; |
| 33 | 35 |
| 36 namespace { | |
| 37 | |
| 38 std::string CookieStringToHeader(const char* cookie_string) { | |
| 39 return std::string("Set-Cookie: ") + cookie_string; | |
| 40 } | |
|
Roger Tawa OOO till Jul 10th
2016/06/14 15:57:40
I think this should be part of the HttpResponseHea
martijnc
2016/06/14 22:18:08
Done.
| |
| 41 | |
| 34 const char kGetAuthCodeValidCookie[] = | 42 const char kGetAuthCodeValidCookie[] = |
| 35 "oauth_code=test-code; Path=/test; Secure; HttpOnly"; | 43 "oauth_code=test-code; Path=/test; Secure; HttpOnly"; |
| 36 const char kGetAuthCodeCookieNoSecure[] = | 44 const char kGetAuthCodeCookieNoSecure[] = |
| 37 "oauth_code=test-code; Path=/test; HttpOnly"; | 45 "oauth_code=test-code; Path=/test; HttpOnly"; |
| 38 const char kGetAuthCodeCookieNoHttpOnly[] = | 46 const char kGetAuthCodeCookieNoHttpOnly[] = |
| 39 "oauth_code=test-code; Path=/test; Secure"; | 47 "oauth_code=test-code; Path=/test; Secure"; |
| 40 const char kGetAuthCodeCookieNoOAuthCode[] = | 48 const char kGetAuthCodeCookieNoOAuthCode[] = |
| 41 "Path=/test; Secure; HttpOnly"; | 49 "Path=/test; Secure; HttpOnly"; |
| 42 const char kGetTokenPairValidResponse[] = | 50 const char kGetTokenPairValidResponse[] = |
| 43 "{" | 51 "{" |
| 44 " \"refresh_token\": \"rt1\"," | 52 " \"refresh_token\": \"rt1\"," |
| 45 " \"access_token\": \"at1\"," | 53 " \"access_token\": \"at1\"," |
| 46 " \"expires_in\": 3600," | 54 " \"expires_in\": 3600," |
| 47 " \"token_type\": \"Bearer\"" | 55 " \"token_type\": \"Bearer\"" |
| 48 "}"; | 56 "}"; |
| 49 | 57 |
| 58 } // namespace | |
| 59 | |
| 50 MockFetcher::MockFetcher(bool success, | 60 MockFetcher::MockFetcher(bool success, |
| 51 const GURL& url, | 61 const GURL& url, |
| 52 const std::string& results, | 62 const std::string& results, |
| 53 net::URLFetcher::RequestType request_type, | 63 net::URLFetcher::RequestType request_type, |
| 54 net::URLFetcherDelegate* d) | 64 net::URLFetcherDelegate* d) |
| 55 : TestURLFetcher(0, url, d) { | 65 : TestURLFetcher(0, url, d) { |
| 56 set_url(url); | 66 set_url(url); |
| 57 net::Error error; | 67 net::Error error; |
| 58 | 68 |
| 59 if (success) { | 69 if (success) { |
| 60 error = net::OK; | 70 error = net::OK; |
| 61 set_response_code(net::HTTP_OK); | 71 set_response_code(net::HTTP_OK); |
| 62 } else { | 72 } else { |
| 63 error = net::ERR_FAILED; | 73 error = net::ERR_FAILED; |
| 64 } | 74 } |
| 65 | 75 |
| 66 set_status(net::URLRequestStatus::FromError(error)); | 76 set_status(net::URLRequestStatus::FromError(error)); |
| 67 SetResponseString(results); | 77 SetResponseString(results); |
| 68 } | 78 } |
| 69 | 79 |
| 70 MockFetcher::MockFetcher(const GURL& url, | 80 MockFetcher::MockFetcher(const GURL& url, |
| 71 const net::URLRequestStatus& status, | 81 const net::URLRequestStatus& status, |
| 72 int response_code, | 82 int response_code, |
| 73 const net::ResponseCookies& cookies, | |
| 74 const std::string& results, | 83 const std::string& results, |
| 75 net::URLFetcher::RequestType request_type, | 84 net::URLFetcher::RequestType request_type, |
| 76 net::URLFetcherDelegate* d) | 85 net::URLFetcherDelegate* d) |
| 77 : TestURLFetcher(0, url, d) { | 86 : TestURLFetcher(0, url, d) { |
| 78 set_url(url); | 87 set_url(url); |
| 79 set_status(status); | 88 set_status(status); |
| 80 set_response_code(response_code); | 89 set_response_code(response_code); |
| 81 set_cookies(cookies); | |
| 82 SetResponseString(results); | 90 SetResponseString(results); |
| 83 } | 91 } |
| 84 | 92 |
| 85 MockFetcher::~MockFetcher() {} | 93 MockFetcher::~MockFetcher() {} |
| 86 | 94 |
| 87 void MockFetcher::Start() { | 95 void MockFetcher::Start() { |
| 88 delegate()->OnURLFetchComplete(this); | 96 delegate()->OnURLFetchComplete(this); |
| 89 } | 97 } |
| 90 | 98 |
| 91 class GaiaAuthFetcherTest : public testing::Test { | 99 class GaiaAuthFetcherTest : public testing::Test { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 &out_error, | 142 &out_error, |
| 135 &out_error_url, | 143 &out_error_url, |
| 136 &out_captcha_url, | 144 &out_captcha_url, |
| 137 &out_captcha_token); | 145 &out_captcha_token); |
| 138 EXPECT_EQ(error, out_error); | 146 EXPECT_EQ(error, out_error); |
| 139 EXPECT_EQ(error_url, out_error_url); | 147 EXPECT_EQ(error_url, out_error_url); |
| 140 EXPECT_EQ(captcha_url, out_captcha_url); | 148 EXPECT_EQ(captcha_url, out_captcha_url); |
| 141 EXPECT_EQ(captcha_token, out_captcha_token); | 149 EXPECT_EQ(captcha_token, out_captcha_token); |
| 142 } | 150 } |
| 143 | 151 |
| 144 net::ResponseCookies cookies_; | |
| 145 GURL issue_auth_token_source_; | 152 GURL issue_auth_token_source_; |
| 146 GURL client_login_to_oauth2_source_; | 153 GURL client_login_to_oauth2_source_; |
| 147 GURL oauth2_token_source_; | 154 GURL oauth2_token_source_; |
| 148 GURL token_auth_source_; | 155 GURL token_auth_source_; |
| 149 GURL merge_session_source_; | 156 GURL merge_session_source_; |
| 150 GURL uberauth_token_source_; | 157 GURL uberauth_token_source_; |
| 151 GURL oauth_login_gurl_; | 158 GURL oauth_login_gurl_; |
| 152 | 159 |
| 153 protected: | 160 protected: |
| 154 net::TestURLRequestContextGetter* GetRequestContext() { | 161 net::TestURLRequestContextGetter* GetRequestContext() { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 | 236 |
| 230 GoogleServiceAuthError expected_error = | 237 GoogleServiceAuthError expected_error = |
| 231 GoogleServiceAuthError::FromConnectionError(error_no); | 238 GoogleServiceAuthError::FromConnectionError(error_no); |
| 232 | 239 |
| 233 MockGaiaConsumer consumer; | 240 MockGaiaConsumer consumer; |
| 234 EXPECT_CALL(consumer, OnIssueAuthTokenFailure(_, expected_error)) | 241 EXPECT_CALL(consumer, OnIssueAuthTokenFailure(_, expected_error)) |
| 235 .Times(1); | 242 .Times(1); |
| 236 | 243 |
| 237 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); | 244 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); |
| 238 | 245 |
| 239 MockFetcher mock_fetcher( | 246 MockFetcher mock_fetcher(issue_auth_token_source_, status, 0, std::string(), |
| 240 issue_auth_token_source_, status, 0, cookies_, std::string(), | 247 net::URLFetcher::GET, &auth); |
| 241 net::URLFetcher::GET, &auth); | |
| 242 auth.OnURLFetchComplete(&mock_fetcher); | 248 auth.OnURLFetchComplete(&mock_fetcher); |
| 243 } | 249 } |
| 244 | 250 |
| 245 | 251 |
| 246 TEST_F(GaiaAuthFetcherTest, ParseRequest) { | 252 TEST_F(GaiaAuthFetcherTest, ParseRequest) { |
| 247 RunParsingTest("SID=sid\nLSID=lsid\nAuth=auth\n", "sid", "lsid", "auth"); | 253 RunParsingTest("SID=sid\nLSID=lsid\nAuth=auth\n", "sid", "lsid", "auth"); |
| 248 RunParsingTest("LSID=lsid\nSID=sid\nAuth=auth\n", "sid", "lsid", "auth"); | 254 RunParsingTest("LSID=lsid\nSID=sid\nAuth=auth\n", "sid", "lsid", "auth"); |
| 249 RunParsingTest("SID=sid\nLSID=lsid\nAuth=auth", "sid", "lsid", "auth"); | 255 RunParsingTest("SID=sid\nLSID=lsid\nAuth=auth", "sid", "lsid", "auth"); |
| 250 RunParsingTest("SID=sid\nAuth=auth\n", "sid", std::string(), "auth"); | 256 RunParsingTest("SID=sid\nAuth=auth\n", "sid", std::string(), "auth"); |
| 251 RunParsingTest("LSID=lsid\nAuth=auth\n", std::string(), "lsid", "auth"); | 257 RunParsingTest("LSID=lsid\nAuth=auth\n", std::string(), "lsid", "auth"); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 268 "CaptchaUrl=C\n", "E", "U", "C", "T"); | 274 "CaptchaUrl=C\n", "E", "U", "C", "T"); |
| 269 } | 275 } |
| 270 | 276 |
| 271 TEST_F(GaiaAuthFetcherTest, WorkingIssueAuthToken) { | 277 TEST_F(GaiaAuthFetcherTest, WorkingIssueAuthToken) { |
| 272 MockGaiaConsumer consumer; | 278 MockGaiaConsumer consumer; |
| 273 EXPECT_CALL(consumer, OnIssueAuthTokenSuccess(_, "token")) | 279 EXPECT_CALL(consumer, OnIssueAuthTokenSuccess(_, "token")) |
| 274 .Times(1); | 280 .Times(1); |
| 275 | 281 |
| 276 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); | 282 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); |
| 277 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); | 283 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); |
| 278 MockFetcher mock_fetcher( | 284 MockFetcher mock_fetcher(issue_auth_token_source_, status, net::HTTP_OK, |
| 279 issue_auth_token_source_, status, net::HTTP_OK, cookies_, "token", | 285 "token", net::URLFetcher::GET, &auth); |
| 280 net::URLFetcher::GET, &auth); | |
| 281 auth.OnURLFetchComplete(&mock_fetcher); | 286 auth.OnURLFetchComplete(&mock_fetcher); |
| 282 } | 287 } |
| 283 | 288 |
| 284 TEST_F(GaiaAuthFetcherTest, CheckTwoFactorResponse) { | 289 TEST_F(GaiaAuthFetcherTest, CheckTwoFactorResponse) { |
| 285 std::string response = | 290 std::string response = |
| 286 base::StringPrintf("Error=BadAuthentication\n%s\n", | 291 base::StringPrintf("Error=BadAuthentication\n%s\n", |
| 287 GaiaAuthFetcher::kSecondFactor); | 292 GaiaAuthFetcher::kSecondFactor); |
| 288 EXPECT_TRUE(GaiaAuthFetcher::IsSecondFactorSuccess(response)); | 293 EXPECT_TRUE(GaiaAuthFetcher::IsSecondFactorSuccess(response)); |
| 289 } | 294 } |
| 290 | 295 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 357 EXPECT_CALL(consumer, OnIssueAuthTokenSuccess("service", "token")) | 362 EXPECT_CALL(consumer, OnIssueAuthTokenSuccess("service", "token")) |
| 358 .Times(1); | 363 .Times(1); |
| 359 | 364 |
| 360 net::TestURLFetcherFactory factory; | 365 net::TestURLFetcherFactory factory; |
| 361 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); | 366 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); |
| 362 auth.StartIssueAuthToken("sid", "lsid", "service"); | 367 auth.StartIssueAuthToken("sid", "lsid", "service"); |
| 363 | 368 |
| 364 EXPECT_TRUE(auth.HasPendingFetch()); | 369 EXPECT_TRUE(auth.HasPendingFetch()); |
| 365 MockFetcher mock_fetcher( | 370 MockFetcher mock_fetcher( |
| 366 issue_auth_token_source_, | 371 issue_auth_token_source_, |
| 367 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), | 372 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), net::HTTP_OK, |
| 368 net::HTTP_OK, cookies_, "token", | 373 "token", net::URLFetcher::GET, &auth); |
| 369 net::URLFetcher::GET, &auth); | |
| 370 auth.OnURLFetchComplete(&mock_fetcher); | 374 auth.OnURLFetchComplete(&mock_fetcher); |
| 371 EXPECT_FALSE(auth.HasPendingFetch()); | 375 EXPECT_FALSE(auth.HasPendingFetch()); |
| 372 } | 376 } |
| 373 | 377 |
| 374 TEST_F(GaiaAuthFetcherTest, FullTokenFailure) { | 378 TEST_F(GaiaAuthFetcherTest, FullTokenFailure) { |
| 375 MockGaiaConsumer consumer; | 379 MockGaiaConsumer consumer; |
| 376 EXPECT_CALL(consumer, OnIssueAuthTokenFailure("service", _)) | 380 EXPECT_CALL(consumer, OnIssueAuthTokenFailure("service", _)) |
| 377 .Times(1); | 381 .Times(1); |
| 378 | 382 |
| 379 net::TestURLFetcherFactory factory; | 383 net::TestURLFetcherFactory factory; |
| 380 | 384 |
| 381 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); | 385 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); |
| 382 auth.StartIssueAuthToken("sid", "lsid", "service"); | 386 auth.StartIssueAuthToken("sid", "lsid", "service"); |
| 383 | 387 |
| 384 EXPECT_TRUE(auth.HasPendingFetch()); | 388 EXPECT_TRUE(auth.HasPendingFetch()); |
| 385 MockFetcher mock_fetcher( | 389 MockFetcher mock_fetcher( |
| 386 issue_auth_token_source_, | 390 issue_auth_token_source_, |
| 387 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), | 391 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), |
| 388 net::HTTP_FORBIDDEN, | 392 net::HTTP_FORBIDDEN, |
| 389 cookies_, | |
| 390 std::string(), | 393 std::string(), |
| 391 net::URLFetcher::GET, | 394 net::URLFetcher::GET, |
| 392 &auth); | 395 &auth); |
| 393 auth.OnURLFetchComplete(&mock_fetcher); | 396 auth.OnURLFetchComplete(&mock_fetcher); |
| 394 EXPECT_FALSE(auth.HasPendingFetch()); | 397 EXPECT_FALSE(auth.HasPendingFetch()); |
| 395 } | 398 } |
| 396 | 399 |
| 397 TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenSuccess) { | 400 TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenSuccess) { |
| 398 MockGaiaConsumer consumer; | 401 MockGaiaConsumer consumer; |
| 399 EXPECT_CALL(consumer, OnClientOAuthCode("test-code")).Times(0); | 402 EXPECT_CALL(consumer, OnClientOAuthCode("test-code")).Times(0); |
| 400 EXPECT_CALL(consumer, OnClientOAuthSuccess( | 403 EXPECT_CALL(consumer, OnClientOAuthSuccess( |
| 401 GaiaAuthConsumer::ClientOAuthResult("rt1", "at1", 3600))).Times(1); | 404 GaiaAuthConsumer::ClientOAuthResult("rt1", "at1", 3600))).Times(1); |
| 402 | 405 |
| 403 net::TestURLFetcherFactory factory; | 406 net::TestURLFetcherFactory factory; |
| 404 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); | 407 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); |
| 405 auth.StartCookieForOAuthLoginTokenExchange("0"); | 408 auth.StartCookieForOAuthLoginTokenExchange("0"); |
| 406 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | 409 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); |
| 407 EXPECT_TRUE(NULL != fetcher); | 410 EXPECT_TRUE(NULL != fetcher); |
| 408 EXPECT_EQ(net::LOAD_NORMAL, fetcher->GetLoadFlags()); | 411 EXPECT_EQ(net::LOAD_NORMAL, fetcher->GetLoadFlags()); |
| 409 EXPECT_EQ(std::string::npos, | 412 EXPECT_EQ(std::string::npos, |
| 410 fetcher->GetOriginalURL().query().find("device_type=chrome")); | 413 fetcher->GetOriginalURL().query().find("device_type=chrome")); |
| 411 | 414 |
| 412 net::ResponseCookies cookies; | |
| 413 cookies.push_back(kGetAuthCodeValidCookie); | |
| 414 EXPECT_TRUE(auth.HasPendingFetch()); | 415 EXPECT_TRUE(auth.HasPendingFetch()); |
| 416 scoped_refptr<net::HttpResponseHeaders> reponse_headers = | |
| 417 new net::HttpResponseHeaders(""); | |
| 418 reponse_headers->AddHeader(CookieStringToHeader(kGetAuthCodeValidCookie)); | |
| 415 MockFetcher mock_fetcher1( | 419 MockFetcher mock_fetcher1( |
| 416 client_login_to_oauth2_source_, | 420 client_login_to_oauth2_source_, |
| 417 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), | 421 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), |
| 418 net::HTTP_OK, | 422 net::HTTP_OK, |
| 419 cookies, | |
| 420 std::string(), | 423 std::string(), |
| 421 net::URLFetcher::POST, | 424 net::URLFetcher::POST, |
| 422 &auth); | 425 &auth); |
| 426 mock_fetcher1.set_response_headers(reponse_headers); | |
| 423 auth.OnURLFetchComplete(&mock_fetcher1); | 427 auth.OnURLFetchComplete(&mock_fetcher1); |
| 424 EXPECT_TRUE(auth.HasPendingFetch()); | 428 EXPECT_TRUE(auth.HasPendingFetch()); |
| 425 MockFetcher mock_fetcher2( | 429 MockFetcher mock_fetcher2( |
| 426 oauth2_token_source_, | 430 oauth2_token_source_, |
| 427 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), | 431 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), net::HTTP_OK, |
| 428 net::HTTP_OK, cookies_, kGetTokenPairValidResponse, | 432 kGetTokenPairValidResponse, net::URLFetcher::POST, &auth); |
| 429 net::URLFetcher::POST, &auth); | |
| 430 auth.OnURLFetchComplete(&mock_fetcher2); | 433 auth.OnURLFetchComplete(&mock_fetcher2); |
| 431 EXPECT_FALSE(auth.HasPendingFetch()); | 434 EXPECT_FALSE(auth.HasPendingFetch()); |
| 432 } | 435 } |
| 433 | 436 |
| 434 TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenSuccessNoTokenFetch) { | 437 TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenSuccessNoTokenFetch) { |
| 435 MockGaiaConsumer consumer; | 438 MockGaiaConsumer consumer; |
| 436 EXPECT_CALL(consumer, OnClientOAuthCode("test-code")).Times(1); | 439 EXPECT_CALL(consumer, OnClientOAuthCode("test-code")).Times(1); |
| 437 EXPECT_CALL(consumer, OnClientOAuthSuccess( | 440 EXPECT_CALL(consumer, OnClientOAuthSuccess( |
| 438 GaiaAuthConsumer::ClientOAuthResult("", "", 0))).Times(0); | 441 GaiaAuthConsumer::ClientOAuthResult("", "", 0))).Times(0); |
| 439 | 442 |
| 440 net::TestURLFetcherFactory factory; | 443 net::TestURLFetcherFactory factory; |
| 441 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); | 444 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); |
| 442 auth.StartCookieForOAuthLoginTokenExchange( | 445 auth.StartCookieForOAuthLoginTokenExchange( |
| 443 false, "0", "ABCDE_12345", ""); | 446 false, "0", "ABCDE_12345", ""); |
| 444 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | 447 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); |
| 445 EXPECT_TRUE(NULL != fetcher); | 448 EXPECT_TRUE(NULL != fetcher); |
| 446 EXPECT_EQ(net::LOAD_NORMAL, fetcher->GetLoadFlags()); | 449 EXPECT_EQ(net::LOAD_NORMAL, fetcher->GetLoadFlags()); |
| 447 EXPECT_EQ(std::string::npos, | 450 EXPECT_EQ(std::string::npos, |
| 448 fetcher->GetOriginalURL().query().find("device_type=chrome")); | 451 fetcher->GetOriginalURL().query().find("device_type=chrome")); |
| 449 | 452 |
| 450 net::ResponseCookies cookies; | 453 scoped_refptr<net::HttpResponseHeaders> reponse_headers = |
| 451 cookies.push_back(kGetAuthCodeValidCookie); | 454 new net::HttpResponseHeaders(""); |
| 455 reponse_headers->AddHeader(CookieStringToHeader(kGetAuthCodeValidCookie)); | |
| 452 EXPECT_TRUE(auth.HasPendingFetch()); | 456 EXPECT_TRUE(auth.HasPendingFetch()); |
| 453 MockFetcher mock_fetcher1( | 457 MockFetcher mock_fetcher1( |
| 454 client_login_to_oauth2_source_, | 458 client_login_to_oauth2_source_, |
| 455 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), | 459 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), |
| 456 net::HTTP_OK, | 460 net::HTTP_OK, |
| 457 cookies, | |
| 458 std::string(), | 461 std::string(), |
| 459 net::URLFetcher::POST, | 462 net::URLFetcher::POST, |
| 460 &auth); | 463 &auth); |
| 464 mock_fetcher1.set_response_headers(reponse_headers); | |
| 461 auth.OnURLFetchComplete(&mock_fetcher1); | 465 auth.OnURLFetchComplete(&mock_fetcher1); |
| 462 EXPECT_FALSE(auth.HasPendingFetch()); | 466 EXPECT_FALSE(auth.HasPendingFetch()); |
| 463 } | 467 } |
| 464 | 468 |
| 465 TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenWithCookies_DeviceId) { | 469 TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenWithCookies_DeviceId) { |
| 466 MockGaiaConsumer consumer; | 470 MockGaiaConsumer consumer; |
| 467 net::TestURLFetcherFactory factory; | 471 net::TestURLFetcherFactory factory; |
| 468 std::string expected_device_id("ABCDE-12345"); | 472 std::string expected_device_id("ABCDE-12345"); |
| 469 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); | 473 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); |
| 470 auth.StartCookieForOAuthLoginTokenExchangeWithDeviceId("0", | 474 auth.StartCookieForOAuthLoginTokenExchangeWithDeviceId("0", |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 483 | 487 |
| 484 TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenClientLoginToOAuth2Failure) { | 488 TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenClientLoginToOAuth2Failure) { |
| 485 MockGaiaConsumer consumer; | 489 MockGaiaConsumer consumer; |
| 486 EXPECT_CALL(consumer, OnClientOAuthFailure(_)) | 490 EXPECT_CALL(consumer, OnClientOAuthFailure(_)) |
| 487 .Times(1); | 491 .Times(1); |
| 488 | 492 |
| 489 net::TestURLFetcherFactory factory; | 493 net::TestURLFetcherFactory factory; |
| 490 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); | 494 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); |
| 491 auth.StartCookieForOAuthLoginTokenExchange(std::string()); | 495 auth.StartCookieForOAuthLoginTokenExchange(std::string()); |
| 492 | 496 |
| 493 net::ResponseCookies cookies; | |
| 494 EXPECT_TRUE(auth.HasPendingFetch()); | 497 EXPECT_TRUE(auth.HasPendingFetch()); |
| 495 MockFetcher mock_fetcher( | 498 MockFetcher mock_fetcher( |
| 496 client_login_to_oauth2_source_, | 499 client_login_to_oauth2_source_, |
| 497 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), | 500 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), |
| 498 net::HTTP_FORBIDDEN, | 501 net::HTTP_FORBIDDEN, |
| 499 cookies, | |
| 500 std::string(), | 502 std::string(), |
| 501 net::URLFetcher::POST, | 503 net::URLFetcher::POST, |
| 502 &auth); | 504 &auth); |
| 503 auth.OnURLFetchComplete(&mock_fetcher); | 505 auth.OnURLFetchComplete(&mock_fetcher); |
| 504 EXPECT_FALSE(auth.HasPendingFetch()); | 506 EXPECT_FALSE(auth.HasPendingFetch()); |
| 505 } | 507 } |
| 506 | 508 |
| 507 TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenOAuth2TokenPairFailure) { | 509 TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenOAuth2TokenPairFailure) { |
| 508 MockGaiaConsumer consumer; | 510 MockGaiaConsumer consumer; |
| 509 EXPECT_CALL(consumer, OnClientOAuthFailure(_)) | 511 EXPECT_CALL(consumer, OnClientOAuthFailure(_)) |
| 510 .Times(1); | 512 .Times(1); |
| 511 | 513 |
| 512 net::TestURLFetcherFactory factory; | 514 net::TestURLFetcherFactory factory; |
| 513 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); | 515 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); |
| 514 auth.StartCookieForOAuthLoginTokenExchange(std::string()); | 516 auth.StartCookieForOAuthLoginTokenExchange(std::string()); |
| 515 | 517 |
| 516 net::ResponseCookies cookies; | 518 scoped_refptr<net::HttpResponseHeaders> reponse_headers = |
| 517 cookies.push_back(kGetAuthCodeValidCookie); | 519 new net::HttpResponseHeaders(""); |
| 520 reponse_headers->AddHeader(CookieStringToHeader(kGetAuthCodeValidCookie)); | |
| 518 EXPECT_TRUE(auth.HasPendingFetch()); | 521 EXPECT_TRUE(auth.HasPendingFetch()); |
| 519 MockFetcher mock_fetcher1( | 522 MockFetcher mock_fetcher1( |
| 520 client_login_to_oauth2_source_, | 523 client_login_to_oauth2_source_, |
| 521 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), | 524 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), |
| 522 net::HTTP_OK, | 525 net::HTTP_OK, |
| 523 cookies, | |
| 524 std::string(), | 526 std::string(), |
| 525 net::URLFetcher::POST, | 527 net::URLFetcher::POST, |
| 526 &auth); | 528 &auth); |
| 529 mock_fetcher1.set_response_headers(reponse_headers); | |
| 527 auth.OnURLFetchComplete(&mock_fetcher1); | 530 auth.OnURLFetchComplete(&mock_fetcher1); |
| 528 EXPECT_TRUE(auth.HasPendingFetch()); | 531 EXPECT_TRUE(auth.HasPendingFetch()); |
| 529 MockFetcher mock_fetcher2( | 532 MockFetcher mock_fetcher2( |
| 530 oauth2_token_source_, | 533 oauth2_token_source_, |
| 531 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), | 534 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), |
| 532 net::HTTP_FORBIDDEN, | 535 net::HTTP_FORBIDDEN, |
| 533 cookies_, | |
| 534 std::string(), | 536 std::string(), |
| 535 net::URLFetcher::POST, | 537 net::URLFetcher::POST, |
| 536 &auth); | 538 &auth); |
| 537 auth.OnURLFetchComplete(&mock_fetcher2); | 539 auth.OnURLFetchComplete(&mock_fetcher2); |
| 538 EXPECT_FALSE(auth.HasPendingFetch()); | 540 EXPECT_FALSE(auth.HasPendingFetch()); |
| 539 } | 541 } |
| 540 | 542 |
| 541 TEST_F(GaiaAuthFetcherTest, MergeSessionSuccess) { | 543 TEST_F(GaiaAuthFetcherTest, MergeSessionSuccess) { |
| 542 MockGaiaConsumer consumer; | 544 MockGaiaConsumer consumer; |
| 543 EXPECT_CALL(consumer, OnMergeSessionSuccess("<html></html>")) | 545 EXPECT_CALL(consumer, OnMergeSessionSuccess("<html></html>")) |
| 544 .Times(1); | 546 .Times(1); |
| 545 | 547 |
| 546 net::TestURLFetcherFactory factory; | 548 net::TestURLFetcherFactory factory; |
| 547 | 549 |
| 548 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); | 550 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); |
| 549 auth.StartMergeSession("myubertoken", std::string()); | 551 auth.StartMergeSession("myubertoken", std::string()); |
| 550 | 552 |
| 551 EXPECT_TRUE(auth.HasPendingFetch()); | 553 EXPECT_TRUE(auth.HasPendingFetch()); |
| 552 MockFetcher mock_fetcher( | 554 MockFetcher mock_fetcher( |
| 553 merge_session_source_, | 555 merge_session_source_, |
| 554 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), | 556 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), net::HTTP_OK, |
| 555 net::HTTP_OK, cookies_, "<html></html>", net::URLFetcher::GET, | 557 "<html></html>", net::URLFetcher::GET, &auth); |
| 556 &auth); | |
| 557 auth.OnURLFetchComplete(&mock_fetcher); | 558 auth.OnURLFetchComplete(&mock_fetcher); |
| 558 EXPECT_FALSE(auth.HasPendingFetch()); | 559 EXPECT_FALSE(auth.HasPendingFetch()); |
| 559 } | 560 } |
| 560 | 561 |
| 561 TEST_F(GaiaAuthFetcherTest, MergeSessionSuccessRedirect) { | 562 TEST_F(GaiaAuthFetcherTest, MergeSessionSuccessRedirect) { |
| 562 MockGaiaConsumer consumer; | 563 MockGaiaConsumer consumer; |
| 563 EXPECT_CALL(consumer, OnMergeSessionSuccess("<html></html>")) | 564 EXPECT_CALL(consumer, OnMergeSessionSuccess("<html></html>")) |
| 564 .Times(1); | 565 .Times(1); |
| 565 | 566 |
| 566 net::TestURLFetcherFactory factory; | 567 net::TestURLFetcherFactory factory; |
| 567 | 568 |
| 568 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); | 569 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); |
| 569 auth.StartMergeSession("myubertoken", std::string()); | 570 auth.StartMergeSession("myubertoken", std::string()); |
| 570 | 571 |
| 571 // Make sure the fetcher created has the expected flags. Set its url() | 572 // Make sure the fetcher created has the expected flags. Set its url() |
| 572 // properties to reflect a redirect. | 573 // properties to reflect a redirect. |
| 573 net::TestURLFetcher* test_fetcher = factory.GetFetcherByID(0); | 574 net::TestURLFetcher* test_fetcher = factory.GetFetcherByID(0); |
| 574 EXPECT_TRUE(test_fetcher != NULL); | 575 EXPECT_TRUE(test_fetcher != NULL); |
| 575 EXPECT_TRUE(test_fetcher->GetLoadFlags() == net::LOAD_NORMAL); | 576 EXPECT_TRUE(test_fetcher->GetLoadFlags() == net::LOAD_NORMAL); |
| 576 EXPECT_TRUE(auth.HasPendingFetch()); | 577 EXPECT_TRUE(auth.HasPendingFetch()); |
| 577 | 578 |
| 578 GURL final_url("http://www.google.com/CheckCookie"); | 579 GURL final_url("http://www.google.com/CheckCookie"); |
| 579 test_fetcher->set_url(final_url); | 580 test_fetcher->set_url(final_url); |
| 580 test_fetcher->set_status( | 581 test_fetcher->set_status( |
| 581 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0)); | 582 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0)); |
| 582 test_fetcher->set_response_code(net::HTTP_OK); | 583 test_fetcher->set_response_code(net::HTTP_OK); |
| 583 test_fetcher->set_cookies(cookies_); | |
| 584 test_fetcher->SetResponseString("<html></html>"); | 584 test_fetcher->SetResponseString("<html></html>"); |
| 585 | 585 |
| 586 auth.OnURLFetchComplete(test_fetcher); | 586 auth.OnURLFetchComplete(test_fetcher); |
| 587 EXPECT_FALSE(auth.HasPendingFetch()); | 587 EXPECT_FALSE(auth.HasPendingFetch()); |
| 588 } | 588 } |
| 589 | 589 |
| 590 TEST_F(GaiaAuthFetcherTest, UberAuthTokenSuccess) { | 590 TEST_F(GaiaAuthFetcherTest, UberAuthTokenSuccess) { |
| 591 MockGaiaConsumer consumer; | 591 MockGaiaConsumer consumer; |
| 592 EXPECT_CALL(consumer, OnUberAuthTokenSuccess("uberToken")) | 592 EXPECT_CALL(consumer, OnUberAuthTokenSuccess("uberToken")) |
| 593 .Times(1); | 593 .Times(1); |
| 594 | 594 |
| 595 net::TestURLFetcherFactory factory; | 595 net::TestURLFetcherFactory factory; |
| 596 | 596 |
| 597 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); | 597 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); |
| 598 auth.StartTokenFetchForUberAuthExchange("myAccessToken"); | 598 auth.StartTokenFetchForUberAuthExchange("myAccessToken"); |
| 599 | 599 |
| 600 EXPECT_TRUE(auth.HasPendingFetch()); | 600 EXPECT_TRUE(auth.HasPendingFetch()); |
| 601 MockFetcher mock_fetcher( | 601 MockFetcher mock_fetcher( |
| 602 uberauth_token_source_, | 602 uberauth_token_source_, |
| 603 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), | 603 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), net::HTTP_OK, |
| 604 net::HTTP_OK, cookies_, "uberToken", net::URLFetcher::POST, | 604 "uberToken", net::URLFetcher::POST, &auth); |
| 605 &auth); | |
| 606 auth.OnURLFetchComplete(&mock_fetcher); | 605 auth.OnURLFetchComplete(&mock_fetcher); |
| 607 EXPECT_FALSE(auth.HasPendingFetch()); | 606 EXPECT_FALSE(auth.HasPendingFetch()); |
| 608 } | 607 } |
| 609 | 608 |
| 610 TEST_F(GaiaAuthFetcherTest, ParseClientLoginToOAuth2Response) { | 609 TEST_F(GaiaAuthFetcherTest, ParseClientLoginToOAuth2Response) { |
| 611 { // No cookies. | 610 { // No cookies. |
| 612 std::string auth_code; | 611 std::string auth_code; |
| 613 net::ResponseCookies cookies; | 612 net::ResponseCookies cookies; |
| 614 EXPECT_FALSE(GaiaAuthFetcher::ParseClientLoginToOAuth2Response( | 613 EXPECT_FALSE(GaiaAuthFetcher::ParseClientLoginToOAuth2Response( |
| 615 cookies, &auth_code)); | 614 cookies, &auth_code)); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 656 result.sid = "sid"; | 655 result.sid = "sid"; |
| 657 result.token = "auth"; | 656 result.token = "auth"; |
| 658 result.data = data; | 657 result.data = data; |
| 659 | 658 |
| 660 MockGaiaConsumer consumer; | 659 MockGaiaConsumer consumer; |
| 661 EXPECT_CALL(consumer, OnClientLoginSuccess(result)) | 660 EXPECT_CALL(consumer, OnClientLoginSuccess(result)) |
| 662 .Times(1); | 661 .Times(1); |
| 663 | 662 |
| 664 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); | 663 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); |
| 665 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); | 664 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); |
| 666 MockFetcher mock_fetcher( | 665 MockFetcher mock_fetcher(oauth_login_gurl_, status, net::HTTP_OK, data, |
| 667 oauth_login_gurl_, status, net::HTTP_OK, cookies_, data, | 666 net::URLFetcher::GET, &auth); |
| 668 net::URLFetcher::GET, &auth); | |
| 669 auth.OnURLFetchComplete(&mock_fetcher); | 667 auth.OnURLFetchComplete(&mock_fetcher); |
| 670 } | 668 } |
| 671 | 669 |
| 672 TEST_F(GaiaAuthFetcherTest, ListAccounts) { | 670 TEST_F(GaiaAuthFetcherTest, ListAccounts) { |
| 673 std::string data("[\"gaia.l.a.r\", [" | 671 std::string data("[\"gaia.l.a.r\", [" |
| 674 "[\"gaia.l.a\", 1, \"First Last\", \"user@gmail.com\", " | 672 "[\"gaia.l.a\", 1, \"First Last\", \"user@gmail.com\", " |
| 675 "\"//googleusercontent.com/A/B/C/D/photo.jpg\", 1, 1, 0]]]"); | 673 "\"//googleusercontent.com/A/B/C/D/photo.jpg\", 1, 1, 0]]]"); |
| 676 MockGaiaConsumer consumer; | 674 MockGaiaConsumer consumer; |
| 677 EXPECT_CALL(consumer, OnListAccountsSuccess(data)).Times(1); | 675 EXPECT_CALL(consumer, OnListAccountsSuccess(data)).Times(1); |
| 678 | 676 |
| 679 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); | 677 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); |
| 680 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); | 678 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); |
| 681 MockFetcher mock_fetcher( | 679 MockFetcher mock_fetcher( |
| 682 GaiaUrls::GetInstance()->ListAccountsURLWithSource(std::string()), | 680 GaiaUrls::GetInstance()->ListAccountsURLWithSource(std::string()), status, |
| 683 status, net::HTTP_OK, cookies_, data, net::URLFetcher::GET, &auth); | 681 net::HTTP_OK, data, net::URLFetcher::GET, &auth); |
| 684 auth.OnURLFetchComplete(&mock_fetcher); | 682 auth.OnURLFetchComplete(&mock_fetcher); |
| 685 } | 683 } |
| 686 | 684 |
| 687 TEST_F(GaiaAuthFetcherTest, LogOutSuccess) { | 685 TEST_F(GaiaAuthFetcherTest, LogOutSuccess) { |
| 688 MockGaiaConsumer consumer; | 686 MockGaiaConsumer consumer; |
| 689 EXPECT_CALL(consumer, OnLogOutSuccess()).Times(1); | 687 EXPECT_CALL(consumer, OnLogOutSuccess()).Times(1); |
| 690 | 688 |
| 691 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); | 689 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); |
| 692 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); | 690 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); |
| 693 MockFetcher mock_fetcher( | 691 MockFetcher mock_fetcher( |
| 694 GaiaUrls::GetInstance()->LogOutURLWithSource(std::string()), status, | 692 GaiaUrls::GetInstance()->LogOutURLWithSource(std::string()), status, |
| 695 net::HTTP_OK, cookies_, std::string(), net::URLFetcher::GET, &auth); | 693 net::HTTP_OK, std::string(), net::URLFetcher::GET, &auth); |
| 696 auth.OnURLFetchComplete(&mock_fetcher); | 694 auth.OnURLFetchComplete(&mock_fetcher); |
| 697 } | 695 } |
| 698 | 696 |
| 699 TEST_F(GaiaAuthFetcherTest, LogOutFailure) { | 697 TEST_F(GaiaAuthFetcherTest, LogOutFailure) { |
| 700 int error_no = net::ERR_CONNECTION_RESET; | 698 int error_no = net::ERR_CONNECTION_RESET; |
| 701 net::URLRequestStatus status(net::URLRequestStatus::FAILED, error_no); | 699 net::URLRequestStatus status(net::URLRequestStatus::FAILED, error_no); |
| 702 | 700 |
| 703 GoogleServiceAuthError expected_error = | 701 GoogleServiceAuthError expected_error = |
| 704 GoogleServiceAuthError::FromConnectionError(error_no); | 702 GoogleServiceAuthError::FromConnectionError(error_no); |
| 705 MockGaiaConsumer consumer; | 703 MockGaiaConsumer consumer; |
| 706 EXPECT_CALL(consumer, OnLogOutFailure(expected_error)).Times(1); | 704 EXPECT_CALL(consumer, OnLogOutFailure(expected_error)).Times(1); |
| 707 | 705 |
| 708 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); | 706 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); |
| 709 | 707 |
| 710 MockFetcher mock_fetcher( | 708 MockFetcher mock_fetcher( |
| 711 GaiaUrls::GetInstance()->LogOutURLWithSource(std::string()), status, 0, | 709 GaiaUrls::GetInstance()->LogOutURLWithSource(std::string()), status, 0, |
| 712 cookies_, std::string(), net::URLFetcher::GET, &auth); | 710 std::string(), net::URLFetcher::GET, &auth); |
| 713 auth.OnURLFetchComplete(&mock_fetcher); | 711 auth.OnURLFetchComplete(&mock_fetcher); |
| 714 } | 712 } |
| 715 | 713 |
| 716 TEST_F(GaiaAuthFetcherTest, GetCheckConnectionInfo) { | 714 TEST_F(GaiaAuthFetcherTest, GetCheckConnectionInfo) { |
| 717 std::string data( | 715 std::string data( |
| 718 "[{\"carryBackToken\": \"token1\", \"url\": \"http://www.google.com\"}]"); | 716 "[{\"carryBackToken\": \"token1\", \"url\": \"http://www.google.com\"}]"); |
| 719 MockGaiaConsumer consumer; | 717 MockGaiaConsumer consumer; |
| 720 EXPECT_CALL(consumer, OnGetCheckConnectionInfoSuccess(data)).Times(1); | 718 EXPECT_CALL(consumer, OnGetCheckConnectionInfoSuccess(data)).Times(1); |
| 721 | 719 |
| 722 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); | 720 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); |
| 723 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); | 721 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); |
| 724 MockFetcher mock_fetcher( | 722 MockFetcher mock_fetcher( |
| 725 GaiaUrls::GetInstance()->GetCheckConnectionInfoURLWithSource( | 723 GaiaUrls::GetInstance()->GetCheckConnectionInfoURLWithSource( |
| 726 std::string()), | 724 std::string()), |
| 727 status, net::HTTP_OK, cookies_, data, net::URLFetcher::GET, &auth); | 725 status, net::HTTP_OK, data, net::URLFetcher::GET, &auth); |
| 728 auth.OnURLFetchComplete(&mock_fetcher); | 726 auth.OnURLFetchComplete(&mock_fetcher); |
| 729 } | 727 } |
| 730 | 728 |
| 731 TEST_F(GaiaAuthFetcherTest, ListIDPSessions) { | 729 TEST_F(GaiaAuthFetcherTest, ListIDPSessions) { |
| 732 std::string data("{\"sessions\":[{\"login_hint\":\"abcdefghijklmnop\"}]}"); | 730 std::string data("{\"sessions\":[{\"login_hint\":\"abcdefghijklmnop\"}]}"); |
| 733 MockGaiaConsumer consumer; | 731 MockGaiaConsumer consumer; |
| 734 EXPECT_CALL(consumer, OnListIdpSessionsSuccess("abcdefghijklmnop")).Times(1); | 732 EXPECT_CALL(consumer, OnListIdpSessionsSuccess("abcdefghijklmnop")).Times(1); |
| 735 | 733 |
| 736 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); | 734 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); |
| 737 auth.StartListIDPSessions(std::string(), std::string()); | 735 auth.StartListIDPSessions(std::string(), std::string()); |
| 738 | 736 |
| 739 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); | 737 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); |
| 740 MockFetcher mock_fetcher( | 738 MockFetcher mock_fetcher(GaiaUrls::GetInstance()->oauth2_iframe_url(), status, |
| 741 GaiaUrls::GetInstance()->oauth2_iframe_url(), | 739 net::HTTP_OK, data, net::URLFetcher::GET, &auth); |
| 742 status, net::HTTP_OK, cookies_, data, net::URLFetcher::GET, &auth); | |
| 743 auth.OnURLFetchComplete(&mock_fetcher); | 740 auth.OnURLFetchComplete(&mock_fetcher); |
| 744 } | 741 } |
| 745 | 742 |
| 746 TEST_F(GaiaAuthFetcherTest, GetTokenResponse) { | 743 TEST_F(GaiaAuthFetcherTest, GetTokenResponse) { |
| 747 MockGaiaConsumer consumer; | 744 MockGaiaConsumer consumer; |
| 748 EXPECT_CALL(consumer, | 745 EXPECT_CALL(consumer, |
| 749 OnGetTokenResponseSuccess( | 746 OnGetTokenResponseSuccess( |
| 750 GaiaAuthConsumer::ClientOAuthResult(std::string(), | 747 GaiaAuthConsumer::ClientOAuthResult(std::string(), |
| 751 "at1", | 748 "at1", |
| 752 3600))).Times(1); | 749 3600))).Times(1); |
| 753 | 750 |
| 754 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); | 751 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); |
| 755 auth.StartGetTokenResponse(std::string(), std::string(), std::string()); | 752 auth.StartGetTokenResponse(std::string(), std::string(), std::string()); |
| 756 | 753 |
| 757 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); | 754 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); |
| 758 MockFetcher mock_fetcher( | 755 MockFetcher mock_fetcher(GaiaUrls::GetInstance()->oauth2_iframe_url(), status, |
| 759 GaiaUrls::GetInstance()->oauth2_iframe_url(), | 756 net::HTTP_OK, kGetTokenPairValidResponse, |
| 760 status, net::HTTP_OK, cookies_, kGetTokenPairValidResponse, | 757 net::URLFetcher::GET, &auth); |
| 761 net::URLFetcher::GET, &auth); | |
| 762 auth.OnURLFetchComplete(&mock_fetcher); | 758 auth.OnURLFetchComplete(&mock_fetcher); |
| 763 } | 759 } |
| OLD | NEW |