Commit bf582604 authored by Mihai Sardarescu's avatar Mihai Sardarescu Committed by Commit Bot

Compact SigninInteractionController EGTests.

As UnifiedConsent is now enabled on UI, it does not make much sense to
have the EGTest for the sign-in flow spread across 2 files. This CL moves
the tests from signin_interaction_controller_unity_egtest.mm to
signin_interaction_controller_egtest.mm

Bug: 1015805
Change-Id: Ia483f6abf58370d169b056ea83e7ce4cc373aa98
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1868955
Commit-Queue: Mihai Sardarescu <msarda@chromium.org>
Reviewed-by: default avatarJérôme Lebel <jlebel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#708939}
parent a014b665
......@@ -50,7 +50,6 @@ source_set("eg_tests") {
testonly = true
sources = [
"signin_interaction_controller_egtest.mm",
"signin_interaction_controller_unity_egtest.mm",
]
deps = [
":eg_test_support",
......
......@@ -17,6 +17,7 @@
#import "ios/chrome/browser/ui/authentication/chrome_signin_view_controller.h"
#import "ios/chrome/browser/ui/authentication/signin_earl_grey_ui.h"
#import "ios/chrome/browser/ui/authentication/signin_earlgrey_utils.h"
#import "ios/chrome/browser/ui/authentication/unified_consent/identity_chooser/identity_chooser_cell.h"
#import "ios/chrome/browser/ui/commands/application_commands.h"
#import "ios/chrome/browser/ui/commands/open_new_tab_command.h"
#import "ios/chrome/browser/ui/content_suggestions/ntp_home_constant.h"
......@@ -31,6 +32,7 @@
#import "ios/chrome/test/earl_grey/chrome_matchers.h"
#import "ios/chrome/test/earl_grey/chrome_test_case.h"
#import "ios/public/provider/chrome/browser/signin/fake_chrome_identity.h"
#import "ios/public/provider/chrome/browser/signin/fake_chrome_identity_interaction_manager.h"
#import "ios/public/provider/chrome/browser/signin/fake_chrome_identity_service.h"
#import "ios/testing/earl_grey/matchers.h"
#import "ios/web/public/web_state.h"
......@@ -96,6 +98,13 @@ void RemoveBrowsingData() {
@"Browsing data was not removed.");
}
// Returns a matcher for |userEmail| in IdentityChooserViewController.
id<GREYMatcher> identityChooserButtonMatcherWithEmail(NSString* userEmail) {
return grey_allOf(grey_accessibilityID(userEmail),
grey_kindOfClass([IdentityChooserCell class]),
grey_sufficientlyVisible(), nil);
}
} // namespace
// Sign-in interaction tests that work both with Unified Consent enabled or
......@@ -126,6 +135,94 @@ void RemoveBrowsingData() {
[SigninEarlGreyUtils checkSignedInWithIdentity:identity];
}
// Tests signing in with one account, switching sync account to a second and
// choosing to keep the browsing data separate during the switch.
- (void)testSignInSwitchAccountsAndKeepDataSeparate {
// The ChromeSigninView's activity indicator must be hidden as the import
// data UI is presented on top of the activity indicator and Earl Grey cannot
// interact with any UI while an animation is active.
std::unique_ptr<base::AutoReset<BOOL>> hideActivityMonitor =
[ChromeSigninViewController hideActivityIndicatorForTesting];
// Set up the fake identities.
ios::FakeChromeIdentityService* identity_service =
ios::FakeChromeIdentityService::GetInstanceFromChromeProvider();
ChromeIdentity* identity1 = [SigninEarlGreyUtils fakeIdentity1];
ChromeIdentity* identity2 = [SigninEarlGreyUtils fakeIdentity2];
identity_service->AddIdentity(identity1);
identity_service->AddIdentity(identity2);
[SigninEarlGreyUI signinWithIdentity:identity1];
[SigninEarlGreyUI signOutWithManagedAccount:NO];
// Sign in with |identity2|.
[ChromeEarlGreyUI openSettingsMenu];
[[EarlGrey selectElementWithMatcher:SecondarySignInButton()]
performAction:grey_tap()];
[SigninEarlGreyUI selectIdentityWithEmail:identity2.userEmail];
[SigninEarlGreyUI confirmSigninConfirmationDialog];
// Switch Sync account to |identity2| should ask whether date should be
// imported or kept separate. Choose to keep data separate.
[[EarlGrey selectElementWithMatcher:
chrome_test_util::SettingsImportDataKeepSeparateButton()]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:chrome_test_util::
SettingsImportDataContinueButton()]
performAction:grey_tap()];
// Check the signed-in user did change.
[SigninEarlGreyUtils checkSignedInWithIdentity:identity2];
[[EarlGrey selectElementWithMatcher:SettingsDoneButton()]
performAction:grey_tap()];
}
// Tests signing in with one account, switching sync account to a second and
// choosing to import the browsing data during the switch.
- (void)testSignInSwitchAccountsAndImportData {
// The ChromeSigninView's activity indicator must be hidden as the import
// data UI is presented on top of the activity indicator and Earl Grey cannot
// interact with any UI while an animation is active.
std::unique_ptr<base::AutoReset<BOOL>> hideActivityMonitor =
[ChromeSigninViewController hideActivityIndicatorForTesting];
// Set up the fake identities.
ios::FakeChromeIdentityService* identity_service =
ios::FakeChromeIdentityService::GetInstanceFromChromeProvider();
ChromeIdentity* identity1 = [SigninEarlGreyUtils fakeIdentity1];
ChromeIdentity* identity2 = [SigninEarlGreyUtils fakeIdentity2];
identity_service->AddIdentity(identity1);
identity_service->AddIdentity(identity2);
// Sign in to |identity1|.
[SigninEarlGreyUI signinWithIdentity:identity1];
[SigninEarlGreyUI signOutWithManagedAccount:NO];
// Sign in with |identity2|.
[ChromeEarlGreyUI openSettingsMenu];
[[EarlGrey selectElementWithMatcher:SecondarySignInButton()]
performAction:grey_tap()];
[SigninEarlGreyUI selectIdentityWithEmail:identity2.userEmail];
[SigninEarlGreyUI confirmSigninConfirmationDialog];
// Switch Sync account to |identity2| should ask whether date should be
// imported or kept separate. Choose to import the data.
[[EarlGrey selectElementWithMatcher:chrome_test_util::
SettingsImportDataImportButton()]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:chrome_test_util::
SettingsImportDataContinueButton()]
performAction:grey_tap()];
// Check the signed-in user did change.
[SigninEarlGreyUtils checkSignedInWithIdentity:identity2];
[[EarlGrey selectElementWithMatcher:SettingsDoneButton()]
performAction:grey_tap()];
}
// Tests that signing out from the Settings works correctly.
- (void)testSignInDisconnectFromChrome {
ChromeIdentity* identity = [SigninEarlGreyUtils fakeIdentity1];
......@@ -467,4 +564,91 @@ void RemoveBrowsingData() {
}
}
// Tests the "ADD ACCOUNT" button in the identity chooser view controller.
- (void)testAddAccountAutomatically {
[ChromeEarlGreyUI openSettingsMenu];
[ChromeEarlGreyUI tapSettingsMenuButton:PrimarySignInButton()];
[[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
// Tap on "ADD ACCOUNT".
[SigninEarlGreyUI tapAddAccountButton];
// Check for the fake SSO screen.
WaitForMatcher(grey_accessibilityID(kFakeAddAccountViewIdentifier));
// Close the SSO view controller.
id<GREYMatcher> matcher =
grey_allOf(chrome_test_util::ButtonWithAccessibilityLabel(@"Cancel"),
grey_sufficientlyVisible(), nil);
[[EarlGrey selectElementWithMatcher:matcher] performAction:grey_tap()];
// Make sure the SSO view controller is fully removed before ending the test.
// The tear down needs to remove other view controllers, and it cannot be done
// during the animation of the SSO view controler.
[[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
}
// Tests to remove the last identity in the identity chooser.
- (void)testRemoveLastAccount {
// Set up a fake identity.
ChromeIdentity* identity = [SigninEarlGreyUtils fakeIdentity1];
ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()->AddIdentity(
identity);
// Open the identity chooser.
[ChromeEarlGreyUI openSettingsMenu];
[ChromeEarlGreyUI tapSettingsMenuButton:SecondarySignInButton()];
WaitForMatcher(identityChooserButtonMatcherWithEmail(identity.userEmail));
// Remove the fake identity.
ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()
->RemoveIdentity(identity);
[[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
// Check that the identity has been removed.
[[EarlGrey selectElementWithMatcher:identityChooserButtonMatcherWithEmail(
identity.userEmail)]
assertWithMatcher:grey_notVisible()];
}
// Opens the add account screen and then cancels it by opening a new tab.
// Ensures that the add account screen is correctly dismissed. crbug.com/462200
//
// TODO(crbug.com/962847): This test crashes when the the add account screen
// is dismissed.
- (void)DISABLED_testSignInCancelAddAccount {
// Add an identity to avoid arriving on the Add Account screen when opening
// sign-in.
ChromeIdentity* identity = [SigninEarlGreyUtils fakeIdentity1];
ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()->AddIdentity(
identity);
[ChromeEarlGreyUI openSettingsMenu];
[ChromeEarlGreyUI tapSettingsMenuButton:SecondarySignInButton()];
// Open Add Account screen.
id<GREYMatcher> add_account_matcher =
chrome_test_util::StaticTextWithAccessibilityLabelId(
IDS_IOS_ACCOUNT_IDENTITY_CHOOSER_ADD_ACCOUNT);
[[EarlGrey selectElementWithMatcher:add_account_matcher]
performAction:grey_tap()];
[[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
// Open new tab to cancel sign-in.
OpenNewTabCommand* command =
[OpenNewTabCommand commandWithURLFromChrome:GURL("about:blank")];
[chrome_test_util::DispatcherForActiveBrowserViewController()
openURLInNewTab:command];
// Wait until the page is opened.
[[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
// Re-open the sign-in screen. If it wasn't correctly dismissed previously,
// this will fail.
[ChromeEarlGreyUI openSettingsMenu];
[ChromeEarlGreyUI tapSettingsMenuButton:SecondarySignInButton()];
[SigninEarlGreyUI selectIdentityWithEmail:identity.userEmail];
VerifyChromeSigninViewVisible();
// Close sign-in screen and Settings.
TapButtonWithLabelId(IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_SKIP_BUTTON);
[[EarlGrey selectElementWithMatcher:SettingsDoneButton()]
performAction:grey_tap()];
}
@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