summaryrefslogtreecommitdiffstats
path: root/google_apis/gaia/gaia_oauth_client_unittest.cc
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-25 03:21:15 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-25 03:21:15 +0000
commit607dba220110b63034c8956c4f45cc859970bf22 (patch)
treec2e376b7136f83700c6ce3fb7c87dd21bd031b9a /google_apis/gaia/gaia_oauth_client_unittest.cc
parent16d1cbc6d2e4064abd2f41614ce9dfc0c8eb89af (diff)
downloadchromium_src-607dba220110b63034c8956c4f45cc859970bf22.zip
chromium_src-607dba220110b63034c8956c4f45cc859970bf22.tar.gz
chromium_src-607dba220110b63034c8956c4f45cc859970bf22.tar.bz2
Add GetUserInfo() in GaiaOAuthClient.
The new method allows getting email of the user given an access token. Review URL: https://chromiumcodereview.appspot.com/11226067 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@164003 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'google_apis/gaia/gaia_oauth_client_unittest.cc')
-rw-r--r--google_apis/gaia/gaia_oauth_client_unittest.cc31
1 files changed, 28 insertions, 3 deletions
diff --git a/google_apis/gaia/gaia_oauth_client_unittest.cc b/google_apis/gaia/gaia_oauth_client_unittest.cc
index 739898d..f21a395 100644
--- a/google_apis/gaia/gaia_oauth_client_unittest.cc
+++ b/google_apis/gaia/gaia_oauth_client_unittest.cc
@@ -104,6 +104,7 @@ class MockOAuthFetcherFactory : public net::URLFetcherFactory,
const std::string kTestAccessToken = "1/fFAGRNJru1FTz70BzhT3Zg";
const std::string kTestRefreshToken =
"1/6BMfW9j53gdGImsixUH6kU5RsR4zwI9lUVX-tqf8JXQ";
+const std::string kTestUserEmail = "a_user@gmail.com";
const int kTestExpiresIn = 3920;
const std::string kDummyGetTokensResult =
@@ -114,6 +115,9 @@ const std::string kDummyGetTokensResult =
const std::string kDummyRefreshTokenResult =
"{\"access_token\":\"" + kTestAccessToken + "\","
"\"expires_in\":" + base::IntToString(kTestExpiresIn) + "}";
+
+const std::string kDummyUserInfoResult =
+ "{\"email\":\"" + kTestUserEmail + "\"}";
}
namespace gaia {
@@ -133,9 +137,11 @@ class MockGaiaOAuthClientDelegate : public gaia::GaiaOAuthClient::Delegate {
~MockGaiaOAuthClientDelegate() {}
MOCK_METHOD3(OnGetTokensResponse, void(const std::string& refresh_token,
- const std::string& access_token, int expires_in_seconds));
+ const std::string& access_token,
+ int expires_in_seconds));
MOCK_METHOD2(OnRefreshTokenResponse, void(const std::string& access_token,
- int expires_in_seconds));
+ int expires_in_seconds));
+ MOCK_METHOD1(OnGetUserInfoResponse, void(const std::string& user_email));
MOCK_METHOD0(OnOAuthError, void());
MOCK_METHOD1(OnNetworkError, void(int response_code));
};
@@ -243,6 +249,25 @@ TEST_F(GaiaOAuthClientTest, RefreshTokenSuccess) {
client_info.redirect_uri = "test_redirect_uri";
GaiaOAuthClient auth(kGaiaOAuth2Url,
profile_.GetRequestContext());
- auth.GetTokensFromAuthCode(client_info, "auth_code", -1, &delegate);
+ auth.RefreshToken(client_info, "refresh_token", -1, &delegate);
}
+
+TEST_F(GaiaOAuthClientTest, GetUserInfo) {
+ MockGaiaOAuthClientDelegate delegate;
+ EXPECT_CALL(delegate, OnGetUserInfoResponse(kTestUserEmail)).Times(1);
+
+ TestingProfile profile;
+
+ MockOAuthFetcherFactory factory;
+ factory.set_results(kDummyUserInfoResult);
+
+ OAuthClientInfo client_info;
+ client_info.client_id = "test_client_id";
+ client_info.client_secret = "test_client_secret";
+ client_info.redirect_uri = "test_redirect_uri";
+ GaiaOAuthClient auth(kGaiaOAuth2Url,
+ profile_.GetRequestContext());
+ auth.GetUserInfo("access_token", 1, &delegate);
+}
+
} // namespace gaia