Fix SaveToPhotosSettingsMediatorTest with UseAccountListFromIdentityManager
If the feature UseAccountListFromIdentityManager is enabled,
SaveToPhotosSettingsMediator receives notifications from IdentityManager
instead of ChromeAccountManagerService. Some test plumbing (in
FakeProfileOAuth2TokenServiceDelegate) was missing for this, and is
added by this CL.
Bug: 377467350
Change-Id: I7b5cb3e3bb52b819fbaa74104da63f5cfbf31360
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6218302
Reviewed-by: Jérôme Lebel <jlebel@chromium.org>
Auto-Submit: Marc Treib <treib@chromium.org>
Reviewed-by: Boris Sazonov <bsazonov@chromium.org>
Commit-Queue: Boris Sazonov <bsazonov@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1414837}
NOKEYCHECK=True
GitOrigin-RevId: 50cbc39f042492cad9ef93d84ec600a38e7f8bdc
diff --git a/chrome/browser/settings/ui_bundled/downloads/save_to_photos/save_to_photos_settings_mediator_unittest.mm b/chrome/browser/settings/ui_bundled/downloads/save_to_photos/save_to_photos_settings_mediator_unittest.mm
index 8238843..31ecca2 100644
--- a/chrome/browser/settings/ui_bundled/downloads/save_to_photos/save_to_photos_settings_mediator_unittest.mm
+++ b/chrome/browser/settings/ui_bundled/downloads/save_to_photos/save_to_photos_settings_mediator_unittest.mm
@@ -96,24 +96,55 @@
BuildIdentityManagerForTests));
profile_ = std::move(builder).Build();
- FakeSystemIdentityManager* system_identity_manager =
- FakeSystemIdentityManager::FromSystemIdentityManager(
- GetApplicationContext()->GetSystemIdentityManager());
fake_identity_a_ = [FakeSystemIdentity fakeIdentity1];
- system_identity_manager->AddIdentity(fake_identity_a_);
+ AddIdentity(fake_identity_a_, /*as_primary=*/true);
fake_identity_b_ = [FakeSystemIdentity fakeIdentity2];
- system_identity_manager->AddIdentity(fake_identity_b_);
-
- signin::MakeAccountAvailable(
- IdentityManagerFactory::GetForProfile(profile_.get()),
- signin::AccountAvailabilityOptionsBuilder()
- .AsPrimary(signin::ConsentLevel::kSignin)
- .WithGaiaId(GaiaId(fake_identity_a_.gaiaID))
- .Build(base::SysNSStringToUTF8(fake_identity_a_.userEmail)));
+ AddIdentity(fake_identity_b_, /*as_primary=*/false);
}
void TearDown() final { [mediator_ disconnect]; }
+ void AddIdentity(id<SystemIdentity> identity, bool as_primary) {
+ FakeSystemIdentityManager* system_identity_manager =
+ FakeSystemIdentityManager::FromSystemIdentityManager(
+ GetApplicationContext()->GetSystemIdentityManager());
+ system_identity_manager->AddIdentity(identity);
+
+ // Note: The (cross-platform) IdentityManager isn't fully hooked up to the
+ // (iOS-specific) SystemIdentityManager in this test, so update it
+ // separately.
+ // TODO(crbug.com/368409110): Improve the test plumbing so that this isn't
+ // necessary. This likely means either adding plumbing towards
+ // SystemIdentityManager to FakeProfileOAuth2TokenService, or alternatively
+ // using the real ProfileOAuth2TokenServiceIOSDelegate here.
+ auto options = signin::AccountAvailabilityOptionsBuilder().WithGaiaId(
+ GaiaId(identity.gaiaID));
+ if (as_primary) {
+ options = options.AsPrimary(signin::ConsentLevel::kSignin);
+ }
+ signin::MakeAccountAvailable(
+ IdentityManagerFactory::GetForProfile(profile_.get()),
+ options.Build(base::SysNSStringToUTF8(identity.userEmail)));
+ }
+
+ void ForgetIdentity(id<SystemIdentity> identity) {
+ FakeSystemIdentityManager* system_identity_manager =
+ FakeSystemIdentityManager::FromSystemIdentityManager(
+ GetApplicationContext()->GetSystemIdentityManager());
+ system_identity_manager->ForgetIdentityFromOtherApplication(identity);
+
+ // Note: The (cross-platform) IdentityManager isn't fully hooked up to the
+ // (iOS-specific) SystemIdentityManager in this test, so update it
+ // separately.
+ // TODO(crbug.com/368409110): Improve the test plumbing so that this isn't
+ // necessary. This likely means either adding plumbing towards
+ // SystemIdentityManager to FakeProfileOAuth2TokenService, or alternatively
+ // using the real ProfileOAuth2TokenServiceIOSDelegate here.
+ signin::RemoveRefreshTokenForAccount(
+ IdentityManagerFactory::GetForProfile(profile_.get()),
+ CoreAccountId::FromGaiaId(GaiaId(identity.gaiaID)));
+ }
+
// Creates a SaveToPhotosSettingsMediator with services from the test browser
// state.
SaveToPhotosSettingsMediator* CreateSaveToPhotosSettingsMediator() {
@@ -137,8 +168,8 @@
// Checks that the identities given to the consumer, either through the
// primary or secondary consumer interfaces, match an expected value
- // `expected_presented_identity`. It does not test the values of
- // `askEveryTimeSwitchOn` or `identityEnabled` in `fake_consumer`.
+ // `saved_identity`. It does not test the values of `askEveryTimeSwitchOn` or
+ // `identityEnabled` in `fake_consumer`.
void CheckFakeConsumerIdentities(
FakeSaveToPhotosSettingsConsumer* fake_consumer,
id<SystemIdentity> saved_identity) {
@@ -282,19 +313,17 @@
mediator.accountConfirmationConsumer = fake_consumer;
mediator.accountSelectionConsumer = fake_consumer;
+ ASSERT_EQ(2U, fake_consumer.identityConfigurators.count);
CheckFakeConsumerIdentities(fake_consumer, fake_identity_a_);
EXPECT_TRUE(fake_consumer.askEveryTimeSwitchOn);
- FakeSystemIdentityManager* system_identity_manager =
- FakeSystemIdentityManager::FromSystemIdentityManager(
- GetApplicationContext()->GetSystemIdentityManager());
- system_identity_manager->ForgetIdentityFromOtherApplication(fake_identity_b_);
+ ForgetIdentity(fake_identity_b_);
CheckFakeConsumerIdentities(fake_consumer, fake_identity_a_);
EXPECT_TRUE(fake_consumer.askEveryTimeSwitchOn);
EXPECT_EQ(1U, fake_consumer.identityConfigurators.count);
fake_identity_b_ = [FakeSystemIdentity fakeIdentity3];
- system_identity_manager->AddIdentity(fake_identity_b_);
+ AddIdentity(fake_identity_b_, /*as_primary=*/false);
CheckFakeConsumerIdentities(fake_consumer, fake_identity_a_);
EXPECT_TRUE(fake_consumer.askEveryTimeSwitchOn);
EXPECT_EQ(2U, fake_consumer.identityConfigurators.count);