Commit 731a1cf7 authored by Antonio Gomes's avatar Antonio Gomes Committed by Commit Bot

[s13n] Convert UserPolicySigninServiceTest way from SigninManager

This makes use of the helper IdentityTestEnvironmentProfileAdaptor.
In order to be able to construct the Profile object the same way as the
test originally was, and additional optional parameter was added to
IdentityTestEnvironmentProfileAdaptor::CreateProfileForIdentityTestEnvironment.

BUG=890783

Change-Id: I5c2a48dd4aa7e7377f8a7806717b513b7f27bfe0
Reviewed-on: https://chromium-review.googlesource.com/c/1301814Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Reviewed-by: default avatarMaksim Ivanov <emaxx@chromium.org>
Commit-Queue: Antonio Gomes <tonikitoo@igalia.com>
Cr-Commit-Position: refs/heads/master@{#606434}
parent 85b48eb3
...@@ -24,9 +24,8 @@ ...@@ -24,9 +24,8 @@
#include "chrome/browser/signin/chrome_signin_client_factory.h" #include "chrome/browser/signin/chrome_signin_client_factory.h"
#include "chrome/browser/signin/fake_account_fetcher_service_builder.h" #include "chrome/browser/signin/fake_account_fetcher_service_builder.h"
#include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h"
#include "chrome/browser/signin/fake_signin_manager_builder.h" #include "chrome/browser/signin/identity_test_environment_profile_adaptor.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h" #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/signin/signin_util.h" #include "chrome/browser/signin/signin_util.h"
#include "chrome/browser/signin/test_signin_client_builder.h" #include "chrome/browser/signin/test_signin_client_builder.h"
#include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/testing_browser_process.h"
...@@ -43,7 +42,6 @@ ...@@ -43,7 +42,6 @@
#include "components/signin/core/browser/account_tracker_service.h" #include "components/signin/core/browser/account_tracker_service.h"
#include "components/signin/core/browser/fake_account_fetcher_service.h" #include "components/signin/core/browser/fake_account_fetcher_service.h"
#include "components/signin/core/browser/fake_profile_oauth2_token_service.h" #include "components/signin/core/browser/fake_profile_oauth2_token_service.h"
#include "components/signin/core/browser/signin_manager.h"
#include "components/sync_preferences/testing_pref_service_syncable.h" #include "components/sync_preferences/testing_pref_service_syncable.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
#include "content/public/browser/notification_details.h" #include "content/public/browser/notification_details.h"
...@@ -135,10 +133,9 @@ class UserPolicySigninServiceTest : public testing::Test { ...@@ -135,10 +133,9 @@ class UserPolicySigninServiceTest : public testing::Test {
base::Bind(&UserPolicySigninServiceTest::OnRegisterCompleted, base::Bind(&UserPolicySigninServiceTest::OnRegisterCompleted,
base::Unretained(this)); base::Unretained(this));
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
GetTokenService()->UpdateCredentials( identity_test_env()->SetRefreshTokenForAccount(
AccountTrackerServiceFactory::GetForProfile(profile_.get()) AccountTrackerServiceFactory::GetForProfile(profile_.get())
->SeedAccountInfo(kTestGaiaId, kTestUser), ->SeedAccountInfo(kTestGaiaId, kTestUser));
"oauth2_login_refresh_token");
service->RegisterForPolicyWithAccountId(kTestUser, kTestGaiaId, callback); service->RegisterForPolicyWithAccountId(kTestUser, kTestGaiaId, callback);
ASSERT_TRUE(IsRequestActive()); ASSERT_TRUE(IsRequestActive());
#else #else
...@@ -174,27 +171,18 @@ class UserPolicySigninServiceTest : public testing::Test { ...@@ -174,27 +171,18 @@ class UserPolicySigninServiceTest : public testing::Test {
// API before creating the profile. // API before creating the profile.
UserCloudPolicyManagerFactory::GetInstance()->RegisterTestingFactory( UserCloudPolicyManagerFactory::GetInstance()->RegisterTestingFactory(
base::BindRepeating(&BuildCloudPolicyManager)); base::BindRepeating(&BuildCloudPolicyManager));
TestingProfile::Builder builder;
builder.SetPrefService( TestingProfile::TestingFactories factories = {
std::unique_ptr<sync_preferences::PrefServiceSyncable>( {AccountFetcherServiceFactory::GetInstance(),
std::move(prefs))); base::BindRepeating(&FakeAccountFetcherServiceBuilder::BuildForTests)},
builder.AddTestingFactory( {ChromeSigninClientFactory::GetInstance(),
SigninManagerFactory::GetInstance(), base::BindRepeating(&signin::BuildTestSigninClient)}};
base::BindRepeating(&BuildFakeSigninManagerForTesting)); profile_ = IdentityTestEnvironmentProfileAdaptor::
builder.AddTestingFactory( CreateProfileForIdentityTestEnvironment(factories, std::move(prefs));
ProfileOAuth2TokenServiceFactory::GetInstance(),
base::BindRepeating(&BuildFakeProfileOAuth2TokenService)); identity_test_env_adaptor_ =
builder.AddTestingFactory( std::make_unique<IdentityTestEnvironmentProfileAdaptor>(profile_.get());
AccountFetcherServiceFactory::GetInstance(),
base::BindRepeating(&FakeAccountFetcherServiceBuilder::BuildForTests));
builder.AddTestingFactory(
ChromeSigninClientFactory::GetInstance(),
base::BindRepeating(&signin::BuildTestSigninClient));
profile_ = builder.Build();
signin_manager_ = static_cast<FakeSigninManager*>(
SigninManagerFactory::GetForProfile(profile_.get()));
// Tests are responsible for freeing the UserCloudPolicyManager instances // Tests are responsible for freeing the UserCloudPolicyManager instances
// they inject. // they inject.
manager_.reset(UserCloudPolicyManagerFactory::GetForBrowserContext( manager_.reset(UserCloudPolicyManagerFactory::GetForBrowserContext(
...@@ -212,6 +200,7 @@ class UserPolicySigninServiceTest : public testing::Test { ...@@ -212,6 +200,7 @@ class UserPolicySigninServiceTest : public testing::Test {
UserPolicySigninServiceFactory::SetDeviceManagementServiceForTesting(NULL); UserPolicySigninServiceFactory::SetDeviceManagementServiceForTesting(NULL);
UserCloudPolicyManagerFactory::GetInstance()->ClearTestingFactory(); UserCloudPolicyManagerFactory::GetInstance()->ClearTestingFactory();
// Free the profile before we clear out the browser prefs. // Free the profile before we clear out the browser prefs.
identity_test_env_adaptor_.reset();
profile_.reset(); profile_.reset();
TestingBrowserProcess* testing_browser_process = TestingBrowserProcess* testing_browser_process =
TestingBrowserProcess::GetGlobal(); TestingBrowserProcess::GetGlobal();
...@@ -225,7 +214,7 @@ class UserPolicySigninServiceTest : public testing::Test { ...@@ -225,7 +214,7 @@ class UserPolicySigninServiceTest : public testing::Test {
virtual void AddProfile() { virtual void AddProfile() {
// For this test, the user should not be signed in yet. // For this test, the user should not be signed in yet.
DCHECK(!signin_manager_->IsAuthenticated()); DCHECK(!identity_test_env()->identity_manager()->HasPrimaryAccount());
// Initializing UserPolicySigninService while the user is not signed in // Initializing UserPolicySigninService while the user is not signed in
// should result in the store being cleared to remove any lingering policy. // should result in the store being cleared to remove any lingering policy.
...@@ -253,8 +242,9 @@ class UserPolicySigninServiceTest : public testing::Test { ...@@ -253,8 +242,9 @@ class UserPolicySigninServiceTest : public testing::Test {
void MakeOAuthTokenFetchSucceed() { void MakeOAuthTokenFetchSucceed() {
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
ASSERT_TRUE(IsRequestActive()); ASSERT_TRUE(IsRequestActive());
GetTokenService()->IssueTokenForAllPendingRequests("access_token", identity_test_env()
base::Time::Now()); ->WaitForAccessTokenRequestIfNecessaryAndRespondWithToken(
"access_token", base::Time::Now());
#else #else
ASSERT_TRUE(IsRequestActive()); ASSERT_TRUE(IsRequestActive());
test_url_loader_factory_.AddResponse( test_url_loader_factory_.AddResponse(
...@@ -268,7 +258,8 @@ class UserPolicySigninServiceTest : public testing::Test { ...@@ -268,7 +258,8 @@ class UserPolicySigninServiceTest : public testing::Test {
void MakeOAuthTokenFetchFail() { void MakeOAuthTokenFetchFail() {
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
ASSERT_TRUE(!GetTokenService()->GetPendingRequests().empty()); ASSERT_TRUE(!GetTokenService()->GetPendingRequests().empty());
GetTokenService()->IssueErrorForAllPendingRequests( identity_test_env()
->WaitForAccessTokenRequestIfNecessaryAndRespondWithError(
GoogleServiceAuthError::FromServiceError("fail")); GoogleServiceAuthError::FromServiceError("fail"));
#else #else
ASSERT_TRUE(test_url_loader_factory_.SimulateResponseForPendingRequest( ASSERT_TRUE(test_url_loader_factory_.SimulateResponseForPendingRequest(
...@@ -291,7 +282,7 @@ class UserPolicySigninServiceTest : public testing::Test { ...@@ -291,7 +282,7 @@ class UserPolicySigninServiceTest : public testing::Test {
RegisterPolicyClientWithCallback(signin_service); RegisterPolicyClientWithCallback(signin_service);
// Sign in to Chrome. // Sign in to Chrome.
signin_manager_->SignIn(kTestGaiaId, kTestUser, ""); identity_test_env()->SetPrimaryAccount(kTestUser);
// Mimic successful oauth token fetch. // Mimic successful oauth token fetch.
MakeOAuthTokenFetchSucceed(); MakeOAuthTokenFetchSucceed();
...@@ -372,7 +363,14 @@ class UserPolicySigninServiceTest : public testing::Test { ...@@ -372,7 +363,14 @@ class UserPolicySigninServiceTest : public testing::Test {
Mock::VerifyAndClearExpectations(this); Mock::VerifyAndClearExpectations(this);
} }
identity::IdentityTestEnvironment* identity_test_env() {
return identity_test_env_adaptor_->identity_test_env();
}
protected:
std::unique_ptr<TestingProfile> profile_; std::unique_ptr<TestingProfile> profile_;
std::unique_ptr<IdentityTestEnvironmentProfileAdaptor>
identity_test_env_adaptor_;
MockUserCloudPolicyStore* mock_store_; // Not owned. MockUserCloudPolicyStore* mock_store_; // Not owned.
SchemaRegistry schema_registry_; SchemaRegistry schema_registry_;
std::unique_ptr<UserCloudPolicyManager> manager_; std::unique_ptr<UserCloudPolicyManager> manager_;
...@@ -381,8 +379,6 @@ class UserPolicySigninServiceTest : public testing::Test { ...@@ -381,8 +379,6 @@ class UserPolicySigninServiceTest : public testing::Test {
// various components asynchronously via tasks, so create fake threads here. // various components asynchronously via tasks, so create fake threads here.
content::TestBrowserThreadBundle thread_bundle_; content::TestBrowserThreadBundle thread_bundle_;
FakeSigninManager* signin_manager_;
// Used in conjunction with OnRegisterCompleted() to test client registration // Used in conjunction with OnRegisterCompleted() to test client registration
// callbacks. // callbacks.
std::string dm_token_; std::string dm_token_;
...@@ -411,8 +407,7 @@ class UserPolicySigninServiceSignedInTest : public UserPolicySigninServiceTest { ...@@ -411,8 +407,7 @@ class UserPolicySigninServiceSignedInTest : public UserPolicySigninServiceTest {
ASSERT_FALSE(manager_->core()->service()); ASSERT_FALSE(manager_->core()->service());
// Set the user as signed in. // Set the user as signed in.
SigninManagerFactory::GetForProfile(profile_.get())-> identity_test_env()->SetPrimaryAccount(kTestUser);
SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser);
// Let the SigninService know that the profile has been created. // Let the SigninService know that the profile has been created.
content::NotificationService::current()->Notify( content::NotificationService::current()->Notify(
...@@ -424,8 +419,7 @@ class UserPolicySigninServiceSignedInTest : public UserPolicySigninServiceTest { ...@@ -424,8 +419,7 @@ class UserPolicySigninServiceSignedInTest : public UserPolicySigninServiceTest {
TEST_F(UserPolicySigninServiceTest, InitWhileSignedOut) { TEST_F(UserPolicySigninServiceTest, InitWhileSignedOut) {
// Make sure user is not signed in. // Make sure user is not signed in.
ASSERT_FALSE(SigninManagerFactory::GetForProfile(profile_.get())-> ASSERT_FALSE(identity_test_env()->identity_manager()->HasPrimaryAccount());
IsAuthenticated());
// UserCloudPolicyManager should not be initialized. // UserCloudPolicyManager should not be initialized.
ASSERT_FALSE(manager_->core()->service()); ASSERT_FALSE(manager_->core()->service());
...@@ -434,8 +428,7 @@ TEST_F(UserPolicySigninServiceTest, InitWhileSignedOut) { ...@@ -434,8 +428,7 @@ TEST_F(UserPolicySigninServiceTest, InitWhileSignedOut) {
#if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
TEST_F(UserPolicySigninServiceTest, InitRefreshTokenAvailableBeforeSignin) { TEST_F(UserPolicySigninServiceTest, InitRefreshTokenAvailableBeforeSignin) {
// Make sure user is not signed in. // Make sure user is not signed in.
ASSERT_FALSE( ASSERT_FALSE(identity_test_env()->identity_manager()->HasPrimaryAccount());
SigninManagerFactory::GetForProfile(profile_.get())->IsAuthenticated());
// No oauth access token yet, so client registration should be deferred. // No oauth access token yet, so client registration should be deferred.
ASSERT_FALSE(IsRequestActive()); ASSERT_FALSE(IsRequestActive());
...@@ -444,13 +437,13 @@ TEST_F(UserPolicySigninServiceTest, InitRefreshTokenAvailableBeforeSignin) { ...@@ -444,13 +437,13 @@ TEST_F(UserPolicySigninServiceTest, InitRefreshTokenAvailableBeforeSignin) {
std::string account_id = std::string account_id =
AccountTrackerServiceFactory::GetForProfile(profile_.get()) AccountTrackerServiceFactory::GetForProfile(profile_.get())
->SeedAccountInfo(kTestGaiaId, kTestUser); ->SeedAccountInfo(kTestGaiaId, kTestUser);
GetTokenService()->UpdateCredentials(account_id, "oauth_login_refresh_token"); identity_test_env()->SetRefreshTokenForAccount(account_id);
// Not signed in yet, so client registration should be deferred. // Not signed in yet, so client registration should be deferred.
ASSERT_FALSE(IsRequestActive()); ASSERT_FALSE(IsRequestActive());
// Sign in to Chrome. // Sign in to Chrome.
signin_manager_->SignIn(kTestGaiaId, kTestUser, ""); identity_test_env()->MakePrimaryAccountAvailable(kTestUser);
// Complete initialization of the store. // Complete initialization of the store.
mock_store_->NotifyStoreLoaded(); mock_store_->NotifyStoreLoaded();
...@@ -478,10 +471,7 @@ TEST_F(UserPolicySigninServiceSignedInTest, InitWhileSignedIn) { ...@@ -478,10 +471,7 @@ TEST_F(UserPolicySigninServiceSignedInTest, InitWhileSignedIn) {
ASSERT_FALSE(IsRequestActive()); ASSERT_FALSE(IsRequestActive());
// Make oauth token available. // Make oauth token available.
GetTokenService()->UpdateCredentials( identity_test_env()->SetRefreshTokenForPrimaryAccount();
SigninManagerFactory::GetForProfile(profile_.get())
->GetAuthenticatedAccountId(),
"oauth_login_refresh_token");
// Client registration should be in progress since we now have an oauth token. // Client registration should be in progress since we now have an oauth token.
EXPECT_EQ(mock_store_->signin_account_id(), test_account_id_); EXPECT_EQ(mock_store_->signin_account_id(), test_account_id_);
...@@ -499,10 +489,7 @@ TEST_F(UserPolicySigninServiceSignedInTest, InitWhileSignedInOAuthError) { ...@@ -499,10 +489,7 @@ TEST_F(UserPolicySigninServiceSignedInTest, InitWhileSignedInOAuthError) {
ASSERT_FALSE(IsRequestActive()); ASSERT_FALSE(IsRequestActive());
// Make oauth token available. // Make oauth token available.
GetTokenService()->UpdateCredentials( identity_test_env()->SetRefreshTokenForPrimaryAccount();
SigninManagerFactory::GetForProfile(profile_.get())
->GetAuthenticatedAccountId(),
"oauth_login_refresh_token");
// Client registration should be in progress since we now have an oauth token. // Client registration should be in progress since we now have an oauth token.
ASSERT_TRUE(IsRequestActive()); ASSERT_TRUE(IsRequestActive());
...@@ -510,7 +497,8 @@ TEST_F(UserPolicySigninServiceSignedInTest, InitWhileSignedInOAuthError) { ...@@ -510,7 +497,8 @@ TEST_F(UserPolicySigninServiceSignedInTest, InitWhileSignedInOAuthError) {
// Now fail the access token fetch. // Now fail the access token fetch.
GoogleServiceAuthError error( GoogleServiceAuthError error(
GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
GetTokenService()->IssueErrorForAllPendingRequests(error); identity_test_env()->WaitForAccessTokenRequestIfNecessaryAndRespondWithError(
error);
ASSERT_FALSE(IsRequestActive()); ASSERT_FALSE(IsRequestActive());
} }
...@@ -520,17 +508,13 @@ TEST_F(UserPolicySigninServiceTest, SignInAfterInit) { ...@@ -520,17 +508,13 @@ TEST_F(UserPolicySigninServiceTest, SignInAfterInit) {
ASSERT_FALSE(manager_->core()->service()); ASSERT_FALSE(manager_->core()->service());
// Now sign in the user. // Now sign in the user.
SigninManagerFactory::GetForProfile(profile_.get()) identity_test_env()->SetPrimaryAccount(kTestUser);
->SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser);
// Complete initialization of the store. // Complete initialization of the store.
mock_store_->NotifyStoreLoaded(); mock_store_->NotifyStoreLoaded();
// Make oauth token available. // Make oauth token available.
GetTokenService()->UpdateCredentials( identity_test_env()->SetRefreshTokenForPrimaryAccount();
SigninManagerFactory::GetForProfile(profile_.get())
->GetAuthenticatedAccountId(),
"oauth_login_refresh_token");
// UserCloudPolicyManager should be initialized. // UserCloudPolicyManager should be initialized.
EXPECT_EQ(mock_store_->signin_account_id(), test_account_id_); EXPECT_EQ(mock_store_->signin_account_id(), test_account_id_);
...@@ -546,18 +530,13 @@ TEST_F(UserPolicySigninServiceTest, SignInWithNonEnterpriseUser) { ...@@ -546,18 +530,13 @@ TEST_F(UserPolicySigninServiceTest, SignInWithNonEnterpriseUser) {
ASSERT_FALSE(manager_->core()->service()); ASSERT_FALSE(manager_->core()->service());
// Now sign in a non-enterprise user (blacklisted gmail.com domain). // Now sign in a non-enterprise user (blacklisted gmail.com domain).
SigninManagerFactory::GetForProfile(profile_.get()) identity_test_env()->SetPrimaryAccount("non_enterprise_user@gmail.com");
->SetAuthenticatedAccountInfo("gaia-id-non_enterprise_user@gmail.com",
"non_enterprise_user@gmail.com");
// Complete initialization of the store. // Complete initialization of the store.
mock_store_->NotifyStoreLoaded(); mock_store_->NotifyStoreLoaded();
// Make oauth token available. // Make oauth token available.
GetTokenService()->UpdateCredentials( identity_test_env()->SetRefreshTokenForPrimaryAccount();
SigninManagerFactory::GetForProfile(profile_.get())
->GetAuthenticatedAccountId(),
"oauth_login_refresh_token");
// UserCloudPolicyManager should not be initialized and there should be no // UserCloudPolicyManager should not be initialized and there should be no
// DMToken request active. // DMToken request active.
...@@ -571,14 +550,10 @@ TEST_F(UserPolicySigninServiceTest, UnregisteredClient) { ...@@ -571,14 +550,10 @@ TEST_F(UserPolicySigninServiceTest, UnregisteredClient) {
ASSERT_FALSE(manager_->core()->service()); ASSERT_FALSE(manager_->core()->service());
// Now sign in the user. // Now sign in the user.
SigninManagerFactory::GetForProfile(profile_.get()) identity_test_env()->SetPrimaryAccount(kTestUser);
->SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser);
// Make oauth token available. // Make oauth token available.
GetTokenService()->UpdateCredentials( identity_test_env()->SetRefreshTokenForPrimaryAccount();
SigninManagerFactory::GetForProfile(profile_.get())
->GetAuthenticatedAccountId(),
"oauth_login_refresh_token");
// UserCloudPolicyManager should be initialized. // UserCloudPolicyManager should be initialized.
EXPECT_EQ(mock_store_->signin_account_id(), test_account_id_); EXPECT_EQ(mock_store_->signin_account_id(), test_account_id_);
...@@ -601,14 +576,10 @@ TEST_F(UserPolicySigninServiceTest, RegisteredClient) { ...@@ -601,14 +576,10 @@ TEST_F(UserPolicySigninServiceTest, RegisteredClient) {
ASSERT_FALSE(manager_->core()->service()); ASSERT_FALSE(manager_->core()->service());
// Now sign in the user. // Now sign in the user.
SigninManagerFactory::GetForProfile(profile_.get()) identity_test_env()->SetPrimaryAccount(kTestUser);
->SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser);
// Make oauth token available. // Make oauth token available.
GetTokenService()->UpdateCredentials( identity_test_env()->SetRefreshTokenForPrimaryAccount();
SigninManagerFactory::GetForProfile(profile_.get())
->GetAuthenticatedAccountId(),
"oauth_login_refresh_token");
// UserCloudPolicyManager should be initialized. // UserCloudPolicyManager should be initialized.
EXPECT_EQ(mock_store_->signin_account_id(), test_account_id_); EXPECT_EQ(mock_store_->signin_account_id(), test_account_id_);
...@@ -650,9 +621,7 @@ TEST_F(UserPolicySigninServiceSignedInTest, SignOutAfterInit) { ...@@ -650,9 +621,7 @@ TEST_F(UserPolicySigninServiceSignedInTest, SignOutAfterInit) {
EXPECT_CALL(*mock_store_, Clear()); EXPECT_CALL(*mock_store_, Clear());
// Now sign out. // Now sign out.
SigninManagerFactory::GetForProfile(profile_.get()) identity_test_env()->ClearPrimaryAccount();
->SignOut(signin_metrics::SIGNOUT_TEST,
signin_metrics::SignoutDelete::IGNORE_METRIC);
// UserCloudPolicyManager should be shut down. // UserCloudPolicyManager should be shut down.
ASSERT_FALSE(manager_->core()->service()); ASSERT_FALSE(manager_->core()->service());
...@@ -821,7 +790,7 @@ TEST_F(UserPolicySigninServiceTest, SignOutThenSignInAgain) { ...@@ -821,7 +790,7 @@ TEST_F(UserPolicySigninServiceTest, SignOutThenSignInAgain) {
ASSERT_NO_FATAL_FAILURE(TestSuccessfulSignin()); ASSERT_NO_FATAL_FAILURE(TestSuccessfulSignin());
EXPECT_CALL(*mock_store_, Clear()); EXPECT_CALL(*mock_store_, Clear());
signin_manager_->ForceSignOut(); identity_test_env()->ClearPrimaryAccount();
ASSERT_FALSE(manager_->core()->service()); ASSERT_FALSE(manager_->core()->service());
// Now sign in again. // Now sign in again.
......
...@@ -36,7 +36,8 @@ std::unique_ptr<TestingProfile> IdentityTestEnvironmentProfileAdaptor:: ...@@ -36,7 +36,8 @@ std::unique_ptr<TestingProfile> IdentityTestEnvironmentProfileAdaptor::
// static // static
std::unique_ptr<TestingProfile> std::unique_ptr<TestingProfile>
IdentityTestEnvironmentProfileAdaptor::CreateProfileForIdentityTestEnvironment( IdentityTestEnvironmentProfileAdaptor::CreateProfileForIdentityTestEnvironment(
const TestingProfile::TestingFactories& input_factories) { const TestingProfile::TestingFactories& input_factories,
std::unique_ptr<sync_preferences::PrefServiceSyncable> prefs) {
TestingProfile::Builder builder; TestingProfile::Builder builder;
for (auto& input_factory : input_factories) { for (auto& input_factory : input_factories) {
...@@ -47,6 +48,9 @@ IdentityTestEnvironmentProfileAdaptor::CreateProfileForIdentityTestEnvironment( ...@@ -47,6 +48,9 @@ IdentityTestEnvironmentProfileAdaptor::CreateProfileForIdentityTestEnvironment(
builder.AddTestingFactory(identity_factory.first, identity_factory.second); builder.AddTestingFactory(identity_factory.first, identity_factory.second);
} }
if (prefs)
builder.SetPrefService(std::move(prefs));
return builder.Build(); return builder.Build();
} }
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define CHROME_BROWSER_SIGNIN_IDENTITY_TEST_ENVIRONMENT_PROFILE_ADAPTOR_H_ #define CHROME_BROWSER_SIGNIN_IDENTITY_TEST_ENVIRONMENT_PROFILE_ADAPTOR_H_
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "services/identity/public/cpp/identity_test_environment.h" #include "services/identity/public/cpp/identity_test_environment.h"
// Adaptor that supports identity::IdentityTestEnvironment's usage in testing // Adaptor that supports identity::IdentityTestEnvironment's usage in testing
...@@ -24,10 +25,11 @@ class IdentityTestEnvironmentProfileAdaptor { ...@@ -24,10 +25,11 @@ class IdentityTestEnvironmentProfileAdaptor {
CreateProfileForIdentityTestEnvironment(); CreateProfileForIdentityTestEnvironment();
// Like the above, but additionally configures the returned Profile with // Like the above, but additionally configures the returned Profile with
// |input_factories|. // |input_factories| and |prefs|.
static std::unique_ptr<TestingProfile> static std::unique_ptr<TestingProfile>
CreateProfileForIdentityTestEnvironment( CreateProfileForIdentityTestEnvironment(
const TestingProfile::TestingFactories& input_factories); const TestingProfile::TestingFactories& input_factories,
std::unique_ptr<sync_preferences::PrefServiceSyncable> prefs = nullptr);
// Appends the set of testing factories that identity::IdentityTestEnvironment // Appends the set of testing factories that identity::IdentityTestEnvironment
// requires to |factories_to_append_to|, which should be the set of testing // requires to |factories_to_append_to|, which should be the set of testing
......
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