Chromium Code Reviews| Index: google_apis/gaia/gaia_auth_fetcher_unittest.cc |
| diff --git a/google_apis/gaia/gaia_auth_fetcher_unittest.cc b/google_apis/gaia/gaia_auth_fetcher_unittest.cc |
| index f281f233e741e156bad22ca69fb085f17a4c20f1..e886f00659e1167d46017c919a57cee2a08e06f3 100644 |
| --- a/google_apis/gaia/gaia_auth_fetcher_unittest.cc |
| +++ b/google_apis/gaia/gaia_auth_fetcher_unittest.cc |
| @@ -8,6 +8,7 @@ |
| #include <string> |
| #include "base/json/json_reader.h" |
| +#include "base/memory/ref_counted.h" |
| #include "base/strings/stringprintf.h" |
| #include "base/values.h" |
| #include "build/build_config.h" |
| @@ -19,6 +20,7 @@ |
| #include "google_apis/google_api_keys.h" |
| #include "net/base/load_flags.h" |
| #include "net/base/net_errors.h" |
| +#include "net/http/http_response_headers.h" |
| #include "net/http/http_status_code.h" |
| #include "net/url_request/test_url_fetcher_factory.h" |
| #include "net/url_request/url_fetcher_delegate.h" |
| @@ -31,6 +33,12 @@ |
| using ::testing::Invoke; |
| using ::testing::_; |
| +namespace { |
| +std::string CookieStringToHeader(const char* cookie_string) { |
| + return std::string("Set-Cookie: ") + cookie_string; |
| +} |
| +} |
|
mmenke
2016/06/08 14:46:44
nit: // namespace
mmenke
2016/06/08 14:46:44
Also, while you're here, this should probably be e
martijnc
2016/06/08 16:08:10
Both done.
|
| + |
| const char kGetAuthCodeValidCookie[] = |
| "oauth_code=test-code; Path=/test; Secure; HttpOnly"; |
| const char kGetAuthCodeCookieNoSecure[] = |
| @@ -70,7 +78,6 @@ MockFetcher::MockFetcher(bool success, |
| MockFetcher::MockFetcher(const GURL& url, |
| const net::URLRequestStatus& status, |
| int response_code, |
| - const net::ResponseCookies& cookies, |
| const std::string& results, |
| net::URLFetcher::RequestType request_type, |
| net::URLFetcherDelegate* d) |
| @@ -78,7 +85,6 @@ MockFetcher::MockFetcher(const GURL& url, |
| set_url(url); |
| set_status(status); |
| set_response_code(response_code); |
| - set_cookies(cookies); |
| SetResponseString(results); |
| } |
| @@ -141,7 +147,6 @@ class GaiaAuthFetcherTest : public testing::Test { |
| EXPECT_EQ(captcha_token, out_captcha_token); |
| } |
| - net::ResponseCookies cookies_; |
| GURL issue_auth_token_source_; |
| GURL client_login_to_oauth2_source_; |
| GURL oauth2_token_source_; |
| @@ -236,9 +241,8 @@ TEST_F(GaiaAuthFetcherTest, TokenNetFailure) { |
| GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); |
| - MockFetcher mock_fetcher( |
| - issue_auth_token_source_, status, 0, cookies_, std::string(), |
| - net::URLFetcher::GET, &auth); |
| + MockFetcher mock_fetcher(issue_auth_token_source_, status, 0, std::string(), |
| + net::URLFetcher::GET, &auth); |
| auth.OnURLFetchComplete(&mock_fetcher); |
| } |
| @@ -275,9 +279,8 @@ TEST_F(GaiaAuthFetcherTest, WorkingIssueAuthToken) { |
| GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); |
| net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); |
| - MockFetcher mock_fetcher( |
| - issue_auth_token_source_, status, net::HTTP_OK, cookies_, "token", |
| - net::URLFetcher::GET, &auth); |
| + MockFetcher mock_fetcher(issue_auth_token_source_, status, net::HTTP_OK, |
| + "token", net::URLFetcher::GET, &auth); |
| auth.OnURLFetchComplete(&mock_fetcher); |
| } |
| @@ -364,9 +367,8 @@ TEST_F(GaiaAuthFetcherTest, FullTokenSuccess) { |
| EXPECT_TRUE(auth.HasPendingFetch()); |
| MockFetcher mock_fetcher( |
| issue_auth_token_source_, |
| - net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), |
| - net::HTTP_OK, cookies_, "token", |
| - net::URLFetcher::GET, &auth); |
| + net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), net::HTTP_OK, |
| + "token", net::URLFetcher::GET, &auth); |
| auth.OnURLFetchComplete(&mock_fetcher); |
| EXPECT_FALSE(auth.HasPendingFetch()); |
| } |
| @@ -386,7 +388,6 @@ TEST_F(GaiaAuthFetcherTest, FullTokenFailure) { |
| issue_auth_token_source_, |
| net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), |
| net::HTTP_FORBIDDEN, |
| - cookies_, |
| std::string(), |
| net::URLFetcher::GET, |
| &auth); |
| @@ -409,24 +410,24 @@ TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenSuccess) { |
| EXPECT_EQ(std::string::npos, |
| fetcher->GetOriginalURL().query().find("device_type=chrome")); |
| - net::ResponseCookies cookies; |
| - cookies.push_back(kGetAuthCodeValidCookie); |
| EXPECT_TRUE(auth.HasPendingFetch()); |
| + scoped_refptr<net::HttpResponseHeaders> reponse_headers = |
| + new net::HttpResponseHeaders(""); |
| + reponse_headers->AddHeader(CookieStringToHeader(kGetAuthCodeValidCookie)); |
| MockFetcher mock_fetcher1( |
| client_login_to_oauth2_source_, |
| net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), |
| net::HTTP_OK, |
| - cookies, |
| std::string(), |
| net::URLFetcher::POST, |
| &auth); |
| + mock_fetcher1.set_response_headers(reponse_headers); |
| auth.OnURLFetchComplete(&mock_fetcher1); |
| EXPECT_TRUE(auth.HasPendingFetch()); |
| MockFetcher mock_fetcher2( |
| oauth2_token_source_, |
| - net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), |
| - net::HTTP_OK, cookies_, kGetTokenPairValidResponse, |
| - net::URLFetcher::POST, &auth); |
| + net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), net::HTTP_OK, |
| + kGetTokenPairValidResponse, net::URLFetcher::POST, &auth); |
| auth.OnURLFetchComplete(&mock_fetcher2); |
| EXPECT_FALSE(auth.HasPendingFetch()); |
| } |
| @@ -447,17 +448,18 @@ TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenSuccessNoTokenFetch) { |
| EXPECT_EQ(std::string::npos, |
| fetcher->GetOriginalURL().query().find("device_type=chrome")); |
| - net::ResponseCookies cookies; |
| - cookies.push_back(kGetAuthCodeValidCookie); |
| + scoped_refptr<net::HttpResponseHeaders> reponse_headers = |
| + new net::HttpResponseHeaders(""); |
| + reponse_headers->AddHeader(CookieStringToHeader(kGetAuthCodeValidCookie)); |
| EXPECT_TRUE(auth.HasPendingFetch()); |
| MockFetcher mock_fetcher1( |
| client_login_to_oauth2_source_, |
| net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), |
| net::HTTP_OK, |
| - cookies, |
| std::string(), |
| net::URLFetcher::POST, |
| &auth); |
| + mock_fetcher1.set_response_headers(reponse_headers); |
| auth.OnURLFetchComplete(&mock_fetcher1); |
| EXPECT_FALSE(auth.HasPendingFetch()); |
| } |
| @@ -490,13 +492,11 @@ TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenClientLoginToOAuth2Failure) { |
| GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); |
| auth.StartCookieForOAuthLoginTokenExchange(std::string()); |
| - net::ResponseCookies cookies; |
| EXPECT_TRUE(auth.HasPendingFetch()); |
| MockFetcher mock_fetcher( |
| client_login_to_oauth2_source_, |
| net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), |
| net::HTTP_FORBIDDEN, |
| - cookies, |
| std::string(), |
| net::URLFetcher::POST, |
| &auth); |
| @@ -513,24 +513,24 @@ TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenOAuth2TokenPairFailure) { |
| GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); |
| auth.StartCookieForOAuthLoginTokenExchange(std::string()); |
| - net::ResponseCookies cookies; |
| - cookies.push_back(kGetAuthCodeValidCookie); |
| + scoped_refptr<net::HttpResponseHeaders> reponse_headers = |
| + new net::HttpResponseHeaders(""); |
| + reponse_headers->AddHeader(CookieStringToHeader(kGetAuthCodeValidCookie)); |
| EXPECT_TRUE(auth.HasPendingFetch()); |
| MockFetcher mock_fetcher1( |
| client_login_to_oauth2_source_, |
| net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), |
| net::HTTP_OK, |
| - cookies, |
| std::string(), |
| net::URLFetcher::POST, |
| &auth); |
| + mock_fetcher1.set_response_headers(reponse_headers); |
| auth.OnURLFetchComplete(&mock_fetcher1); |
| EXPECT_TRUE(auth.HasPendingFetch()); |
| MockFetcher mock_fetcher2( |
| oauth2_token_source_, |
| net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), |
| net::HTTP_FORBIDDEN, |
| - cookies_, |
| std::string(), |
| net::URLFetcher::POST, |
| &auth); |
| @@ -551,9 +551,8 @@ TEST_F(GaiaAuthFetcherTest, MergeSessionSuccess) { |
| EXPECT_TRUE(auth.HasPendingFetch()); |
| MockFetcher mock_fetcher( |
| merge_session_source_, |
| - net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), |
| - net::HTTP_OK, cookies_, "<html></html>", net::URLFetcher::GET, |
| - &auth); |
| + net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), net::HTTP_OK, |
| + "<html></html>", net::URLFetcher::GET, &auth); |
| auth.OnURLFetchComplete(&mock_fetcher); |
| EXPECT_FALSE(auth.HasPendingFetch()); |
| } |
| @@ -580,7 +579,6 @@ TEST_F(GaiaAuthFetcherTest, MergeSessionSuccessRedirect) { |
| test_fetcher->set_status( |
| net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0)); |
| test_fetcher->set_response_code(net::HTTP_OK); |
| - test_fetcher->set_cookies(cookies_); |
| test_fetcher->SetResponseString("<html></html>"); |
| auth.OnURLFetchComplete(test_fetcher); |
| @@ -600,9 +598,8 @@ TEST_F(GaiaAuthFetcherTest, UberAuthTokenSuccess) { |
| EXPECT_TRUE(auth.HasPendingFetch()); |
| MockFetcher mock_fetcher( |
| uberauth_token_source_, |
| - net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), |
| - net::HTTP_OK, cookies_, "uberToken", net::URLFetcher::POST, |
| - &auth); |
| + net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), net::HTTP_OK, |
| + "uberToken", net::URLFetcher::POST, &auth); |
| auth.OnURLFetchComplete(&mock_fetcher); |
| EXPECT_FALSE(auth.HasPendingFetch()); |
| } |
| @@ -663,9 +660,8 @@ TEST_F(GaiaAuthFetcherTest, StartOAuthLogin) { |
| GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); |
| net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); |
| - MockFetcher mock_fetcher( |
| - oauth_login_gurl_, status, net::HTTP_OK, cookies_, data, |
| - net::URLFetcher::GET, &auth); |
| + MockFetcher mock_fetcher(oauth_login_gurl_, status, net::HTTP_OK, data, |
| + net::URLFetcher::GET, &auth); |
| auth.OnURLFetchComplete(&mock_fetcher); |
| } |
| @@ -679,8 +675,8 @@ TEST_F(GaiaAuthFetcherTest, ListAccounts) { |
| GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); |
| net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); |
| MockFetcher mock_fetcher( |
| - GaiaUrls::GetInstance()->ListAccountsURLWithSource(std::string()), |
| - status, net::HTTP_OK, cookies_, data, net::URLFetcher::GET, &auth); |
| + GaiaUrls::GetInstance()->ListAccountsURLWithSource(std::string()), status, |
| + net::HTTP_OK, data, net::URLFetcher::GET, &auth); |
| auth.OnURLFetchComplete(&mock_fetcher); |
| } |
| @@ -692,7 +688,7 @@ TEST_F(GaiaAuthFetcherTest, LogOutSuccess) { |
| net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); |
| MockFetcher mock_fetcher( |
| GaiaUrls::GetInstance()->LogOutURLWithSource(std::string()), status, |
| - net::HTTP_OK, cookies_, std::string(), net::URLFetcher::GET, &auth); |
| + net::HTTP_OK, std::string(), net::URLFetcher::GET, &auth); |
| auth.OnURLFetchComplete(&mock_fetcher); |
| } |
| @@ -709,7 +705,7 @@ TEST_F(GaiaAuthFetcherTest, LogOutFailure) { |
| MockFetcher mock_fetcher( |
| GaiaUrls::GetInstance()->LogOutURLWithSource(std::string()), status, 0, |
| - cookies_, std::string(), net::URLFetcher::GET, &auth); |
| + std::string(), net::URLFetcher::GET, &auth); |
| auth.OnURLFetchComplete(&mock_fetcher); |
| } |
| @@ -724,7 +720,7 @@ TEST_F(GaiaAuthFetcherTest, GetCheckConnectionInfo) { |
| MockFetcher mock_fetcher( |
| GaiaUrls::GetInstance()->GetCheckConnectionInfoURLWithSource( |
| std::string()), |
| - status, net::HTTP_OK, cookies_, data, net::URLFetcher::GET, &auth); |
| + status, net::HTTP_OK, data, net::URLFetcher::GET, &auth); |
| auth.OnURLFetchComplete(&mock_fetcher); |
| } |
| @@ -737,9 +733,8 @@ TEST_F(GaiaAuthFetcherTest, ListIDPSessions) { |
| auth.StartListIDPSessions(std::string(), std::string()); |
| net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); |
| - MockFetcher mock_fetcher( |
| - GaiaUrls::GetInstance()->oauth2_iframe_url(), |
| - status, net::HTTP_OK, cookies_, data, net::URLFetcher::GET, &auth); |
| + MockFetcher mock_fetcher(GaiaUrls::GetInstance()->oauth2_iframe_url(), status, |
| + net::HTTP_OK, data, net::URLFetcher::GET, &auth); |
| auth.OnURLFetchComplete(&mock_fetcher); |
| } |
| @@ -755,9 +750,8 @@ TEST_F(GaiaAuthFetcherTest, GetTokenResponse) { |
| auth.StartGetTokenResponse(std::string(), std::string(), std::string()); |
| net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); |
| - MockFetcher mock_fetcher( |
| - GaiaUrls::GetInstance()->oauth2_iframe_url(), |
| - status, net::HTTP_OK, cookies_, kGetTokenPairValidResponse, |
| - net::URLFetcher::GET, &auth); |
| + MockFetcher mock_fetcher(GaiaUrls::GetInstance()->oauth2_iframe_url(), status, |
| + net::HTTP_OK, kGetTokenPairValidResponse, |
| + net::URLFetcher::GET, &auth); |
| auth.OnURLFetchComplete(&mock_fetcher); |
| } |