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

Unified Diff: chrome/browser/extensions/api/identity/identity_apitest.cc

Issue 12929014: Identity API: Pop-up a sign-in dialog if gaia credentials are bad (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: address code review comments Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 3a17641de942cf9b56cc2535550a490cee15addc..8c709c5e190ce8e56ff034e69f63f6eea3441aa2 100644
--- a/chrome/browser/extensions/api/identity/identity_apitest.cc
+++ b/chrome/browser/extensions/api/identity/identity_apitest.cc
@@ -12,7 +12,6 @@
#include "chrome/browser/extensions/extension_function_test_utils.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
-#include "chrome/browser/ui/webui/signin/login_ui_service.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/extensions/api/identity/oauth2_manifest_handler.h"
@@ -39,18 +38,13 @@ namespace utils = extension_function_test_utils;
static const char kAccessToken[] = "auth_token";
-class TestLoginUI : public LoginUIService::LoginUI {
- public:
- virtual void FocusUI() OVERRIDE {}
- virtual void CloseUI() OVERRIDE {}
-};
-
class TestOAuth2MintTokenFlow : public OAuth2MintTokenFlow {
public:
enum ResultType {
ISSUE_ADVICE_SUCCESS,
MINT_TOKEN_SUCCESS,
- MINT_TOKEN_FAILURE
+ MINT_TOKEN_FAILURE,
+ MINT_TOKEN_BAD_CREDENTIALS
};
TestOAuth2MintTokenFlow(ResultType result,
@@ -72,6 +66,11 @@ class TestOAuth2MintTokenFlow : public OAuth2MintTokenFlow {
break;
}
case MINT_TOKEN_FAILURE: {
+ GoogleServiceAuthError error(GoogleServiceAuthError::CONNECTION_FAILED);
+ delegate_->OnMintTokenFailure(error);
+ break;
+ }
+ case MINT_TOKEN_BAD_CREDENTIALS: {
GoogleServiceAuthError error(
GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
delegate_->OnMintTokenFailure(error);
@@ -89,11 +88,16 @@ class TestOAuth2MintTokenFlow : public OAuth2MintTokenFlow {
class MockGetAuthTokenFunction : public IdentityGetAuthTokenFunction {
public:
- MockGetAuthTokenFunction() : install_ui_result_(false),
+ MockGetAuthTokenFunction() : login_ui_result_(true),
+ install_ui_result_(false),
login_ui_shown_(false),
install_ui_shown_(false) {
}
+ void set_login_ui_result(bool result) {
+ login_ui_result_ = result;
+ }
+
void set_install_ui_result(bool result) {
install_ui_result_ = result;
}
@@ -106,18 +110,13 @@ class MockGetAuthTokenFunction : public IdentityGetAuthTokenFunction {
return install_ui_shown_;
}
- virtual void StartObservingLoginService() OVERRIDE {
- // Do nothing in tests.
- }
- virtual void StopObservingLoginService() OVERRIDE {
- // Do nothing in tests.
- }
-
virtual void ShowLoginPopup() OVERRIDE {
+ EXPECT_FALSE(login_ui_shown_);
login_ui_shown_ = true;
- // Explicitly call OnLoginUIClosed.
- TestLoginUI login_ui;;
- OnLoginUIClosed(&login_ui);
+ if (login_ui_result_)
+ SigninSuccess("fake_refresh_token");
+ else
+ SigninFailed();
}
virtual void ShowOAuthApprovalDialog(
@@ -131,11 +130,13 @@ class MockGetAuthTokenFunction : public IdentityGetAuthTokenFunction {
InstallUIAbort(true);
}
- MOCK_CONST_METHOD0(HasLoginToken, bool ());
+ MOCK_CONST_METHOD0(HasLoginToken, bool());
MOCK_METHOD1(CreateMintTokenFlow,
OAuth2MintTokenFlow* (OAuth2MintTokenFlow::Mode mode));
+
private:
~MockGetAuthTokenFunction() {}
+ bool login_ui_result_;
bool install_ui_result_;
bool login_ui_shown_;
bool install_ui_shown_;
@@ -207,7 +208,6 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
func->set_extension(CreateExtension(CLIENT_ID | SCOPES));
EXPECT_CALL(*func.get(), HasLoginToken())
- .WillOnce(Return(true))
.WillOnce(Return(true));
TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow(
TestOAuth2MintTokenFlow::MINT_TOKEN_FAILURE, func.get());
@@ -220,11 +220,26 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
}
IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
+ NonInteractiveMintBadCredentials) {
+ scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
+ 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());
+ EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false));
+ EXPECT_FALSE(func->login_ui_shown());
+ EXPECT_FALSE(func->install_ui_shown());
+}
+
+IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
NonInteractiveSuccess) {
scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
func->set_extension(CreateExtension(CLIENT_ID | SCOPES));
EXPECT_CALL(*func.get(), HasLoginToken())
- .WillOnce(Return(true))
.WillOnce(Return(true));
TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow(
TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get());
@@ -242,7 +257,8 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
InteractiveLoginCanceled) {
scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
func->set_extension(CreateExtension(CLIENT_ID | SCOPES));
- EXPECT_CALL(*func.get(), HasLoginToken()).WillRepeatedly(Return(false));
+ EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(false));
+ func->set_login_ui_result(false);
std::string error = utils::RunFunctionAndReturnError(
func.get(), "[{\"interactive\": true}]", browser());
EXPECT_EQ(std::string(errors::kUserNotSignedIn), error);
@@ -251,13 +267,43 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
}
IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
- InteractiveLoginSuccessMintFailure) {
+ InteractiveMintBadCredentialsLoginCanceled) {
scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
func->set_extension(CreateExtension(CLIENT_ID | SCOPES));
EXPECT_CALL(*func.get(), HasLoginToken())
- .WillOnce(Return(false))
.WillOnce(Return(true));
TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow(
+ TestOAuth2MintTokenFlow::MINT_TOKEN_BAD_CREDENTIALS, func.get());
+ EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow));
+ func->set_login_ui_result(false);
+ std::string error = utils::RunFunctionAndReturnError(
+ func.get(), "[{\"interactive\": true}]", browser());
+ EXPECT_EQ(errors::kUserNotSignedIn, error);
+ EXPECT_TRUE(func->login_ui_shown());
+ EXPECT_FALSE(func->install_ui_shown());
+}
+
+IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
+ InteractiveLoginSuccessNoToken) {
+ scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
+ 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());
+ EXPECT_EQ(std::string(errors::kUserNotSignedIn), error);
+ EXPECT_TRUE(func->login_ui_shown());
+ EXPECT_FALSE(func->install_ui_shown());
+}
+
+IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
+ InteractiveLoginSuccessMintFailure) {
+ scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
+ 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));
std::string error = utils::RunFunctionAndReturnError(
@@ -272,8 +318,8 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
func->set_extension(CreateExtension(CLIENT_ID | SCOPES));
EXPECT_CALL(*func.get(), HasLoginToken())
- .WillOnce(Return(false))
- .WillOnce(Return(true));
+ .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));
@@ -291,8 +337,8 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
func->set_extension(CreateExtension(CLIENT_ID | SCOPES));
EXPECT_CALL(*func.get(), HasLoginToken())
- .WillOnce(Return(false))
- .WillOnce(Return(true));
+ .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));
@@ -309,9 +355,8 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
func->set_extension(CreateExtension(CLIENT_ID | SCOPES));
EXPECT_CALL(*func.get(), HasLoginToken())
- .WillOnce(Return(false))
- .WillOnce(Return(true))
- .WillOnce(Return(true));
+ .WillOnce(Return(false));
+ func->set_login_ui_result(true);
TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow(
TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get());
TestOAuth2MintTokenFlow* flow2 = new TestOAuth2MintTokenFlow(
@@ -333,9 +378,8 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
func->set_extension(CreateExtension(CLIENT_ID | SCOPES));
EXPECT_CALL(*func.get(), HasLoginToken())
- .WillOnce(Return(false))
- .WillOnce(Return(true))
- .WillOnce(Return(true));
+ .WillOnce(Return(false));
+ func->set_login_ui_result(true);
TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow(
TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get());
TestOAuth2MintTokenFlow* flow2 = new TestOAuth2MintTokenFlow(
@@ -359,7 +403,6 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
func->set_extension(CreateExtension(CLIENT_ID | SCOPES));
EXPECT_CALL(*func.get(), HasLoginToken())
- .WillOnce(Return(true))
.WillOnce(Return(true));
TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow(
TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get());
@@ -377,8 +420,6 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
func->set_extension(CreateExtension(CLIENT_ID | SCOPES));
EXPECT_CALL(*func.get(), HasLoginToken())
- .WillOnce(Return(true))
- .WillOnce(Return(true))
.WillOnce(Return(true));
TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow(
TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get());
@@ -398,6 +439,28 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
EXPECT_TRUE(func->install_ui_shown());
}
+IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
+ InteractiveApprovalDoneMintBadCredentials) {
+ scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
+ func->set_extension(CreateExtension(CLIENT_ID | SCOPES));
+ EXPECT_CALL(*func.get(), HasLoginToken())
+ .WillOnce(Return(true));
+ TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow(
+ TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get());
+ TestOAuth2MintTokenFlow* flow2 = new TestOAuth2MintTokenFlow(
+ TestOAuth2MintTokenFlow::MINT_TOKEN_BAD_CREDENTIALS, func.get());
+ EXPECT_CALL(*func.get(), CreateMintTokenFlow(_))
+ .WillOnce(Return(flow1))
+ .WillOnce(Return(flow2));
+
+ func->set_install_ui_result(true);
+ std::string error = utils::RunFunctionAndReturnError(
+ func.get(), "[{\"interactive\": true}]", browser());
+ EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false));
+ EXPECT_FALSE(func->login_ui_shown());
+ EXPECT_TRUE(func->install_ui_shown());
+}
+
class LaunchWebAuthFlowFunctionTest : public ExtensionBrowserTest {
protected:
void RunAndCheckBounds(
@@ -410,7 +473,7 @@ class LaunchWebAuthFlowFunctionTest : public ExtensionBrowserTest {
chrome::NOTIFICATION_BROWSER_WINDOW_READY,
content::NotificationService::AllSources());
- scoped_refptr<IdentityLaunchWebAuthFlowFunction> function(
+ scoped_refptr<IdentityLaunchWebAuthFlowFunction> function(
new IdentityLaunchWebAuthFlowFunction());
scoped_refptr<Extension> empty_extension(
utils::CreateEmptyExtension());

Powered by Google App Engine
This is Rietveld 408576698