Commit 583b8ce4 authored by Mihai Sardarescu's avatar Mihai Sardarescu Committed by Commit Bot

Update all sign-in earl grey tests for Unified Consent.

This CL ensures that all tests in theSigninIntegrationTest pass
when the Unified Consent Feature is enabled. In achieves this in
the following steps.

1. It splits the SigninInteractionControllerTestCase class in 3:
a) SigninInteractionControllerTestCase: test cases that pass both when
Unified consent is enabled or disabled;
b) SigninInteractionControllerUnityDisabledTestCase: test cases that require
Unified Consent to be disabled;
c) SigninInteractionControllerUnityEnabledTestCase: test cases that require
Unified Consent to be enabled;

2. It updates all necessary tests in the SigninInteractionControllerTestCase
to pass when the Unified Consent is enabled.

3. It includes SigninInteractionControllerTestCase both in
ios_chrome_ui_egtests (that run with Unified Consent enabled) and
in ios_chrome_unified_consent_ui_tests (that run with Unified Consent disabled).

Bug: 960260

Change-Id: I0be1945ff290bd2fcbba44d64f733658c623b369
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1599009
Commit-Queue: Mihai Sardarescu <msarda@chromium.org>
Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Reviewed-by: default avatarJérôme Lebel <jlebel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#659466}
parent e6e0574c
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#include <memory>
#include "base/auto_reset.h"
#include "base/timer/timer.h" #include "base/timer/timer.h"
#include "components/signin/core/browser/signin_metrics.h" #include "components/signin/core/browser/signin_metrics.h"
#import "ios/chrome/browser/signin/constants.h" #import "ios/chrome/browser/signin/constants.h"
...@@ -122,6 +125,10 @@ using TimerGeneratorBlock = std::unique_ptr<base::OneShotTimer> (^)(); ...@@ -122,6 +125,10 @@ using TimerGeneratorBlock = std::unique_ptr<base::OneShotTimer> (^)();
// base::OneShotTimer. // base::OneShotTimer.
@property(nonatomic, copy) TimerGeneratorBlock timerGenerator; @property(nonatomic, copy) TimerGeneratorBlock timerGenerator;
// Returns an AutoReset object that ensures that all future
// ChromeSigninViewController instances will not present the activity indicator.
+ (std::unique_ptr<base::AutoReset<BOOL>>)hideActivityIndicatorForTesting;
@end @end
#endif // IOS_CHROME_BROWSER_UI_AUTHENTICATION_CHROME_SIGNIN_VIEW_CONTROLLER_H_ #endif // IOS_CHROME_BROWSER_UI_AUTHENTICATION_CHROME_SIGNIN_VIEW_CONTROLLER_H_
...@@ -65,6 +65,9 @@ ...@@ -65,6 +65,9 @@
namespace { namespace {
// Controls whether the activity indicator should be added to the sign-in view.
BOOL gChromeSigninViewControllerShowsActivityIndicator = YES;
// Default animation duration. // Default animation duration.
const CGFloat kAnimationDuration = 0.5f; const CGFloat kAnimationDuration = 0.5f;
...@@ -939,12 +942,15 @@ enum AuthenticationState { ...@@ -939,12 +942,15 @@ enum AuthenticationState {
_secondaryButton.hidden = YES; _secondaryButton.hidden = YES;
[self.view addSubview:_secondaryButton]; [self.view addSubview:_secondaryButton];
_activityIndicator = [[MDCActivityIndicator alloc] initWithFrame:CGRectZero]; if (gChromeSigninViewControllerShowsActivityIndicator) {
[_activityIndicator setDelegate:self]; _activityIndicator =
[_activityIndicator setStrokeWidth:3]; [[MDCActivityIndicator alloc] initWithFrame:CGRectZero];
[_activityIndicator [_activityIndicator setDelegate:self];
setCycleColors:@[ [[MDCPalette cr_bluePalette] tint500] ]]; [_activityIndicator setStrokeWidth:3];
[self.view addSubview:_activityIndicator]; [_activityIndicator
setCycleColors:@[ [[MDCPalette cr_bluePalette] tint500] ]];
[self.view addSubview:_activityIndicator];
}
_gradientView = [[UIView alloc] initWithFrame:CGRectZero]; _gradientView = [[UIView alloc] initWithFrame:CGRectZero];
_gradientLayer = [CAGradientLayer layer]; _gradientLayer = [CAGradientLayer layer];
...@@ -1253,4 +1259,9 @@ enum AuthenticationState { ...@@ -1253,4 +1259,9 @@ enum AuthenticationState {
_timerGenerator = [timerGenerator copy]; _timerGenerator = [timerGenerator copy];
} }
+ (std::unique_ptr<base::AutoReset<BOOL>>)hideActivityIndicatorForTesting {
return std::make_unique<base::AutoReset<BOOL>>(
&gChromeSigninViewControllerShowsActivityIndicator, NO);
}
@end @end
...@@ -61,17 +61,7 @@ using chrome_test_util::SettingsDoneButton; ...@@ -61,17 +61,7 @@ using chrome_test_util::SettingsDoneButton;
[ChromeEarlGreyUI openSettingsMenu]; [ChromeEarlGreyUI openSettingsMenu];
[ChromeEarlGreyUI [ChromeEarlGreyUI
tapSettingsMenuButton:chrome_test_util::SecondarySignInButton()]; tapSettingsMenuButton:chrome_test_util::SecondarySignInButton()];
if (base::FeatureList::IsEnabled(unified_consent::kUnifiedConsent)) { [self selectIdentityWithEmail:identity.userEmail];
[[EarlGrey
selectElementWithMatcher:grey_allOf(
grey_accessibilityID(identity.userEmail),
grey_kindOfClass(
[IdentityChooserCell class]),
grey_sufficientlyVisible(), nil)]
performAction:grey_tap()];
} else {
[self selectIdentityWithEmail:identity.userEmail];
}
[self confirmSigninConfirmationDialog]; [self confirmSigninConfirmationDialog];
[[EarlGrey selectElementWithMatcher:SettingsDoneButton()] [[EarlGrey selectElementWithMatcher:SettingsDoneButton()]
performAction:grey_tap()]; performAction:grey_tap()];
...@@ -81,11 +71,21 @@ using chrome_test_util::SettingsDoneButton; ...@@ -81,11 +71,21 @@ using chrome_test_util::SettingsDoneButton;
} }
+ (void)selectIdentityWithEmail:(NSString*)userEmail { + (void)selectIdentityWithEmail:(NSString*)userEmail {
// Sign in to |userEmail|. if (base::FeatureList::IsEnabled(unified_consent::kUnifiedConsent)) {
[[EarlGrey selectElementWithMatcher:ButtonWithAccessibilityLabel(userEmail)] // Assumes that the identity chooser is visible.
performAction:grey_tap()]; [[EarlGrey
[[EarlGrey selectElementWithMatcher:AccountConsistencySetupSigninButton()] selectElementWithMatcher:grey_allOf(grey_accessibilityID(userEmail),
performAction:grey_tap()]; grey_kindOfClass(
[IdentityChooserCell class]),
grey_sufficientlyVisible(), nil)]
performAction:grey_tap()];
} else {
// Sign in to |userEmail|.
[[EarlGrey selectElementWithMatcher:ButtonWithAccessibilityLabel(userEmail)]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:AccountConsistencySetupSigninButton()]
performAction:grey_tap()];
}
} }
+ (void)tapSettingsLink { + (void)tapSettingsLink {
......
...@@ -10,6 +10,12 @@ ...@@ -10,6 +10,12 @@
@class AdvancedSigninSettingsCoordinator; @class AdvancedSigninSettingsCoordinator;
@protocol ApplicationCommands; @protocol ApplicationCommands;
// The accessibility identifier for the navigation "Confirm" button.
extern NSString* const kSyncSettingsConfirmButtonId;
// The accessibility identifier for the navigation "Cancel" button.
extern NSString* const kSyncSettingsCancelButtonId;
// AdvancedSigninSettingsCoordinator delegate. // AdvancedSigninSettingsCoordinator delegate.
@protocol AdvancedSigninSettingsCoordinatorDelegate <NSObject> @protocol AdvancedSigninSettingsCoordinatorDelegate <NSObject>
......
...@@ -31,6 +31,11 @@ ...@@ -31,6 +31,11 @@
using l10n_util::GetNSString; using l10n_util::GetNSString;
NSString* const kSyncSettingsConfirmButtonId =
@"kAdvancedSyncSettingsConfirmButtonId";
NSString* const kSyncSettingsCancelButtonId =
@"kAdvancedSyncSettingsCancelButtonId";
// Advanced sign-in settings result. // Advanced sign-in settings result.
typedef NS_ENUM(NSInteger, AdvancedSigninSettingsCoordinatorResult) { typedef NS_ENUM(NSInteger, AdvancedSigninSettingsCoordinatorResult) {
// The user confirmed the advanced sync settings. // The user confirmed the advanced sync settings.
...@@ -151,6 +156,7 @@ typedef NS_ENUM(NSInteger, AdvancedSigninSettingsCoordinatorResult) { ...@@ -151,6 +156,7 @@ typedef NS_ENUM(NSInteger, AdvancedSigninSettingsCoordinatorResult) {
initWithBarButtonSystemItem:UIBarButtonSystemItemCancel initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
target:self target:self
action:@selector(navigationCancelButtonAction)]; action:@selector(navigationCancelButtonAction)];
cancelButton.accessibilityIdentifier = kSyncSettingsCancelButtonId;
return cancelButton; return cancelButton;
} }
...@@ -162,6 +168,7 @@ typedef NS_ENUM(NSInteger, AdvancedSigninSettingsCoordinatorResult) { ...@@ -162,6 +168,7 @@ typedef NS_ENUM(NSInteger, AdvancedSigninSettingsCoordinatorResult) {
style:UIBarButtonItemStyleDone style:UIBarButtonItemStyleDone
target:self target:self
action:@selector(navigationConfirmButtonAction)]; action:@selector(navigationConfirmButtonAction)];
confirmButton.accessibilityIdentifier = kSyncSettingsConfirmButtonId;
return confirmButton; return confirmButton;
} }
......
...@@ -16,6 +16,9 @@ extern NSString* const kImportDataImportCellId; ...@@ -16,6 +16,9 @@ extern NSString* const kImportDataImportCellId;
// The accessibility identifier of the Keep Data Separate cell. // The accessibility identifier of the Keep Data Separate cell.
extern NSString* const kImportDataKeepSeparateCellId; extern NSString* const kImportDataKeepSeparateCellId;
// The accessiblity identifier of the Continue navigation button.
extern NSString* const kImportDataContinueButtonId;
// Notifies of the user action on the corresponding // Notifies of the user action on the corresponding
// ImportDataTableViewController. // ImportDataTableViewController.
@protocol ImportDataControllerDelegate @protocol ImportDataControllerDelegate
......
...@@ -24,6 +24,7 @@ NSString* const kImportDataImportCellId = @"kImportDataImportCellId"; ...@@ -24,6 +24,7 @@ NSString* const kImportDataImportCellId = @"kImportDataImportCellId";
// The accessibility identifier of the Keep Data Separate cell. // The accessibility identifier of the Keep Data Separate cell.
NSString* const kImportDataKeepSeparateCellId = NSString* const kImportDataKeepSeparateCellId =
@"kImportDataKeepSeparateCellId"; @"kImportDataKeepSeparateCellId";
NSString* const kImportDataContinueButtonId = @"kImportDataContinueButtonId";
namespace { namespace {
...@@ -89,7 +90,8 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -89,7 +90,8 @@ typedef NS_ENUM(NSInteger, ItemType) {
style:UIBarButtonItemStyleDone style:UIBarButtonItemStyleDone
target:self target:self
action:@selector(didTapContinue)]; action:@selector(didTapContinue)];
self.navigationItem.rightBarButtonItem.accessibilityIdentifier =
kImportDataContinueButtonId;
[self loadModel]; [self loadModel];
} }
......
...@@ -29,18 +29,43 @@ source_set("signin_interaction") { ...@@ -29,18 +29,43 @@ source_set("signin_interaction") {
] ]
} }
source_set("eg_test_support") {
configs += [ "//build/config/compiler:enable_arc" ]
testonly = true
sources = [
"signin_interaction_controller_egtest_util.h",
"signin_interaction_controller_egtest_util.mm",
]
deps = [
"//base",
"//base/test:test_support",
"//components/unified_consent",
"//ios/chrome/app/strings",
"//ios/chrome/browser/ui/authentication:eg_test_support",
"//ios/chrome/test/app:test_support",
"//ios/chrome/test/earl_grey:test_support",
"//ios/public/provider/chrome/browser/signin:test_support",
"//ios/testing/earl_grey:earl_grey_support",
]
}
source_set("eg_tests") { source_set("eg_tests") {
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
testonly = true testonly = true
sources = [ sources = [
"signin_interaction_controller_egtest.mm", "signin_interaction_controller_egtest.mm",
"signin_interaction_controller_unity_disabled_egtest.mm",
] ]
deps = [ deps = [
":eg_test_support",
"//base", "//base",
"//base/test:test_support", "//base/test:test_support",
"//components/unified_consent",
"//ios/chrome/app/strings", "//ios/chrome/app/strings",
"//ios/chrome/browser", "//ios/chrome/browser",
"//ios/chrome/browser/signin", "//ios/chrome/browser/signin",
"//ios/chrome/browser/ui/authentication",
"//ios/chrome/browser/ui/authentication:eg_test_support", "//ios/chrome/browser/ui/authentication:eg_test_support",
"//ios/chrome/browser/ui/authentication/cells", "//ios/chrome/browser/ui/authentication/cells",
"//ios/chrome/browser/ui/commands", "//ios/chrome/browser/ui/commands",
...@@ -60,18 +85,31 @@ source_set("unity_eg_tests") { ...@@ -60,18 +85,31 @@ source_set("unity_eg_tests") {
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
testonly = true testonly = true
sources = [ sources = [
"signin_interaction_controller_egtest.mm",
"signin_interaction_controller_unity_egtest.mm", "signin_interaction_controller_unity_egtest.mm",
] ]
deps = [ deps = [
":eg_test_support",
"//base", "//base",
"//base/test:test_support", "//base/test:test_support",
"//components/unified_consent", "//components/unified_consent",
"//ios/chrome/app/strings",
"//ios/chrome/app/strings:ios_strings_grit", "//ios/chrome/app/strings:ios_strings_grit",
"//ios/chrome/browser",
"//ios/chrome/browser/signin",
"//ios/chrome/browser/ui/authentication",
"//ios/chrome/browser/ui/authentication:eg_test_support", "//ios/chrome/browser/ui/authentication:eg_test_support",
"//ios/chrome/browser/ui/authentication/cells",
"//ios/chrome/browser/ui/authentication/unified_consent/identity_chooser:identity_chooser_ui", "//ios/chrome/browser/ui/authentication/unified_consent/identity_chooser:identity_chooser_ui",
"//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/content_suggestions:content_suggestions_constant",
"//ios/chrome/browser/ui/settings",
"//ios/chrome/browser/ui/util",
"//ios/chrome/test/app:test_support",
"//ios/chrome/test/earl_grey:test_support", "//ios/chrome/test/earl_grey:test_support",
"//ios/public/provider/chrome/browser/signin:test_support", "//ios/public/provider/chrome/browser/signin:test_support",
"//ios/testing/earl_grey:earl_grey_support", "//ios/testing/earl_grey:earl_grey_support",
"//ios/third_party/earl_grey:earl_grey+link",
"//ui/base", "//ui/base",
] ]
libs = [ "XCTest.framework" ] libs = [ "XCTest.framework" ]
......
...@@ -8,13 +8,16 @@ ...@@ -8,13 +8,16 @@
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#import "base/test/ios/wait_util.h" #import "base/test/ios/wait_util.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "components/unified_consent/feature.h"
#include "ios/chrome/browser/system_flags.h" #include "ios/chrome/browser/system_flags.h"
#import "ios/chrome/browser/ui/authentication/cells/signin_promo_view.h" #import "ios/chrome/browser/ui/authentication/cells/signin_promo_view.h"
#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_earl_grey_ui.h"
#import "ios/chrome/browser/ui/authentication/signin_earlgrey_utils.h" #import "ios/chrome/browser/ui/authentication/signin_earlgrey_utils.h"
#import "ios/chrome/browser/ui/commands/application_commands.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/commands/open_new_tab_command.h"
#import "ios/chrome/browser/ui/content_suggestions/ntp_home_constant.h" #import "ios/chrome/browser/ui/content_suggestions/ntp_home_constant.h"
#import "ios/chrome/browser/ui/signin_interaction/signin_interaction_controller_egtest_util.h"
#include "ios/chrome/browser/ui/util/ui_util.h" #include "ios/chrome/browser/ui/util/ui_util.h"
#include "ios/chrome/grit/ios_strings.h" #include "ios/chrome/grit/ios_strings.h"
#import "ios/chrome/test/app/chrome_test_util.h" #import "ios/chrome/test/app/chrome_test_util.h"
...@@ -32,45 +35,10 @@ ...@@ -32,45 +35,10 @@
using chrome_test_util::BookmarksNavigationBarDoneButton; using chrome_test_util::BookmarksNavigationBarDoneButton;
using chrome_test_util::SecondarySignInButton; using chrome_test_util::SecondarySignInButton;
using chrome_test_util::SettingsDoneButton; using chrome_test_util::SettingsDoneButton;
using chrome_test_util::SyncSettingsConfirmButton;
namespace { // Sign-in interaction tests that work both with Unified Consent enabled or
// disabled.
// Changes the EarlGrey synchronization status to |enabled|.
void SetEarlGreySynchronizationEnabled(BOOL enabled) {
[[GREYConfiguration sharedInstance]
setValue:[NSNumber numberWithBool:enabled]
forConfigKey:kGREYConfigKeySynchronizationEnabled];
}
// Taps the button with accessibility label |label|.
void TapButtonWithAccessibilityLabel(NSString* label) {
id<GREYMatcher> matcher =
chrome_test_util::ButtonWithAccessibilityLabel(label);
[[EarlGrey selectElementWithMatcher:matcher] performAction:grey_tap()];
}
// Taps the button with accessibility labelId |message_id|.
void TapButtonWithLabelId(int message_id) {
id<GREYMatcher> matcher =
chrome_test_util::ButtonWithAccessibilityLabelId(message_id);
[[EarlGrey selectElementWithMatcher:matcher] performAction:grey_tap()];
}
// Wait until |matcher| is accessible (not nil)
void WaitForMatcher(id<GREYMatcher> matcher) {
ConditionBlock condition = ^{
NSError* error = nil;
[[EarlGrey selectElementWithMatcher:matcher] assertWithMatcher:grey_notNil()
error:&error];
return error == nil;
};
GREYAssert(base::test::ios::WaitUntilConditionOrTimeout(
base::test::ios::kWaitForUIElementTimeout, condition),
@"Waiting for matcher %@ failed.", matcher);
}
} // namespace
@interface SigninInteractionControllerTestCase : ChromeTestCase @interface SigninInteractionControllerTestCase : ChromeTestCase
@end @end
...@@ -91,133 +59,6 @@ void WaitForMatcher(id<GREYMatcher> matcher) { ...@@ -91,133 +59,6 @@ void WaitForMatcher(id<GREYMatcher> matcher) {
[SigninEarlGreyUtils checkSignedInWithIdentity:identity]); [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 {
// 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];
[ChromeEarlGreyUI openSettingsMenu];
// Open accounts settings, then sync settings.
[[EarlGrey selectElementWithMatcher:chrome_test_util::SettingsAccountButton()]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:chrome_test_util::AccountsSyncButton()]
performAction:grey_tap()];
// Switch Sync account to |identity2|.
TapButtonWithAccessibilityLabel(identity2.userEmail);
[[EarlGrey selectElementWithMatcher:
chrome_test_util::SettingsImportDataKeepSeparateButton()]
performAction:grey_tap()];
id<GREYMatcher> matcher = grey_allOf(
chrome_test_util::ButtonWithAccessibilityLabelId(
IDS_IOS_OPTIONS_IMPORT_DATA_CONTINUE_BUTTON),
grey_not(grey_accessibilityTrait(UIAccessibilityTraitNotEnabled)), nil);
[[EarlGrey selectElementWithMatcher:matcher] performAction:grey_tap()];
// Check the signed-in user did change.
CHROME_EG_ASSERT_NO_ERROR(
[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 {
// 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];
[ChromeEarlGreyUI openSettingsMenu];
// Open accounts settings, then sync settings.
[[EarlGrey selectElementWithMatcher:chrome_test_util::SettingsAccountButton()]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:chrome_test_util::AccountsSyncButton()]
performAction:grey_tap()];
// Switch Sync account to |identity2|.
TapButtonWithAccessibilityLabel(identity2.userEmail);
[[EarlGrey selectElementWithMatcher:chrome_test_util::
SettingsImportDataImportButton()]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:
grey_allOf(chrome_test_util::ButtonWithAccessibilityLabelId(
IDS_IOS_OPTIONS_IMPORT_DATA_CONTINUE_BUTTON),
grey_userInteractionEnabled(), nil)]
performAction:grey_tap()];
// Check the signed-in user did change.
CHROME_EG_ASSERT_NO_ERROR(
[SigninEarlGreyUtils checkSignedInWithIdentity:identity2]);
[[EarlGrey selectElementWithMatcher:SettingsDoneButton()]
performAction:grey_tap()];
}
// Tests that switching from a managed account to a non-managed account works
// correctly and displays the expected warnings.
- (void)testSignInSwitchManagedAccount {
// Set up the fake identities.
ios::FakeChromeIdentityService* identity_service =
ios::FakeChromeIdentityService::GetInstanceFromChromeProvider();
ChromeIdentity* managed_identity = [SigninEarlGreyUtils fakeManagedIdentity];
ChromeIdentity* identity = [SigninEarlGreyUtils fakeIdentity1];
identity_service->AddIdentity(managed_identity);
identity_service->AddIdentity(identity);
[ChromeEarlGreyUI openSettingsMenu];
[ChromeEarlGreyUI tapSettingsMenuButton:SecondarySignInButton()];
[SigninEarlGreyUI selectIdentityWithEmail:managed_identity.userEmail];
// Accept warning for signing into a managed identity, with synchronization
// off due to an infinite spinner.
SetEarlGreySynchronizationEnabled(NO);
WaitForMatcher(chrome_test_util::ButtonWithAccessibilityLabelId(
IDS_IOS_MANAGED_SIGNIN_ACCEPT_BUTTON));
TapButtonWithLabelId(IDS_IOS_MANAGED_SIGNIN_ACCEPT_BUTTON);
SetEarlGreySynchronizationEnabled(YES);
[SigninEarlGreyUI confirmSigninConfirmationDialog];
CHROME_EG_ASSERT_NO_ERROR(
[SigninEarlGreyUtils checkSignedInWithIdentity:managed_identity]);
// Switch Sync account to |identity|.
[[EarlGrey selectElementWithMatcher:chrome_test_util::SettingsAccountButton()]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:chrome_test_util::AccountsSyncButton()]
performAction:grey_tap()];
TapButtonWithAccessibilityLabel(identity.userEmail);
SetEarlGreySynchronizationEnabled(NO);
WaitForMatcher(chrome_test_util::ButtonWithAccessibilityLabelId(
IDS_IOS_MANAGED_SWITCH_ACCEPT_BUTTON));
TapButtonWithLabelId(IDS_IOS_MANAGED_SWITCH_ACCEPT_BUTTON);
SetEarlGreySynchronizationEnabled(YES);
CHROME_EG_ASSERT_NO_ERROR(
[SigninEarlGreyUtils checkSignedInWithIdentity:identity]);
[[EarlGrey selectElementWithMatcher:SettingsDoneButton()]
performAction:grey_tap()];
}
// Tests that signing out from the Settings works correctly. // Tests that signing out from the Settings works correctly.
- (void)testSignInDisconnectFromChrome { - (void)testSignInDisconnectFromChrome {
ChromeIdentity* identity = [SigninEarlGreyUtils fakeIdentity1]; ChromeIdentity* identity = [SigninEarlGreyUtils fakeIdentity1];
...@@ -306,16 +147,15 @@ void WaitForMatcher(id<GREYMatcher> matcher) { ...@@ -306,16 +147,15 @@ void WaitForMatcher(id<GREYMatcher> matcher) {
[SigninEarlGreyUI selectIdentityWithEmail:identity.userEmail]; [SigninEarlGreyUI selectIdentityWithEmail:identity.userEmail];
// Wait until the next screen appears. // Wait until the next screen appears.
id<GREYMatcher> settings_link_matcher = grey_allOf( [SigninEarlGreyUI tapSettingsLink];
grey_accessibilityLabel(@"Settings"), grey_sufficientlyVisible(), nil);
WaitForMatcher(settings_link_matcher); if (unified_consent::IsUnifiedConsentFeatureEnabled()) {
// Tap Settings link. [[EarlGrey selectElementWithMatcher:SyncSettingsConfirmButton()]
[[EarlGrey selectElementWithMatcher:settings_link_matcher] performAction:grey_tap()];
performAction:grey_tap()]; } else {
[[EarlGrey selectElementWithMatcher:SettingsDoneButton()]
[[EarlGrey selectElementWithMatcher:SettingsDoneButton()] performAction:grey_tap()];
performAction:grey_tap()]; }
// All Settings should be gone and user signed in. // All Settings should be gone and user signed in.
id<GREYMatcher> settings_matcher = id<GREYMatcher> settings_matcher =
...@@ -349,53 +189,10 @@ void WaitForMatcher(id<GREYMatcher> matcher) { ...@@ -349,53 +189,10 @@ void WaitForMatcher(id<GREYMatcher> matcher) {
// this will fail. // this will fail.
[ChromeEarlGreyUI openSettingsMenu]; [ChromeEarlGreyUI openSettingsMenu];
[ChromeEarlGreyUI tapSettingsMenuButton:SecondarySignInButton()]; [ChromeEarlGreyUI tapSettingsMenuButton:SecondarySignInButton()];
id<GREYMatcher> signin_matcher = if (unified_consent::IsUnifiedConsentFeatureEnabled())
chrome_test_util::StaticTextWithAccessibilityLabelId( [SigninEarlGreyUI selectIdentityWithEmail:identity.userEmail];
IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_DESCRIPTION);
[[EarlGrey selectElementWithMatcher:signin_matcher]
assertWithMatcher:grey_sufficientlyVisible()];
// Close sign-in screen and Settings.
TapButtonWithLabelId(IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_SKIP_BUTTON);
[[EarlGrey selectElementWithMatcher:SettingsDoneButton()]
performAction:grey_tap()];
}
// 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
- (void)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. VerifyChromeSigninViewVisible();
id<GREYMatcher> add_account_matcher =
chrome_test_util::StaticTextWithAccessibilityLabelId(
IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_ADD_ACCOUNT_BUTTON);
[[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];
// Re-open the sign-in screen. If it wasn't correctly dismissed previously,
// this will fail.
[ChromeEarlGreyUI openSettingsMenu];
[ChromeEarlGreyUI tapSettingsMenuButton:SecondarySignInButton()];
id<GREYMatcher> signin_matcher =
chrome_test_util::StaticTextWithAccessibilityLabelId(
IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_DESCRIPTION);
[[EarlGrey selectElementWithMatcher:signin_matcher]
assertWithMatcher:grey_sufficientlyVisible()];
// Close sign-in screen and Settings. // Close sign-in screen and Settings.
TapButtonWithLabelId(IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_SKIP_BUTTON); TapButtonWithLabelId(IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_SKIP_BUTTON);
...@@ -437,9 +234,17 @@ void WaitForMatcher(id<GREYMatcher> matcher) { ...@@ -437,9 +234,17 @@ void WaitForMatcher(id<GREYMatcher> matcher) {
performAction:grey_tap()]; performAction:grey_tap()];
TapButtonWithLabelId(IDS_IOS_DISCONNECT_DIALOG_CONTINUE_BUTTON_MOBILE); TapButtonWithLabelId(IDS_IOS_DISCONNECT_DIALOG_CONTINUE_BUTTON_MOBILE);
CHROME_EG_ASSERT_NO_ERROR([SigninEarlGreyUtils checkSignedOut]); CHROME_EG_ASSERT_NO_ERROR([SigninEarlGreyUtils checkSignedOut]);
// Sign in with |identity1|.
[[EarlGrey selectElementWithMatcher:SecondarySignInButton()] [[EarlGrey selectElementWithMatcher:SecondarySignInButton()]
performAction:grey_tap()]; performAction:grey_tap()];
[SigninEarlGreyUI selectIdentityWithEmail:identity1.userEmail]; [SigninEarlGreyUI selectIdentityWithEmail:identity1.userEmail];
if (unified_consent::IsUnifiedConsentFeatureEnabled()) {
// With unified consent, the authentication flow is only created when the
// confirm button is selected. Note that authentication flow actually
/// blocks as the "Clear Browsing Before Syncing" dialog is presented.
[SigninEarlGreyUI confirmSigninConfirmationDialog];
}
// Open new tab to cancel sign-in. // Open new tab to cancel sign-in.
OpenNewTabCommand* command = OpenNewTabCommand* command =
...@@ -451,11 +256,9 @@ void WaitForMatcher(id<GREYMatcher> matcher) { ...@@ -451,11 +256,9 @@ void WaitForMatcher(id<GREYMatcher> matcher) {
// this will fail. // this will fail.
[ChromeEarlGreyUI openSettingsMenu]; [ChromeEarlGreyUI openSettingsMenu];
[ChromeEarlGreyUI tapSettingsMenuButton:SecondarySignInButton()]; [ChromeEarlGreyUI tapSettingsMenuButton:SecondarySignInButton()];
id<GREYMatcher> signin_matcher = if (unified_consent::IsUnifiedConsentFeatureEnabled())
chrome_test_util::StaticTextWithAccessibilityLabelId( [SigninEarlGreyUI selectIdentityWithEmail:identity1.userEmail];
IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_DESCRIPTION); VerifyChromeSigninViewVisible();
[[EarlGrey selectElementWithMatcher:signin_matcher]
assertWithMatcher:grey_sufficientlyVisible()];
// Close sign-in screen and Settings. // Close sign-in screen and Settings.
TapButtonWithLabelId(IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_SKIP_BUTTON); TapButtonWithLabelId(IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_SKIP_BUTTON);
...@@ -478,11 +281,9 @@ void WaitForMatcher(id<GREYMatcher> matcher) { ...@@ -478,11 +281,9 @@ void WaitForMatcher(id<GREYMatcher> matcher) {
[ChromeEarlGreyUI tapSettingsMenuButton:SecondarySignInButton()]; [ChromeEarlGreyUI tapSettingsMenuButton:SecondarySignInButton()];
// Assert sign-in screen was shown. // Assert sign-in screen was shown.
id<GREYMatcher> signin_matcher = if (unified_consent::IsUnifiedConsentFeatureEnabled())
chrome_test_util::StaticTextWithAccessibilityLabelId( [SigninEarlGreyUI selectIdentityWithEmail:identity.userEmail];
IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_DESCRIPTION); VerifyChromeSigninViewVisible();
[[EarlGrey selectElementWithMatcher:signin_matcher]
assertWithMatcher:grey_sufficientlyVisible()];
// Open new tab to cancel sign-in. // Open new tab to cancel sign-in.
OpenNewTabCommand* command = OpenNewTabCommand* command =
...@@ -495,8 +296,9 @@ void WaitForMatcher(id<GREYMatcher> matcher) { ...@@ -495,8 +296,9 @@ void WaitForMatcher(id<GREYMatcher> matcher) {
[ChromeEarlGreyUI openToolsMenu]; [ChromeEarlGreyUI openToolsMenu];
[ChromeEarlGreyUI tapToolsMenuButton:chrome_test_util::BookmarksMenuButton()]; [ChromeEarlGreyUI tapToolsMenuButton:chrome_test_util::BookmarksMenuButton()];
[ChromeEarlGreyUI tapSettingsMenuButton:SecondarySignInButton()]; [ChromeEarlGreyUI tapSettingsMenuButton:SecondarySignInButton()];
[[EarlGrey selectElementWithMatcher:signin_matcher] if (unified_consent::IsUnifiedConsentFeatureEnabled())
assertWithMatcher:grey_sufficientlyVisible()]; [SigninEarlGreyUI selectIdentityWithEmail:identity.userEmail];
VerifyChromeSigninViewVisible();
// Close sign-in screen and Bookmarks. // Close sign-in screen and Bookmarks.
TapButtonWithLabelId(IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_SKIP_BUTTON); TapButtonWithLabelId(IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_SKIP_BUTTON);
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_SIGNIN_INTERACTION_SIGNIN_INTERACTION_CONTROLLER_EGTEST_UTIL_H_
#define IOS_CHROME_BROWSER_UI_SIGNIN_INTERACTION_SIGNIN_INTERACTION_CONTROLLER_EGTEST_UTIL_H_
#import <EarlGrey/EarlGrey.h>
#import <Foundation/Foundation.h>
// Changes the EarlGrey synchronization status to |enabled|.
void SetEarlGreySynchronizationEnabled(BOOL enabled);
// Taps the button with accessibility label |label|.
void TapButtonWithAccessibilityLabel(NSString* label);
// Taps the button with accessibility labelId |message_id|.
void TapButtonWithLabelId(int message_id);
// Verifies that the Chrome sign-in view is visible.
void VerifyChromeSigninViewVisible();
// Wait until |matcher| is accessible (not nil).
void WaitForMatcher(id<GREYMatcher> matcher);
#endif // IOS_CHROME_BROWSER_UI_SIGNIN_INTERACTION_SIGNIN_INTERACTION_CONTROLLER_EGTEST_UTIL_H_
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/ui/signin_interaction/signin_interaction_controller_egtest_util.h"
#import "base/test/ios/wait_util.h"
#include "components/unified_consent/feature.h"
#import "ios/chrome/browser/ui/authentication/signin_earlgrey_utils.h"
#include "ios/chrome/grit/ios_strings.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h"
#import "ios/chrome/test/earl_grey/chrome_error_util.h"
#import "ios/chrome/test/earl_grey/chrome_matchers.h"
#import "ios/chrome/test/earl_grey/chrome_test_case.h"
#
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
void SetEarlGreySynchronizationEnabled(BOOL enabled) {
[[GREYConfiguration sharedInstance]
setValue:[NSNumber numberWithBool:enabled]
forConfigKey:kGREYConfigKeySynchronizationEnabled];
}
void TapButtonWithAccessibilityLabel(NSString* label) {
id<GREYMatcher> matcher =
chrome_test_util::ButtonWithAccessibilityLabel(label);
[[EarlGrey selectElementWithMatcher:matcher] performAction:grey_tap()];
}
void TapButtonWithLabelId(int message_id) {
id<GREYMatcher> matcher =
chrome_test_util::ButtonWithAccessibilityLabelId(message_id);
[[EarlGrey selectElementWithMatcher:matcher] performAction:grey_tap()];
}
void VerifyChromeSigninViewVisible() {
id<GREYMatcher> signin_matcher =
chrome_test_util::StaticTextWithAccessibilityLabelId(
unified_consent::IsUnifiedConsentFeatureEnabled()
? IDS_IOS_ACCOUNT_UNIFIED_CONSENT_SYNC_SUBTITLE
: IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_DESCRIPTION);
[[EarlGrey selectElementWithMatcher:signin_matcher]
assertWithMatcher:grey_sufficientlyVisible()];
}
void WaitForMatcher(id<GREYMatcher> matcher) {
ConditionBlock condition = ^{
NSError* error = nil;
[[EarlGrey selectElementWithMatcher:matcher] assertWithMatcher:grey_notNil()
error:&error];
return error == nil;
};
GREYAssert(base::test::ios::WaitUntilConditionOrTimeout(
base::test::ios::kWaitForUIElementTimeout, condition),
@"Waiting for matcher %@ failed.", matcher);
}
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import <EarlGrey/EarlGrey.h>
#import <XCTest/XCTest.h>
#include "base/auto_reset.h"
#include "base/strings/sys_string_conversions.h"
#import "base/test/ios/wait_util.h"
#include "base/test/scoped_feature_list.h"
#include "components/unified_consent/feature.h"
#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/commands/application_commands.h"
#import "ios/chrome/browser/ui/commands/open_new_tab_command.h"
#import "ios/chrome/browser/ui/signin_interaction/signin_interaction_controller_egtest_util.h"
#include "ios/chrome/browser/ui/util/ui_util.h"
#include "ios/chrome/grit/ios_strings.h"
#import "ios/chrome/test/app/chrome_test_util.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h"
#import "ios/chrome/test/earl_grey/chrome_error_util.h"
#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_service.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
using chrome_test_util::SecondarySignInButton;
using chrome_test_util::SettingsDoneButton;
// Sign-in interaction tests that requires Unified Consent to be disabled.
@interface SigninInteractionControllerUnityDisabledTestCase : ChromeTestCase
@end
@implementation SigninInteractionControllerUnityDisabledTestCase
- (void)setUp {
[super setUp];
CHECK(!unified_consent::IsUnifiedConsentFeatureEnabled())
<< "This test suite must be run with Unified Consent feature disabled.";
}
// Tests that switching from a managed account to a non-managed account works
// correctly and displays the expected warnings.
- (void)testSignInSwitchManagedAccount {
// Set up the fake identities.
ios::FakeChromeIdentityService* identity_service =
ios::FakeChromeIdentityService::GetInstanceFromChromeProvider();
ChromeIdentity* managed_identity = [SigninEarlGreyUtils fakeManagedIdentity];
ChromeIdentity* identity = [SigninEarlGreyUtils fakeIdentity1];
identity_service->AddIdentity(managed_identity);
identity_service->AddIdentity(identity);
[ChromeEarlGreyUI openSettingsMenu];
[ChromeEarlGreyUI tapSettingsMenuButton:SecondarySignInButton()];
[SigninEarlGreyUI selectIdentityWithEmail:managed_identity.userEmail];
// Accept warning for signing into a managed identity, with synchronization
// off due to an infinite spinner.
SetEarlGreySynchronizationEnabled(NO);
WaitForMatcher(chrome_test_util::ButtonWithAccessibilityLabelId(
IDS_IOS_MANAGED_SIGNIN_ACCEPT_BUTTON));
TapButtonWithLabelId(IDS_IOS_MANAGED_SIGNIN_ACCEPT_BUTTON);
SetEarlGreySynchronizationEnabled(YES);
[SigninEarlGreyUI confirmSigninConfirmationDialog];
CHROME_EG_ASSERT_NO_ERROR(
[SigninEarlGreyUtils checkSignedInWithIdentity:managed_identity]);
// Switch Sync account to |identity|.
[[EarlGrey selectElementWithMatcher:chrome_test_util::SettingsAccountButton()]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:chrome_test_util::AccountsSyncButton()]
performAction:grey_tap()];
TapButtonWithAccessibilityLabel(identity.userEmail);
SetEarlGreySynchronizationEnabled(NO);
WaitForMatcher(chrome_test_util::ButtonWithAccessibilityLabelId(
IDS_IOS_MANAGED_SWITCH_ACCEPT_BUTTON));
TapButtonWithLabelId(IDS_IOS_MANAGED_SWITCH_ACCEPT_BUTTON);
SetEarlGreySynchronizationEnabled(YES);
CHROME_EG_ASSERT_NO_ERROR(
[SigninEarlGreyUtils checkSignedInWithIdentity:identity]);
[[EarlGrey selectElementWithMatcher:SettingsDoneButton()]
performAction:grey_tap()];
}
// 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 {
// 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];
[ChromeEarlGreyUI openSettingsMenu];
// Open accounts settings, then sync settings.
[[EarlGrey selectElementWithMatcher:chrome_test_util::SettingsAccountButton()]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:chrome_test_util::AccountsSyncButton()]
performAction:grey_tap()];
// Switch Sync account to |identity2|.
TapButtonWithAccessibilityLabel(identity2.userEmail);
[[EarlGrey selectElementWithMatcher:
chrome_test_util::SettingsImportDataKeepSeparateButton()]
performAction:grey_tap()];
id<GREYMatcher> matcher = grey_allOf(
chrome_test_util::ButtonWithAccessibilityLabelId(
IDS_IOS_OPTIONS_IMPORT_DATA_CONTINUE_BUTTON),
grey_not(grey_accessibilityTrait(UIAccessibilityTraitNotEnabled)), nil);
[[EarlGrey selectElementWithMatcher:matcher] performAction:grey_tap()];
// Check the signed-in user did change.
CHROME_EG_ASSERT_NO_ERROR(
[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 {
// 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];
[ChromeEarlGreyUI openSettingsMenu];
// Open accounts settings, then sync settings.
[[EarlGrey selectElementWithMatcher:chrome_test_util::SettingsAccountButton()]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:chrome_test_util::AccountsSyncButton()]
performAction:grey_tap()];
// Switch Sync account to |identity2|.
TapButtonWithAccessibilityLabel(identity2.userEmail);
[[EarlGrey selectElementWithMatcher:chrome_test_util::
SettingsImportDataImportButton()]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:
grey_allOf(chrome_test_util::ButtonWithAccessibilityLabelId(
IDS_IOS_OPTIONS_IMPORT_DATA_CONTINUE_BUTTON),
grey_userInteractionEnabled(), nil)]
performAction:grey_tap()];
// Check the signed-in user did change.
CHROME_EG_ASSERT_NO_ERROR(
[SigninEarlGreyUtils checkSignedInWithIdentity:identity2]);
[[EarlGrey selectElementWithMatcher:SettingsDoneButton()]
performAction:grey_tap()];
}
// 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
- (void)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(
unified_consent::IsUnifiedConsentFeatureEnabled()
? IDS_IOS_ACCOUNT_IDENTITY_CHOOSER_ADD_ACCOUNT
: IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_ADD_ACCOUNT_BUTTON);
[[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];
// Re-open the sign-in screen. If it wasn't correctly dismissed previously,
// this will fail.
[ChromeEarlGreyUI openSettingsMenu];
[ChromeEarlGreyUI tapSettingsMenuButton:SecondarySignInButton()];
if (unified_consent::IsUnifiedConsentFeatureEnabled())
[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
...@@ -5,12 +5,18 @@ ...@@ -5,12 +5,18 @@
#import <EarlGrey/EarlGrey.h> #import <EarlGrey/EarlGrey.h>
#import <XCTest/XCTest.h> #import <XCTest/XCTest.h>
#include "base/auto_reset.h"
#import "base/test/ios/wait_util.h" #import "base/test/ios/wait_util.h"
#include "components/unified_consent/feature.h" #include "components/unified_consent/feature.h"
#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_earl_grey_ui.h"
#import "ios/chrome/browser/ui/authentication/signin_earlgrey_utils.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/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/signin_interaction/signin_interaction_controller_egtest_util.h"
#include "ios/chrome/grit/ios_strings.h" #include "ios/chrome/grit/ios_strings.h"
#import "ios/chrome/test/app/chrome_test_util.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h" #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h"
#import "ios/chrome/test/earl_grey/chrome_error_util.h" #import "ios/chrome/test/earl_grey/chrome_error_util.h"
#import "ios/chrome/test/earl_grey/chrome_matchers.h" #import "ios/chrome/test/earl_grey/chrome_matchers.h"
...@@ -19,6 +25,7 @@ ...@@ -19,6 +25,7 @@
#import "ios/public/provider/chrome/browser/signin/fake_chrome_identity_interaction_manager.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/public/provider/chrome/browser/signin/fake_chrome_identity_service.h"
#import "ios/testing/earl_grey/matchers.h" #import "ios/testing/earl_grey/matchers.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/l10n/l10n_util_mac.h" #include "ui/base/l10n/l10n_util_mac.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
...@@ -32,19 +39,6 @@ using chrome_test_util::SettingsDoneButton; ...@@ -32,19 +39,6 @@ using chrome_test_util::SettingsDoneButton;
namespace { namespace {
// Wait until |matcher| is accessible (not nil)
void WaitForMatcher(id<GREYMatcher> matcher) {
ConditionBlock condition = ^{
NSError* error = nil;
[[EarlGrey selectElementWithMatcher:matcher] assertWithMatcher:grey_notNil()
error:&error];
return error == nil;
};
GREYAssert(base::test::ios::WaitUntilConditionOrTimeout(
base::test::ios::kWaitForUIElementTimeout, condition),
@"Waiting for matcher %@ failed.", matcher);
}
// Returns a matcher for |userEmail| in IdentityChooserViewController. // Returns a matcher for |userEmail| in IdentityChooserViewController.
id<GREYMatcher> identityChooserButtonMatcherWithEmail(NSString* userEmail) { id<GREYMatcher> identityChooserButtonMatcherWithEmail(NSString* userEmail) {
return grey_allOf(grey_accessibilityID(userEmail), return grey_allOf(grey_accessibilityID(userEmail),
...@@ -59,12 +53,32 @@ id<GREYMatcher> addIdentityButtonInIdentityChooser() { ...@@ -59,12 +53,32 @@ id<GREYMatcher> addIdentityButtonInIdentityChooser() {
IDS_IOS_ACCOUNT_UNIFIED_CONSENT_ADD_ACCOUNT)); IDS_IOS_ACCOUNT_UNIFIED_CONSENT_ADD_ACCOUNT));
} }
// Opens Accounts Settings and tap the sign out button. Assumes that the main
// settings page is visible.
void SignOutFromSettings() {
[[EarlGrey selectElementWithMatcher:chrome_test_util::SettingsAccountButton()]
performAction:grey_tap()];
const CGFloat scroll_displacement = 100.0;
[[[EarlGrey
selectElementWithMatcher:grey_allOf(
chrome_test_util::SignOutAccountsButton(),
grey_interactable(), nil)]
usingSearchAction:grey_scrollInDirection(kGREYDirectionDown,
scroll_displacement)
onElementWithMatcher:chrome_test_util::SettingsAccountsCollectionView()]
performAction:grey_tap()];
TapButtonWithLabelId(IDS_IOS_DISCONNECT_DIALOG_CONTINUE_BUTTON_MOBILE);
CHROME_EG_ASSERT_NO_ERROR([SigninEarlGreyUtils checkSignedOut]);
}
} // namespace } // namespace
@interface SigninInteractionControllerTestCase : ChromeTestCase // Sign-in interactions tests that require Unified Consent to be enabled.
@interface SigninInteractionControllerUnityEnabledTestCase : ChromeTestCase
@end @end
@implementation SigninInteractionControllerTestCase @implementation SigninInteractionControllerUnityEnabledTestCase
- (void)setUp { - (void)setUp {
[super setUp]; [super setUp];
...@@ -73,23 +87,8 @@ id<GREYMatcher> addIdentityButtonInIdentityChooser() { ...@@ -73,23 +87,8 @@ id<GREYMatcher> addIdentityButtonInIdentityChooser() {
<< "This test suite must be run with Unified Consent feature enabled."; << "This test suite must be run with Unified Consent feature enabled.";
} }
// Tests that opening the sign-in screen from the Settings and signing in works
// correctly when there is already an identity on the device.
- (void)testSignInOneUser {
// Set up a fake identity.
ChromeIdentity* identity = [SigninEarlGreyUtils fakeIdentity1];
ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()->AddIdentity(
identity);
[SigninEarlGreyUI signinWithIdentity:identity];
// Check |identity| is signed-in.
CHROME_EG_ASSERT_NO_ERROR(
[SigninEarlGreyUtils checkSignedInWithIdentity:identity]);
}
// Tests the "ADD ACCOUNT" button in the identity chooser view controller. // Tests the "ADD ACCOUNT" button in the identity chooser view controller.
- (void)testAddAccountAutomatcially { - (void)testAddAccountAutomatically {
[ChromeEarlGreyUI openSettingsMenu]; [ChromeEarlGreyUI openSettingsMenu];
[ChromeEarlGreyUI tapSettingsMenuButton:PrimarySignInButton()]; [ChromeEarlGreyUI tapSettingsMenuButton:PrimarySignInButton()];
[[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; [[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
...@@ -131,4 +130,142 @@ id<GREYMatcher> addIdentityButtonInIdentityChooser() { ...@@ -131,4 +130,142 @@ id<GREYMatcher> addIdentityButtonInIdentityChooser() {
assertWithMatcher:grey_notVisible()]; assertWithMatcher:grey_notVisible()];
} }
// Tests signing in with one account, switching sync account to a second and
// choosing to keep the browsing data separate during the switch.
//
// TODO(crbug.com/962843): This test is crashing due to a recent change in
// |page_placeholder_tab_helper.mm|.
- (void)DISABLED_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];
[ChromeEarlGreyUI openSettingsMenu];
SignOutFromSettings();
// Sign in with |identity2|.
[[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.
CHROME_EG_ASSERT_NO_ERROR(
[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];
[ChromeEarlGreyUI openSettingsMenu];
SignOutFromSettings();
// Sign in with |identity2|.
[[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.
CHROME_EG_ASSERT_NO_ERROR(
[SigninEarlGreyUtils checkSignedInWithIdentity:identity2]);
[[EarlGrey selectElementWithMatcher:SettingsDoneButton()]
performAction:grey_tap()];
}
// 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(
unified_consent::IsUnifiedConsentFeatureEnabled()
? IDS_IOS_ACCOUNT_IDENTITY_CHOOSER_ADD_ACCOUNT
: IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_ADD_ACCOUNT_BUTTON);
[[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];
// Re-open the sign-in screen. If it wasn't correctly dismissed previously,
// this will fail.
[ChromeEarlGreyUI openSettingsMenu];
[ChromeEarlGreyUI tapSettingsMenuButton:SecondarySignInButton()];
if (unified_consent::IsUnifiedConsentFeatureEnabled())
[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 @end
...@@ -153,6 +153,10 @@ id<GREYMatcher> SettingsMenuButton(); ...@@ -153,6 +153,10 @@ id<GREYMatcher> SettingsMenuButton();
// Returns matcher for the "Done" button in the settings' navigation bar. // Returns matcher for the "Done" button in the settings' navigation bar.
id<GREYMatcher> SettingsDoneButton(); id<GREYMatcher> SettingsDoneButton();
// Returns matcher for the "Confirm" button in the Sync and Google Services
// settings' navigation bar.
id<GREYMatcher> SyncSettingsConfirmButton();
// Returns matcher for the tools menu table view. // Returns matcher for the tools menu table view.
id<GREYMatcher> ToolsMenuView(); id<GREYMatcher> ToolsMenuView();
...@@ -181,6 +185,9 @@ id<GREYMatcher> SettingsImportDataImportButton(); ...@@ -181,6 +185,9 @@ id<GREYMatcher> SettingsImportDataImportButton();
// Returns matcher for the Keep Data Separate cell in switch sync account view. // Returns matcher for the Keep Data Separate cell in switch sync account view.
id<GREYMatcher> SettingsImportDataKeepSeparateButton(); id<GREYMatcher> SettingsImportDataKeepSeparateButton();
// Returns matcher for the Keep Data Separate cell in switch sync account view.
id<GREYMatcher> SettingsImportDataContinueButton();
// Returns matcher for the Manage Synced Data button in sync setting view. // Returns matcher for the Manage Synced Data button in sync setting view.
id<GREYMatcher> SettingsSyncManageSyncedDataButton(); id<GREYMatcher> SettingsSyncManageSyncedDataButton();
......
...@@ -197,6 +197,10 @@ id<GREYMatcher> SettingsDoneButton() { ...@@ -197,6 +197,10 @@ id<GREYMatcher> SettingsDoneButton() {
return [ChromeMatchersAppInterface settingsDoneButton]; return [ChromeMatchersAppInterface settingsDoneButton];
} }
id<GREYMatcher> SyncSettingsConfirmButton() {
return [ChromeMatchersAppInterface syncSettingsConfirmButton];
}
id<GREYMatcher> ToolsMenuView() { id<GREYMatcher> ToolsMenuView() {
return [ChromeMatchersAppInterface toolsMenuView]; return [ChromeMatchersAppInterface toolsMenuView];
} }
...@@ -229,6 +233,10 @@ id<GREYMatcher> SettingsImportDataKeepSeparateButton() { ...@@ -229,6 +233,10 @@ id<GREYMatcher> SettingsImportDataKeepSeparateButton() {
return [ChromeMatchersAppInterface settingsImportDataKeepSeparateButton]; return [ChromeMatchersAppInterface settingsImportDataKeepSeparateButton];
} }
id<GREYMatcher> SettingsImportDataContinueButton() {
return [ChromeMatchersAppInterface settingsImportDataContinueButton];
}
id<GREYMatcher> SettingsSyncManageSyncedDataButton() { id<GREYMatcher> SettingsSyncManageSyncedDataButton() {
return [ChromeMatchersAppInterface settingsSyncManageSyncedDataButton]; return [ChromeMatchersAppInterface settingsSyncManageSyncedDataButton];
} }
......
...@@ -154,6 +154,10 @@ ...@@ -154,6 +154,10 @@
// Returns matcher for the "Done" button in the settings' navigation bar. // Returns matcher for the "Done" button in the settings' navigation bar.
+ (id<GREYMatcher>)settingsDoneButton; + (id<GREYMatcher>)settingsDoneButton;
// Returns matcher for the "Confirm" button in the Sync and Google services
// settings' navigation bar.
+ (id<GREYMatcher>)syncSettingsConfirmButton;
// Returns matcher for the tools menu table view. // Returns matcher for the tools menu table view.
+ (id<GREYMatcher>)toolsMenuView; + (id<GREYMatcher>)toolsMenuView;
...@@ -182,6 +186,10 @@ ...@@ -182,6 +186,10 @@
// Returns matcher for the Keep Data Separate cell in switch sync account view. // Returns matcher for the Keep Data Separate cell in switch sync account view.
+ (id<GREYMatcher>)settingsImportDataKeepSeparateButton; + (id<GREYMatcher>)settingsImportDataKeepSeparateButton;
// Returns matcher for the Continue navigation button in switch sync account
// view.
+ (id<GREYMatcher>)settingsImportDataContinueButton;
// Returns matcher for the Manage Synced Data button in sync setting view. // Returns matcher for the Manage Synced Data button in sync setting view.
+ (id<GREYMatcher>)settingsSyncManageSyncedDataButton; + (id<GREYMatcher>)settingsSyncManageSyncedDataButton;
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#import "ios/chrome/browser/ui/settings/clear_browsing_data/clear_browsing_data_collection_view_controller.h" #import "ios/chrome/browser/ui/settings/clear_browsing_data/clear_browsing_data_collection_view_controller.h"
#import "ios/chrome/browser/ui/settings/clear_browsing_data/clear_browsing_data_ui_constants.h" #import "ios/chrome/browser/ui/settings/clear_browsing_data/clear_browsing_data_ui_constants.h"
#import "ios/chrome/browser/ui/settings/google_services/accounts_table_view_controller.h" #import "ios/chrome/browser/ui/settings/google_services/accounts_table_view_controller.h"
#import "ios/chrome/browser/ui/settings/google_services/advanced_signin_settings_coordinator.h"
#import "ios/chrome/browser/ui/settings/import_data_table_view_controller.h" #import "ios/chrome/browser/ui/settings/import_data_table_view_controller.h"
#import "ios/chrome/browser/ui/settings/settings_table_view_controller.h" #import "ios/chrome/browser/ui/settings/settings_table_view_controller.h"
#import "ios/chrome/browser/ui/settings/sync/sync_settings_table_view_controller.h" #import "ios/chrome/browser/ui/settings/sync/sync_settings_table_view_controller.h"
...@@ -389,6 +390,10 @@ UIView* SubviewWithAccessibilityIdentifier(NSString* accessibility_id, ...@@ -389,6 +390,10 @@ UIView* SubviewWithAccessibilityIdentifier(NSString* accessibility_id,
return grey_accessibilityID(kSettingsDoneButtonId); return grey_accessibilityID(kSettingsDoneButtonId);
} }
+ (id<GREYMatcher>)syncSettingsConfirmButton {
return grey_accessibilityID(kSyncSettingsConfirmButtonId);
}
+ (id<GREYMatcher>)toolsMenuView { + (id<GREYMatcher>)toolsMenuView {
return grey_accessibilityID(kPopupMenuToolsMenuTableViewId); return grey_accessibilityID(kPopupMenuToolsMenuTableViewId);
} }
...@@ -421,6 +426,10 @@ UIView* SubviewWithAccessibilityIdentifier(NSString* accessibility_id, ...@@ -421,6 +426,10 @@ UIView* SubviewWithAccessibilityIdentifier(NSString* accessibility_id,
return grey_accessibilityID(kImportDataKeepSeparateCellId); return grey_accessibilityID(kImportDataKeepSeparateCellId);
} }
+ (id<GREYMatcher>)settingsImportDataContinueButton {
return grey_accessibilityID(kImportDataContinueButtonId);
}
+ (id<GREYMatcher>)settingsSyncManageSyncedDataButton { + (id<GREYMatcher>)settingsSyncManageSyncedDataButton {
return grey_accessibilityID(kSettingsSyncId); return grey_accessibilityID(kSettingsSyncId);
} }
......
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