| Index: chrome/browser/extensions/api/identity/identity_apitest.cc
|
| diff --git a/chrome/browser/extensions/api/identity/identity_apitest.cc b/chrome/browser/extensions/api/identity/identity_apitest.cc
|
| index fbf29dfaa83e1444cb8cc7f633798ddf5910b6a2..f66fec2f2cb2eaf1946c10f6ecd662ad0abf8dbe 100644
|
| --- a/chrome/browser/extensions/api/identity/identity_apitest.cc
|
| +++ b/chrome/browser/extensions/api/identity/identity_apitest.cc
|
| @@ -269,101 +269,11 @@ class WaitForGURLAndCloseWindow : public content::WindowedNotificationObserver {
|
|
|
| } // namespace
|
|
|
| -class MockGetAuthTokenFunction : public IdentityGetAuthTokenFunction {
|
| - public:
|
| - MockGetAuthTokenFunction() : login_access_token_result_(true),
|
| - login_ui_result_(true),
|
| - scope_ui_result_(true),
|
| - login_ui_shown_(false),
|
| - scope_ui_shown_(false) {
|
| - }
|
| -
|
| - void set_login_access_token_result(bool result) {
|
| - login_access_token_result_ = result;
|
| - }
|
| -
|
| - void set_login_ui_result(bool result) {
|
| - login_ui_result_ = result;
|
| - }
|
| -
|
| - void set_scope_ui_failure(GaiaWebAuthFlow::Failure failure) {
|
| - scope_ui_result_ = false;
|
| - scope_ui_failure_ = failure;
|
| - }
|
| -
|
| - void set_scope_ui_oauth_error(const std::string& oauth_error) {
|
| - scope_ui_result_ = false;
|
| - scope_ui_failure_ = GaiaWebAuthFlow::OAUTH_ERROR;
|
| - scope_ui_oauth_error_ = oauth_error;
|
| - }
|
| -
|
| - bool login_ui_shown() const {
|
| - return login_ui_shown_;
|
| - }
|
| -
|
| - bool scope_ui_shown() const {
|
| - return scope_ui_shown_;
|
| - }
|
| -
|
| - const ExtensionTokenKey* extension_token_key() { return token_key_.get(); }
|
| -
|
| - virtual void StartLoginAccessTokenRequest() OVERRIDE {
|
| - if (login_access_token_result_) {
|
| - OnGetTokenSuccess(login_token_request_.get(), "access_token",
|
| - base::Time::Now() + base::TimeDelta::FromHours(1LL));
|
| - } else {
|
| - GoogleServiceAuthError error(
|
| - GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
|
| - OnGetTokenFailure(login_token_request_.get(), error);
|
| - }
|
| - }
|
| -
|
| - virtual void ShowLoginPopup() OVERRIDE {
|
| - EXPECT_FALSE(login_ui_shown_);
|
| - login_ui_shown_ = true;
|
| - if (login_ui_result_)
|
| - SigninSuccess();
|
| - else
|
| - SigninFailed();
|
| - }
|
| -
|
| - virtual void ShowOAuthApprovalDialog(
|
| - const IssueAdviceInfo& issue_advice) OVERRIDE {
|
| - scope_ui_shown_ = true;
|
| -
|
| - if (scope_ui_result_) {
|
| - OnGaiaFlowCompleted(kAccessToken, "3600");
|
| - } else if (scope_ui_failure_ == GaiaWebAuthFlow::SERVICE_AUTH_ERROR) {
|
| - GoogleServiceAuthError error(GoogleServiceAuthError::CONNECTION_FAILED);
|
| - OnGaiaFlowFailure(scope_ui_failure_, error, "");
|
| - } else {
|
| - GoogleServiceAuthError error(GoogleServiceAuthError::NONE);
|
| - OnGaiaFlowFailure(scope_ui_failure_, error, scope_ui_oauth_error_);
|
| - }
|
| - }
|
| -
|
| - MOCK_CONST_METHOD0(HasLoginToken, bool());
|
| - MOCK_METHOD1(CreateMintTokenFlow,
|
| - OAuth2MintTokenFlow* (const std::string& login_access_token));
|
| -
|
| - private:
|
| - ~MockGetAuthTokenFunction() {}
|
| - bool login_access_token_result_;
|
| - bool login_ui_result_;
|
| - bool scope_ui_result_;
|
| - GaiaWebAuthFlow::Failure scope_ui_failure_;
|
| - std::string scope_ui_oauth_error_;
|
| - bool login_ui_shown_;
|
| - bool scope_ui_shown_;
|
| -};
|
| -
|
| -// TODO(courage): Replace MockGetAuthTokenFunction with
|
| -// FakeGetAuthTokenFunction in all tests.
|
| -
|
| class FakeGetAuthTokenFunction : public IdentityGetAuthTokenFunction {
|
| public:
|
| FakeGetAuthTokenFunction()
|
| : login_access_token_result_(true),
|
| + auto_login_access_token_(true),
|
| login_ui_result_(true),
|
| scope_ui_result_(true),
|
| login_ui_shown_(false),
|
| @@ -373,12 +283,22 @@ class FakeGetAuthTokenFunction : public IdentityGetAuthTokenFunction {
|
| login_access_token_result_ = result;
|
| }
|
|
|
| + void set_auto_login_access_token(bool automatic) {
|
| + auto_login_access_token_ = automatic;
|
| + }
|
| +
|
| void set_login_ui_result(bool result) { login_ui_result_ = result; }
|
|
|
| void set_mint_token_flow(scoped_ptr<OAuth2MintTokenFlow> flow) {
|
| flow_ = flow.Pass();
|
| }
|
|
|
| + void set_mint_token_result(TestOAuth2MintTokenFlow::ResultType result_type) {
|
| + set_mint_token_flow(scoped_ptr<TestOAuth2MintTokenFlow>(
|
| + new TestOAuth2MintTokenFlow(result_type, this))
|
| + .PassAs<OAuth2MintTokenFlow>());
|
| + }
|
| +
|
| void set_scope_ui_failure(GaiaWebAuthFlow::Failure failure) {
|
| scope_ui_result_ = false;
|
| scope_ui_failure_ = failure;
|
| @@ -396,6 +316,24 @@ class FakeGetAuthTokenFunction : public IdentityGetAuthTokenFunction {
|
|
|
| std::string login_access_token() const { return login_access_token_; }
|
|
|
| + virtual void StartLoginAccessTokenRequest() OVERRIDE {
|
| + if (auto_login_access_token_) {
|
| + if (login_access_token_result_) {
|
| + OnGetTokenSuccess(login_token_request_.get(),
|
| + "access_token",
|
| + base::Time::Now() + base::TimeDelta::FromHours(1LL));
|
| + } else {
|
| + GoogleServiceAuthError error(
|
| + GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
|
| + OnGetTokenFailure(login_token_request_.get(), error);
|
| + }
|
| + } else {
|
| + // Make a request to the token service. The test now must tell
|
| + // the token service to issue an access token (or an error).
|
| + IdentityGetAuthTokenFunction::StartLoginAccessTokenRequest();
|
| + }
|
| + }
|
| +
|
| virtual void ShowLoginPopup() OVERRIDE {
|
| EXPECT_FALSE(login_ui_shown_);
|
| login_ui_shown_ = true;
|
| @@ -423,6 +361,8 @@ class FakeGetAuthTokenFunction : public IdentityGetAuthTokenFunction {
|
| virtual OAuth2MintTokenFlow* CreateMintTokenFlow(
|
| const std::string& login_access_token) OVERRIDE {
|
| EXPECT_TRUE(login_access_token_.empty());
|
| + // Save the login token used to create the flow so tests can see
|
| + // what account was used.
|
| login_access_token_ = login_access_token;
|
| return flow_.release();
|
| }
|
| @@ -430,6 +370,7 @@ class FakeGetAuthTokenFunction : public IdentityGetAuthTokenFunction {
|
| private:
|
| virtual ~FakeGetAuthTokenFunction() {}
|
| bool login_access_token_result_;
|
| + bool auto_login_access_token_;
|
| bool login_ui_result_;
|
| bool scope_ui_result_;
|
| GaiaWebAuthFlow::Failure scope_ui_failure_;
|
| @@ -705,6 +646,18 @@ class GetAuthTokenFunctionTest : public AsyncExtensionBrowserTest {
|
| #else
|
| signin_manager_->SignIn(account_key, "password");
|
| #endif
|
| + token_service_->IssueRefreshTokenForUser(account_key, "refresh_token");
|
| + }
|
| +
|
| + void IssueLoginRefreshTokenForAccount(const std::string account_key) {
|
| + token_service_->IssueRefreshTokenForUser(account_key, "refresh_token");
|
| + }
|
| +
|
| + void IssueLoginAccessTokenForAccount(const std::string account_key) {
|
| + token_service_->IssueAllTokensForAccount(
|
| + account_key,
|
| + "access_token-" + account_key,
|
| + base::Time::Now() + base::TimeDelta::FromSeconds(3600));
|
| }
|
|
|
| void SetAccountState(gaia::AccountIds ids, bool is_signed_in) {
|
| @@ -796,7 +749,7 @@ class GetAuthTokenFunctionTest : public AsyncExtensionBrowserTest {
|
|
|
| IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
| NoClientId) {
|
| - scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
|
| + scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
|
| func->set_extension(CreateExtension(SCOPES));
|
| std::string error = utils::RunFunctionAndReturnError(
|
| func.get(), "[{}]", browser());
|
| @@ -807,7 +760,7 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
|
|
| IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
| NoScopes) {
|
| - scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
|
| + scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
|
| func->set_extension(CreateExtension(CLIENT_ID));
|
| std::string error = utils::RunFunctionAndReturnError(
|
| func.get(), "[{}]", browser());
|
| @@ -818,9 +771,8 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
|
|
| IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
| NonInteractiveNotSignedIn) {
|
| - scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
|
| + scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
|
| func->set_extension(CreateExtension(CLIENT_ID | SCOPES));
|
| - EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(false));
|
| std::string error = utils::RunFunctionAndReturnError(
|
| func.get(), "[{}]", browser());
|
| EXPECT_EQ(std::string(errors::kUserNotSignedIn), error);
|
| @@ -830,15 +782,12 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
|
|
| IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
| NonInteractiveMintFailure) {
|
| - scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
|
| + SignIn("primary@example.com");
|
| + scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
|
| func->set_extension(CreateExtension(CLIENT_ID | SCOPES));
|
| - EXPECT_CALL(*func.get(), HasLoginToken())
|
| - .WillOnce(Return(true));
|
| - TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow(
|
| - TestOAuth2MintTokenFlow::MINT_TOKEN_FAILURE, func.get());
|
| - EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow));
|
| - std::string error = utils::RunFunctionAndReturnError(
|
| - func.get(), "[{}]", browser());
|
| + func->set_mint_token_result(TestOAuth2MintTokenFlow::MINT_TOKEN_FAILURE);
|
| + std::string error =
|
| + utils::RunFunctionAndReturnError(func.get(), "[{}]", browser());
|
| EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false));
|
| EXPECT_FALSE(func->login_ui_shown());
|
| EXPECT_FALSE(func->scope_ui_shown());
|
| @@ -846,10 +795,9 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
|
|
| IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
| NonInteractiveLoginAccessTokenFailure) {
|
| - scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
|
| + SignIn("primary@example.com");
|
| + scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
|
| func->set_extension(CreateExtension(CLIENT_ID | SCOPES));
|
| - EXPECT_CALL(*func.get(), HasLoginToken())
|
| - .WillOnce(Return(true));
|
| func->set_login_access_token_result(false);
|
| std::string error = utils::RunFunctionAndReturnError(
|
| func.get(), "[{}]", browser());
|
| @@ -858,15 +806,13 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
|
|
| IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
| NonInteractiveMintAdviceSuccess) {
|
| + SignIn("primary@example.com");
|
| scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES));
|
| - scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
|
| + scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
|
| func->set_extension(extension.get());
|
| - EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true));
|
| - TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow(
|
| - TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get());
|
| - EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow));
|
| - std::string error = utils::RunFunctionAndReturnError(
|
| - func.get(), "[{}]", browser());
|
| + func->set_mint_token_result(TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS);
|
| + std::string error =
|
| + utils::RunFunctionAndReturnError(func.get(), "[{}]", browser());
|
| EXPECT_EQ(std::string(errors::kNoGrant), error);
|
| EXPECT_FALSE(func->login_ui_shown());
|
| EXPECT_FALSE(func->scope_ui_shown());
|
| @@ -877,15 +823,13 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
|
|
| IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
| NonInteractiveMintBadCredentials) {
|
| - scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
|
| + SignIn("primary@example.com");
|
| + scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
|
| func->set_extension(CreateExtension(CLIENT_ID | SCOPES));
|
| - EXPECT_CALL(*func.get(), HasLoginToken())
|
| - .WillOnce(Return(true));
|
| - TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow(
|
| - TestOAuth2MintTokenFlow::MINT_TOKEN_BAD_CREDENTIALS, func.get());
|
| - EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow));
|
| - std::string error = utils::RunFunctionAndReturnError(
|
| - func.get(), "[{}]", browser());
|
| + func->set_mint_token_result(
|
| + TestOAuth2MintTokenFlow::MINT_TOKEN_BAD_CREDENTIALS);
|
| + std::string error =
|
| + utils::RunFunctionAndReturnError(func.get(), "[{}]", browser());
|
| EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false));
|
| EXPECT_FALSE(func->login_ui_shown());
|
| EXPECT_FALSE(func->scope_ui_shown());
|
| @@ -893,12 +837,11 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
|
|
| IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
| NonInteractiveMintServiceError) {
|
| - scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
|
| + SignIn("primary@example.com");
|
| + scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
|
| func->set_extension(CreateExtension(CLIENT_ID | SCOPES));
|
| - EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true));
|
| - TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow(
|
| - TestOAuth2MintTokenFlow::MINT_TOKEN_SERVICE_ERROR, func.get());
|
| - EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow));
|
| + func->set_mint_token_result(
|
| + TestOAuth2MintTokenFlow::MINT_TOKEN_SERVICE_ERROR);
|
| std::string error =
|
| utils::RunFunctionAndReturnError(func.get(), "[{}]", browser());
|
| EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false));
|
| @@ -908,21 +851,19 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
|
|
| IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
| NoOptionsSuccess) {
|
| + SignIn("primary@example.com");
|
| #if defined(OS_WIN) && defined(USE_ASH)
|
| // Disable this test in Metro+Ash for now (http://crbug.com/262796).
|
| if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
|
| return;
|
| #endif
|
|
|
| - scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
|
| + scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
|
| scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES));
|
| func->set_extension(extension.get());
|
| - EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true));
|
| - TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow(
|
| - TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get());
|
| - EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow));
|
| - scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult(
|
| - func.get(), "[]", browser()));
|
| + func->set_mint_token_result(TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS);
|
| + scoped_ptr<base::Value> value(
|
| + utils::RunFunctionAndReturnSingleResult(func.get(), "[]", browser()));
|
| std::string access_token;
|
| EXPECT_TRUE(value->GetAsString(&access_token));
|
| EXPECT_EQ(std::string(kAccessToken), access_token);
|
| @@ -934,19 +875,17 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
|
|
| IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
| NonInteractiveSuccess) {
|
| + SignIn("primary@example.com");
|
| #if defined(OS_WIN) && defined(USE_ASH)
|
| // Disable this test in Metro+Ash for now (http://crbug.com/262796).
|
| if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
|
| return;
|
| #endif
|
|
|
| - scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
|
| + scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
|
| scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES));
|
| func->set_extension(extension.get());
|
| - EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true));
|
| - TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow(
|
| - TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get());
|
| - EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow));
|
| + func->set_mint_token_result(TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS);
|
| scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult(
|
| func.get(), "[{}]", browser()));
|
| std::string access_token;
|
| @@ -960,9 +899,8 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
|
|
| IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
| InteractiveLoginCanceled) {
|
| - scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
|
| + scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
|
| func->set_extension(CreateExtension(CLIENT_ID | SCOPES));
|
| - EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(false));
|
| func->set_login_ui_result(false);
|
| std::string error = utils::RunFunctionAndReturnError(
|
| func.get(), "[{\"interactive\": true}]", browser());
|
| @@ -973,13 +911,11 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
|
|
| IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
| InteractiveMintBadCredentialsLoginCanceled) {
|
| - scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
|
| + SignIn("primary@example.com");
|
| + scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
|
| func->set_extension(CreateExtension(CLIENT_ID | SCOPES));
|
| - EXPECT_CALL(*func.get(), HasLoginToken())
|
| - .WillOnce(Return(true));
|
| - TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow(
|
| - TestOAuth2MintTokenFlow::MINT_TOKEN_BAD_CREDENTIALS, func.get());
|
| - EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow));
|
| + func->set_mint_token_result(
|
| + TestOAuth2MintTokenFlow::MINT_TOKEN_BAD_CREDENTIALS);
|
| func->set_login_ui_result(false);
|
| std::string error = utils::RunFunctionAndReturnError(
|
| func.get(), "[{\"interactive\": true}]", browser());
|
| @@ -990,9 +926,8 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
|
|
| IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
| InteractiveLoginSuccessNoToken) {
|
| - scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
|
| + scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
|
| func->set_extension(CreateExtension(CLIENT_ID | SCOPES));
|
| - EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(false));
|
| func->set_login_ui_result(false);
|
| std::string error = utils::RunFunctionAndReturnError(
|
| func.get(), "[{\"interactive\": true}]", browser());
|
| @@ -1003,14 +938,10 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
|
|
| IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
| InteractiveLoginSuccessMintFailure) {
|
| - scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
|
| + scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
|
| func->set_extension(CreateExtension(CLIENT_ID | SCOPES));
|
| - EXPECT_CALL(*func.get(), HasLoginToken())
|
| - .WillOnce(Return(false));
|
| func->set_login_ui_result(true);
|
| - TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow(
|
| - TestOAuth2MintTokenFlow::MINT_TOKEN_FAILURE, func.get());
|
| - EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow));
|
| + func->set_mint_token_result(TestOAuth2MintTokenFlow::MINT_TOKEN_FAILURE);
|
| std::string error = utils::RunFunctionAndReturnError(
|
| func.get(), "[{\"interactive\": true}]", browser());
|
| EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false));
|
| @@ -1020,9 +951,8 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
|
|
| IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
| InteractiveLoginSuccessLoginAccessTokenFailure) {
|
| - scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
|
| + scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
|
| func->set_extension(CreateExtension(CLIENT_ID | SCOPES));
|
| - EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(false));
|
| func->set_login_ui_result(true);
|
| func->set_login_access_token_result(false);
|
| std::string error = utils::RunFunctionAndReturnError(
|
| @@ -1034,14 +964,10 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
|
|
| IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
| InteractiveLoginSuccessMintSuccess) {
|
| - scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
|
| + scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
|
| func->set_extension(CreateExtension(CLIENT_ID | SCOPES));
|
| - EXPECT_CALL(*func.get(), HasLoginToken())
|
| - .WillOnce(Return(false));
|
| func->set_login_ui_result(true);
|
| - TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow(
|
| - TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get());
|
| - EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow));
|
| + func->set_mint_token_result(TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS);
|
| scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult(
|
| func.get(), "[{\"interactive\": true}]", browser()));
|
| std::string access_token;
|
| @@ -1053,14 +979,10 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
|
|
| IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
| InteractiveLoginSuccessApprovalAborted) {
|
| - scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
|
| + scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
|
| func->set_extension(CreateExtension(CLIENT_ID | SCOPES));
|
| - EXPECT_CALL(*func.get(), HasLoginToken())
|
| - .WillOnce(Return(false));
|
| func->set_login_ui_result(true);
|
| - TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow(
|
| - TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get());
|
| - EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow));
|
| + func->set_mint_token_result(TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS);
|
| func->set_scope_ui_failure(GaiaWebAuthFlow::WINDOW_CLOSED);
|
| std::string error = utils::RunFunctionAndReturnError(
|
| func.get(), "[{\"interactive\": true}]", browser());
|
| @@ -1072,14 +994,10 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
| IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
| InteractiveLoginSuccessApprovalSuccess) {
|
| scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES));
|
| - scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
|
| + scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
|
| func->set_extension(extension.get());
|
| - EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(false));
|
| func->set_login_ui_result(true);
|
| - TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow(
|
| - TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get());
|
| - EXPECT_CALL(*func.get(), CreateMintTokenFlow(_))
|
| - .WillOnce(Return(flow));
|
| + func->set_mint_token_result(TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS);
|
|
|
| scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult(
|
| func.get(), "[{\"interactive\": true}]", browser()));
|
| @@ -1092,13 +1010,10 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
|
|
| IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
| InteractiveApprovalAborted) {
|
| - scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
|
| + SignIn("primary@example.com");
|
| + scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
|
| func->set_extension(CreateExtension(CLIENT_ID | SCOPES));
|
| - EXPECT_CALL(*func.get(), HasLoginToken())
|
| - .WillOnce(Return(true));
|
| - TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow(
|
| - TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get());
|
| - EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow));
|
| + func->set_mint_token_result(TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS);
|
| func->set_scope_ui_failure(GaiaWebAuthFlow::WINDOW_CLOSED);
|
| std::string error = utils::RunFunctionAndReturnError(
|
| func.get(), "[{\"interactive\": true}]", browser());
|
| @@ -1109,13 +1024,10 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
|
|
| IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
| InteractiveApprovalLoadFailed) {
|
| - scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
|
| + SignIn("primary@example.com");
|
| + scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
|
| func->set_extension(CreateExtension(CLIENT_ID | SCOPES));
|
| - EXPECT_CALL(*func.get(), HasLoginToken())
|
| - .WillOnce(Return(true));
|
| - TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow(
|
| - TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get());
|
| - EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow));
|
| + func->set_mint_token_result(TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS);
|
| func->set_scope_ui_failure(GaiaWebAuthFlow::LOAD_FAILED);
|
| std::string error = utils::RunFunctionAndReturnError(
|
| func.get(), "[{\"interactive\": true}]", browser());
|
| @@ -1126,13 +1038,10 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
|
|
| IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
| InteractiveApprovalInvalidRedirect) {
|
| - scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
|
| + SignIn("primary@example.com");
|
| + scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
|
| func->set_extension(CreateExtension(CLIENT_ID | SCOPES));
|
| - EXPECT_CALL(*func.get(), HasLoginToken())
|
| - .WillOnce(Return(true));
|
| - TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow(
|
| - TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get());
|
| - EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow));
|
| + func->set_mint_token_result(TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS);
|
| func->set_scope_ui_failure(GaiaWebAuthFlow::INVALID_REDIRECT);
|
| std::string error = utils::RunFunctionAndReturnError(
|
| func.get(), "[{\"interactive\": true}]", browser());
|
| @@ -1143,13 +1052,10 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
|
|
| IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
| InteractiveApprovalConnectionFailure) {
|
| - scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
|
| + SignIn("primary@example.com");
|
| + scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
|
| func->set_extension(CreateExtension(CLIENT_ID | SCOPES));
|
| - EXPECT_CALL(*func.get(), HasLoginToken())
|
| - .WillOnce(Return(true));
|
| - TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow(
|
| - TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get());
|
| - EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow));
|
| + func->set_mint_token_result(TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS);
|
| func->set_scope_ui_failure(GaiaWebAuthFlow::SERVICE_AUTH_ERROR);
|
| std::string error = utils::RunFunctionAndReturnError(
|
| func.get(), "[{\"interactive\": true}]", browser());
|
| @@ -1160,6 +1066,7 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
|
|
| IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
| InteractiveApprovalOAuthErrors) {
|
| + SignIn("primary@example.com");
|
| scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES));
|
|
|
| std::map<std::string, std::string> error_map;
|
| @@ -1172,16 +1079,13 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
| it = error_map.begin();
|
| it != error_map.end();
|
| ++it) {
|
| - scoped_refptr<MockGetAuthTokenFunction> func(
|
| - new MockGetAuthTokenFunction());
|
| + scoped_refptr<FakeGetAuthTokenFunction> func(
|
| + new FakeGetAuthTokenFunction());
|
| func->set_extension(extension.get());
|
| - EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true));
|
| // Make sure we don't get a cached issue_advice result, which would cause
|
| // flow to be leaked.
|
| id_api()->EraseAllCachedTokens();
|
| - TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow(
|
| - TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get());
|
| - EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow));
|
| + func->set_mint_token_result(TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS);
|
| func->set_scope_ui_oauth_error(it->first);
|
| std::string error = utils::RunFunctionAndReturnError(
|
| func.get(), "[{\"interactive\": true}]", browser());
|
| @@ -1193,14 +1097,11 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
|
|
| IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
| InteractiveApprovalSuccess) {
|
| + SignIn("primary@example.com");
|
| scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES));
|
| - scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
|
| + scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
|
| func->set_extension(extension.get());
|
| - EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true));
|
| - TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow(
|
| - TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get());
|
| - EXPECT_CALL(*func.get(), CreateMintTokenFlow(_))
|
| - .WillOnce(Return(flow));
|
| + func->set_mint_token_result(TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS);
|
|
|
| scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult(
|
| func.get(), "[{\"interactive\": true}]", browser()));
|
| @@ -1215,8 +1116,9 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
| }
|
|
|
| IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, NoninteractiveQueue) {
|
| + SignIn("primary@example.com");
|
| scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES));
|
| - scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
|
| + scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
|
| func->set_extension(extension.get());
|
|
|
| // Create a fake request to block the queue.
|
| @@ -1229,15 +1131,12 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, NoninteractiveQueue) {
|
|
|
| // The real request will start processing, but wait in the queue behind
|
| // the blocker.
|
| - EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true));
|
| RunFunctionAsync(func.get(), "[{}]");
|
| // Verify that we have fetched the login token at this point.
|
| testing::Mock::VerifyAndClearExpectations(func.get());
|
|
|
| // The flow will be created after the first queued request clears.
|
| - TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow(
|
| - TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get());
|
| - EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow));
|
| + func->set_mint_token_result(TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS);
|
|
|
| QueueRequestComplete(type, &queued_request);
|
|
|
| @@ -1250,8 +1149,9 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, NoninteractiveQueue) {
|
| }
|
|
|
| IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, InteractiveQueue) {
|
| + SignIn("primary@example.com");
|
| scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES));
|
| - scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
|
| + scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
|
| func->set_extension(extension.get());
|
|
|
| // Create a fake request to block the queue.
|
| @@ -1264,10 +1164,7 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, InteractiveQueue) {
|
|
|
| // The real request will start processing, but wait in the queue behind
|
| // the blocker.
|
| - EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true));
|
| - TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow(
|
| - TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get());
|
| - EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow1));
|
| + func->set_mint_token_result(TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS);
|
| RunFunctionAsync(func.get(), "[{\"interactive\": true}]");
|
| // Verify that we have fetched the login token and run the first flow.
|
| testing::Mock::VerifyAndClearExpectations(func.get());
|
| @@ -1286,8 +1183,9 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, InteractiveQueue) {
|
| }
|
|
|
| IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, InteractiveQueueShutdown) {
|
| + SignIn("primary@example.com");
|
| scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES));
|
| - scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
|
| + scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
|
| func->set_extension(extension.get());
|
|
|
| // Create a fake request to block the queue.
|
| @@ -1300,10 +1198,7 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, InteractiveQueueShutdown) {
|
|
|
| // The real request will start processing, but wait in the queue behind
|
| // the blocker.
|
| - EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true));
|
| - TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow(
|
| - TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get());
|
| - EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow1));
|
| + func->set_mint_token_result(TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS);
|
| RunFunctionAsync(func.get(), "[{\"interactive\": true}]");
|
| // Verify that we have fetched the login token and run the first flow.
|
| testing::Mock::VerifyAndClearExpectations(func.get());
|
| @@ -1319,13 +1214,14 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, InteractiveQueueShutdown) {
|
| }
|
|
|
| IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, NoninteractiveShutdown) {
|
| + SignIn("primary@example.com");
|
| scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES));
|
| - scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
|
| + scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
|
| func->set_extension(extension.get());
|
|
|
| - EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true));
|
| - TestHangOAuth2MintTokenFlow* flow = new TestHangOAuth2MintTokenFlow();
|
| - EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow));
|
| + scoped_ptr<TestHangOAuth2MintTokenFlow> flow(
|
| + new TestHangOAuth2MintTokenFlow());
|
| + func->set_mint_token_flow(flow.PassAs<OAuth2MintTokenFlow>());
|
| RunFunctionAsync(func.get(), "[{\"interactive\": false}]");
|
|
|
| // After the request is canceled, the function will complete.
|
| @@ -1335,8 +1231,9 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, NoninteractiveShutdown) {
|
|
|
| IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
| InteractiveQueuedNoninteractiveFails) {
|
| + SignIn("primary@example.com");
|
| scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES));
|
| - scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
|
| + scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
|
| func->set_extension(extension.get());
|
|
|
| // Create a fake request to block the interactive queue.
|
| @@ -1349,7 +1246,6 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
|
|
| // Non-interactive requests fail without hitting GAIA, because a
|
| // consent UI is known to be up.
|
| - EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true));
|
| std::string error = utils::RunFunctionAndReturnError(
|
| func.get(), "[{}]", browser());
|
| EXPECT_EQ(std::string(errors::kNoGrant), error);
|
| @@ -1361,8 +1257,9 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
|
|
| IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
| NonInteractiveCacheHit) {
|
| + SignIn("primary@example.com");
|
| scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES));
|
| - scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
|
| + scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
|
| func->set_extension(extension.get());
|
|
|
| // pre-populate the cache with a token
|
| @@ -1371,8 +1268,6 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
| SetCachedToken(token);
|
|
|
| // Get a token. Should not require a GAIA request.
|
| - EXPECT_CALL(*func.get(), HasLoginToken())
|
| - .WillOnce(Return(true));
|
| scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult(
|
| func.get(), "[{}]", browser()));
|
| std::string access_token;
|
| @@ -1384,8 +1279,9 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
|
|
| IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
| NonInteractiveIssueAdviceCacheHit) {
|
| + SignIn("primary@example.com");
|
| scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES));
|
| - scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
|
| + scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
|
| func->set_extension(extension.get());
|
|
|
| // pre-populate the cache with advice
|
| @@ -1394,8 +1290,6 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
| SetCachedToken(token);
|
|
|
| // Should return an error without a GAIA request.
|
| - EXPECT_CALL(*func.get(), HasLoginToken())
|
| - .WillOnce(Return(true));
|
| std::string error = utils::RunFunctionAndReturnError(
|
| func.get(), "[{}]", browser());
|
| EXPECT_EQ(std::string(errors::kNoGrant), error);
|
| @@ -1405,8 +1299,9 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
|
|
| IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
| InteractiveCacheHit) {
|
| + SignIn("primary@example.com");
|
| scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES));
|
| - scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
|
| + scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
|
| func->set_extension(extension.get());
|
|
|
| // Create a fake request to block the queue.
|
| @@ -1419,10 +1314,7 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
|
|
| // The real request will start processing, but wait in the queue behind
|
| // the blocker.
|
| - EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true));
|
| - TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow(
|
| - TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get());
|
| - EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow));
|
| + func->set_mint_token_result(TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS);
|
| RunFunctionAsync(func.get(), "[{\"interactive\": true}]");
|
|
|
| // Populate the cache with a token while the request is blocked.
|
| @@ -1445,7 +1337,7 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
|
|
| IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
| LoginInvalidatesTokenCache) {
|
| - scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
|
| + scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
|
| scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES));
|
| func->set_extension(extension.get());
|
|
|
| @@ -1456,13 +1348,8 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
|
|
| // Because the user is not signed in, the token will be removed,
|
| // and we'll hit GAIA for new tokens.
|
| - EXPECT_CALL(*func.get(), HasLoginToken())
|
| - .WillOnce(Return(false));
|
| func->set_login_ui_result(true);
|
| - TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow(
|
| - TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get());
|
| - EXPECT_CALL(*func.get(), CreateMintTokenFlow(_))
|
| - .WillOnce(Return(flow));
|
| + func->set_mint_token_result(TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS);
|
|
|
| scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult(
|
| func.get(), "[{\"interactive\": true}]", browser()));
|
| @@ -1476,7 +1363,7 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
| }
|
|
|
| IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, ComponentWithChromeClientId) {
|
| - scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
|
| + scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
|
| scoped_refptr<const Extension> extension(
|
| CreateExtension(SCOPES | AS_COMPONENT));
|
| func->set_extension(extension.get());
|
| @@ -1487,7 +1374,7 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, ComponentWithChromeClientId) {
|
| }
|
|
|
| IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, ComponentWithNormalClientId) {
|
| - scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
|
| + scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
|
| scoped_refptr<const Extension> extension(
|
| CreateExtension(CLIENT_ID | SCOPES | AS_COMPONENT));
|
| func->set_extension(extension.get());
|
| @@ -1496,24 +1383,18 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, ComponentWithNormalClientId) {
|
|
|
| IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, MultiDefaultUser) {
|
| SignIn("primary@example.com");
|
| - token_service_->IssueRefreshTokenForUser("primary@example.com",
|
| - "refresh_token");
|
| SetAccountState(CreateIds("primary@example.com", "1"), true);
|
| SetAccountState(CreateIds("secondary@example.com", "2"), true);
|
|
|
| scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
|
| scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES));
|
| func->set_extension(extension.get());
|
| - func->set_mint_token_flow(
|
| - scoped_ptr<OAuth2MintTokenFlow>(new TestOAuth2MintTokenFlow(
|
| - TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get())));
|
| + func->set_auto_login_access_token(false);
|
| + func->set_mint_token_result(TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS);
|
|
|
| RunFunctionAsync(func.get(), "[{}]");
|
|
|
| - token_service_->IssueAllTokensForAccount(
|
| - "primary@example.com",
|
| - "access_token-primary@example.com",
|
| - base::Time::Now() + base::TimeDelta::FromSeconds(3600));
|
| + IssueLoginAccessTokenForAccount("primary@example.com");
|
|
|
| scoped_ptr<base::Value> value(WaitForSingleResult(func.get()));
|
| std::string access_token;
|
| @@ -1526,24 +1407,19 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, MultiDefaultUser) {
|
|
|
| IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, MultiPrimaryUser) {
|
| SignIn("primary@example.com");
|
| - token_service_->IssueRefreshTokenForUser("primary@example.com",
|
| - "refresh_token");
|
| + IssueLoginRefreshTokenForAccount("secondary@example.com");
|
| SetAccountState(CreateIds("primary@example.com", "1"), true);
|
| SetAccountState(CreateIds("secondary@example.com", "2"), true);
|
|
|
| scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
|
| scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES));
|
| func->set_extension(extension.get());
|
| - func->set_mint_token_flow(
|
| - scoped_ptr<OAuth2MintTokenFlow>(new TestOAuth2MintTokenFlow(
|
| - TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get())));
|
| + func->set_auto_login_access_token(false);
|
| + func->set_mint_token_result(TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS);
|
|
|
| RunFunctionAsync(func.get(), "[{\"account\": { \"id\": \"1\" } }]");
|
|
|
| - token_service_->IssueAllTokensForAccount(
|
| - "primary@example.com",
|
| - "access_token-primary@example.com",
|
| - base::Time::Now() + base::TimeDelta::FromSeconds(3600));
|
| + IssueLoginAccessTokenForAccount("primary@example.com");
|
|
|
| scoped_ptr<base::Value> value(WaitForSingleResult(func.get()));
|
| std::string access_token;
|
| @@ -1556,24 +1432,19 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, MultiPrimaryUser) {
|
|
|
| IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, MultiSecondaryUser) {
|
| SignIn("primary@example.com");
|
| - token_service_->IssueRefreshTokenForUser("secondary@example.com",
|
| - "refresh_token");
|
| + IssueLoginRefreshTokenForAccount("secondary@example.com");
|
| SetAccountState(CreateIds("primary@example.com", "1"), true);
|
| SetAccountState(CreateIds("secondary@example.com", "2"), true);
|
|
|
| scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
|
| scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES));
|
| func->set_extension(extension.get());
|
| - func->set_mint_token_flow(
|
| - scoped_ptr<OAuth2MintTokenFlow>(new TestOAuth2MintTokenFlow(
|
| - TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get())));
|
| + func->set_auto_login_access_token(false);
|
| + func->set_mint_token_result(TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS);
|
|
|
| RunFunctionAsync(func.get(), "[{\"account\": { \"id\": \"2\" } }]");
|
|
|
| - token_service_->IssueAllTokensForAccount(
|
| - "secondary@example.com",
|
| - "access_token-secondary@example.com",
|
| - base::Time::Now() + base::TimeDelta::FromSeconds(3600));
|
| + IssueLoginAccessTokenForAccount("secondary@example.com");
|
|
|
| scoped_ptr<base::Value> value(WaitForSingleResult(func.get()));
|
| std::string access_token;
|
| @@ -1584,30 +1455,94 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, MultiSecondaryUser) {
|
| EXPECT_EQ("access_token-secondary@example.com", func->login_access_token());
|
| }
|
|
|
| -// TODO(courage): negative cases for secondary accounts
|
| +IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, MultiUnknownUser) {
|
| + SignIn("primary@example.com");
|
| + IssueLoginRefreshTokenForAccount("secondary@example.com");
|
| + SetAccountState(CreateIds("primary@example.com", "1"), true);
|
| + SetAccountState(CreateIds("secondary@example.com", "2"), true);
|
| +
|
| + scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
|
| + scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES));
|
| + func->set_extension(extension.get());
|
| + func->set_auto_login_access_token(false);
|
| +
|
| + std::string error = utils::RunFunctionAndReturnError(
|
| + func.get(), "[{\"account\": { \"id\": \"3\" } }]", browser());
|
| + EXPECT_EQ(std::string(errors::kUserNotSignedIn), error);
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
| + MultiSecondaryNonInteractiveMintFailure) {
|
| + SignIn("primary@example.com");
|
| + IssueLoginRefreshTokenForAccount("secondary@example.com");
|
| + SetAccountState(CreateIds("primary@example.com", "1"), true);
|
| + SetAccountState(CreateIds("secondary@example.com", "2"), true);
|
| +
|
| + scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
|
| + func->set_extension(CreateExtension(CLIENT_ID | SCOPES));
|
| + func->set_mint_token_result(TestOAuth2MintTokenFlow::MINT_TOKEN_FAILURE);
|
| + std::string error = utils::RunFunctionAndReturnError(
|
| + func.get(), "[{\"account\": { \"id\": \"2\" } }]", browser());
|
| + EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false));
|
| + EXPECT_FALSE(func->login_ui_shown());
|
| + EXPECT_FALSE(func->scope_ui_shown());
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
| + MultiSecondaryNonInteractiveLoginAccessTokenFailure) {
|
| + SignIn("primary@example.com");
|
| + IssueLoginRefreshTokenForAccount("secondary@example.com");
|
| + SetAccountState(CreateIds("primary@example.com", "1"), true);
|
| + SetAccountState(CreateIds("secondary@example.com", "2"), true);
|
| +
|
| + scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
|
| + func->set_extension(CreateExtension(CLIENT_ID | SCOPES));
|
| + func->set_login_access_token_result(false);
|
| + std::string error = utils::RunFunctionAndReturnError(
|
| + func.get(), "[{\"account\": { \"id\": \"2\" } }]", browser());
|
| + EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false));
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
|
| + MultiSecondaryInteractiveApprovalAborted) {
|
| + SignIn("primary@example.com");
|
| + IssueLoginRefreshTokenForAccount("secondary@example.com");
|
| + SetAccountState(CreateIds("primary@example.com", "1"), true);
|
| + SetAccountState(CreateIds("secondary@example.com", "2"), true);
|
| +
|
| + scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
|
| + func->set_extension(CreateExtension(CLIENT_ID | SCOPES));
|
| + func->set_mint_token_result(TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS);
|
| + func->set_scope_ui_failure(GaiaWebAuthFlow::WINDOW_CLOSED);
|
| + std::string error = utils::RunFunctionAndReturnError(
|
| + func.get(),
|
| + "[{\"account\": { \"id\": \"2\" }, \"interactive\": true}]",
|
| + browser());
|
| + EXPECT_EQ(std::string(errors::kUserRejected), error);
|
| + EXPECT_FALSE(func->login_ui_shown());
|
| + EXPECT_TRUE(func->scope_ui_shown());
|
| +}
|
|
|
| IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, ScopesDefault) {
|
| - scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
|
| + SignIn("primary@example.com");
|
| + scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
|
| scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES));
|
| func->set_extension(extension.get());
|
| - EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true));
|
| - TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow(
|
| - TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get());
|
| - EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow));
|
| + func->set_mint_token_result(TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS);
|
| scoped_ptr<base::Value> value(
|
| utils::RunFunctionAndReturnSingleResult(func.get(), "[{}]", browser()));
|
| std::string access_token;
|
| EXPECT_TRUE(value->GetAsString(&access_token));
|
| EXPECT_EQ(std::string(kAccessToken), access_token);
|
|
|
| - const ExtensionTokenKey* token_key = func->extension_token_key();
|
| + const ExtensionTokenKey* token_key = func->GetExtensionTokenKeyForTest();
|
| EXPECT_EQ(2ul, token_key->scopes.size());
|
| EXPECT_TRUE(ContainsKey(token_key->scopes, "scope1"));
|
| EXPECT_TRUE(ContainsKey(token_key->scopes, "scope2"));
|
| }
|
|
|
| IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, ScopesEmpty) {
|
| - scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
|
| + scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
|
| scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES));
|
| func->set_extension(extension.get());
|
|
|
| @@ -1618,39 +1553,35 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, ScopesEmpty) {
|
| }
|
|
|
| IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, ScopesEmail) {
|
| - scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
|
| + SignIn("primary@example.com");
|
| + scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
|
| scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES));
|
| func->set_extension(extension.get());
|
| - EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true));
|
| - TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow(
|
| - TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get());
|
| - EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow));
|
| + func->set_mint_token_result(TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS);
|
| scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult(
|
| func.get(), "[{\"scopes\": [\"email\"]}]", browser()));
|
| std::string access_token;
|
| EXPECT_TRUE(value->GetAsString(&access_token));
|
| EXPECT_EQ(std::string(kAccessToken), access_token);
|
|
|
| - const ExtensionTokenKey* token_key = func->extension_token_key();
|
| + const ExtensionTokenKey* token_key = func->GetExtensionTokenKeyForTest();
|
| EXPECT_EQ(1ul, token_key->scopes.size());
|
| EXPECT_TRUE(ContainsKey(token_key->scopes, "email"));
|
| }
|
|
|
| IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, ScopesEmailFooBar) {
|
| - scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
|
| + SignIn("primary@example.com");
|
| + scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
|
| scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES));
|
| func->set_extension(extension.get());
|
| - EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true));
|
| - TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow(
|
| - TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get());
|
| - EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow));
|
| + func->set_mint_token_result(TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS);
|
| scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult(
|
| func.get(), "[{\"scopes\": [\"email\", \"foo\", \"bar\"]}]", browser()));
|
| std::string access_token;
|
| EXPECT_TRUE(value->GetAsString(&access_token));
|
| EXPECT_EQ(std::string(kAccessToken), access_token);
|
|
|
| - const ExtensionTokenKey* token_key = func->extension_token_key();
|
| + const ExtensionTokenKey* token_key = func->GetExtensionTokenKeyForTest();
|
| EXPECT_EQ(3ul, token_key->scopes.size());
|
| EXPECT_TRUE(ContainsKey(token_key->scopes, "email"));
|
| EXPECT_TRUE(ContainsKey(token_key->scopes, "foo"));
|
|
|