Commit 8d52d3e3 authored by Nohemi Fernandez's avatar Nohemi Fernandez Committed by Commit Bot

[iOS] Fix race condition in SignedInAccountsViewController.

The potential race condition occurs when the accounts with refresh
tokens becomes misaligned with the accounts in the Chrome Identity
service.

Bug: 1069950
Change-Id: Icdf3542ca69026f06a4cc8b793a0c2f1bc3518e8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2375368
Commit-Queue: Nohemi Fernandez <fernandex@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#801715}
parent 4e9cbb66
...@@ -119,6 +119,12 @@ BOOL gSignedInAccountsViewControllerIsShown = NO; ...@@ -119,6 +119,12 @@ BOOL gSignedInAccountsViewControllerIsShown = NO;
ChromeIdentity* identity = ios::GetChromeBrowserProvider() ChromeIdentity* identity = ios::GetChromeBrowserProvider()
->GetChromeIdentityService() ->GetChromeIdentityService()
->GetIdentityWithGaiaID(account.gaia); ->GetIdentityWithGaiaID(account.gaia);
// If the account with a refresh token is invalidated during this operation
// then |identity| will be nil. Do not process it in this case.
if (!identity) {
continue;
}
CollectionViewItem* item = [self accountItem:identity]; CollectionViewItem* item = [self accountItem:identity];
[model addItem:item toSectionWithIdentifier:SectionIdentifierAccounts]; [model addItem:item toSectionWithIdentifier:SectionIdentifierAccounts];
[mutableIdentityMap setObject:item forKey:identity.gaiaID]; [mutableIdentityMap setObject:item forKey:identity.gaiaID];
......
...@@ -589,4 +589,26 @@ void ChooseImportOrKeepDataSepareteDialog(id<GREYMatcher> choiceButtonMatcher) { ...@@ -589,4 +589,26 @@ void ChooseImportOrKeepDataSepareteDialog(id<GREYMatcher> choiceButtonMatcher) {
performAction:grey_tap()]; performAction:grey_tap()];
} }
// Simulates a potential race condition in which the account is invalidated
// after the user taps the Settings button to navigate to the identity
// choosing UI. Depending on the timing, the account removal may occur after
// the UI has retrieved the list of valid accounts. The test ensures that in
// this case no account is presented to the user.
- (void)testAccountInvalidatedDuringSignin {
FakeChromeIdentity* fakeIdentity = [SigninEarlGrey fakeIdentity1];
[SigninEarlGrey addFakeIdentity:fakeIdentity];
[ChromeEarlGreyUI openSettingsMenu];
[ChromeEarlGreyUI tapSettingsMenuButton:SecondarySignInButton()];
// Invalidate account after menu generation. If the underlying code does not
// handle the race condition of removing an identity while showing menu is in
// progress this test will likely be flaky.
[SigninEarlGrey forgetFakeIdentity:fakeIdentity];
// Check that the identity has been removed.
[[EarlGrey selectElementWithMatcher:identityChooserButtonMatcherWithEmail(
fakeIdentity.userEmail)]
assertWithMatcher:grey_notVisible()];
}
@end @end
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