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

Unified Diff: chrome/common/net/gaia/oauth2_access_token_fetcher_unittest.cc

Issue 8728038: Allow passing in a list of scopes to the access token fetcher class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month 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
« no previous file with comments | « chrome/common/net/gaia/oauth2_access_token_fetcher.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/net/gaia/oauth2_access_token_fetcher_unittest.cc
===================================================================
--- chrome/common/net/gaia/oauth2_access_token_fetcher_unittest.cc (revision 112048)
+++ chrome/common/net/gaia/oauth2_access_token_fetcher_unittest.cc (working copy)
@@ -35,6 +35,8 @@
using testing::Return;
namespace {
+typedef std::vector<std::string> ScopeList;
+
static const char kValidTokenResponse[] =
"{"
" \"access_token\": \"at1\","
@@ -78,7 +80,7 @@
public:
OAuth2AccessTokenFetcherTest()
: ui_thread_(BrowserThread::UI, &message_loop_),
- fetcher_(&consumer_, profile_.GetRequestContext(), "test") {
+ fetcher_(&consumer_, profile_.GetRequestContext()) {
}
virtual ~OAuth2AccessTokenFetcherTest() { }
@@ -114,14 +116,14 @@
TEST_F(OAuth2AccessTokenFetcherTest, GetAccessTokenRequestFailure) {
TestURLFetcher* url_fetcher = SetupGetAccessToken(false, 0, "");
EXPECT_CALL(consumer_, OnGetTokenFailure(_)).Times(1);
- fetcher_.Start("client_id", "client_secret", "refresh_token");
+ fetcher_.Start("client_id", "client_secret", "refresh_token", ScopeList());
fetcher_.OnURLFetchComplete(url_fetcher);
}
TEST_F(OAuth2AccessTokenFetcherTest, GetAccessTokenResponseCodeFailure) {
TestURLFetcher* url_fetcher = SetupGetAccessToken(true, RC_FORBIDDEN, "");
EXPECT_CALL(consumer_, OnGetTokenFailure(_)).Times(1);
- fetcher_.Start("client_id", "client_secret", "refresh_token");
+ fetcher_.Start("client_id", "client_secret", "refresh_token", ScopeList());
fetcher_.OnURLFetchComplete(url_fetcher);
}
@@ -129,10 +131,52 @@
TestURLFetcher* url_fetcher = SetupGetAccessToken(
true, RC_REQUEST_OK, kValidTokenResponse);
EXPECT_CALL(consumer_, OnGetTokenSuccess("at1")).Times(1);
- fetcher_.Start("client_id", "client_secret", "refresh_token");
+ fetcher_.Start("client_id", "client_secret", "refresh_token", ScopeList());
fetcher_.OnURLFetchComplete(url_fetcher);
}
+TEST_F(OAuth2AccessTokenFetcherTest, 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()));
+ }
+
+ { // One scope.
+ std::string body =
+ "client_id=cid1&"
+ "client_secret=cs1&"
+ "grant_type=refresh_token&"
+ "refresh_token=rt1&"
+ "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));
+ }
+
+ { // Multiple scopes.
+ std::string body =
+ "client_id=cid1&"
+ "client_secret=cs1&"
+ "grant_type=refresh_token&"
+ "refresh_token=rt1&"
+ "scope=https://www.googleapis.com/foo,"
+ "https://www.googleapis.com/bar,"
+ "https://www.googleapis.com/baz";
+ ScopeList scopes;
+ 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));
+ }
+}
+
TEST_F(OAuth2AccessTokenFetcherTest, ParseGetAccessTokenResponse) {
{ // No body.
TestURLFetcher url_fetcher(0, GURL("www.google.com"), NULL);
« no previous file with comments | « chrome/common/net/gaia/oauth2_access_token_fetcher.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698