OLD | NEW |
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/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
11 #include "chrome/common/net/gaia/gaia_urls.h" | 12 #include "base/values.h" |
12 #include "chrome/common/net/gaia/google_service_auth_error.h" | 13 #include "chrome/common/net/gaia/google_service_auth_error.h" |
13 #include "chrome/common/net/gaia/oauth2_access_token_consumer.h" | |
14 #include "chrome/common/net/gaia/oauth2_access_token_fetcher.h" | |
15 #include "chrome/common/net/gaia/oauth2_mint_token_consumer.h" | |
16 #include "chrome/common/net/gaia/oauth2_mint_token_fetcher.h" | |
17 #include "chrome/common/net/gaia/oauth2_mint_token_flow.h" | 14 #include "chrome/common/net/gaia/oauth2_mint_token_flow.h" |
| 15 #include "content/test/test_url_fetcher_factory.h" |
| 16 #include "net/url_request/url_request_status.h" |
18 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
20 | 19 |
| 20 using content::URLFetcher; |
| 21 using net::URLRequestStatus; |
21 using testing::_; | 22 using testing::_; |
22 using testing::Return; | 23 using testing::StrictMock; |
23 | 24 |
24 namespace { | 25 namespace { |
| 26 |
| 27 static const char kValidTokenResponse[] = |
| 28 "{" |
| 29 " \"token\": \"at1\"," |
| 30 " \"issueAdvice\": \"Auto\"" |
| 31 "}"; |
| 32 static const char kTokenResponseNoAccessToken[] = |
| 33 "{" |
| 34 " \"issueAdvice\": \"Auto\"" |
| 35 "}"; |
| 36 |
| 37 static const char kValidIssueAdviceResponse[] = |
| 38 "{" |
| 39 " \"issueAdvice\": \"consent\"," |
| 40 " \"consent\": {" |
| 41 " \"oauthClient\": {" |
| 42 " \"name\": \"Test app\"," |
| 43 " \"iconUri\": \"\"," |
| 44 " \"developerEmail\": \"munjal@chromium.org\"" |
| 45 " }," |
| 46 " \"scopes\": [" |
| 47 " {" |
| 48 " \"description\": \"Manage your calendars\"," |
| 49 " \"detail\": \"\nView and manage your calendars\n\"" |
| 50 " }," |
| 51 " {" |
| 52 " \"description\": \"Manage your documents\"," |
| 53 " \"detail\": \"\nView your documents\nUpload new documents\n\"" |
| 54 " }" |
| 55 " ]" |
| 56 " }" |
| 57 "}"; |
| 58 |
| 59 static const char kIssueAdviceResponseNoDescription[] = |
| 60 "{" |
| 61 " \"issueAdvice\": \"consent\"," |
| 62 " \"consent\": {" |
| 63 " \"oauthClient\": {" |
| 64 " \"name\": \"Test app\"," |
| 65 " \"iconUri\": \"\"," |
| 66 " \"developerEmail\": \"munjal@chromium.org\"" |
| 67 " }," |
| 68 " \"scopes\": [" |
| 69 " {" |
| 70 " \"description\": \"Manage your calendars\"," |
| 71 " \"detail\": \"\nView and manage your calendars\n\"" |
| 72 " }," |
| 73 " {" |
| 74 " \"detail\": \"\nView your documents\nUpload new documents\n\"" |
| 75 " }" |
| 76 " ]" |
| 77 " }" |
| 78 "}"; |
| 79 |
| 80 static const char kIssueAdviceResponseNoDetail[] = |
| 81 "{" |
| 82 " \"issueAdvice\": \"consent\"," |
| 83 " \"consent\": {" |
| 84 " \"oauthClient\": {" |
| 85 " \"name\": \"Test app\"," |
| 86 " \"iconUri\": \"\"," |
| 87 " \"developerEmail\": \"munjal@chromium.org\"" |
| 88 " }," |
| 89 " \"scopes\": [" |
| 90 " {" |
| 91 " \"description\": \"Manage your calendars\"," |
| 92 " \"detail\": \"\nView and manage your calendars\n\"" |
| 93 " }," |
| 94 " {" |
| 95 " \"description\": \"Manage your documents\"" |
| 96 " }" |
| 97 " ]" |
| 98 " }" |
| 99 "}"; |
| 100 |
25 std::vector<std::string> CreateTestScopes() { | 101 std::vector<std::string> CreateTestScopes() { |
26 std::vector<std::string> scopes; | 102 std::vector<std::string> scopes; |
27 scopes.push_back("scope1"); | 103 scopes.push_back("http://scope1"); |
28 scopes.push_back("scope2"); | 104 scopes.push_back("http://scope2"); |
29 return scopes; | 105 return scopes; |
30 } | 106 } |
31 } | 107 |
| 108 static IssueAdviceInfo CreateIssueAdvice() { |
| 109 IssueAdviceInfo ia; |
| 110 IssueAdviceInfoEntry e1; |
| 111 e1.description = "Manage your calendars"; |
| 112 e1.details.push_back("View and manage your calendars"); |
| 113 ia.push_back(e1); |
| 114 IssueAdviceInfoEntry e2; |
| 115 e2.description = "Manage your documents"; |
| 116 e2.details.push_back("View your documents"); |
| 117 e2.details.push_back("Upload new documents"); |
| 118 ia.push_back(e2); |
| 119 return ia; |
| 120 } |
| 121 |
| 122 } // namespace |
32 | 123 |
33 class MockDelegate : public OAuth2MintTokenFlow::Delegate { | 124 class MockDelegate : public OAuth2MintTokenFlow::Delegate { |
34 public: | 125 public: |
35 MockDelegate() {} | 126 MockDelegate() {} |
36 ~MockDelegate() {} | 127 ~MockDelegate() {} |
37 | 128 |
38 MOCK_METHOD1(OnMintTokenSuccess, void(const std::string& access_token)); | 129 MOCK_METHOD1(OnMintTokenSuccess, void(const std::string& access_token)); |
| 130 MOCK_METHOD1(OnIssueAdviceSuccess, |
| 131 void (const IssueAdviceInfo& issue_advice)); |
39 MOCK_METHOD1(OnMintTokenFailure, | 132 MOCK_METHOD1(OnMintTokenFailure, |
40 void(const GoogleServiceAuthError& error)); | 133 void(const GoogleServiceAuthError& error)); |
41 }; | 134 }; |
42 | 135 |
43 class MockOAuth2AccessTokenFetcher : public OAuth2AccessTokenFetcher { | 136 class MockMintTokenFlow : public OAuth2MintTokenFlow { |
44 public: | 137 public: |
45 MockOAuth2AccessTokenFetcher(OAuth2AccessTokenConsumer* consumer, | 138 explicit MockMintTokenFlow(MockDelegate* delegate, |
46 net::URLRequestContextGetter* getter) | 139 const OAuth2MintTokenFlow::Parameters& parameters ) |
47 : OAuth2AccessTokenFetcher(consumer, getter) {} | 140 : OAuth2MintTokenFlow(NULL, delegate, parameters) {} |
48 ~MockOAuth2AccessTokenFetcher() {} | 141 ~MockMintTokenFlow() {} |
49 | |
50 MOCK_METHOD4(Start, | |
51 void (const std::string& client_id, | |
52 const std::string& client_secret, | |
53 const std::string& refresh_token, | |
54 const std::vector<std::string>& scopes)); | |
55 }; | |
56 | |
57 class MockOAuth2MintTokenFetcher : public OAuth2MintTokenFetcher { | |
58 public: | |
59 MockOAuth2MintTokenFetcher(OAuth2MintTokenConsumer* consumer, | |
60 net::URLRequestContextGetter* getter) | |
61 : OAuth2MintTokenFetcher(consumer, getter, "test") {} | |
62 ~MockOAuth2MintTokenFetcher() {} | |
63 | |
64 MOCK_METHOD4(Start, | |
65 void (const std::string& oauth_login_access_token, | |
66 const std::string& client_id, | |
67 const std::vector<std::string>& scopes, | |
68 const std::string& origin)); | |
69 }; | |
70 | |
71 class MockOAuth2MintTokenFlow : public OAuth2MintTokenFlow { | |
72 public: | |
73 explicit MockOAuth2MintTokenFlow(MockDelegate* delegate) | |
74 : OAuth2MintTokenFlow(NULL, delegate) {} | |
75 ~MockOAuth2MintTokenFlow() {} | |
76 | 142 |
77 MOCK_METHOD0(CreateAccessTokenFetcher, OAuth2AccessTokenFetcher*()); | 143 MOCK_METHOD0(CreateAccessTokenFetcher, OAuth2AccessTokenFetcher*()); |
78 MOCK_METHOD0(CreateMintTokenFetcher, OAuth2MintTokenFetcher*()); | 144 MOCK_METHOD0(CreateMintTokenFetcher, OAuth2MintTokenFetcher*()); |
79 }; | 145 }; |
80 | 146 |
81 class OAuth2MintTokenFlowTest : public testing::Test { | 147 class OAuth2MintTokenFlowTest : public testing::Test { |
82 public: | 148 public: |
83 OAuth2MintTokenFlowTest() { | 149 OAuth2MintTokenFlowTest() {} |
84 flow_.reset(new MockOAuth2MintTokenFlow(&delegate_)); | |
85 access_token_fetcher_.reset(new MockOAuth2AccessTokenFetcher( | |
86 flow_.get(), NULL)); | |
87 mint_token_fetcher_.reset(new MockOAuth2MintTokenFetcher( | |
88 flow_.get(), NULL)); | |
89 } | |
90 | |
91 virtual ~OAuth2MintTokenFlowTest() { } | 150 virtual ~OAuth2MintTokenFlowTest() { } |
92 | 151 |
93 protected: | 152 protected: |
94 void SetAccessTokenFetcherFailure(const std::string& rt, | 153 void CreateFlow(OAuth2MintTokenFlow::Mode mode) { |
95 const GoogleServiceAuthError& error) { | 154 return CreateFlow(&delegate_, mode); |
96 EXPECT_CALL(*access_token_fetcher_, | 155 } |
97 Start(GaiaUrls::GetInstance()->oauth2_chrome_client_id(), | 156 |
98 GaiaUrls::GetInstance()->oauth2_chrome_client_secret(), | 157 void CreateFlow(MockDelegate* delegate, |
99 rt, std::vector<std::string>())) | 158 OAuth2MintTokenFlow::Mode mode) { |
100 .Times(1); | 159 std::string rt = "refresh_token"; |
101 EXPECT_CALL(*flow_, CreateAccessTokenFetcher()) | 160 std::string ext_id = "ext1"; |
102 .WillOnce(Return(access_token_fetcher_.release())); | 161 std::string client_id = "client1"; |
103 EXPECT_CALL(delegate_, OnMintTokenFailure(error)) | 162 std::vector<std::string> scopes(CreateTestScopes()); |
104 .Times(1); | 163 flow_.reset(new MockMintTokenFlow( |
105 } | 164 delegate, |
106 | 165 OAuth2MintTokenFlow::Parameters(rt, ext_id, client_id, scopes, mode))); |
107 void SetAccessTokenFetcherSuccess(const std::string& rt) { | 166 } |
108 EXPECT_CALL(*access_token_fetcher_, | 167 |
109 Start(GaiaUrls::GetInstance()->oauth2_chrome_client_id(), | 168 // Helper to parse the given string to DictionaryValue. |
110 GaiaUrls::GetInstance()->oauth2_chrome_client_secret(), | 169 static base::DictionaryValue* ParseJson(const std::string& str) { |
111 rt, std::vector<std::string>())) | 170 base::JSONReader reader; |
112 .Times(1); | 171 scoped_ptr<Value> value(reader.Read(str, false)); |
113 EXPECT_CALL(*flow_, CreateAccessTokenFetcher()) | 172 EXPECT_TRUE(value.get()); |
114 .WillOnce(Return(access_token_fetcher_.release())); | 173 EXPECT_EQ(Value::TYPE_DICTIONARY, value->GetType()); |
115 } | 174 return static_cast<base::DictionaryValue*>(value.release()); |
116 | 175 } |
117 void SetMintTokenFetcherFailure(const std::string& rt, | 176 |
118 const std::string& ext_id, | 177 scoped_ptr<MockMintTokenFlow> flow_; |
119 const std::string& client_id, | 178 StrictMock<MockDelegate> delegate_; |
120 const std::vector<std::string>& scopes, | |
121 const GoogleServiceAuthError& error) { | |
122 EXPECT_CALL(*mint_token_fetcher_, | |
123 Start(rt, client_id, scopes, ext_id)) | |
124 .Times(1); | |
125 EXPECT_CALL(*flow_, CreateMintTokenFetcher()) | |
126 .WillOnce(Return(mint_token_fetcher_.release())); | |
127 EXPECT_CALL(delegate_, OnMintTokenFailure(error)) | |
128 .Times(1); | |
129 } | |
130 | |
131 void SetMintTokenFetcherSuccess(const std::string& rt, | |
132 const std::string& ext_id, | |
133 const std::string& client_id, | |
134 const std::vector<std::string>& scopes, | |
135 const std::string& at) { | |
136 EXPECT_CALL(*mint_token_fetcher_, | |
137 Start(rt, client_id, scopes, ext_id)) | |
138 .Times(1); | |
139 EXPECT_CALL(*flow_, CreateMintTokenFetcher()) | |
140 .WillOnce(Return(mint_token_fetcher_.release())); | |
141 EXPECT_CALL(delegate_, OnMintTokenSuccess(at)) | |
142 .Times(1); | |
143 } | |
144 | |
145 scoped_ptr<MockOAuth2MintTokenFlow> flow_; | |
146 scoped_ptr<MockOAuth2AccessTokenFetcher> access_token_fetcher_; | |
147 scoped_ptr<MockOAuth2MintTokenFetcher> mint_token_fetcher_; | |
148 MockDelegate delegate_; | |
149 }; | 179 }; |
150 | 180 |
151 TEST_F(OAuth2MintTokenFlowTest, LoginAccessTokenFailure) { | 181 TEST_F(OAuth2MintTokenFlowTest, CreateApiCallBody) { |
152 std::string rt = "refresh_token"; | 182 { // Issue advice mode. |
153 std::string ext_id = "ext1"; | 183 CreateFlow(OAuth2MintTokenFlow::MODE_ISSUE_ADVICE); |
154 std::string client_id = "client1"; | 184 std::string body = flow_->CreateApiCallBody(); |
155 std::vector<std::string> scopes(CreateTestScopes()); | 185 std::string expected_body( |
156 std::string at = "access_token"; | 186 "force=false" |
157 GoogleServiceAuthError err(GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | 187 "&response_type=none" |
158 | 188 "&scope=http://scope1+http://scope2" |
159 SetAccessTokenFetcherFailure(rt, err); | 189 "&client_id=client1" |
160 | 190 "&origin=ext1"); |
161 flow_->Start(rt, ext_id, client_id, scopes); | 191 EXPECT_EQ(expected_body, body); |
162 flow_->OnGetTokenFailure(err); | 192 } |
163 } | 193 { // Record grant mode. |
164 | 194 CreateFlow(OAuth2MintTokenFlow::MODE_RECORD_GRANT); |
165 TEST_F(OAuth2MintTokenFlowTest, MintAccessTokenFailure) { | 195 std::string body = flow_->CreateApiCallBody(); |
166 std::string rt = "refresh_token"; | 196 std::string expected_body( |
167 std::string ext_id = "ext1"; | 197 "force=true" |
168 std::string client_id = "client1"; | 198 "&response_type=none" |
169 std::vector<std::string> scopes(CreateTestScopes()); | 199 "&scope=http://scope1+http://scope2" |
170 std::string at = "access_token"; | 200 "&client_id=client1" |
171 GoogleServiceAuthError err(GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | 201 "&origin=ext1"); |
172 | 202 EXPECT_EQ(expected_body, body); |
173 SetAccessTokenFetcherSuccess(rt); | 203 } |
174 SetMintTokenFetcherFailure(at, ext_id, client_id, scopes, err); | 204 { // Mint token no force mode. |
175 | 205 CreateFlow(OAuth2MintTokenFlow::MODE_MINT_TOKEN_NO_FORCE); |
176 flow_->Start(rt, ext_id, client_id, scopes); | 206 std::string body = flow_->CreateApiCallBody(); |
177 flow_->OnGetTokenSuccess(at); | 207 std::string expected_body( |
178 flow_->OnMintTokenFailure(err); | 208 "force=false" |
179 } | 209 "&response_type=token" |
180 | 210 "&scope=http://scope1+http://scope2" |
181 TEST_F(OAuth2MintTokenFlowTest, Success) { | 211 "&client_id=client1" |
182 std::string rt = "refresh_token"; | 212 "&origin=ext1"); |
183 std::string ext_id = "ext1"; | 213 EXPECT_EQ(expected_body, body); |
184 std::string client_id = "client1"; | 214 } |
185 std::vector<std::string> scopes(CreateTestScopes()); | 215 { // Mint token force mode. |
186 std::string at = "access_token"; | 216 CreateFlow(OAuth2MintTokenFlow::MODE_MINT_TOKEN_FORCE); |
187 std::string result = "app_access_token"; | 217 std::string body = flow_->CreateApiCallBody(); |
188 | 218 std::string expected_body( |
189 SetAccessTokenFetcherSuccess(rt); | 219 "force=true" |
190 SetMintTokenFetcherSuccess(at, ext_id, client_id, scopes, result); | 220 "&response_type=token" |
191 | 221 "&scope=http://scope1+http://scope2" |
192 flow_->Start(rt, ext_id, client_id, scopes); | 222 "&client_id=client1" |
193 flow_->OnGetTokenSuccess(at); | 223 "&origin=ext1"); |
194 flow_->OnMintTokenSuccess(result); | 224 EXPECT_EQ(expected_body, body); |
195 } | 225 } |
| 226 } |
| 227 |
| 228 TEST_F(OAuth2MintTokenFlowTest, ParseMintTokenResponse) { |
| 229 { // Access token missing. |
| 230 scoped_ptr<base::DictionaryValue> json( |
| 231 ParseJson(kTokenResponseNoAccessToken)); |
| 232 std::string at; |
| 233 EXPECT_FALSE(OAuth2MintTokenFlow::ParseMintTokenResponse(json.get(), &at)); |
| 234 EXPECT_TRUE(at.empty()); |
| 235 } |
| 236 { // All good. |
| 237 scoped_ptr<base::DictionaryValue> json(ParseJson(kValidTokenResponse)); |
| 238 std::string at; |
| 239 EXPECT_TRUE(OAuth2MintTokenFlow::ParseMintTokenResponse(json.get(), &at)); |
| 240 EXPECT_EQ("at1", at); |
| 241 } |
| 242 } |
| 243 |
| 244 TEST_F(OAuth2MintTokenFlowTest, ParseIssueAdviceResponse) { |
| 245 { // Description missing. |
| 246 scoped_ptr<base::DictionaryValue> json( |
| 247 ParseJson(kIssueAdviceResponseNoDescription)); |
| 248 IssueAdviceInfo ia; |
| 249 EXPECT_FALSE(OAuth2MintTokenFlow::ParseIssueAdviceResponse( |
| 250 json.get(), &ia)); |
| 251 EXPECT_TRUE(ia.empty()); |
| 252 } |
| 253 { // Detail missing. |
| 254 scoped_ptr<base::DictionaryValue> json( |
| 255 ParseJson(kIssueAdviceResponseNoDetail)); |
| 256 IssueAdviceInfo ia; |
| 257 EXPECT_FALSE(OAuth2MintTokenFlow::ParseIssueAdviceResponse( |
| 258 json.get(), &ia)); |
| 259 EXPECT_TRUE(ia.empty()); |
| 260 } |
| 261 { // All good. |
| 262 scoped_ptr<base::DictionaryValue> json( |
| 263 ParseJson(kValidIssueAdviceResponse)); |
| 264 IssueAdviceInfo ia; |
| 265 EXPECT_TRUE(OAuth2MintTokenFlow::ParseIssueAdviceResponse( |
| 266 json.get(), &ia)); |
| 267 IssueAdviceInfo ia_expected(CreateIssueAdvice()); |
| 268 EXPECT_EQ(ia_expected, ia); |
| 269 } |
| 270 } |
| 271 |
| 272 TEST_F(OAuth2MintTokenFlowTest, ProcessApiCallSuccess) { |
| 273 { // No body. |
| 274 TestURLFetcher url_fetcher(1, GURL("http://www.google.com"), NULL); |
| 275 url_fetcher.SetResponseString(""); |
| 276 CreateFlow(OAuth2MintTokenFlow::MODE_MINT_TOKEN_NO_FORCE); |
| 277 EXPECT_CALL(delegate_, OnMintTokenFailure(_)); |
| 278 flow_->ProcessApiCallSuccess(&url_fetcher); |
| 279 } |
| 280 { // Bad json. |
| 281 TestURLFetcher url_fetcher(1, GURL("http://www.google.com"), NULL); |
| 282 url_fetcher.SetResponseString("foo"); |
| 283 CreateFlow(OAuth2MintTokenFlow::MODE_MINT_TOKEN_NO_FORCE); |
| 284 EXPECT_CALL(delegate_, OnMintTokenFailure(_)); |
| 285 flow_->ProcessApiCallSuccess(&url_fetcher); |
| 286 } |
| 287 { // Valid json: no access token. |
| 288 TestURLFetcher url_fetcher(1, GURL("http://www.google.com"), NULL); |
| 289 url_fetcher.SetResponseString(kTokenResponseNoAccessToken); |
| 290 CreateFlow(OAuth2MintTokenFlow::MODE_MINT_TOKEN_NO_FORCE); |
| 291 EXPECT_CALL(delegate_, OnMintTokenFailure(_)); |
| 292 flow_->ProcessApiCallSuccess(&url_fetcher); |
| 293 } |
| 294 { // Valid json: good token response. |
| 295 TestURLFetcher url_fetcher(1, GURL("http://www.google.com"), NULL); |
| 296 url_fetcher.SetResponseString(kValidTokenResponse); |
| 297 CreateFlow(OAuth2MintTokenFlow::MODE_MINT_TOKEN_NO_FORCE); |
| 298 EXPECT_CALL(delegate_, OnMintTokenSuccess("at1")); |
| 299 flow_->ProcessApiCallSuccess(&url_fetcher); |
| 300 } |
| 301 { // Valid json: no description. |
| 302 TestURLFetcher url_fetcher(1, GURL("http://www.google.com"), NULL); |
| 303 url_fetcher.SetResponseString(kIssueAdviceResponseNoDescription); |
| 304 CreateFlow(OAuth2MintTokenFlow::MODE_ISSUE_ADVICE); |
| 305 EXPECT_CALL(delegate_, OnMintTokenFailure(_)); |
| 306 flow_->ProcessApiCallSuccess(&url_fetcher); |
| 307 } |
| 308 { // Valid json: no detail. |
| 309 TestURLFetcher url_fetcher(1, GURL("http://www.google.com"), NULL); |
| 310 url_fetcher.SetResponseString(kIssueAdviceResponseNoDetail); |
| 311 CreateFlow(OAuth2MintTokenFlow::MODE_ISSUE_ADVICE); |
| 312 EXPECT_CALL(delegate_, OnMintTokenFailure(_)); |
| 313 flow_->ProcessApiCallSuccess(&url_fetcher); |
| 314 } |
| 315 { // Valid json: good issue advice response. |
| 316 TestURLFetcher url_fetcher(1, GURL("http://www.google.com"), NULL); |
| 317 url_fetcher.SetResponseString(kValidIssueAdviceResponse); |
| 318 CreateFlow(OAuth2MintTokenFlow::MODE_ISSUE_ADVICE); |
| 319 IssueAdviceInfo ia(CreateIssueAdvice()); |
| 320 EXPECT_CALL(delegate_, OnIssueAdviceSuccess(ia)); |
| 321 flow_->ProcessApiCallSuccess(&url_fetcher); |
| 322 } |
| 323 } |
| 324 |
| 325 TEST_F(OAuth2MintTokenFlowTest, ProcessApiCallFailure) { |
| 326 { // Null delegate should work fine. |
| 327 TestURLFetcher url_fetcher(1, GURL("http://www.google.com"), NULL); |
| 328 url_fetcher.set_status(URLRequestStatus(URLRequestStatus::FAILED, 101)); |
| 329 CreateFlow(NULL, OAuth2MintTokenFlow::MODE_MINT_TOKEN_NO_FORCE); |
| 330 flow_->ProcessApiCallFailure(&url_fetcher); |
| 331 } |
| 332 |
| 333 { // Non-null delegate. |
| 334 TestURLFetcher url_fetcher(1, GURL("http://www.google.com"), NULL); |
| 335 url_fetcher.set_status(URLRequestStatus(URLRequestStatus::FAILED, 101)); |
| 336 CreateFlow(OAuth2MintTokenFlow::MODE_MINT_TOKEN_NO_FORCE); |
| 337 EXPECT_CALL(delegate_, OnMintTokenFailure(_)); |
| 338 flow_->ProcessApiCallFailure(&url_fetcher); |
| 339 } |
| 340 } |
| 341 |
| 342 TEST_F(OAuth2MintTokenFlowTest, ProcessMintAccessTokenFailure) { |
| 343 { // Null delegate should work fine. |
| 344 GoogleServiceAuthError error( |
| 345 GoogleServiceAuthError::FromConnectionError(101)); |
| 346 CreateFlow(NULL, OAuth2MintTokenFlow::MODE_MINT_TOKEN_NO_FORCE); |
| 347 flow_->ProcessMintAccessTokenFailure(error); |
| 348 } |
| 349 |
| 350 { // Non-null delegate. |
| 351 GoogleServiceAuthError error( |
| 352 GoogleServiceAuthError::FromConnectionError(101)); |
| 353 CreateFlow(OAuth2MintTokenFlow::MODE_MINT_TOKEN_NO_FORCE); |
| 354 EXPECT_CALL(delegate_, OnMintTokenFailure(error)); |
| 355 flow_->ProcessMintAccessTokenFailure(error); |
| 356 } |
| 357 } |
OLD | NEW |