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 #include "base/string_util.h" | 5 #include "base/string_util.h" |
6 #include "base/stringprintf.h" | 6 #include "base/stringprintf.h" |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "chrome/browser/extensions/api/identity/identity_api.h" | 8 #include "chrome/browser/extensions/api/identity/identity_api.h" |
9 #include "chrome/browser/extensions/extension_apitest.h" | 9 #include "chrome/browser/extensions/extension_apitest.h" |
10 #include "chrome/browser/extensions/extension_browsertest.h" | 10 #include "chrome/browser/extensions/extension_browsertest.h" |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 | 186 |
187 ProfileKeyedService* IdentityAPITestFactory(content::BrowserContext* profile) { | 187 ProfileKeyedService* IdentityAPITestFactory(content::BrowserContext* profile) { |
188 return new IdentityAPI(static_cast<Profile*>(profile)); | 188 return new IdentityAPI(static_cast<Profile*>(profile)); |
189 } | 189 } |
190 | 190 |
191 } // namespace | 191 } // namespace |
192 | 192 |
193 class MockGetAuthTokenFunction : public IdentityGetAuthTokenFunction { | 193 class MockGetAuthTokenFunction : public IdentityGetAuthTokenFunction { |
194 public: | 194 public: |
195 MockGetAuthTokenFunction() : login_ui_result_(true), | 195 MockGetAuthTokenFunction() : login_ui_result_(true), |
196 install_ui_result_(false), | 196 scope_ui_result_(true), |
197 login_ui_shown_(false), | 197 login_ui_shown_(false), |
198 install_ui_shown_(false) { | 198 scope_ui_shown_(false) { |
199 } | 199 } |
200 | 200 |
201 void set_login_ui_result(bool result) { | 201 void set_login_ui_result(bool result) { |
202 login_ui_result_ = result; | 202 login_ui_result_ = result; |
203 } | 203 } |
204 | 204 |
205 void set_install_ui_result(bool result) { | 205 void set_scope_ui_failure(GaiaWebAuthFlow::Failure failure) { |
206 install_ui_result_ = result; | 206 scope_ui_result_ = false; |
| 207 scope_ui_failure_ = failure; |
| 208 } |
| 209 |
| 210 void set_scope_ui_oauth_error(const std::string& oauth_error) { |
| 211 scope_ui_oauth_error_ = oauth_error; |
207 } | 212 } |
208 | 213 |
209 bool login_ui_shown() const { | 214 bool login_ui_shown() const { |
210 return login_ui_shown_; | 215 return login_ui_shown_; |
211 } | 216 } |
212 | 217 |
213 bool install_ui_shown() const { | 218 bool scope_ui_shown() const { |
214 return install_ui_shown_; | 219 return scope_ui_shown_; |
215 } | 220 } |
216 | 221 |
217 virtual void ShowLoginPopup() OVERRIDE { | 222 virtual void ShowLoginPopup() OVERRIDE { |
218 EXPECT_FALSE(login_ui_shown_); | 223 EXPECT_FALSE(login_ui_shown_); |
219 login_ui_shown_ = true; | 224 login_ui_shown_ = true; |
220 if (login_ui_result_) | 225 if (login_ui_result_) |
221 SigninSuccess("fake_refresh_token"); | 226 SigninSuccess("fake_refresh_token"); |
222 else | 227 else |
223 SigninFailed(); | 228 SigninFailed(); |
224 } | 229 } |
225 | 230 |
226 virtual void ShowOAuthApprovalDialog( | 231 virtual void ShowOAuthApprovalDialog( |
227 const IssueAdviceInfo& issue_advice) OVERRIDE { | 232 const IssueAdviceInfo& issue_advice) OVERRIDE { |
228 install_ui_shown_ = true; | 233 scope_ui_shown_ = true; |
229 // Call InstallUIProceed or InstallUIAbort based on the flag. | 234 |
230 if (install_ui_result_) | 235 if (scope_ui_result_) { |
231 InstallUIProceed(); | 236 if (scope_ui_oauth_error_.empty()) |
232 else | 237 OnGaiaFlowCompleted(kAccessToken, "3600", ""); |
233 InstallUIAbort(true); | 238 else |
| 239 OnGaiaFlowCompleted("", "", scope_ui_oauth_error_); |
| 240 } else if (scope_ui_failure_ == GaiaWebAuthFlow::SERVICE_AUTH_ERROR) { |
| 241 GoogleServiceAuthError error(GoogleServiceAuthError::CONNECTION_FAILED); |
| 242 OnGaiaFlowFailure(scope_ui_failure_, error); |
| 243 } else { |
| 244 GoogleServiceAuthError error(GoogleServiceAuthError::NONE); |
| 245 OnGaiaFlowFailure(scope_ui_failure_, error); |
| 246 } |
234 } | 247 } |
235 | 248 |
236 MOCK_CONST_METHOD0(HasLoginToken, bool()); | 249 MOCK_CONST_METHOD0(HasLoginToken, bool()); |
237 MOCK_METHOD1(CreateMintTokenFlow, | 250 MOCK_METHOD1(CreateMintTokenFlow, |
238 OAuth2MintTokenFlow* (OAuth2MintTokenFlow::Mode mode)); | 251 OAuth2MintTokenFlow* (OAuth2MintTokenFlow::Mode mode)); |
239 | 252 |
240 private: | 253 private: |
241 ~MockGetAuthTokenFunction() {} | 254 ~MockGetAuthTokenFunction() {} |
242 bool login_ui_result_; | 255 bool login_ui_result_; |
243 bool install_ui_result_; | 256 bool scope_ui_result_; |
| 257 GaiaWebAuthFlow::Failure scope_ui_failure_; |
| 258 std::string scope_ui_oauth_error_; |
244 bool login_ui_shown_; | 259 bool login_ui_shown_; |
245 bool install_ui_shown_; | 260 bool scope_ui_shown_; |
246 }; | 261 }; |
247 | 262 |
248 class MockQueuedMintRequest : public IdentityMintRequestQueue::Request { | 263 class MockQueuedMintRequest : public IdentityMintRequestQueue::Request { |
249 public: | 264 public: |
250 MOCK_METHOD1(StartMintToken, void(IdentityMintRequestQueue::MintType)); | 265 MOCK_METHOD1(StartMintToken, void(IdentityMintRequestQueue::MintType)); |
251 }; | 266 }; |
252 | 267 |
253 class GetAuthTokenFunctionTest : public AsyncExtensionBrowserTest { | 268 class GetAuthTokenFunctionTest : public AsyncExtensionBrowserTest { |
254 protected: | 269 protected: |
255 enum OAuth2Fields { | 270 enum OAuth2Fields { |
(...skipping 27 matching lines...) Expand all Loading... |
283 }; | 298 }; |
284 | 299 |
285 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 300 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
286 NoClientId) { | 301 NoClientId) { |
287 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 302 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
288 func->set_extension(CreateExtension(SCOPES)); | 303 func->set_extension(CreateExtension(SCOPES)); |
289 std::string error = utils::RunFunctionAndReturnError( | 304 std::string error = utils::RunFunctionAndReturnError( |
290 func.get(), "[{}]", browser()); | 305 func.get(), "[{}]", browser()); |
291 EXPECT_EQ(std::string(errors::kInvalidClientId), error); | 306 EXPECT_EQ(std::string(errors::kInvalidClientId), error); |
292 EXPECT_FALSE(func->login_ui_shown()); | 307 EXPECT_FALSE(func->login_ui_shown()); |
293 EXPECT_FALSE(func->install_ui_shown()); | 308 EXPECT_FALSE(func->scope_ui_shown()); |
294 } | 309 } |
295 | 310 |
296 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 311 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
297 NoScopes) { | 312 NoScopes) { |
298 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 313 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
299 func->set_extension(CreateExtension(CLIENT_ID)); | 314 func->set_extension(CreateExtension(CLIENT_ID)); |
300 std::string error = utils::RunFunctionAndReturnError( | 315 std::string error = utils::RunFunctionAndReturnError( |
301 func.get(), "[{}]", browser()); | 316 func.get(), "[{}]", browser()); |
302 EXPECT_EQ(std::string(errors::kInvalidScopes), error); | 317 EXPECT_EQ(std::string(errors::kInvalidScopes), error); |
303 EXPECT_FALSE(func->login_ui_shown()); | 318 EXPECT_FALSE(func->login_ui_shown()); |
304 EXPECT_FALSE(func->install_ui_shown()); | 319 EXPECT_FALSE(func->scope_ui_shown()); |
305 } | 320 } |
306 | 321 |
307 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 322 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
308 NonInteractiveNotSignedIn) { | 323 NonInteractiveNotSignedIn) { |
309 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 324 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
310 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 325 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
311 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(false)); | 326 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(false)); |
312 std::string error = utils::RunFunctionAndReturnError( | 327 std::string error = utils::RunFunctionAndReturnError( |
313 func.get(), "[{}]", browser()); | 328 func.get(), "[{}]", browser()); |
314 EXPECT_EQ(std::string(errors::kUserNotSignedIn), error); | 329 EXPECT_EQ(std::string(errors::kUserNotSignedIn), error); |
315 EXPECT_FALSE(func->login_ui_shown()); | 330 EXPECT_FALSE(func->login_ui_shown()); |
316 EXPECT_FALSE(func->install_ui_shown()); | 331 EXPECT_FALSE(func->scope_ui_shown()); |
317 } | 332 } |
318 | 333 |
319 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 334 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
320 NonInteractiveMintFailure) { | 335 NonInteractiveMintFailure) { |
321 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 336 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
322 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 337 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
323 EXPECT_CALL(*func.get(), HasLoginToken()) | 338 EXPECT_CALL(*func.get(), HasLoginToken()) |
324 .WillOnce(Return(true)); | 339 .WillOnce(Return(true)); |
325 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( | 340 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
326 TestOAuth2MintTokenFlow::MINT_TOKEN_FAILURE, func.get()); | 341 TestOAuth2MintTokenFlow::MINT_TOKEN_FAILURE, func.get()); |
327 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); | 342 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
328 std::string error = utils::RunFunctionAndReturnError( | 343 std::string error = utils::RunFunctionAndReturnError( |
329 func.get(), "[{}]", browser()); | 344 func.get(), "[{}]", browser()); |
330 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false)); | 345 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false)); |
331 EXPECT_FALSE(func->login_ui_shown()); | 346 EXPECT_FALSE(func->login_ui_shown()); |
332 EXPECT_FALSE(func->install_ui_shown()); | 347 EXPECT_FALSE(func->scope_ui_shown()); |
333 } | 348 } |
334 | 349 |
335 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 350 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
336 NonInteractiveMintAdviceSuccess) { | 351 NonInteractiveMintAdviceSuccess) { |
337 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 352 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
338 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 353 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
339 func->set_extension(extension); | 354 func->set_extension(extension); |
340 EXPECT_CALL(*func.get(), HasLoginToken()) | 355 EXPECT_CALL(*func.get(), HasLoginToken()) |
341 .WillOnce(Return(true)); | 356 .WillOnce(Return(true)); |
342 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( | 357 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
343 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); | 358 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); |
344 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); | 359 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
345 std::string error = utils::RunFunctionAndReturnError( | 360 std::string error = utils::RunFunctionAndReturnError( |
346 func.get(), "[{}]", browser()); | 361 func.get(), "[{}]", browser()); |
347 EXPECT_EQ(std::string(errors::kNoGrant), error); | 362 EXPECT_EQ(std::string(errors::kNoGrant), error); |
348 EXPECT_FALSE(func->login_ui_shown()); | 363 EXPECT_FALSE(func->login_ui_shown()); |
349 EXPECT_FALSE(func->install_ui_shown()); | 364 EXPECT_FALSE(func->scope_ui_shown()); |
350 | 365 |
351 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); | 366 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); |
352 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_ADVICE, | 367 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_ADVICE, |
353 id_api()->GetCachedToken(extension->id(), | 368 id_api()->GetCachedToken(extension->id(), |
354 oauth2_info.scopes).status()); | 369 oauth2_info.scopes).status()); |
355 } | 370 } |
356 | 371 |
357 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 372 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
358 NonInteractiveMintBadCredentials) { | 373 NonInteractiveMintBadCredentials) { |
359 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 374 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
360 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 375 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
361 EXPECT_CALL(*func.get(), HasLoginToken()) | 376 EXPECT_CALL(*func.get(), HasLoginToken()) |
362 .WillOnce(Return(true)); | 377 .WillOnce(Return(true)); |
363 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( | 378 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
364 TestOAuth2MintTokenFlow::MINT_TOKEN_BAD_CREDENTIALS, func.get()); | 379 TestOAuth2MintTokenFlow::MINT_TOKEN_BAD_CREDENTIALS, func.get()); |
365 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); | 380 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
366 std::string error = utils::RunFunctionAndReturnError( | 381 std::string error = utils::RunFunctionAndReturnError( |
367 func.get(), "[{}]", browser()); | 382 func.get(), "[{}]", browser()); |
368 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false)); | 383 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false)); |
369 EXPECT_FALSE(func->login_ui_shown()); | 384 EXPECT_FALSE(func->login_ui_shown()); |
370 EXPECT_FALSE(func->install_ui_shown()); | 385 EXPECT_FALSE(func->scope_ui_shown()); |
371 } | 386 } |
372 | 387 |
373 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 388 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
374 NonInteractiveSuccess) { | 389 NonInteractiveSuccess) { |
375 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 390 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
376 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 391 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
377 func->set_extension(extension); | 392 func->set_extension(extension); |
378 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); | 393 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); |
379 EXPECT_CALL(*func.get(), HasLoginToken()) | 394 EXPECT_CALL(*func.get(), HasLoginToken()) |
380 .WillOnce(Return(true)); | 395 .WillOnce(Return(true)); |
381 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( | 396 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
382 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get()); | 397 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get()); |
383 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); | 398 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
384 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( | 399 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( |
385 func.get(), "[{}]", browser())); | 400 func.get(), "[{}]", browser())); |
386 std::string access_token; | 401 std::string access_token; |
387 EXPECT_TRUE(value->GetAsString(&access_token)); | 402 EXPECT_TRUE(value->GetAsString(&access_token)); |
388 EXPECT_EQ(std::string(kAccessToken), access_token); | 403 EXPECT_EQ(std::string(kAccessToken), access_token); |
389 EXPECT_FALSE(func->login_ui_shown()); | 404 EXPECT_FALSE(func->login_ui_shown()); |
390 EXPECT_FALSE(func->install_ui_shown()); | 405 EXPECT_FALSE(func->scope_ui_shown()); |
391 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_TOKEN, | 406 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_TOKEN, |
392 id_api()->GetCachedToken(extension->id(), | 407 id_api()->GetCachedToken(extension->id(), |
393 oauth2_info.scopes).status()); | 408 oauth2_info.scopes).status()); |
394 } | 409 } |
395 | 410 |
396 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 411 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
397 InteractiveLoginCanceled) { | 412 InteractiveLoginCanceled) { |
398 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 413 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
399 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 414 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
400 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(false)); | 415 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(false)); |
401 func->set_login_ui_result(false); | 416 func->set_login_ui_result(false); |
402 std::string error = utils::RunFunctionAndReturnError( | 417 std::string error = utils::RunFunctionAndReturnError( |
403 func.get(), "[{\"interactive\": true}]", browser()); | 418 func.get(), "[{\"interactive\": true}]", browser()); |
404 EXPECT_EQ(std::string(errors::kUserNotSignedIn), error); | 419 EXPECT_EQ(std::string(errors::kUserNotSignedIn), error); |
405 EXPECT_TRUE(func->login_ui_shown()); | 420 EXPECT_TRUE(func->login_ui_shown()); |
406 EXPECT_FALSE(func->install_ui_shown()); | 421 EXPECT_FALSE(func->scope_ui_shown()); |
407 } | 422 } |
408 | 423 |
409 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 424 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
410 InteractiveMintBadCredentialsLoginCanceled) { | 425 InteractiveMintBadCredentialsLoginCanceled) { |
411 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 426 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
412 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 427 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
413 EXPECT_CALL(*func.get(), HasLoginToken()) | 428 EXPECT_CALL(*func.get(), HasLoginToken()) |
414 .WillOnce(Return(true)); | 429 .WillOnce(Return(true)); |
415 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( | 430 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
416 TestOAuth2MintTokenFlow::MINT_TOKEN_BAD_CREDENTIALS, func.get()); | 431 TestOAuth2MintTokenFlow::MINT_TOKEN_BAD_CREDENTIALS, func.get()); |
417 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); | 432 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
418 func->set_login_ui_result(false); | 433 func->set_login_ui_result(false); |
419 std::string error = utils::RunFunctionAndReturnError( | 434 std::string error = utils::RunFunctionAndReturnError( |
420 func.get(), "[{\"interactive\": true}]", browser()); | 435 func.get(), "[{\"interactive\": true}]", browser()); |
421 EXPECT_EQ(std::string(errors::kUserNotSignedIn), error); | 436 EXPECT_EQ(std::string(errors::kUserNotSignedIn), error); |
422 EXPECT_TRUE(func->login_ui_shown()); | 437 EXPECT_TRUE(func->login_ui_shown()); |
423 EXPECT_FALSE(func->install_ui_shown()); | 438 EXPECT_FALSE(func->scope_ui_shown()); |
424 } | 439 } |
425 | 440 |
426 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 441 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
427 InteractiveLoginSuccessNoToken) { | 442 InteractiveLoginSuccessNoToken) { |
428 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 443 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
429 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 444 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
430 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(false)); | 445 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(false)); |
431 func->set_login_ui_result(false); | 446 func->set_login_ui_result(false); |
432 std::string error = utils::RunFunctionAndReturnError( | 447 std::string error = utils::RunFunctionAndReturnError( |
433 func.get(), "[{\"interactive\": true}]", browser()); | 448 func.get(), "[{\"interactive\": true}]", browser()); |
434 EXPECT_EQ(std::string(errors::kUserNotSignedIn), error); | 449 EXPECT_EQ(std::string(errors::kUserNotSignedIn), error); |
435 EXPECT_TRUE(func->login_ui_shown()); | 450 EXPECT_TRUE(func->login_ui_shown()); |
436 EXPECT_FALSE(func->install_ui_shown()); | 451 EXPECT_FALSE(func->scope_ui_shown()); |
437 } | 452 } |
438 | 453 |
439 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 454 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
440 InteractiveLoginSuccessMintFailure) { | 455 InteractiveLoginSuccessMintFailure) { |
441 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 456 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
442 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 457 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
443 EXPECT_CALL(*func.get(), HasLoginToken()) | 458 EXPECT_CALL(*func.get(), HasLoginToken()) |
444 .WillOnce(Return(false)); | 459 .WillOnce(Return(false)); |
445 func->set_login_ui_result(true); | 460 func->set_login_ui_result(true); |
446 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( | 461 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
447 TestOAuth2MintTokenFlow::MINT_TOKEN_FAILURE, func.get()); | 462 TestOAuth2MintTokenFlow::MINT_TOKEN_FAILURE, func.get()); |
448 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); | 463 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
449 std::string error = utils::RunFunctionAndReturnError( | 464 std::string error = utils::RunFunctionAndReturnError( |
450 func.get(), "[{\"interactive\": true}]", browser()); | 465 func.get(), "[{\"interactive\": true}]", browser()); |
451 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false)); | 466 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false)); |
452 EXPECT_TRUE(func->login_ui_shown()); | 467 EXPECT_TRUE(func->login_ui_shown()); |
453 EXPECT_FALSE(func->install_ui_shown()); | 468 EXPECT_FALSE(func->scope_ui_shown()); |
454 } | 469 } |
455 | 470 |
456 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 471 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
457 InteractiveLoginSuccessMintSuccess) { | 472 InteractiveLoginSuccessMintSuccess) { |
458 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 473 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
459 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 474 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
460 EXPECT_CALL(*func.get(), HasLoginToken()) | 475 EXPECT_CALL(*func.get(), HasLoginToken()) |
461 .WillOnce(Return(false)); | 476 .WillOnce(Return(false)); |
462 func->set_login_ui_result(true); | 477 func->set_login_ui_result(true); |
463 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( | 478 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
464 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get()); | 479 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get()); |
465 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); | 480 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
466 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( | 481 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( |
467 func.get(), "[{\"interactive\": true}]", browser())); | 482 func.get(), "[{\"interactive\": true}]", browser())); |
468 std::string access_token; | 483 std::string access_token; |
469 EXPECT_TRUE(value->GetAsString(&access_token)); | 484 EXPECT_TRUE(value->GetAsString(&access_token)); |
470 EXPECT_EQ(std::string(kAccessToken), access_token); | 485 EXPECT_EQ(std::string(kAccessToken), access_token); |
471 EXPECT_TRUE(func->login_ui_shown()); | 486 EXPECT_TRUE(func->login_ui_shown()); |
472 EXPECT_FALSE(func->install_ui_shown()); | 487 EXPECT_FALSE(func->scope_ui_shown()); |
473 } | 488 } |
474 | 489 |
475 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 490 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
476 InteractiveLoginSuccessApprovalAborted) { | 491 InteractiveLoginSuccessApprovalAborted) { |
477 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 492 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
478 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 493 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
479 EXPECT_CALL(*func.get(), HasLoginToken()) | 494 EXPECT_CALL(*func.get(), HasLoginToken()) |
480 .WillOnce(Return(false)); | 495 .WillOnce(Return(false)); |
481 func->set_login_ui_result(true); | 496 func->set_login_ui_result(true); |
482 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( | 497 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
483 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); | 498 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); |
484 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); | 499 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
485 func->set_install_ui_result(false); | 500 func->set_scope_ui_failure(GaiaWebAuthFlow::WINDOW_CLOSED); |
486 std::string error = utils::RunFunctionAndReturnError( | 501 std::string error = utils::RunFunctionAndReturnError( |
487 func.get(), "[{\"interactive\": true}]", browser()); | 502 func.get(), "[{\"interactive\": true}]", browser()); |
488 EXPECT_EQ(std::string(errors::kUserRejected), error); | 503 EXPECT_EQ(std::string(errors::kUserRejected), error); |
489 EXPECT_TRUE(func->login_ui_shown()); | 504 EXPECT_TRUE(func->login_ui_shown()); |
490 EXPECT_TRUE(func->install_ui_shown()); | 505 EXPECT_TRUE(func->scope_ui_shown()); |
491 } | 506 } |
492 | 507 |
493 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 508 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
494 InteractiveLoginSuccessApprovalDoneMintFailure) { | 509 InteractiveLoginSuccessApprovalSuccess) { |
| 510 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
495 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 511 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
496 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 512 func->set_extension(extension); |
497 EXPECT_CALL(*func.get(), HasLoginToken()) | 513 EXPECT_CALL(*func.get(), HasLoginToken()) |
498 .WillOnce(Return(false)); | 514 .WillOnce(Return(false)); |
499 func->set_login_ui_result(true); | 515 func->set_login_ui_result(true); |
500 TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow( | 516 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
501 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); | 517 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); |
502 TestOAuth2MintTokenFlow* flow2 = new TestOAuth2MintTokenFlow( | |
503 TestOAuth2MintTokenFlow::MINT_TOKEN_FAILURE, func.get()); | |
504 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)) | 518 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)) |
505 .WillOnce(Return(flow1)) | 519 .WillOnce(Return(flow)); |
506 .WillOnce(Return(flow2)); | |
507 | 520 |
508 func->set_install_ui_result(true); | |
509 std::string error = utils::RunFunctionAndReturnError( | |
510 func.get(), "[{\"interactive\": true}]", browser()); | |
511 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false)); | |
512 EXPECT_TRUE(func->login_ui_shown()); | |
513 EXPECT_TRUE(func->install_ui_shown()); | |
514 } | |
515 | |
516 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | |
517 InteractiveLoginSuccessApprovalDoneMintSuccess) { | |
518 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | |
519 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | |
520 func->set_extension(extension); | |
521 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); | |
522 EXPECT_CALL(*func.get(), HasLoginToken()) | |
523 .WillOnce(Return(false)); | |
524 func->set_login_ui_result(true); | |
525 TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow( | |
526 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); | |
527 TestOAuth2MintTokenFlow* flow2 = new TestOAuth2MintTokenFlow( | |
528 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get()); | |
529 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)) | |
530 .WillOnce(Return(flow1)) | |
531 .WillOnce(Return(flow2)); | |
532 | |
533 func->set_install_ui_result(true); | |
534 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( | 521 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( |
535 func.get(), "[{\"interactive\": true}]", browser())); | 522 func.get(), "[{\"interactive\": true}]", browser())); |
536 std::string access_token; | 523 std::string access_token; |
537 EXPECT_TRUE(value->GetAsString(&access_token)); | 524 EXPECT_TRUE(value->GetAsString(&access_token)); |
538 EXPECT_EQ(std::string(kAccessToken), access_token); | 525 EXPECT_EQ(std::string(kAccessToken), access_token); |
539 EXPECT_TRUE(func->login_ui_shown()); | 526 EXPECT_TRUE(func->login_ui_shown()); |
540 EXPECT_TRUE(func->install_ui_shown()); | 527 EXPECT_TRUE(func->scope_ui_shown()); |
541 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_TOKEN, | |
542 id_api()->GetCachedToken(extension->id(), | |
543 oauth2_info.scopes).status()); | |
544 } | 528 } |
545 | 529 |
546 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 530 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
547 InteractiveApprovalAborted) { | 531 InteractiveApprovalAborted) { |
548 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 532 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
549 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 533 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
550 EXPECT_CALL(*func.get(), HasLoginToken()) | 534 EXPECT_CALL(*func.get(), HasLoginToken()) |
551 .WillOnce(Return(true)); | 535 .WillOnce(Return(true)); |
552 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( | 536 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
553 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); | 537 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); |
554 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); | 538 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
555 func->set_install_ui_result(false); | 539 func->set_scope_ui_failure(GaiaWebAuthFlow::WINDOW_CLOSED); |
556 std::string error = utils::RunFunctionAndReturnError( | 540 std::string error = utils::RunFunctionAndReturnError( |
557 func.get(), "[{\"interactive\": true}]", browser()); | 541 func.get(), "[{\"interactive\": true}]", browser()); |
558 EXPECT_EQ(std::string(errors::kUserRejected), error); | 542 EXPECT_EQ(std::string(errors::kUserRejected), error); |
559 EXPECT_FALSE(func->login_ui_shown()); | 543 EXPECT_FALSE(func->login_ui_shown()); |
560 EXPECT_TRUE(func->install_ui_shown()); | 544 EXPECT_TRUE(func->scope_ui_shown()); |
561 } | 545 } |
562 | 546 |
563 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 547 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
564 InteractiveApprovalDoneMintSuccess) { | 548 InteractiveApprovalInvalidRedirect) { |
565 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 549 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
566 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 550 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
567 EXPECT_CALL(*func.get(), HasLoginToken()) | 551 EXPECT_CALL(*func.get(), HasLoginToken()) |
568 .WillOnce(Return(true)); | 552 .WillOnce(Return(true)); |
569 TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow( | 553 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
570 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); | 554 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); |
571 TestOAuth2MintTokenFlow* flow2 = new TestOAuth2MintTokenFlow( | 555 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
572 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get()); | 556 func->set_scope_ui_failure(GaiaWebAuthFlow::INVALID_REDIRECT); |
| 557 std::string error = utils::RunFunctionAndReturnError( |
| 558 func.get(), "[{\"interactive\": true}]", browser()); |
| 559 EXPECT_EQ(std::string(errors::kInvalidRedirect), error); |
| 560 EXPECT_FALSE(func->login_ui_shown()); |
| 561 EXPECT_TRUE(func->scope_ui_shown()); |
| 562 } |
| 563 |
| 564 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
| 565 InteractiveApprovalConnectionFailure) { |
| 566 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
| 567 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
| 568 EXPECT_CALL(*func.get(), HasLoginToken()) |
| 569 .WillOnce(Return(true)); |
| 570 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
| 571 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); |
| 572 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
| 573 func->set_scope_ui_failure(GaiaWebAuthFlow::SERVICE_AUTH_ERROR); |
| 574 std::string error = utils::RunFunctionAndReturnError( |
| 575 func.get(), "[{\"interactive\": true}]", browser()); |
| 576 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false)); |
| 577 EXPECT_FALSE(func->login_ui_shown()); |
| 578 EXPECT_TRUE(func->scope_ui_shown()); |
| 579 } |
| 580 |
| 581 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
| 582 InteractiveApprovalOAuthErrors) { |
| 583 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
| 584 |
| 585 std::map<std::string, std::string> error_map; |
| 586 error_map.insert(std::make_pair("access_denied", errors::kUserRejected)); |
| 587 error_map.insert(std::make_pair("invalid_scope", errors::kInvalidScopes)); |
| 588 error_map.insert(std::make_pair( |
| 589 "unmapped_error", std::string(errors::kAuthFailure) + "unmapped_error")); |
| 590 |
| 591 for (std::map<std::string, std::string>::const_iterator |
| 592 it = error_map.begin(); |
| 593 it != error_map.end(); |
| 594 ++it) { |
| 595 scoped_refptr<MockGetAuthTokenFunction> func( |
| 596 new MockGetAuthTokenFunction()); |
| 597 func->set_extension(extension); |
| 598 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true)); |
| 599 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
| 600 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); |
| 601 ON_CALL(*func.get(), CreateMintTokenFlow(_)).WillByDefault(Return(flow)); |
| 602 func->set_scope_ui_oauth_error(it->first); |
| 603 std::string error = utils::RunFunctionAndReturnError( |
| 604 func.get(), "[{\"interactive\": true}]", browser()); |
| 605 EXPECT_EQ(it->second, error); |
| 606 EXPECT_FALSE(func->login_ui_shown()); |
| 607 EXPECT_TRUE(func->scope_ui_shown()); |
| 608 } |
| 609 } |
| 610 |
| 611 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
| 612 InteractiveApprovalSuccess) { |
| 613 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
| 614 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); |
| 615 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
| 616 func->set_extension(extension); |
| 617 EXPECT_CALL(*func.get(), HasLoginToken()) |
| 618 .WillOnce(Return(true)); |
| 619 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
| 620 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); |
573 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)) | 621 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)) |
574 .WillOnce(Return(flow1)) | 622 .WillOnce(Return(flow)); |
575 .WillOnce(Return(flow2)); | |
576 | 623 |
577 func->set_install_ui_result(true); | |
578 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( | 624 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( |
579 func.get(), "[{\"interactive\": true}]", browser())); | 625 func.get(), "[{\"interactive\": true}]", browser())); |
580 std::string access_token; | 626 std::string access_token; |
581 EXPECT_TRUE(value->GetAsString(&access_token)); | 627 EXPECT_TRUE(value->GetAsString(&access_token)); |
582 EXPECT_EQ(std::string(kAccessToken), access_token); | 628 EXPECT_EQ(std::string(kAccessToken), access_token); |
583 EXPECT_FALSE(func->login_ui_shown()); | 629 EXPECT_FALSE(func->login_ui_shown()); |
584 EXPECT_TRUE(func->install_ui_shown()); | 630 EXPECT_TRUE(func->scope_ui_shown()); |
585 } | |
586 | 631 |
587 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 632 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_TOKEN, |
588 InteractiveApprovalDoneMintBadCredentials) { | 633 id_api()->GetCachedToken(extension->id(), |
589 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 634 oauth2_info.scopes).status()); |
590 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | |
591 EXPECT_CALL(*func.get(), HasLoginToken()) | |
592 .WillOnce(Return(true)); | |
593 TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow( | |
594 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); | |
595 TestOAuth2MintTokenFlow* flow2 = new TestOAuth2MintTokenFlow( | |
596 TestOAuth2MintTokenFlow::MINT_TOKEN_BAD_CREDENTIALS, func.get()); | |
597 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)) | |
598 .WillOnce(Return(flow1)) | |
599 .WillOnce(Return(flow2)); | |
600 | |
601 func->set_install_ui_result(true); | |
602 std::string error = utils::RunFunctionAndReturnError( | |
603 func.get(), "[{\"interactive\": true}]", browser()); | |
604 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false)); | |
605 EXPECT_FALSE(func->login_ui_shown()); | |
606 EXPECT_TRUE(func->install_ui_shown()); | |
607 } | 635 } |
608 | 636 |
609 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, NoninteractiveQueue) { | 637 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, NoninteractiveQueue) { |
610 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 638 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
611 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 639 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
612 func->set_extension(extension); | 640 func->set_extension(extension); |
613 | 641 |
614 // Create a fake request to block the queue. | 642 // Create a fake request to block the queue. |
615 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); | 643 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); |
616 std::set<std::string> scopes(oauth2_info.scopes.begin(), | 644 std::set<std::string> scopes(oauth2_info.scopes.begin(), |
(...skipping 21 matching lines...) Expand all Loading... |
638 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get()); | 666 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get()); |
639 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); | 667 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
640 | 668 |
641 queue->RequestComplete(type, extension->id(), scopes, &queued_request); | 669 queue->RequestComplete(type, extension->id(), scopes, &queued_request); |
642 | 670 |
643 scoped_ptr<base::Value> value(WaitForSingleResult(func)); | 671 scoped_ptr<base::Value> value(WaitForSingleResult(func)); |
644 std::string access_token; | 672 std::string access_token; |
645 EXPECT_TRUE(value->GetAsString(&access_token)); | 673 EXPECT_TRUE(value->GetAsString(&access_token)); |
646 EXPECT_EQ(std::string(kAccessToken), access_token); | 674 EXPECT_EQ(std::string(kAccessToken), access_token); |
647 EXPECT_FALSE(func->login_ui_shown()); | 675 EXPECT_FALSE(func->login_ui_shown()); |
648 EXPECT_FALSE(func->install_ui_shown()); | 676 EXPECT_FALSE(func->scope_ui_shown()); |
649 } | 677 } |
650 | 678 |
651 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, InteractiveQueue) { | 679 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, InteractiveQueue) { |
652 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 680 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
653 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 681 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
654 func->set_extension(extension); | 682 func->set_extension(extension); |
655 | 683 |
656 // Create a fake request to block the queue. | 684 // Create a fake request to block the queue. |
657 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); | 685 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); |
658 std::set<std::string> scopes(oauth2_info.scopes.begin(), | 686 std::set<std::string> scopes(oauth2_info.scopes.begin(), |
(...skipping 11 matching lines...) Expand all Loading... |
670 | 698 |
671 // The real request will start processing, but wait in the queue behind | 699 // The real request will start processing, but wait in the queue behind |
672 // the blocker. | 700 // the blocker. |
673 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true)); | 701 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true)); |
674 TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow( | 702 TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow( |
675 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); | 703 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); |
676 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow1)); | 704 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow1)); |
677 RunFunctionAsync(func, "[{\"interactive\": true}]"); | 705 RunFunctionAsync(func, "[{\"interactive\": true}]"); |
678 // Verify that we have fetched the login token and run the first flow. | 706 // Verify that we have fetched the login token and run the first flow. |
679 testing::Mock::VerifyAndClearExpectations(func); | 707 testing::Mock::VerifyAndClearExpectations(func); |
680 EXPECT_FALSE(func->install_ui_shown()); | 708 EXPECT_FALSE(func->scope_ui_shown()); |
681 | 709 |
682 // The UI will be displayed and the second flow will be created | 710 // The UI will be displayed and a token retrieved after the first |
683 // after the first queued request clears. | 711 // queued request clears. |
684 func->set_install_ui_result(true); | |
685 TestOAuth2MintTokenFlow* flow2 = new TestOAuth2MintTokenFlow( | |
686 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get()); | |
687 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow2)); | |
688 | |
689 queue->RequestComplete(type, extension->id(), scopes, &queued_request); | 712 queue->RequestComplete(type, extension->id(), scopes, &queued_request); |
690 | 713 |
691 scoped_ptr<base::Value> value(WaitForSingleResult(func)); | 714 scoped_ptr<base::Value> value(WaitForSingleResult(func)); |
692 std::string access_token; | 715 std::string access_token; |
693 EXPECT_TRUE(value->GetAsString(&access_token)); | 716 EXPECT_TRUE(value->GetAsString(&access_token)); |
694 EXPECT_EQ(std::string(kAccessToken), access_token); | 717 EXPECT_EQ(std::string(kAccessToken), access_token); |
695 EXPECT_FALSE(func->login_ui_shown()); | 718 EXPECT_FALSE(func->login_ui_shown()); |
696 EXPECT_TRUE(func->install_ui_shown()); | 719 EXPECT_TRUE(func->scope_ui_shown()); |
697 } | 720 } |
698 | 721 |
699 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 722 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
700 InteractiveQueuedNoninteractiveFails) { | 723 InteractiveQueuedNoninteractiveFails) { |
701 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 724 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
702 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 725 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
703 func->set_extension(extension); | 726 func->set_extension(extension); |
704 | 727 |
705 // Create a fake request to block the interactive queue. | 728 // Create a fake request to block the interactive queue. |
706 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); | 729 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); |
(...skipping 10 matching lines...) Expand all Loading... |
717 EXPECT_CALL(queued_request, StartMintToken(type)).Times(1); | 740 EXPECT_CALL(queued_request, StartMintToken(type)).Times(1); |
718 queue->RequestStart(type, extension->id(), scopes, &queued_request); | 741 queue->RequestStart(type, extension->id(), scopes, &queued_request); |
719 | 742 |
720 // Non-interactive requests fail without hitting GAIA, because a | 743 // Non-interactive requests fail without hitting GAIA, because a |
721 // consent UI is known to be up. | 744 // consent UI is known to be up. |
722 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true)); | 745 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true)); |
723 std::string error = utils::RunFunctionAndReturnError( | 746 std::string error = utils::RunFunctionAndReturnError( |
724 func.get(), "[{}]", browser()); | 747 func.get(), "[{}]", browser()); |
725 EXPECT_EQ(std::string(errors::kNoGrant), error); | 748 EXPECT_EQ(std::string(errors::kNoGrant), error); |
726 EXPECT_FALSE(func->login_ui_shown()); | 749 EXPECT_FALSE(func->login_ui_shown()); |
727 EXPECT_FALSE(func->install_ui_shown()); | 750 EXPECT_FALSE(func->scope_ui_shown()); |
728 | 751 |
729 queue->RequestComplete(type, extension->id(), scopes, &queued_request); | 752 queue->RequestComplete(type, extension->id(), scopes, &queued_request); |
730 } | 753 } |
731 | 754 |
732 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 755 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
733 NonInteractiveCacheHit) { | 756 NonInteractiveCacheHit) { |
734 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 757 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
735 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 758 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
736 func->set_extension(extension); | 759 func->set_extension(extension); |
737 | 760 |
738 // pre-populate the cache with a token | 761 // pre-populate the cache with a token |
739 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); | 762 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); |
740 IdentityTokenCacheValue token(kAccessToken, | 763 IdentityTokenCacheValue token(kAccessToken, |
741 base::TimeDelta::FromSeconds(3600)); | 764 base::TimeDelta::FromSeconds(3600)); |
742 id_api()->SetCachedToken(extension->id(), oauth2_info.scopes, token); | 765 id_api()->SetCachedToken(extension->id(), oauth2_info.scopes, token); |
743 | 766 |
744 // Get a token. Should not require a GAIA request. | 767 // Get a token. Should not require a GAIA request. |
745 EXPECT_CALL(*func.get(), HasLoginToken()) | 768 EXPECT_CALL(*func.get(), HasLoginToken()) |
746 .WillOnce(Return(true)); | 769 .WillOnce(Return(true)); |
747 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( | 770 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( |
748 func.get(), "[{}]", browser())); | 771 func.get(), "[{}]", browser())); |
749 std::string access_token; | 772 std::string access_token; |
750 EXPECT_TRUE(value->GetAsString(&access_token)); | 773 EXPECT_TRUE(value->GetAsString(&access_token)); |
751 EXPECT_EQ(std::string(kAccessToken), access_token); | 774 EXPECT_EQ(std::string(kAccessToken), access_token); |
752 EXPECT_FALSE(func->login_ui_shown()); | 775 EXPECT_FALSE(func->login_ui_shown()); |
753 EXPECT_FALSE(func->install_ui_shown()); | 776 EXPECT_FALSE(func->scope_ui_shown()); |
754 } | 777 } |
755 | 778 |
756 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 779 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
757 NonInteractiveIssueAdviceCacheHit) { | 780 NonInteractiveIssueAdviceCacheHit) { |
758 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 781 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
759 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 782 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
760 func->set_extension(extension); | 783 func->set_extension(extension); |
761 | 784 |
762 // pre-populate the cache with advice | 785 // pre-populate the cache with advice |
763 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); | 786 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); |
764 IssueAdviceInfo info; | 787 IssueAdviceInfo info; |
765 IdentityTokenCacheValue token(info); | 788 IdentityTokenCacheValue token(info); |
766 id_api()->SetCachedToken(extension->id(), oauth2_info.scopes, token); | 789 id_api()->SetCachedToken(extension->id(), oauth2_info.scopes, token); |
767 | 790 |
768 // Should return an error without a GAIA request. | 791 // Should return an error without a GAIA request. |
769 EXPECT_CALL(*func.get(), HasLoginToken()) | 792 EXPECT_CALL(*func.get(), HasLoginToken()) |
770 .WillOnce(Return(true)); | 793 .WillOnce(Return(true)); |
771 std::string error = utils::RunFunctionAndReturnError( | 794 std::string error = utils::RunFunctionAndReturnError( |
772 func.get(), "[{}]", browser()); | 795 func.get(), "[{}]", browser()); |
773 EXPECT_EQ(std::string(errors::kNoGrant), error); | 796 EXPECT_EQ(std::string(errors::kNoGrant), error); |
774 EXPECT_FALSE(func->login_ui_shown()); | 797 EXPECT_FALSE(func->login_ui_shown()); |
775 EXPECT_FALSE(func->install_ui_shown()); | 798 EXPECT_FALSE(func->scope_ui_shown()); |
776 } | 799 } |
777 | 800 |
778 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 801 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
779 InteractiveCacheHit) { | 802 InteractiveCacheHit) { |
780 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 803 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
781 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 804 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
782 func->set_extension(extension); | 805 func->set_extension(extension); |
783 | 806 |
784 // Create a fake request to block the queue. | 807 // Create a fake request to block the queue. |
785 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); | 808 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); |
(...skipping 23 matching lines...) Expand all Loading... |
809 // When we wake up the request, it returns the cached token without | 832 // When we wake up the request, it returns the cached token without |
810 // displaying a UI, or hitting GAIA. | 833 // displaying a UI, or hitting GAIA. |
811 | 834 |
812 queue->RequestComplete(type, extension->id(), scopes, &queued_request); | 835 queue->RequestComplete(type, extension->id(), scopes, &queued_request); |
813 | 836 |
814 scoped_ptr<base::Value> value(WaitForSingleResult(func)); | 837 scoped_ptr<base::Value> value(WaitForSingleResult(func)); |
815 std::string access_token; | 838 std::string access_token; |
816 EXPECT_TRUE(value->GetAsString(&access_token)); | 839 EXPECT_TRUE(value->GetAsString(&access_token)); |
817 EXPECT_EQ(std::string(kAccessToken), access_token); | 840 EXPECT_EQ(std::string(kAccessToken), access_token); |
818 EXPECT_FALSE(func->login_ui_shown()); | 841 EXPECT_FALSE(func->login_ui_shown()); |
819 EXPECT_FALSE(func->install_ui_shown()); | 842 EXPECT_FALSE(func->scope_ui_shown()); |
820 } | 843 } |
821 | 844 |
822 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 845 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
823 LoginInvalidatesTokenCache) { | 846 LoginInvalidatesTokenCache) { |
824 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 847 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
825 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 848 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
826 func->set_extension(extension); | 849 func->set_extension(extension); |
827 | 850 |
828 // pre-populate the cache with a token | 851 // pre-populate the cache with a token |
829 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); | 852 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); |
830 IdentityTokenCacheValue token(kAccessToken, | 853 IdentityTokenCacheValue token(kAccessToken, |
831 base::TimeDelta::FromSeconds(3600)); | 854 base::TimeDelta::FromSeconds(3600)); |
832 id_api()->SetCachedToken(extension->id(), oauth2_info.scopes, token); | 855 id_api()->SetCachedToken(extension->id(), oauth2_info.scopes, token); |
833 | 856 |
834 // Because the user is not signed in, the token will be removed, | 857 // Because the user is not signed in, the token will be removed, |
835 // and we'll hit GAIA for new tokens. | 858 // and we'll hit GAIA for new tokens. |
836 EXPECT_CALL(*func.get(), HasLoginToken()) | 859 EXPECT_CALL(*func.get(), HasLoginToken()) |
837 .WillOnce(Return(false)); | 860 .WillOnce(Return(false)); |
838 func->set_login_ui_result(true); | 861 func->set_login_ui_result(true); |
839 TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow( | 862 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
840 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); | 863 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); |
841 TestOAuth2MintTokenFlow* flow2 = new TestOAuth2MintTokenFlow( | |
842 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get()); | |
843 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)) | 864 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)) |
844 .WillOnce(Return(flow1)) | 865 .WillOnce(Return(flow)); |
845 .WillOnce(Return(flow2)); | |
846 | 866 |
847 func->set_install_ui_result(true); | |
848 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( | 867 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( |
849 func.get(), "[{\"interactive\": true}]", browser())); | 868 func.get(), "[{\"interactive\": true}]", browser())); |
850 std::string access_token; | 869 std::string access_token; |
851 EXPECT_TRUE(value->GetAsString(&access_token)); | 870 EXPECT_TRUE(value->GetAsString(&access_token)); |
852 EXPECT_EQ(std::string(kAccessToken), access_token); | 871 EXPECT_EQ(std::string(kAccessToken), access_token); |
853 EXPECT_TRUE(func->login_ui_shown()); | 872 EXPECT_TRUE(func->login_ui_shown()); |
854 EXPECT_TRUE(func->install_ui_shown()); | 873 EXPECT_TRUE(func->scope_ui_shown()); |
855 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_TOKEN, | 874 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_TOKEN, |
856 id_api()->GetCachedToken(extension->id(), | 875 id_api()->GetCachedToken(extension->id(), |
857 oauth2_info.scopes).status()); | 876 oauth2_info.scopes).status()); |
858 } | 877 } |
859 | 878 |
860 class RemoveCachedAuthTokenFunctionTest : public ExtensionBrowserTest { | 879 class RemoveCachedAuthTokenFunctionTest : public ExtensionBrowserTest { |
861 protected: | 880 protected: |
862 bool InvalidateDefaultToken() { | 881 bool InvalidateDefaultToken() { |
863 scoped_refptr<IdentityRemoveCachedAuthTokenFunction> func( | 882 scoped_refptr<IdentityRemoveCachedAuthTokenFunction> func( |
864 new IdentityRemoveCachedAuthTokenFunction); | 883 new IdentityRemoveCachedAuthTokenFunction); |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1042 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( | 1061 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( |
1043 function, args, browser())); | 1062 function, args, browser())); |
1044 | 1063 |
1045 std::string url; | 1064 std::string url; |
1046 EXPECT_TRUE(value->GetAsString(&url)); | 1065 EXPECT_TRUE(value->GetAsString(&url)); |
1047 EXPECT_EQ(std::string("https://abcdefghij.chromiumapp.org/callback#test"), | 1066 EXPECT_EQ(std::string("https://abcdefghij.chromiumapp.org/callback#test"), |
1048 url); | 1067 url); |
1049 } | 1068 } |
1050 | 1069 |
1051 } // namespace extensions | 1070 } // namespace extensions |
OLD | NEW |