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 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.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/signin_manager_factory.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/pref_names.h"
......@@ -48,9 +47,7 @@
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/prefs/pref_service.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_manager.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/browsing_data_filter_builder.h"
......@@ -71,6 +68,8 @@
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.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/simple_url_loader.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -530,20 +529,20 @@ class BrowsingDataRemoverBrowserTest : public InProcessBrowserTest {
class DiceBrowsingDataRemoverBrowserTest
: public BrowsingDataRemoverBrowserTest {
public:
void AddAccountToProfile(const std::string& account_id,
AccountInfo AddAccountToProfile(const std::string& account_id,
Profile* profile,
bool is_primary) {
ProfileOAuth2TokenService* token_service =
ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
token_service->UpdateCredentials(account_id, "token");
ASSERT_TRUE(token_service->RefreshTokenIsAvailable(account_id));
auto* identity_manager = IdentityManagerFactory::GetForProfile(profile);
if (is_primary) {
SigninManager* signin_manager =
SigninManagerFactory::GetForProfile(profile);
DCHECK(!signin_manager->IsAuthenticated());
signin_manager->SetAuthenticatedAccountInfo(account_id,
DCHECK(!identity_manager->HasPrimaryAccount());
return identity::MakePrimaryAccountAvailable(identity_manager,
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:
......@@ -574,21 +573,27 @@ IN_PROC_BROWSER_TEST_F(DiceBrowsingDataRemoverBrowserTest, SyncToken) {
ASSERT_TRUE(SetGaiaCookieForProfile(profile));
// Set a Sync account and a secondary account.
const char kPrimaryAccountId[] = "primary_account_id";
AccountInfo primary_account =
AddAccountToProfile(kPrimaryAccountId, profile, /*is_primary=*/true);
const char kSecondaryAccountId[] = "secondary_account_id";
AccountInfo secondary_account =
AddAccountToProfile(kSecondaryAccountId, profile, /*is_primary=*/false);
// Clear cookies.
RemoveAndWait(content::BrowsingDataRemover::DATA_TYPE_COOKIES);
// Check that the Sync account was not removed and Sync was paused.
ProfileOAuth2TokenService* token_service =
ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
EXPECT_TRUE(token_service->RefreshTokenIsAvailable(kPrimaryAccountId));
EXPECT_EQ(GoogleServiceAuthError::InvalidGaiaCredentialsReason::
identity::IdentityManager* identity_manager =
IdentityManagerFactory::GetForProfile(profile);
EXPECT_TRUE(
identity_manager->HasAccountWithRefreshToken(primary_account.account_id));
EXPECT_EQ(
GoogleServiceAuthError::InvalidGaiaCredentialsReason::
CREDENTIALS_REJECTED_BY_CLIENT,
token_service->GetAuthError(kPrimaryAccountId)
identity_manager
->GetErrorStateOfRefreshTokenForAccount(primary_account.account_id)
.GetInvalidGaiaCredentialsReason());
// 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
......@@ -600,8 +605,10 @@ IN_PROC_BROWSER_TEST_F(DiceBrowsingDataRemoverBrowserTest,
ASSERT_TRUE(SetGaiaCookieForProfile(profile));
// Set a Sync account and a secondary account.
const char kPrimaryAccountId[] = "primary_account_id";
AccountInfo primary_account =
AddAccountToProfile(kPrimaryAccountId, profile, /*is_primary=*/true);
const char kSecondaryAccountId[] = "secondary_account_id";
AccountInfo secondary_account =
AddAccountToProfile(kSecondaryAccountId, profile, /*is_primary=*/false);
// Sync data is being deleted.
std::unique_ptr<AccountReconcilor::ScopedSyncedDataDeletion> deletion =
......@@ -610,12 +617,15 @@ IN_PROC_BROWSER_TEST_F(DiceBrowsingDataRemoverBrowserTest,
// Clear cookies.
RemoveAndWait(content::BrowsingDataRemover::DATA_TYPE_COOKIES);
// Check that the Sync token was not revoked.
ProfileOAuth2TokenService* token_service =
ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
EXPECT_TRUE(token_service->RefreshTokenIsAvailable(kPrimaryAccountId));
EXPECT_FALSE(token_service->RefreshTokenHasError(kPrimaryAccountId));
auto* identity_manager = IdentityManagerFactory::GetForProfile(profile);
EXPECT_TRUE(
identity_manager->HasAccountWithRefreshToken(primary_account.account_id));
EXPECT_FALSE(
identity_manager->HasAccountWithRefreshTokenInPersistentErrorState(
primary_account.account_id));
// 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
......@@ -626,13 +636,15 @@ IN_PROC_BROWSER_TEST_F(DiceBrowsingDataRemoverBrowserTest, SyncTokenError) {
ASSERT_TRUE(SetGaiaCookieForProfile(profile));
// Set a Sync account with authentication error.
const char kAccountId[] = "account_id";
AccountInfo primary_account =
AddAccountToProfile(kAccountId, profile, /*is_primary=*/true);
ProfileOAuth2TokenService* token_service =
ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
token_service->GetDelegate()->UpdateAuthError(
kAccountId, GoogleServiceAuthError::FromInvalidGaiaCredentialsReason(
auto* identity_manager = IdentityManagerFactory::GetForProfile(profile);
identity::SetAccountWithRefreshTokenInPersistentErrorState(
identity_manager, primary_account.account_id,
GoogleServiceAuthError::FromInvalidGaiaCredentialsReason(
GoogleServiceAuthError::InvalidGaiaCredentialsReason::
CREDENTIALS_REJECTED_BY_SERVER));
// Sync data is being deleted.
std::unique_ptr<AccountReconcilor::ScopedSyncedDataDeletion> deletion =
AccountReconcilorFactory::GetForProfile(profile)
......@@ -640,10 +652,13 @@ IN_PROC_BROWSER_TEST_F(DiceBrowsingDataRemoverBrowserTest, SyncTokenError) {
// Clear cookies.
RemoveAndWait(content::BrowsingDataRemover::DATA_TYPE_COOKIES);
// Check that the account was not removed and Sync was paused.
EXPECT_TRUE(token_service->RefreshTokenIsAvailable(kAccountId));
EXPECT_EQ(GoogleServiceAuthError::InvalidGaiaCredentialsReason::
EXPECT_TRUE(
identity_manager->HasAccountWithRefreshToken(primary_account.account_id));
EXPECT_EQ(
GoogleServiceAuthError::InvalidGaiaCredentialsReason::
CREDENTIALS_REJECTED_BY_CLIENT,
token_service->GetAuthError(kAccountId)
identity_manager
->GetErrorStateOfRefreshTokenForAccount(primary_account.account_id)
.GetInvalidGaiaCredentialsReason());
}
......@@ -655,13 +670,14 @@ IN_PROC_BROWSER_TEST_F(DiceBrowsingDataRemoverBrowserTest, NoSync) {
ASSERT_TRUE(SetGaiaCookieForProfile(profile));
// Set a non-Sync account.
const char kAccountId[] = "account_id";
AccountInfo secondary_account =
AddAccountToProfile(kAccountId, profile, /*is_primary=*/false);
// Clear cookies.
RemoveAndWait(content::BrowsingDataRemover::DATA_TYPE_COOKIES);
// Check that the account was removed.
ProfileOAuth2TokenService* token_service =
ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
EXPECT_FALSE(token_service->RefreshTokenIsAvailable(kAccountId));
auto* identity_manager = IdentityManagerFactory::GetForProfile(profile);
EXPECT_FALSE(identity_manager->HasAccountWithRefreshToken(
secondary_account.account_id));
}
#endif
......
......@@ -304,6 +304,10 @@ class IdentityManager : public SigninManagerBase::Observer,
const std::string& account_id);
friend void UpdateAccountInfoForAccount(IdentityManager* identity_manager,
AccountInfo account_info);
friend void SetAccountWithRefreshTokenInPersistentErrorState(
IdentityManager* identity_manager,
const std::string& account_id,
const GoogleServiceAuthError& auth_error);
friend MultiProfileDownloadNotificationTest;
friend file_manager::MultiProfileFilesAppBrowserTest;
......
......@@ -353,4 +353,14 @@ std::string GetTestGaiaIdForEmail(const std::string& email) {
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
......@@ -11,6 +11,7 @@
#include "components/signin/core/browser/account_info.h"
class FakeGaiaCookieManagerService;
class GoogleServiceAuthError;
// Test-related utilities that don't fit in either IdentityTestEnvironment or
// IdentityManager itself. NOTE: Using these utilities directly is discouraged,
......@@ -127,6 +128,11 @@ void UpdateAccountInfoForAccount(IdentityManager* identity_manager,
std::string GetTestGaiaIdForEmail(const std::string& email);
void SetAccountWithRefreshTokenInPersistentErrorState(
IdentityManager* identity_manager,
const std::string& account_id,
const GoogleServiceAuthError& auth_error);
} // namespace identity
#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