Commit 62659544 authored by Sergio Villar Senin's avatar Sergio Villar Senin Committed by Commit Bot

Convert browsing_data_remover_browsertest.cc to Identity service

Replaced the usage of ProfileOAuth2TokenService and SigninManager by
identity API calls.

This CL adds a new function to the identity_test_utils.h set to set
the auth error of a given account with a refresh token.

Bug: 903859
Change-Id: I29e1ae3bee6ba7f69404f5f2bb7152fa0db9101d
Reviewed-on: https://chromium-review.googlesource.com/c/1352250Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Reviewed-by: default avatarJoshua Bell <jsbell@chromium.org>
Commit-Queue: Sergio Villar <svillar@igalia.com>
Cr-Commit-Position: refs/heads/master@{#611821}
parent 638ce695
...@@ -36,9 +36,8 @@ ...@@ -36,9 +36,8 @@
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/signin/account_reconcilor_factory.h" #include "chrome/browser/signin/account_reconcilor_factory.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h" #include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/signin/scoped_account_consistency.h" #include "chrome/browser/signin/scoped_account_consistency.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
...@@ -48,9 +47,7 @@ ...@@ -48,9 +47,7 @@
#include "components/content_settings/core/browser/host_content_settings_map.h" #include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/signin/core/browser/account_reconcilor.h" #include "components/signin/core/browser/account_reconcilor.h"
#include "components/signin/core/browser/profile_oauth2_token_service.h"
#include "components/signin/core/browser/signin_buildflags.h" #include "components/signin/core/browser/signin_buildflags.h"
#include "components/signin/core/browser/signin_manager.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/browsing_data_filter_builder.h" #include "content/public/browser/browsing_data_filter_builder.h"
...@@ -71,6 +68,8 @@ ...@@ -71,6 +68,8 @@
#include "net/dns/mock_host_resolver.h" #include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h" #include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h" #include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "services/identity/public/cpp/identity_manager.h"
#include "services/identity/public/cpp/identity_test_utils.h"
#include "services/network/public/cpp/features.h" #include "services/network/public/cpp/features.h"
#include "services/network/public/cpp/simple_url_loader.h" #include "services/network/public/cpp/simple_url_loader.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -530,20 +529,20 @@ class BrowsingDataRemoverBrowserTest : public InProcessBrowserTest { ...@@ -530,20 +529,20 @@ class BrowsingDataRemoverBrowserTest : public InProcessBrowserTest {
class DiceBrowsingDataRemoverBrowserTest class DiceBrowsingDataRemoverBrowserTest
: public BrowsingDataRemoverBrowserTest { : public BrowsingDataRemoverBrowserTest {
public: public:
void AddAccountToProfile(const std::string& account_id, AccountInfo AddAccountToProfile(const std::string& account_id,
Profile* profile, Profile* profile,
bool is_primary) { bool is_primary) {
ProfileOAuth2TokenService* token_service = auto* identity_manager = IdentityManagerFactory::GetForProfile(profile);
ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
token_service->UpdateCredentials(account_id, "token");
ASSERT_TRUE(token_service->RefreshTokenIsAvailable(account_id));
if (is_primary) { if (is_primary) {
SigninManager* signin_manager = DCHECK(!identity_manager->HasPrimaryAccount());
SigninManagerFactory::GetForProfile(profile); return identity::MakePrimaryAccountAvailable(identity_manager,
DCHECK(!signin_manager->IsAuthenticated());
signin_manager->SetAuthenticatedAccountInfo(account_id,
account_id + "@gmail.com"); account_id + "@gmail.com");
} }
auto account_info =
identity::MakeAccountAvailable(identity_manager, account_id);
DCHECK(
identity_manager->HasAccountWithRefreshToken(account_info.account_id));
return account_info;
} }
private: private:
...@@ -574,21 +573,27 @@ IN_PROC_BROWSER_TEST_F(DiceBrowsingDataRemoverBrowserTest, SyncToken) { ...@@ -574,21 +573,27 @@ IN_PROC_BROWSER_TEST_F(DiceBrowsingDataRemoverBrowserTest, SyncToken) {
ASSERT_TRUE(SetGaiaCookieForProfile(profile)); ASSERT_TRUE(SetGaiaCookieForProfile(profile));
// Set a Sync account and a secondary account. // Set a Sync account and a secondary account.
const char kPrimaryAccountId[] = "primary_account_id"; const char kPrimaryAccountId[] = "primary_account_id";
AccountInfo primary_account =
AddAccountToProfile(kPrimaryAccountId, profile, /*is_primary=*/true); AddAccountToProfile(kPrimaryAccountId, profile, /*is_primary=*/true);
const char kSecondaryAccountId[] = "secondary_account_id"; const char kSecondaryAccountId[] = "secondary_account_id";
AccountInfo secondary_account =
AddAccountToProfile(kSecondaryAccountId, profile, /*is_primary=*/false); AddAccountToProfile(kSecondaryAccountId, profile, /*is_primary=*/false);
// Clear cookies. // Clear cookies.
RemoveAndWait(content::BrowsingDataRemover::DATA_TYPE_COOKIES); RemoveAndWait(content::BrowsingDataRemover::DATA_TYPE_COOKIES);
// Check that the Sync account was not removed and Sync was paused. // Check that the Sync account was not removed and Sync was paused.
ProfileOAuth2TokenService* token_service = identity::IdentityManager* identity_manager =
ProfileOAuth2TokenServiceFactory::GetForProfile(profile); IdentityManagerFactory::GetForProfile(profile);
EXPECT_TRUE(token_service->RefreshTokenIsAvailable(kPrimaryAccountId)); EXPECT_TRUE(
EXPECT_EQ(GoogleServiceAuthError::InvalidGaiaCredentialsReason:: identity_manager->HasAccountWithRefreshToken(primary_account.account_id));
EXPECT_EQ(
GoogleServiceAuthError::InvalidGaiaCredentialsReason::
CREDENTIALS_REJECTED_BY_CLIENT, CREDENTIALS_REJECTED_BY_CLIENT,
token_service->GetAuthError(kPrimaryAccountId) identity_manager
->GetErrorStateOfRefreshTokenForAccount(primary_account.account_id)
.GetInvalidGaiaCredentialsReason()); .GetInvalidGaiaCredentialsReason());
// Check that the secondary token was revoked. // Check that the secondary token was revoked.
EXPECT_FALSE(token_service->RefreshTokenIsAvailable(kSecondaryAccountId)); EXPECT_FALSE(identity_manager->HasAccountWithRefreshToken(
secondary_account.account_id));
} }
// Test that Sync is not paused when cookies are cleared, if synced data is // Test that Sync is not paused when cookies are cleared, if synced data is
...@@ -600,8 +605,10 @@ IN_PROC_BROWSER_TEST_F(DiceBrowsingDataRemoverBrowserTest, ...@@ -600,8 +605,10 @@ IN_PROC_BROWSER_TEST_F(DiceBrowsingDataRemoverBrowserTest,
ASSERT_TRUE(SetGaiaCookieForProfile(profile)); ASSERT_TRUE(SetGaiaCookieForProfile(profile));
// Set a Sync account and a secondary account. // Set a Sync account and a secondary account.
const char kPrimaryAccountId[] = "primary_account_id"; const char kPrimaryAccountId[] = "primary_account_id";
AccountInfo primary_account =
AddAccountToProfile(kPrimaryAccountId, profile, /*is_primary=*/true); AddAccountToProfile(kPrimaryAccountId, profile, /*is_primary=*/true);
const char kSecondaryAccountId[] = "secondary_account_id"; const char kSecondaryAccountId[] = "secondary_account_id";
AccountInfo secondary_account =
AddAccountToProfile(kSecondaryAccountId, profile, /*is_primary=*/false); AddAccountToProfile(kSecondaryAccountId, profile, /*is_primary=*/false);
// Sync data is being deleted. // Sync data is being deleted.
std::unique_ptr<AccountReconcilor::ScopedSyncedDataDeletion> deletion = std::unique_ptr<AccountReconcilor::ScopedSyncedDataDeletion> deletion =
...@@ -610,12 +617,15 @@ IN_PROC_BROWSER_TEST_F(DiceBrowsingDataRemoverBrowserTest, ...@@ -610,12 +617,15 @@ IN_PROC_BROWSER_TEST_F(DiceBrowsingDataRemoverBrowserTest,
// Clear cookies. // Clear cookies.
RemoveAndWait(content::BrowsingDataRemover::DATA_TYPE_COOKIES); RemoveAndWait(content::BrowsingDataRemover::DATA_TYPE_COOKIES);
// Check that the Sync token was not revoked. // Check that the Sync token was not revoked.
ProfileOAuth2TokenService* token_service = auto* identity_manager = IdentityManagerFactory::GetForProfile(profile);
ProfileOAuth2TokenServiceFactory::GetForProfile(profile); EXPECT_TRUE(
EXPECT_TRUE(token_service->RefreshTokenIsAvailable(kPrimaryAccountId)); identity_manager->HasAccountWithRefreshToken(primary_account.account_id));
EXPECT_FALSE(token_service->RefreshTokenHasError(kPrimaryAccountId)); EXPECT_FALSE(
identity_manager->HasAccountWithRefreshTokenInPersistentErrorState(
primary_account.account_id));
// Check that the secondary token was revoked. // Check that the secondary token was revoked.
EXPECT_FALSE(token_service->RefreshTokenIsAvailable(kSecondaryAccountId)); EXPECT_FALSE(identity_manager->HasAccountWithRefreshToken(
secondary_account.account_id));
} }
// Test that Sync is paused when cookies are cleared if Sync was in error, even // Test that Sync is paused when cookies are cleared if Sync was in error, even
...@@ -626,13 +636,15 @@ IN_PROC_BROWSER_TEST_F(DiceBrowsingDataRemoverBrowserTest, SyncTokenError) { ...@@ -626,13 +636,15 @@ IN_PROC_BROWSER_TEST_F(DiceBrowsingDataRemoverBrowserTest, SyncTokenError) {
ASSERT_TRUE(SetGaiaCookieForProfile(profile)); ASSERT_TRUE(SetGaiaCookieForProfile(profile));
// Set a Sync account with authentication error. // Set a Sync account with authentication error.
const char kAccountId[] = "account_id"; const char kAccountId[] = "account_id";
AccountInfo primary_account =
AddAccountToProfile(kAccountId, profile, /*is_primary=*/true); AddAccountToProfile(kAccountId, profile, /*is_primary=*/true);
ProfileOAuth2TokenService* token_service = auto* identity_manager = IdentityManagerFactory::GetForProfile(profile);
ProfileOAuth2TokenServiceFactory::GetForProfile(profile); identity::SetAccountWithRefreshTokenInPersistentErrorState(
token_service->GetDelegate()->UpdateAuthError( identity_manager, primary_account.account_id,
kAccountId, GoogleServiceAuthError::FromInvalidGaiaCredentialsReason( GoogleServiceAuthError::FromInvalidGaiaCredentialsReason(
GoogleServiceAuthError::InvalidGaiaCredentialsReason:: GoogleServiceAuthError::InvalidGaiaCredentialsReason::
CREDENTIALS_REJECTED_BY_SERVER)); CREDENTIALS_REJECTED_BY_SERVER));
// Sync data is being deleted. // Sync data is being deleted.
std::unique_ptr<AccountReconcilor::ScopedSyncedDataDeletion> deletion = std::unique_ptr<AccountReconcilor::ScopedSyncedDataDeletion> deletion =
AccountReconcilorFactory::GetForProfile(profile) AccountReconcilorFactory::GetForProfile(profile)
...@@ -640,10 +652,13 @@ IN_PROC_BROWSER_TEST_F(DiceBrowsingDataRemoverBrowserTest, SyncTokenError) { ...@@ -640,10 +652,13 @@ IN_PROC_BROWSER_TEST_F(DiceBrowsingDataRemoverBrowserTest, SyncTokenError) {
// Clear cookies. // Clear cookies.
RemoveAndWait(content::BrowsingDataRemover::DATA_TYPE_COOKIES); RemoveAndWait(content::BrowsingDataRemover::DATA_TYPE_COOKIES);
// Check that the account was not removed and Sync was paused. // Check that the account was not removed and Sync was paused.
EXPECT_TRUE(token_service->RefreshTokenIsAvailable(kAccountId)); EXPECT_TRUE(
EXPECT_EQ(GoogleServiceAuthError::InvalidGaiaCredentialsReason:: identity_manager->HasAccountWithRefreshToken(primary_account.account_id));
EXPECT_EQ(
GoogleServiceAuthError::InvalidGaiaCredentialsReason::
CREDENTIALS_REJECTED_BY_CLIENT, CREDENTIALS_REJECTED_BY_CLIENT,
token_service->GetAuthError(kAccountId) identity_manager
->GetErrorStateOfRefreshTokenForAccount(primary_account.account_id)
.GetInvalidGaiaCredentialsReason()); .GetInvalidGaiaCredentialsReason());
} }
...@@ -655,13 +670,14 @@ IN_PROC_BROWSER_TEST_F(DiceBrowsingDataRemoverBrowserTest, NoSync) { ...@@ -655,13 +670,14 @@ IN_PROC_BROWSER_TEST_F(DiceBrowsingDataRemoverBrowserTest, NoSync) {
ASSERT_TRUE(SetGaiaCookieForProfile(profile)); ASSERT_TRUE(SetGaiaCookieForProfile(profile));
// Set a non-Sync account. // Set a non-Sync account.
const char kAccountId[] = "account_id"; const char kAccountId[] = "account_id";
AccountInfo secondary_account =
AddAccountToProfile(kAccountId, profile, /*is_primary=*/false); AddAccountToProfile(kAccountId, profile, /*is_primary=*/false);
// Clear cookies. // Clear cookies.
RemoveAndWait(content::BrowsingDataRemover::DATA_TYPE_COOKIES); RemoveAndWait(content::BrowsingDataRemover::DATA_TYPE_COOKIES);
// Check that the account was removed. // Check that the account was removed.
ProfileOAuth2TokenService* token_service = auto* identity_manager = IdentityManagerFactory::GetForProfile(profile);
ProfileOAuth2TokenServiceFactory::GetForProfile(profile); EXPECT_FALSE(identity_manager->HasAccountWithRefreshToken(
EXPECT_FALSE(token_service->RefreshTokenIsAvailable(kAccountId)); secondary_account.account_id));
} }
#endif #endif
......
...@@ -304,6 +304,10 @@ class IdentityManager : public SigninManagerBase::Observer, ...@@ -304,6 +304,10 @@ class IdentityManager : public SigninManagerBase::Observer,
const std::string& account_id); const std::string& account_id);
friend void UpdateAccountInfoForAccount(IdentityManager* identity_manager, friend void UpdateAccountInfoForAccount(IdentityManager* identity_manager,
AccountInfo account_info); AccountInfo account_info);
friend void SetAccountWithRefreshTokenInPersistentErrorState(
IdentityManager* identity_manager,
const std::string& account_id,
const GoogleServiceAuthError& auth_error);
friend MultiProfileDownloadNotificationTest; friend MultiProfileDownloadNotificationTest;
friend file_manager::MultiProfileFilesAppBrowserTest; friend file_manager::MultiProfileFilesAppBrowserTest;
......
...@@ -353,4 +353,14 @@ std::string GetTestGaiaIdForEmail(const std::string& email) { ...@@ -353,4 +353,14 @@ std::string GetTestGaiaIdForEmail(const std::string& email) {
return gaia_id; return gaia_id;
} }
void SetAccountWithRefreshTokenInPersistentErrorState(
IdentityManager* identity_manager,
const std::string& account_id,
const GoogleServiceAuthError& auth_error) {
identity_manager->GetTokenService()->GetDelegate()->UpdateAuthError(
account_id, GoogleServiceAuthError::FromInvalidGaiaCredentialsReason(
GoogleServiceAuthError::InvalidGaiaCredentialsReason::
CREDENTIALS_REJECTED_BY_SERVER));
}
} // namespace identity } // namespace identity
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "components/signin/core/browser/account_info.h" #include "components/signin/core/browser/account_info.h"
class FakeGaiaCookieManagerService; class FakeGaiaCookieManagerService;
class GoogleServiceAuthError;
// Test-related utilities that don't fit in either IdentityTestEnvironment or // Test-related utilities that don't fit in either IdentityTestEnvironment or
// IdentityManager itself. NOTE: Using these utilities directly is discouraged, // IdentityManager itself. NOTE: Using these utilities directly is discouraged,
...@@ -127,6 +128,11 @@ void UpdateAccountInfoForAccount(IdentityManager* identity_manager, ...@@ -127,6 +128,11 @@ void UpdateAccountInfoForAccount(IdentityManager* identity_manager,
std::string GetTestGaiaIdForEmail(const std::string& email); std::string GetTestGaiaIdForEmail(const std::string& email);
void SetAccountWithRefreshTokenInPersistentErrorState(
IdentityManager* identity_manager,
const std::string& account_id,
const GoogleServiceAuthError& auth_error);
} // namespace identity } // namespace identity
#endif // SERVICES_IDENTITY_PUBLIC_CPP_IDENTITY_TEST_UTILS_H_ #endif // SERVICES_IDENTITY_PUBLIC_CPP_IDENTITY_TEST_UTILS_H_
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