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

Side by Side Diff: google_apis/gaia/oauth2_access_token_fetcher_impl_unittest.cc

Issue 1239993004: Fix all failed and canceled URLRequestStatuses without errors. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix more failures Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 OAuth2AccessTokenFetcherImpl. 5 // A complete set of unit tests for OAuth2AccessTokenFetcherImpl.
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
11 #include "base/thread_task_runner_handle.h" 11 #include "base/thread_task_runner_handle.h"
12 #include "google_apis/gaia/gaia_urls.h" 12 #include "google_apis/gaia/gaia_urls.h"
13 #include "google_apis/gaia/google_service_auth_error.h" 13 #include "google_apis/gaia/google_service_auth_error.h"
14 #include "google_apis/gaia/oauth2_access_token_consumer.h" 14 #include "google_apis/gaia/oauth2_access_token_consumer.h"
15 #include "google_apis/gaia/oauth2_access_token_fetcher_impl.h" 15 #include "google_apis/gaia/oauth2_access_token_fetcher_impl.h"
16 #include "net/base/net_errors.h"
16 #include "net/http/http_status_code.h" 17 #include "net/http/http_status_code.h"
17 #include "net/url_request/test_url_fetcher_factory.h" 18 #include "net/url_request/test_url_fetcher_factory.h"
18 #include "net/url_request/url_fetcher.h" 19 #include "net/url_request/url_fetcher.h"
19 #include "net/url_request/url_fetcher_delegate.h" 20 #include "net/url_request/url_fetcher_delegate.h"
20 #include "net/url_request/url_fetcher_factory.h" 21 #include "net/url_request/url_fetcher_factory.h"
21 #include "net/url_request/url_request.h" 22 #include "net/url_request/url_request.h"
22 #include "net/url_request/url_request_status.h" 23 #include "net/url_request/url_request_status.h"
23 #include "net/url_request/url_request_test_util.h" 24 #include "net/url_request/url_request_test_util.h"
24 #include "testing/gmock/include/gmock/gmock.h" 25 #include "testing/gmock/include/gmock/gmock.h"
25 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 base::RunLoop().RunUntilIdle(); 100 base::RunLoop().RunUntilIdle();
100 } 101 }
101 102
102 ~OAuth2AccessTokenFetcherImplTest() override {} 103 ~OAuth2AccessTokenFetcherImplTest() override {}
103 104
104 virtual TestURLFetcher* SetupGetAccessToken(bool fetch_succeeds, 105 virtual TestURLFetcher* SetupGetAccessToken(bool fetch_succeeds,
105 int response_code, 106 int response_code,
106 const std::string& body) { 107 const std::string& body) {
107 GURL url(GaiaUrls::GetInstance()->oauth2_token_url()); 108 GURL url(GaiaUrls::GetInstance()->oauth2_token_url());
108 TestURLFetcher* url_fetcher = new TestURLFetcher(0, url, &fetcher_); 109 TestURLFetcher* url_fetcher = new TestURLFetcher(0, url, &fetcher_);
109 URLRequestStatus::Status status = 110 net::Error error = fetch_succeeds ? net::OK : net::ERR_FAILED;
110 fetch_succeeds ? URLRequestStatus::SUCCESS : URLRequestStatus::FAILED; 111 url_fetcher->set_status(URLRequestStatus::FromError(error));
111 url_fetcher->set_status(URLRequestStatus(status, 0));
112 112
113 if (response_code != 0) 113 if (response_code != 0)
114 url_fetcher->set_response_code(response_code); 114 url_fetcher->set_response_code(response_code);
115 115
116 if (!body.empty()) 116 if (!body.empty())
117 url_fetcher->SetResponseString(body); 117 url_fetcher->SetResponseString(body);
118 118
119 EXPECT_CALL(factory_, CreateURLFetcherMock(_, url, _, _)) 119 EXPECT_CALL(factory_, CreateURLFetcherMock(_, url, _, _))
120 .WillOnce(Return(url_fetcher)); 120 .WillOnce(Return(url_fetcher));
121 return url_fetcher; 121 return url_fetcher;
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 TestURLFetcher url_fetcher(0, GURL("http://www.google.com"), NULL); 265 TestURLFetcher url_fetcher(0, GURL("http://www.google.com"), NULL);
266 url_fetcher.SetResponseString(kValidFailureTokenResponse); 266 url_fetcher.SetResponseString(kValidFailureTokenResponse);
267 267
268 std::string error; 268 std::string error;
269 EXPECT_TRUE( 269 EXPECT_TRUE(
270 OAuth2AccessTokenFetcherImpl::ParseGetAccessTokenFailureResponse( 270 OAuth2AccessTokenFetcherImpl::ParseGetAccessTokenFailureResponse(
271 &url_fetcher, &error)); 271 &url_fetcher, &error));
272 EXPECT_EQ("invalid_grant", error); 272 EXPECT_EQ("invalid_grant", error);
273 } 273 }
274 } 274 }
OLDNEW
« no previous file with comments | « google_apis/gaia/gaia_oauth_client_unittest.cc ('k') | google_apis/gaia/oauth2_api_call_flow_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698