Commit 64cbe663 authored by Colin Blundell's avatar Colin Blundell Committed by Commit Bot

Port GaiaInfoUpdateService unittest to use IdentityTestEnvironment

This is possible now that we have infrastructure that glues an
IdentityTestEnvironment instance to a Profile, and it enables removing
the test's knowledge of SigninManager.

Bug: 896180
Change-Id: I074c0d2886561b264612ce2d34c5ca41b81de3be
Reviewed-on: https://chromium-review.googlesource.com/c/1286810Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Commit-Queue: Colin Blundell <blundell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#600715}
parent 25c3fa99
......@@ -18,10 +18,8 @@
#include "chrome/browser/profiles/profile_info_cache.h"
#include "chrome/browser/profiles/profile_info_cache_unittest.h"
#include "chrome/browser/profiles/profiles_state.h"
#include "chrome/browser/signin/account_tracker_service_factory.h"
#include "chrome/browser/signin/chrome_signin_client_factory.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/signin/identity_test_environment_profile_adaptor.h"
#include "chrome/browser/signin/test_signin_client_builder.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_browser_process.h"
......@@ -82,6 +80,9 @@ class GAIAInfoUpdateServiceTestBase : public ProfileInfoCacheTest {
service_.reset(new NiceMock<GAIAInfoUpdateServiceMock>(profile()));
downloader_.reset(new NiceMock<ProfileDownloaderMock>(service()));
}
identity_test_env_adaptor_ =
std::make_unique<IdentityTestEnvironmentProfileAdaptor>(profile());
};
void TearDown() override {
......@@ -100,6 +101,10 @@ class GAIAInfoUpdateServiceTestBase : public ProfileInfoCacheTest {
return profile_;
}
identity::IdentityTestEnvironment* identity_test_env() {
return identity_test_env_adaptor_->identity_test_env();
}
ProfileAttributesStorage* storage() {
return testing_profile_manager_.profile_attributes_storage();
}
......@@ -112,6 +117,8 @@ class GAIAInfoUpdateServiceTestBase : public ProfileInfoCacheTest {
testing_factories.emplace_back(
ChromeSigninClientFactory::GetInstance(),
base::BindRepeating(&signin::BuildTestSigninClient));
IdentityTestEnvironmentProfileAdaptor::
AppendIdentityTestEnvironmentFactories(&testing_factories);
Profile* profile = testing_profile_manager_.CreateTestingProfile(
name, std::unique_ptr<sync_preferences::PrefServiceSyncable>(),
base::UTF8ToUTF16(name), 0, std::string(),
......@@ -178,6 +185,8 @@ class GAIAInfoUpdateServiceTestBase : public ProfileInfoCacheTest {
const bool create_gaia_info_service_on_setup_;
Profile* profile_ = nullptr;
std::unique_ptr<IdentityTestEnvironmentProfileAdaptor>
identity_test_env_adaptor_;
std::unique_ptr<NiceMock<GAIAInfoUpdateServiceMock>> service_;
std::unique_ptr<NiceMock<ProfileDownloaderMock>> downloader_;
......@@ -333,9 +342,7 @@ TEST_F(GAIAInfoUpdateServiceTest, ScheduleUpdate) {
#if !defined(OS_CHROMEOS)
TEST_F(GAIAInfoUpdateServiceTest, LogOut) {
identity::SetPrimaryAccount(SigninManagerFactory::GetForProfile(profile()),
IdentityManagerFactory::GetForProfile(profile()),
"pat@example.com");
identity_test_env()->SetPrimaryAccount("pat@example.com");
base::string16 gaia_name = base::UTF8ToUTF16("Pat Foo");
ASSERT_EQ(1u, storage()->GetNumberOfProfiles());
......@@ -351,9 +358,7 @@ TEST_F(GAIAInfoUpdateServiceTest, LogOut) {
EXPECT_FALSE(service()->GetCachedPictureURL().empty());
// Log out.
identity::ClearPrimaryAccount(
SigninManagerFactory::GetForProfile(profile()),
IdentityManagerFactory::GetForProfile(profile()));
identity_test_env()->ClearPrimaryAccount();
// Verify that the GAIA name and picture, and picture URL are unset.
EXPECT_TRUE(entry->GetGAIAName().empty());
EXPECT_EQ(nullptr, entry->GetGAIAPicture());
......@@ -363,15 +368,11 @@ TEST_F(GAIAInfoUpdateServiceTest, LogOut) {
TEST_F(GAIAInfoUpdateServiceTest, LogIn) {
// Log in.
EXPECT_CALL(*service(), Update());
identity::SetPrimaryAccount(SigninManagerFactory::GetForProfile(profile()),
IdentityManagerFactory::GetForProfile(profile()),
"pat@example.com");
identity_test_env()->SetPrimaryAccount("pat@example.com");
}
TEST_F(GAIAInfoUpdateServiceTest, RestoreAvatarIndexOnLogout) {
identity::SetPrimaryAccount(SigninManagerFactory::GetForProfile(profile()),
IdentityManagerFactory::GetForProfile(profile()),
"pat@example.com");
identity_test_env()->SetPrimaryAccount("pat@example.com");
const size_t kLocalAvatarIndex = 10;
const size_t kRemoteAvatarIndex = 5;
......@@ -385,17 +386,14 @@ TEST_F(GAIAInfoUpdateServiceTest, RestoreAvatarIndexOnLogout) {
EXPECT_EQ(kRemoteAvatarIndex, entry->GetAvatarIconIndex());
// Log out.
identity::ClearPrimaryAccount(
SigninManagerFactory::GetForProfile(profile()),
IdentityManagerFactory::GetForProfile(profile()));
identity_test_env()->ClearPrimaryAccount();
EXPECT_EQ(kLocalAvatarIndex, entry->GetAvatarIconIndex());
}
TEST_F(GAIAInfoUpdateServiceMiscTest, ClearGaiaInfoOnStartup) {
// Simulate a state where the profile entry has GAIA related information
// when there is not primary account set.
EXPECT_FALSE(
IdentityManagerFactory::GetForProfile(profile())->HasPrimaryAccount());
EXPECT_FALSE(identity_test_env()->identity_manager()->HasPrimaryAccount());
ASSERT_EQ(1u, storage()->GetNumberOfProfiles());
ProfileAttributesEntry* entry = storage()->GetAllProfilesAttributes().front();
entry->SetGAIAName(base::UTF8ToUTF16("foo"));
......
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