Convert signin_profile_attributes_updater_unittest.cc to use IdentityTestEnvironment |
|||
Issue descriptionIt should do so via IdentityTestEnvironmentProfileAdaptor. In this fashion, we should be able to eliminate the usage of SigninManager, ProfileOAuth2TokenService, and AccountTrackerService. Note that it looks to me like this work can be done independently from the conversion of the production code ( crbug.com/920152 ).
,
Jan 10
,
Jan 11
I am facing a problem with this conversion. Main point is here:
#if defined(OS_CHROMEOS)
// Returns a SigninManager that authenticated at creation.
std::unique_ptr<KeyedService> BuildAuthenticatedSigninManager(
content::BrowserContext* context) {
std::unique_ptr<KeyedService> signin_manager =
BuildFakeSigninManagerForTesting(context);
static_cast<SigninManagerBase*>(signin_manager.get())
->SetAuthenticatedAccountInfo("gaia", "example@email.com");
return signin_manager;
}
#endif
On ChromeOS, SigninManager is authenticated right after it is created by the factory method provided by the test.
Problem is that if we convert the test to use IdentityTestEnvProfileAdaptor, it loses this ability (to authenticate the SigninManager when it is created), and test fails.
In fact, I tried two things:
- Convert the test to IdentityTestEnvProfileAdaptor (and hence remove BuildAuthenticatedSigninManager completely) and call IdentityTestEnv::SetPrimaryAccount (or even MakePrimaryAccountAvailable) right after the profile is created in ::SetUp, but test fails.
- As a simple exercise, I also tried to leave the test unchanged (ie no IdentityManager conversion performed) and simply move the call to SigninManagerBase::SetAuthenticatedAccountInfo from the factory method to the ::SetUp method, again right after the profile is created, and tests starts to fail too.
For instance, it fails here:
https://cs.chromium.org/chromium/src/chrome/browser/signin/signin_profile_attributes_updater_unittest.cc?dr&q=signin_profile_attributes_updater_unittest.&g=0&l=128
Colin, anything that rings a bell here?
,
Jan 11
Hi Antonio, Thanks! So the problem here is that SigninProfileAttributesUpdater is created with the Profile, so if we set the primary account any later than inline during Profile creation, SigninProfileAttributesUpdater won't see it on ChromeOS (since the OnPrimaryAccountSet observer callback doesn't get fired on ChromeOS). I would just do the following: - inject a custom factory function for SigninProfileAttributesUpdater itself - Have that factory function first call identity::MakePrimaryAccountAvailable() and then do return static_cast<BrowserContextKeyedServiceFactory*>(SigninProfileAttributesUpdaterFactory::GetInstance())->BuildServiceInstanceFor(profile); In other words, simply ensure that the primary account is set before the SigninProfileAttributesUpdater instance is created, which is what the tests require.
,
Jan 14
Great suggestion, Colin! This is now CL https://crrev.com/c/1409982. One remark: I could not call return static_cast<BrowserContextKeyedServiceFactory*>(SigninProfileAttributesUpdaterFactory::GetInstance())->BuildServiceInstanceFor(profile); as originally stated because BuildServiceInstanceFor is protected. Alternatively, I added a BuildServiceInstanceForTesting method to BrowserContextKeyedServiceFactory. This approach is also used in other parts of the code, eg https://cs.chromium.org/chromium/src/chrome/browser/extensions/menu_manager_factory.cc?l=31 |
|||
►
Sign in to add a comment |
|||
Comment 1 Deleted