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