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

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

Issue 14329014: Identity API: Add token cache and identity.invalidateAuthToken. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rounding third rebase Created 7 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « google_apis/gaia/oauth2_mint_token_flow.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 OAuth2MintTokenFlow. 5 // A complete set of unit tests for OAuth2MintTokenFlow.
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
(...skipping 11 matching lines...) Expand all
22 using net::URLFetcher; 22 using net::URLFetcher;
23 using net::URLRequestStatus; 23 using net::URLRequestStatus;
24 using testing::_; 24 using testing::_;
25 using testing::StrictMock; 25 using testing::StrictMock;
26 26
27 namespace { 27 namespace {
28 28
29 static const char kValidTokenResponse[] = 29 static const char kValidTokenResponse[] =
30 "{" 30 "{"
31 " \"token\": \"at1\"," 31 " \"token\": \"at1\","
32 " \"issueAdvice\": \"Auto\"" 32 " \"issueAdvice\": \"Auto\","
33 " \"expiresIn\": \"3600\""
33 "}"; 34 "}";
34 static const char kTokenResponseNoAccessToken[] = 35 static const char kTokenResponseNoAccessToken[] =
35 "{" 36 "{"
36 " \"issueAdvice\": \"Auto\"" 37 " \"issueAdvice\": \"Auto\""
37 "}"; 38 "}";
38 39
39 static const char kValidIssueAdviceResponse[] = 40 static const char kValidIssueAdviceResponse[] =
40 "{" 41 "{"
41 " \"issueAdvice\": \"consent\"," 42 " \"issueAdvice\": \"consent\","
42 " \"consent\": {" 43 " \"consent\": {"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 e2.details.push_back(ASCIIToUTF16("Upload new documents")); 120 e2.details.push_back(ASCIIToUTF16("Upload new documents"));
120 ia.push_back(e2); 121 ia.push_back(e2);
121 return ia; 122 return ia;
122 } 123 }
123 124
124 class MockDelegate : public OAuth2MintTokenFlow::Delegate { 125 class MockDelegate : public OAuth2MintTokenFlow::Delegate {
125 public: 126 public:
126 MockDelegate() {} 127 MockDelegate() {}
127 ~MockDelegate() {} 128 ~MockDelegate() {}
128 129
129 MOCK_METHOD1(OnMintTokenSuccess, void(const std::string& access_token)); 130 MOCK_METHOD2(OnMintTokenSuccess, void(const std::string& access_token,
131 int time_to_live));
130 MOCK_METHOD1(OnIssueAdviceSuccess, 132 MOCK_METHOD1(OnIssueAdviceSuccess,
131 void (const IssueAdviceInfo& issue_advice)); 133 void (const IssueAdviceInfo& issue_advice));
132 MOCK_METHOD1(OnMintTokenFailure, 134 MOCK_METHOD1(OnMintTokenFailure,
133 void(const GoogleServiceAuthError& error)); 135 void(const GoogleServiceAuthError& error));
134 }; 136 };
135 137
136 class MockMintTokenFlow : public OAuth2MintTokenFlow { 138 class MockMintTokenFlow : public OAuth2MintTokenFlow {
137 public: 139 public:
138 explicit MockMintTokenFlow(MockDelegate* delegate, 140 explicit MockMintTokenFlow(MockDelegate* delegate,
139 const OAuth2MintTokenFlow::Parameters& parameters ) 141 const OAuth2MintTokenFlow::Parameters& parameters )
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 "&origin=ext1"); 225 "&origin=ext1");
224 EXPECT_EQ(expected_body, body); 226 EXPECT_EQ(expected_body, body);
225 } 227 }
226 } 228 }
227 229
228 TEST_F(OAuth2MintTokenFlowTest, ParseMintTokenResponse) { 230 TEST_F(OAuth2MintTokenFlowTest, ParseMintTokenResponse) {
229 { // Access token missing. 231 { // Access token missing.
230 scoped_ptr<base::DictionaryValue> json( 232 scoped_ptr<base::DictionaryValue> json(
231 ParseJson(kTokenResponseNoAccessToken)); 233 ParseJson(kTokenResponseNoAccessToken));
232 std::string at; 234 std::string at;
233 EXPECT_FALSE(OAuth2MintTokenFlow::ParseMintTokenResponse(json.get(), &at)); 235 int ttl;
236 EXPECT_FALSE(OAuth2MintTokenFlow::ParseMintTokenResponse(json.get(), &at,
237 &ttl));
234 EXPECT_TRUE(at.empty()); 238 EXPECT_TRUE(at.empty());
235 } 239 }
236 { // All good. 240 { // All good.
237 scoped_ptr<base::DictionaryValue> json(ParseJson(kValidTokenResponse)); 241 scoped_ptr<base::DictionaryValue> json(ParseJson(kValidTokenResponse));
238 std::string at; 242 std::string at;
239 EXPECT_TRUE(OAuth2MintTokenFlow::ParseMintTokenResponse(json.get(), &at)); 243 int ttl;
244 EXPECT_TRUE(OAuth2MintTokenFlow::ParseMintTokenResponse(json.get(), &at,
245 &ttl));
240 EXPECT_EQ("at1", at); 246 EXPECT_EQ("at1", at);
247 EXPECT_EQ(3600, ttl);
241 } 248 }
242 } 249 }
243 250
244 TEST_F(OAuth2MintTokenFlowTest, ParseIssueAdviceResponse) { 251 TEST_F(OAuth2MintTokenFlowTest, ParseIssueAdviceResponse) {
245 { // Description missing. 252 { // Description missing.
246 scoped_ptr<base::DictionaryValue> json( 253 scoped_ptr<base::DictionaryValue> json(
247 ParseJson(kIssueAdviceResponseNoDescription)); 254 ParseJson(kIssueAdviceResponseNoDescription));
248 IssueAdviceInfo ia; 255 IssueAdviceInfo ia;
249 EXPECT_FALSE(OAuth2MintTokenFlow::ParseIssueAdviceResponse( 256 EXPECT_FALSE(OAuth2MintTokenFlow::ParseIssueAdviceResponse(
250 json.get(), &ia)); 257 json.get(), &ia));
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 TestURLFetcher url_fetcher(1, GURL("http://www.google.com"), NULL); 295 TestURLFetcher url_fetcher(1, GURL("http://www.google.com"), NULL);
289 url_fetcher.SetResponseString(kTokenResponseNoAccessToken); 296 url_fetcher.SetResponseString(kTokenResponseNoAccessToken);
290 CreateFlow(OAuth2MintTokenFlow::MODE_MINT_TOKEN_NO_FORCE); 297 CreateFlow(OAuth2MintTokenFlow::MODE_MINT_TOKEN_NO_FORCE);
291 EXPECT_CALL(delegate_, OnMintTokenFailure(_)); 298 EXPECT_CALL(delegate_, OnMintTokenFailure(_));
292 flow_->ProcessApiCallSuccess(&url_fetcher); 299 flow_->ProcessApiCallSuccess(&url_fetcher);
293 } 300 }
294 { // Valid json: good token response. 301 { // Valid json: good token response.
295 TestURLFetcher url_fetcher(1, GURL("http://www.google.com"), NULL); 302 TestURLFetcher url_fetcher(1, GURL("http://www.google.com"), NULL);
296 url_fetcher.SetResponseString(kValidTokenResponse); 303 url_fetcher.SetResponseString(kValidTokenResponse);
297 CreateFlow(OAuth2MintTokenFlow::MODE_MINT_TOKEN_NO_FORCE); 304 CreateFlow(OAuth2MintTokenFlow::MODE_MINT_TOKEN_NO_FORCE);
298 EXPECT_CALL(delegate_, OnMintTokenSuccess("at1")); 305 EXPECT_CALL(delegate_, OnMintTokenSuccess("at1", 3600));
299 flow_->ProcessApiCallSuccess(&url_fetcher); 306 flow_->ProcessApiCallSuccess(&url_fetcher);
300 } 307 }
301 { // Valid json: no description. 308 { // Valid json: no description.
302 TestURLFetcher url_fetcher(1, GURL("http://www.google.com"), NULL); 309 TestURLFetcher url_fetcher(1, GURL("http://www.google.com"), NULL);
303 url_fetcher.SetResponseString(kIssueAdviceResponseNoDescription); 310 url_fetcher.SetResponseString(kIssueAdviceResponseNoDescription);
304 CreateFlow(OAuth2MintTokenFlow::MODE_ISSUE_ADVICE); 311 CreateFlow(OAuth2MintTokenFlow::MODE_ISSUE_ADVICE);
305 EXPECT_CALL(delegate_, OnMintTokenFailure(_)); 312 EXPECT_CALL(delegate_, OnMintTokenFailure(_));
306 flow_->ProcessApiCallSuccess(&url_fetcher); 313 flow_->ProcessApiCallSuccess(&url_fetcher);
307 } 314 }
308 { // Valid json: no detail. 315 { // Valid json: no detail.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 } 355 }
349 356
350 { // Non-null delegate. 357 { // Non-null delegate.
351 GoogleServiceAuthError error( 358 GoogleServiceAuthError error(
352 GoogleServiceAuthError::FromConnectionError(101)); 359 GoogleServiceAuthError::FromConnectionError(101));
353 CreateFlow(OAuth2MintTokenFlow::MODE_MINT_TOKEN_NO_FORCE); 360 CreateFlow(OAuth2MintTokenFlow::MODE_MINT_TOKEN_NO_FORCE);
354 EXPECT_CALL(delegate_, OnMintTokenFailure(error)); 361 EXPECT_CALL(delegate_, OnMintTokenFailure(error));
355 flow_->ProcessMintAccessTokenFailure(error); 362 flow_->ProcessMintAccessTokenFailure(error);
356 } 363 }
357 } 364 }
OLDNEW
« no previous file with comments | « google_apis/gaia/oauth2_mint_token_flow.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698