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

Unified Diff: google_apis/gaia/oauth2_access_token_fetcher_impl_unittest.cc

Issue 182573003: Extract OAuth2AccessTokenFetcher interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add missing file. Created 6 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: google_apis/gaia/oauth2_access_token_fetcher_impl_unittest.cc
diff --git a/google_apis/gaia/oauth2_access_token_fetcher_unittest.cc b/google_apis/gaia/oauth2_access_token_fetcher_impl_unittest.cc
similarity index 62%
rename from google_apis/gaia/oauth2_access_token_fetcher_unittest.cc
rename to google_apis/gaia/oauth2_access_token_fetcher_impl_unittest.cc
index 37610900152320543dfa33e518c21f0f537ea374..d056389e106a9763874929b195ffec355314f37b 100644
--- a/google_apis/gaia/oauth2_access_token_fetcher_unittest.cc
+++ b/google_apis/gaia/oauth2_access_token_fetcher_impl_unittest.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
-// A complete set of unit tests for OAuth2AccessTokenFetcher.
+// A complete set of unit tests for OAuth2AccessTokenFetcherImpl.
#include <string>
@@ -11,7 +11,7 @@
#include "google_apis/gaia/gaia_urls.h"
#include "google_apis/gaia/google_service_auth_error.h"
#include "google_apis/gaia/oauth2_access_token_consumer.h"
-#include "google_apis/gaia/oauth2_access_token_fetcher.h"
+#include "google_apis/gaia/oauth2_access_token_fetcher_impl.h"
#include "net/http/http_status_code.h"
#include "net/url_request/test_url_fetcher_factory.h"
#include "net/url_request/url_fetcher.h"
@@ -57,18 +57,15 @@ static const char kValidFailureTokenResponse[] =
class MockUrlFetcherFactory : public ScopedURLFetcherFactory,
public URLFetcherFactory {
-public:
- MockUrlFetcherFactory()
- : ScopedURLFetcherFactory(this) {
- }
+ public:
+ MockUrlFetcherFactory() : ScopedURLFetcherFactory(this) {}
virtual ~MockUrlFetcherFactory() {}
- MOCK_METHOD4(
- CreateURLFetcher,
- URLFetcher* (int id,
- const GURL& url,
- URLFetcher::RequestType request_type,
- URLFetcherDelegate* d));
+ MOCK_METHOD4(CreateURLFetcher,
+ URLFetcher*(int id,
+ const GURL& url,
+ URLFetcher::RequestType request_type,
+ URLFetcherDelegate* d));
};
class MockOAuth2AccessTokenConsumer : public OAuth2AccessTokenConsumer {
@@ -76,24 +73,24 @@ class MockOAuth2AccessTokenConsumer : public OAuth2AccessTokenConsumer {
MockOAuth2AccessTokenConsumer() {}
~MockOAuth2AccessTokenConsumer() {}
- MOCK_METHOD2(OnGetTokenSuccess, void(const std::string& access_token,
- const base::Time& expiration_time));
- MOCK_METHOD1(OnGetTokenFailure,
- void(const GoogleServiceAuthError& error));
+ MOCK_METHOD2(OnGetTokenSuccess,
+ void(const std::string& access_token,
+ const base::Time& expiration_time));
+ MOCK_METHOD1(OnGetTokenFailure, void(const GoogleServiceAuthError& error));
};
} // namespace
-class OAuth2AccessTokenFetcherTest : public testing::Test {
+class OAuth2AccessTokenFetcherImplTest : public testing::Test {
public:
- OAuth2AccessTokenFetcherTest()
- : request_context_getter_(new net::TestURLRequestContextGetter(
- base::MessageLoopProxy::current())),
- fetcher_(&consumer_, request_context_getter_) {
+ OAuth2AccessTokenFetcherImplTest()
+ : request_context_getter_(new net::TestURLRequestContextGetter(
+ base::MessageLoopProxy::current())),
+ fetcher_(&consumer_, request_context_getter_) {
base::RunLoop().RunUntilIdle();
}
- virtual ~OAuth2AccessTokenFetcherTest() {}
+ virtual ~OAuth2AccessTokenFetcherImplTest() {}
virtual TestURLFetcher* SetupGetAccessToken(bool fetch_succeeds,
int response_code,
@@ -120,43 +117,48 @@ class OAuth2AccessTokenFetcherTest : public testing::Test {
MockUrlFetcherFactory factory_;
MockOAuth2AccessTokenConsumer consumer_;
scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_;
- OAuth2AccessTokenFetcher fetcher_;
+ OAuth2AccessTokenFetcherImpl fetcher_;
};
// These four tests time out, see http://crbug.com/113446.
-TEST_F(OAuth2AccessTokenFetcherTest, DISABLED_GetAccessTokenRequestFailure) {
+TEST_F(OAuth2AccessTokenFetcherImplTest,
+ DISABLED_GetAccessTokenRequestFailure) {
TestURLFetcher* url_fetcher = SetupGetAccessToken(false, 0, std::string());
EXPECT_CALL(consumer_, OnGetTokenFailure(_)).Times(1);
- fetcher_.Start("client_id", "client_secret", "refresh_token", ScopeList());
+ fetcher_.Start(
+ "client_id", "client_secret", "refresh_token", ScopeList());
fetcher_.OnURLFetchComplete(url_fetcher);
}
-TEST_F(OAuth2AccessTokenFetcherTest,
+TEST_F(OAuth2AccessTokenFetcherImplTest,
DISABLED_GetAccessTokenResponseCodeFailure) {
TestURLFetcher* url_fetcher =
SetupGetAccessToken(true, net::HTTP_FORBIDDEN, std::string());
EXPECT_CALL(consumer_, OnGetTokenFailure(_)).Times(1);
- fetcher_.Start("client_id", "client_secret", "refresh_token", ScopeList());
+ fetcher_.Start(
+ "client_id", "client_secret", "refresh_token", ScopeList());
fetcher_.OnURLFetchComplete(url_fetcher);
}
-TEST_F(OAuth2AccessTokenFetcherTest, DISABLED_Success) {
- TestURLFetcher* url_fetcher = SetupGetAccessToken(
- true, net::HTTP_OK, kValidTokenResponse);
+TEST_F(OAuth2AccessTokenFetcherImplTest, DISABLED_Success) {
+ TestURLFetcher* url_fetcher =
+ SetupGetAccessToken(true, net::HTTP_OK, kValidTokenResponse);
EXPECT_CALL(consumer_, OnGetTokenSuccess("at1", _)).Times(1);
- fetcher_.Start("client_id", "client_secret", "refresh_token", ScopeList());
+ fetcher_.Start(
+ "client_id", "client_secret", "refresh_token", ScopeList());
fetcher_.OnURLFetchComplete(url_fetcher);
}
-TEST_F(OAuth2AccessTokenFetcherTest, DISABLED_MakeGetAccessTokenBody) {
+TEST_F(OAuth2AccessTokenFetcherImplTest, DISABLED_MakeGetAccessTokenBody) {
{ // No scope.
std::string body =
"client_id=cid1&"
"client_secret=cs1&"
"grant_type=refresh_token&"
"refresh_token=rt1";
- EXPECT_EQ(body, OAuth2AccessTokenFetcher::MakeGetAccessTokenBody(
- "cid1", "cs1", "rt1", ScopeList()));
+ EXPECT_EQ(body,
+ OAuth2AccessTokenFetcherImpl::MakeGetAccessTokenBody(
+ "cid1", "cs1", "rt1", ScopeList()));
}
{ // One scope.
@@ -168,8 +170,9 @@ TEST_F(OAuth2AccessTokenFetcherTest, DISABLED_MakeGetAccessTokenBody) {
"scope=https://www.googleapis.com/foo";
ScopeList scopes;
scopes.push_back("https://www.googleapis.com/foo");
- EXPECT_EQ(body, OAuth2AccessTokenFetcher::MakeGetAccessTokenBody(
- "cid1", "cs1", "rt1", scopes));
+ EXPECT_EQ(body,
+ OAuth2AccessTokenFetcherImpl::MakeGetAccessTokenBody(
+ "cid1", "cs1", "rt1", scopes));
}
{ // Multiple scopes.
@@ -185,8 +188,9 @@ TEST_F(OAuth2AccessTokenFetcherTest, DISABLED_MakeGetAccessTokenBody) {
scopes.push_back("https://www.googleapis.com/foo");
scopes.push_back("https://www.googleapis.com/bar");
scopes.push_back("https://www.googleapis.com/baz");
- EXPECT_EQ(body, OAuth2AccessTokenFetcher::MakeGetAccessTokenBody(
- "cid1", "cs1", "rt1", scopes));
+ EXPECT_EQ(body,
+ OAuth2AccessTokenFetcherImpl::MakeGetAccessTokenBody(
+ "cid1", "cs1", "rt1", scopes));
}
}
@@ -195,15 +199,16 @@ TEST_F(OAuth2AccessTokenFetcherTest, DISABLED_MakeGetAccessTokenBody) {
#define MAYBE_ParseGetAccessTokenResponse DISABLED_ParseGetAccessTokenResponse
#else
#define MAYBE_ParseGetAccessTokenResponse ParseGetAccessTokenResponse
-#endif // defined(OS_WIN)
-TEST_F(OAuth2AccessTokenFetcherTest, MAYBE_ParseGetAccessTokenResponse) {
+#endif // defined(OS_WIN)
+TEST_F(OAuth2AccessTokenFetcherImplTest, MAYBE_ParseGetAccessTokenResponse) {
{ // No body.
TestURLFetcher url_fetcher(0, GURL("www.google.com"), NULL);
std::string at;
int expires_in;
- EXPECT_FALSE(OAuth2AccessTokenFetcher::ParseGetAccessTokenSuccessResponse(
- &url_fetcher, &at, &expires_in));
+ EXPECT_FALSE(
+ OAuth2AccessTokenFetcherImpl::ParseGetAccessTokenSuccessResponse(
+ &url_fetcher, &at, &expires_in));
EXPECT_TRUE(at.empty());
}
{ // Bad json.
@@ -212,8 +217,9 @@ TEST_F(OAuth2AccessTokenFetcherTest, MAYBE_ParseGetAccessTokenResponse) {
std::string at;
int expires_in;
- EXPECT_FALSE(OAuth2AccessTokenFetcher::ParseGetAccessTokenSuccessResponse(
- &url_fetcher, &at, &expires_in));
+ EXPECT_FALSE(
+ OAuth2AccessTokenFetcherImpl::ParseGetAccessTokenSuccessResponse(
+ &url_fetcher, &at, &expires_in));
EXPECT_TRUE(at.empty());
}
{ // Valid json: access token missing.
@@ -222,8 +228,9 @@ TEST_F(OAuth2AccessTokenFetcherTest, MAYBE_ParseGetAccessTokenResponse) {
std::string at;
int expires_in;
- EXPECT_FALSE(OAuth2AccessTokenFetcher::ParseGetAccessTokenSuccessResponse(
- &url_fetcher, &at, &expires_in));
+ EXPECT_FALSE(
+ OAuth2AccessTokenFetcherImpl::ParseGetAccessTokenSuccessResponse(
+ &url_fetcher, &at, &expires_in));
EXPECT_TRUE(at.empty());
}
{ // Valid json: all good.
@@ -232,27 +239,30 @@ TEST_F(OAuth2AccessTokenFetcherTest, MAYBE_ParseGetAccessTokenResponse) {
std::string at;
int expires_in;
- EXPECT_TRUE(OAuth2AccessTokenFetcher::ParseGetAccessTokenSuccessResponse(
- &url_fetcher, &at, &expires_in));
+ EXPECT_TRUE(
+ OAuth2AccessTokenFetcherImpl::ParseGetAccessTokenSuccessResponse(
+ &url_fetcher, &at, &expires_in));
EXPECT_EQ("at1", at);
EXPECT_EQ(3600, expires_in);
}
{ // Valid json: invalid error response.
- TestURLFetcher url_fetcher(0, GURL("www.google.com"), NULL);
- url_fetcher.SetResponseString(kTokenResponseNoAccessToken);
-
- std::string error;
- EXPECT_FALSE(OAuth2AccessTokenFetcher::ParseGetAccessTokenFailureResponse(
- &url_fetcher, &error));
- EXPECT_TRUE(error.empty());
- }
- { // Valid json: error response.
- TestURLFetcher url_fetcher(0, GURL("www.google.com"), NULL);
- url_fetcher.SetResponseString(kValidFailureTokenResponse);
-
- std::string error;
- EXPECT_TRUE(OAuth2AccessTokenFetcher::ParseGetAccessTokenFailureResponse(
- &url_fetcher, &error));
- EXPECT_EQ("invalid_grant", error);
- }
+ TestURLFetcher url_fetcher(0, GURL("www.google.com"), NULL);
+ url_fetcher.SetResponseString(kTokenResponseNoAccessToken);
+
+ std::string error;
+ EXPECT_FALSE(
+ OAuth2AccessTokenFetcherImpl::ParseGetAccessTokenFailureResponse(
+ &url_fetcher, &error));
+ EXPECT_TRUE(error.empty());
+ }
+ { // Valid json: error response.
+ TestURLFetcher url_fetcher(0, GURL("www.google.com"), NULL);
+ url_fetcher.SetResponseString(kValidFailureTokenResponse);
+
+ std::string error;
+ EXPECT_TRUE(
+ OAuth2AccessTokenFetcherImpl::ParseGetAccessTokenFailureResponse(
+ &url_fetcher, &error));
+ EXPECT_EQ("invalid_grant", error);
+ }
}
« no previous file with comments | « google_apis/gaia/oauth2_access_token_fetcher_impl.cc ('k') | google_apis/gaia/oauth2_access_token_fetcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698