Commit 82e2a47a authored by David Roger's avatar David Roger Committed by Commit Bot

[signin] Remove usage of AuthErrorProvider from tests (2)

Going forward the default API for interacting with authentication error
should be the token service rather than the SigninErrorController.
This CL updates tests to use the token service instead of
AuthErrorProvider to set authentication errors.

Bug: 836212
Change-Id: I9b5629bad7b17b6cab70978cc23bbc828bf62d61
Reviewed-on: https://chromium-review.googlesource.com/1016904
Commit-Queue: David Roger <droger@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Cr-Commit-Position: refs/heads/master@{#561830}
parent 2d32fab3
......@@ -23,7 +23,6 @@
#include "chrome/browser/extensions/chrome_extension_test_notification_observer.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_error_controller_factory.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.h"
......@@ -38,9 +37,7 @@
#include "components/browser_sync/browser_sync_switches.h"
#include "components/prefs/pref_service.h"
#include "components/signin/core/browser/account_tracker_service.h"
#include "components/signin/core/browser/fake_auth_status_provider.h"
#include "components/signin/core/browser/profile_oauth2_token_service.h"
#include "components/signin/core/browser/signin_error_controller.h"
#include "components/user_manager/user.h"
#include "components/user_manager/user_manager.h"
#include "content/public/browser/browser_thread.h"
......@@ -49,6 +46,7 @@
#include "extensions/browser/process_manager.h"
#include "extensions/test/extension_test_message_listener.h"
#include "extensions/test/result_catcher.h"
#include "google_apis/gaia/oauth2_token_service_delegate.h"
#include "net/cookies/canonical_cookie.h"
#include "net/cookies/cookie_store.h"
#include "net/test/embedded_test_server/http_request.h"
......@@ -638,9 +636,8 @@ IN_PROC_BROWSER_TEST_F(OAuth2Test, PRE_SetInvalidTokenStatus) {
StartNewUserSession(true);
}
// Tests that an auth error reported by SigninErrorController marks invalid auth
// token status despite OAuth2LoginManager thinks merge session is done
// successfully
// Tests that an auth error marks invalid auth token status despite
// OAuth2LoginManager thinks merge session is done successfully
IN_PROC_BROWSER_TEST_F(OAuth2Test, SetInvalidTokenStatus) {
RequestDeferrer list_accounts_request_deferer;
AddRequestDeferer("/ListAccounts", &list_accounts_request_deferer);
......@@ -674,12 +671,12 @@ IN_PROC_BROWSER_TEST_F(OAuth2Test, SetInvalidTokenStatus) {
ASSERT_NE(OAuth2LoginManager::SESSION_RESTORE_DONE, login_manager->state());
// Generate an auth error.
SigninErrorController* const error_controller =
SigninErrorControllerFactory::GetForProfile(profile());
FakeAuthStatusProvider auth_provider(error_controller);
auth_provider.SetAuthError(
kTestEmail, GoogleServiceAuthError(
GoogleServiceAuthError::State::INVALID_GAIA_CREDENTIALS));
ProfileOAuth2TokenServiceFactory::GetForProfile(profile())
->GetDelegate()
->UpdateAuthError(
kTestEmail,
GoogleServiceAuthError(
GoogleServiceAuthError::State::INVALID_GAIA_CREDENTIALS));
// Let go /ListAccounts request.
list_accounts_request_deferer.UnblockRequest();
......
......@@ -14,18 +14,13 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/login/users/mock_user_manager.h"
#include "chrome/browser/notifications/notification_display_service_tester.h"
#include "chrome/browser/signin/fake_signin_manager_builder.h"
#include "chrome/browser/signin/signin_error_controller_factory.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_error_notifier_factory_ash.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/test/base/browser_with_test_window_test.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/testing_profile_manager.h"
#include "components/signin/core/browser/fake_auth_status_provider.h"
#include "components/signin/core/browser/signin_error_controller.h"
#include "components/signin/core/browser/signin_manager.h"
#include "components/signin/core/browser/profile_oauth2_token_service.h"
#include "components/user_manager/scoped_user_manager.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "google_apis/gaia/oauth2_token_service_delegate.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/message_center/public/cpp/notification.h"
......@@ -47,88 +42,62 @@ class SigninErrorNotifierTest : public BrowserWithTestWindowTest {
user_manager_enabler_ = std::make_unique<user_manager::ScopedUserManager>(
base::WrapUnique(mock_user_manager_));
error_controller_ =
SigninErrorControllerFactory::GetForProfile(GetProfile());
SigninErrorNotifierFactory::GetForProfile(GetProfile());
display_service_ =
std::make_unique<NotificationDisplayServiceTester>(profile());
}
TestingProfile::TestingFactories GetTestingFactories() override {
return {{SigninManagerFactory::GetInstance(), BuildFakeSigninManagerBase}};
void SetAuthError(const GoogleServiceAuthError& error) {
// TODO(https://crbug.com/836212): Do not use the delegate directly, because
// it is internal API.
ProfileOAuth2TokenService* token_service =
ProfileOAuth2TokenServiceFactory::GetForProfile(profile());
if (!token_service->RefreshTokenIsAvailable(kTestAccountId))
token_service->UpdateCredentials(kTestAccountId, "refresh_token");
token_service->GetDelegate()->UpdateAuthError(kTestAccountId, error);
}
protected:
SigninErrorController* error_controller_;
std::unique_ptr<NotificationDisplayServiceTester> display_service_;
chromeos::MockUserManager* mock_user_manager_; // Not owned.
std::unique_ptr<user_manager::ScopedUserManager> user_manager_enabler_;
};
TEST_F(SigninErrorNotifierTest, NoErrorAuthStatusProviders) {
EXPECT_FALSE(display_service_->GetNotification(kNotificationId));
{
// Add a provider (removes itself on exiting this scope).
FakeAuthStatusProvider provider(error_controller_);
EXPECT_FALSE(display_service_->GetNotification(kNotificationId));
}
TEST_F(SigninErrorNotifierTest, NoNotification) {
EXPECT_FALSE(display_service_->GetNotification(kNotificationId));
}
TEST_F(SigninErrorNotifierTest, ErrorAuthStatusProvider) {
{
FakeAuthStatusProvider provider(error_controller_);
EXPECT_FALSE(display_service_->GetNotification(kNotificationId));
{
FakeAuthStatusProvider error_provider(error_controller_);
error_provider.SetAuthError(
kTestAccountId,
GoogleServiceAuthError(
GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS));
EXPECT_TRUE(display_service_->GetNotification(kNotificationId));
}
// error_provider is removed now that we've left that scope.
EXPECT_FALSE(display_service_->GetNotification(kNotificationId));
}
// All providers should be removed now.
TEST_F(SigninErrorNotifierTest, ErrorReset) {
EXPECT_FALSE(display_service_->GetNotification(kNotificationId));
SetAuthError(
GoogleServiceAuthError(GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS));
EXPECT_TRUE(display_service_->GetNotification(kNotificationId));
SetAuthError(GoogleServiceAuthError::AuthErrorNone());
EXPECT_FALSE(display_service_->GetNotification(kNotificationId));
}
TEST_F(SigninErrorNotifierTest, AuthStatusProviderErrorTransition) {
{
FakeAuthStatusProvider provider0(error_controller_);
FakeAuthStatusProvider provider1(error_controller_);
provider0.SetAuthError(
kTestAccountId,
GoogleServiceAuthError(
GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS));
TEST_F(SigninErrorNotifierTest, ErrorTransition) {
SetAuthError(
GoogleServiceAuthError(GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS));
base::Optional<message_center::Notification> notification =
display_service_->GetNotification(kNotificationId);
ASSERT_TRUE(notification);
base::string16 message = notification->message();
EXPECT_FALSE(message.empty());
// Now set another auth error and clear the original.
provider1.SetAuthError(
kTestAccountId,
GoogleServiceAuthError(
GoogleServiceAuthError::UNEXPECTED_SERVICE_RESPONSE));
provider0.SetAuthError(
kTestAccountId,
GoogleServiceAuthError::AuthErrorNone());
notification = display_service_->GetNotification(kNotificationId);
ASSERT_TRUE(notification);
base::string16 new_message = notification->message();
EXPECT_FALSE(new_message.empty());
ASSERT_NE(new_message, message);
provider1.SetAuthError(
kTestAccountId, GoogleServiceAuthError::AuthErrorNone());
EXPECT_FALSE(display_service_->GetNotification(kNotificationId));
}
base::Optional<message_center::Notification> notification =
display_service_->GetNotification(kNotificationId);
ASSERT_TRUE(notification);
base::string16 message = notification->message();
EXPECT_FALSE(message.empty());
// Now set another auth error.
SetAuthError(GoogleServiceAuthError(
GoogleServiceAuthError::UNEXPECTED_SERVICE_RESPONSE));
notification = display_service_->GetNotification(kNotificationId);
ASSERT_TRUE(notification);
base::string16 new_message = notification->message();
EXPECT_FALSE(new_message.empty());
ASSERT_NE(new_message, message);
}
// Verify that SigninErrorNotifier ignores certain errors.
......@@ -160,9 +129,8 @@ TEST_F(SigninErrorNotifierTest, AuthStatusEnumerateAllErrors) {
for (size_t i = 0; i < arraysize(table); ++i) {
if (GoogleServiceAuthError::IsDeprecated(table[i].error_state))
continue;
FakeAuthStatusProvider provider(error_controller_);
provider.SetAuthError(kTestAccountId,
GoogleServiceAuthError(table[i].error_state));
SetAuthError(GoogleServiceAuthError(table[i].error_state));
base::Optional<message_center::Notification> notification =
display_service_->GetNotification(kNotificationId);
ASSERT_EQ(table[i].is_error, !!notification);
......@@ -171,6 +139,7 @@ TEST_F(SigninErrorNotifierTest, AuthStatusEnumerateAllErrors) {
EXPECT_FALSE(notification->message().empty());
EXPECT_EQ((size_t)1, notification->buttons().size());
}
SetAuthError(GoogleServiceAuthError::AuthErrorNone());
}
}
......
......@@ -15,6 +15,7 @@
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/browser/signin/fake_signin_manager_builder.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_error_controller_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
......@@ -31,7 +32,7 @@
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "components/prefs/pref_service.h"
#include "components/signin/core/browser/fake_auth_status_provider.h"
#include "components/signin/core/browser/profile_oauth2_token_service.h"
#include "components/signin/core/browser/signin_manager.h"
#include "components/sync/base/sync_prefs.h"
#include "components/sync_preferences/pref_service_syncable.h"
......@@ -43,6 +44,7 @@
#include "content/public/test/test_browser_thread_bundle.h"
#include "content/public/test/test_web_ui.h"
#include "content/public/test/web_contents_tester.h"
#include "google_apis/gaia/oauth2_token_service_delegate.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/layout.h"
......@@ -64,6 +66,7 @@ MATCHER_P(ModelTypeSetMatches, value, "") {
}
const char kTestUser[] = "chrome.p13n.test@gmail.com";
const char kTestGaiaID[] = "123456789";
const char kTestCallbackId[] = "test-callback-id";
// Returns a ModelTypeSet with all user selectable types set.
......@@ -201,7 +204,7 @@ class PeopleHandlerTest : public ChromeRenderViewHostTestHarness {
mock_signin_ = SigninManagerFactory::GetForProfile(profile());
std::string username = GetTestUser();
if (!username.empty())
mock_signin_->SetAuthenticatedAccountInfo(username, username);
mock_signin_->SetAuthenticatedAccountInfo(kTestGaiaID, username);
mock_pss_ = static_cast<ProfileSyncServiceMock*>(
ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse(
......@@ -763,11 +766,17 @@ TEST_F(PeopleHandlerTest, ShowSigninOnAuthError) {
GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
SetupInitializedProfileSyncService();
mock_signin_->SetAuthenticatedAccountInfo(kTestUser, kTestUser);
FakeAuthStatusProvider provider(
SigninErrorControllerFactory::GetForProfile(profile()));
provider.SetAuthError(kTestUser, error_);
EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
mock_signin_->SetAuthenticatedAccountInfo(kTestGaiaID, kTestUser);
std::string account_id = mock_signin_->GetAuthenticatedAccountId();
// TODO(https://crbug.com/836212): Do not use the delegate directly, because
// it is internal API.
ProfileOAuth2TokenService* token_service =
ProfileOAuth2TokenServiceFactory::GetForProfile(profile());
token_service->UpdateCredentials(account_id, "refresh_token");
token_service->GetDelegate()->UpdateAuthError(account_id, error_);
EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false));
EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
.WillRepeatedly(Return(false));
EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment