Commit cced5f68 authored by Nohemi Fernandez's avatar Nohemi Fernandez Committed by Commit Bot

[iOS] Consolidate managed and non-managed identity test APIs.

In testing APIs we can distinguish between managed and non-managed
identities based on their email and do not need to ask clients for this
information.

Bug: 1103274
Change-Id: I7b2980d049d0fe65ae0247bf3d9485b14f89877a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2353453
Commit-Queue: Nohemi Fernandez <fernandex@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798593}
parent c898845e
...@@ -196,6 +196,7 @@ source_set("eg_test_support+eg2") { ...@@ -196,6 +196,7 @@ source_set("eg_test_support+eg2") {
"//ios/chrome/test/earl_grey:eg_test_support+eg2", "//ios/chrome/test/earl_grey:eg_test_support+eg2",
"//ios/public/provider/chrome/browser/signin", "//ios/public/provider/chrome/browser/signin",
"//ios/public/provider/chrome/browser/signin:fake_chrome_identity", "//ios/public/provider/chrome/browser/signin:fake_chrome_identity",
"//ios/public/provider/chrome/browser/signin:test_support",
"//ios/testing/earl_grey:eg_test_support+eg2", "//ios/testing/earl_grey:eg_test_support+eg2",
"//ios/third_party/earl_grey2:test_lib", "//ios/third_party/earl_grey2:test_lib",
"//ui/base", "//ui/base",
......
...@@ -82,8 +82,7 @@ void ChooseImportOrKeepDataSepareteDialog(id<GREYMatcher> choiceButtonMatcher) { ...@@ -82,8 +82,7 @@ void ChooseImportOrKeepDataSepareteDialog(id<GREYMatcher> choiceButtonMatcher) {
// Sign in to |fakeIdentity1|. // Sign in to |fakeIdentity1|.
[SigninEarlGreyUI signinWithFakeIdentity:fakeIdentity1]; [SigninEarlGreyUI signinWithFakeIdentity:fakeIdentity1];
[SigninEarlGreyUI [SigninEarlGreyUI signOut];
signOutWithSignOutConfirmation:SignOutConfirmationNonManagedUser];
// Sign in with |fakeIdentity2|. // Sign in with |fakeIdentity2|.
[ChromeEarlGreyUI openSettingsMenu]; [ChromeEarlGreyUI openSettingsMenu];
...@@ -128,8 +127,6 @@ void ChooseImportOrKeepDataSepareteDialog(id<GREYMatcher> choiceButtonMatcher) { ...@@ -128,8 +127,6 @@ void ChooseImportOrKeepDataSepareteDialog(id<GREYMatcher> choiceButtonMatcher) {
- (void)testSignInOneUser { - (void)testSignInOneUser {
// Set up a fake identity. // Set up a fake identity.
FakeChromeIdentity* fakeIdentity = [SigninEarlGrey fakeIdentity1]; FakeChromeIdentity* fakeIdentity = [SigninEarlGrey fakeIdentity1];
[SigninEarlGrey addFakeIdentity:fakeIdentity];
[SigninEarlGreyUI signinWithFakeIdentity:fakeIdentity]; [SigninEarlGreyUI signinWithFakeIdentity:fakeIdentity];
// Check |fakeIdentity| is signed-in. // Check |fakeIdentity| is signed-in.
...@@ -151,30 +148,21 @@ void ChooseImportOrKeepDataSepareteDialog(id<GREYMatcher> choiceButtonMatcher) { ...@@ -151,30 +148,21 @@ void ChooseImportOrKeepDataSepareteDialog(id<GREYMatcher> choiceButtonMatcher) {
// Tests that signing out from the Settings works correctly. // Tests that signing out from the Settings works correctly.
- (void)testSignInDisconnectFromChrome { - (void)testSignInDisconnectFromChrome {
FakeChromeIdentity* fakeIdentity = [SigninEarlGrey fakeIdentity1]; FakeChromeIdentity* fakeIdentity = [SigninEarlGrey fakeIdentity1];
[SigninEarlGrey addFakeIdentity:fakeIdentity];
// Sign in to |fakeIdentity|.
[SigninEarlGreyUI signinWithFakeIdentity:fakeIdentity]; [SigninEarlGreyUI signinWithFakeIdentity:fakeIdentity];
// Sign out. // Sign out.
[SigninEarlGreyUI [SigninEarlGreyUI signOut];
signOutWithSignOutConfirmation:SignOutConfirmationNonManagedUser];
} }
// Tests that signing out of a managed account from the Settings works // Tests that signing out of a managed account from the Settings works
// correctly. // correctly.
- (void)testSignInDisconnectFromChromeManaged { - (void)testSignInDisconnectFromChromeManaged {
FakeChromeIdentity* fakeIdentity = [SigninEarlGrey fakeManagedIdentity];
// Sign-in with a managed account. // Sign-in with a managed account.
[SigninEarlGreyUI signinWithFakeIdentity:fakeIdentity isManagedAccount:YES]; FakeChromeIdentity* fakeIdentity = [SigninEarlGrey fakeManagedIdentity];
[SigninEarlGreyUI signinWithFakeIdentity:fakeIdentity];
// Sign out. // Sign out.
[SigninEarlGreyUI [SigninEarlGreyUI signOutAndClearDataFromDevice];
signOutWithSignOutConfirmation:SignOutConfirmationManagedUser];
// Check that there is no signed in user.
[SigninEarlGrey verifySignedOut];
} }
// Tests that signing in, tapping the Settings link on the confirmation screen // Tests that signing in, tapping the Settings link on the confirmation screen
...@@ -253,8 +241,7 @@ void ChooseImportOrKeepDataSepareteDialog(id<GREYMatcher> choiceButtonMatcher) { ...@@ -253,8 +241,7 @@ void ChooseImportOrKeepDataSepareteDialog(id<GREYMatcher> choiceButtonMatcher) {
[SigninEarlGreyUI signinWithFakeIdentity:fakeIdentity2]; [SigninEarlGreyUI signinWithFakeIdentity:fakeIdentity2];
// Sign out. // Sign out.
[SigninEarlGreyUI [SigninEarlGreyUI signOut];
signOutWithSignOutConfirmation:SignOutConfirmationNonManagedUser];
// Sign in with |fakeIdentity1|. // Sign in with |fakeIdentity1|.
[ChromeEarlGreyUI openSettingsMenu]; [ChromeEarlGreyUI openSettingsMenu];
[[EarlGrey selectElementWithMatcher:SecondarySignInButton()] [[EarlGrey selectElementWithMatcher:SecondarySignInButton()]
......
...@@ -32,8 +32,13 @@ ...@@ -32,8 +32,13 @@
+ (void)forgetFakeIdentity:(FakeChromeIdentity*)fakeIdentity; + (void)forgetFakeIdentity:(FakeChromeIdentity*)fakeIdentity;
// Returns the gaia ID of the signed-in account. // Returns the gaia ID of the signed-in account.
// If there is no signed-in account returns an empty string.
+ (NSString*)primaryAccountGaiaID; + (NSString*)primaryAccountGaiaID;
// Returns the email of the signed-in account.
// If there is no signed-in account returns an empty string.
+ (NSString*)primaryAccountEmail;
// Checks that no identity is signed in. // Checks that no identity is signed in.
+ (BOOL)isSignedOut; + (BOOL)isSignedOut;
......
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
} }
+ (FakeChromeIdentity*)fakeManagedIdentity { + (FakeChromeIdentity*)fakeManagedIdentity {
return [FakeChromeIdentity identityWithEmail:@"foo@managed.com" return [FakeChromeIdentity identityWithEmail:@"foo@google.com"
gaiaID:@"fooManagedID" gaiaID:@"fooManagedID"
name:@"Fake Managed"]; name:@"Fake Managed"];
} }
...@@ -57,20 +57,30 @@ ...@@ -57,20 +57,30 @@
} }
+ (NSString*)primaryAccountGaiaID { + (NSString*)primaryAccountGaiaID {
ChromeBrowserState* browser_state = ChromeBrowserState* browserState =
chrome_test_util::GetOriginalBrowserState(); chrome_test_util::GetOriginalBrowserState();
CoreAccountInfo info = CoreAccountInfo info =
IdentityManagerFactory::GetForBrowserState(browser_state) IdentityManagerFactory::GetForBrowserState(browserState)
->GetPrimaryAccountInfo(); ->GetPrimaryAccountInfo();
return base::SysUTF8ToNSString(info.gaia); return base::SysUTF8ToNSString(info.gaia);
} }
+ (NSString*)primaryAccountEmail {
ChromeBrowserState* browserState =
chrome_test_util::GetOriginalBrowserState();
CoreAccountInfo info =
IdentityManagerFactory::GetForBrowserState(browserState)
->GetPrimaryAccountInfo();
return base::SysUTF8ToNSString(info.email);
}
+ (BOOL)isSignedOut { + (BOOL)isSignedOut {
ChromeBrowserState* browser_state = ChromeBrowserState* browserState =
chrome_test_util::GetOriginalBrowserState(); chrome_test_util::GetOriginalBrowserState();
return !IdentityManagerFactory::GetForBrowserState(browser_state) return !IdentityManagerFactory::GetForBrowserState(browserState)
->HasPrimaryAccount(); ->HasPrimaryAccount();
} }
...@@ -81,18 +91,18 @@ ...@@ -81,18 +91,18 @@
} }
+ (BOOL)isAuthenticated { + (BOOL)isAuthenticated {
ChromeBrowserState* browser_state = ChromeBrowserState* browserState =
chrome_test_util::GetOriginalBrowserState(); chrome_test_util::GetOriginalBrowserState();
AuthenticationService* authentication_service = AuthenticationService* authentication_service =
AuthenticationServiceFactory::GetForBrowserState(browser_state); AuthenticationServiceFactory::GetForBrowserState(browserState);
return authentication_service->IsAuthenticated(); return authentication_service->IsAuthenticated();
} }
+ (void)signOut { + (void)signOut {
ChromeBrowserState* browser_state = ChromeBrowserState* browserState =
chrome_test_util::GetOriginalBrowserState(); chrome_test_util::GetOriginalBrowserState();
AuthenticationService* authentication_service = AuthenticationService* authentication_service =
AuthenticationServiceFactory::GetForBrowserState(browser_state); AuthenticationServiceFactory::GetForBrowserState(browserState);
authentication_service->SignOut(signin_metrics::SIGNOUT_TEST, authentication_service->SignOut(signin_metrics::SIGNOUT_TEST,
/*force_clear_browsing_data=*/false, nil); /*force_clear_browsing_data=*/false, nil);
} }
......
...@@ -17,18 +17,25 @@ typedef NS_ENUM(NSInteger, SignOutConfirmation) { ...@@ -17,18 +17,25 @@ typedef NS_ENUM(NSInteger, SignOutConfirmation) {
SignOutConfirmationNonManagedUserWithClearedData, SignOutConfirmationNonManagedUserWithClearedData,
}; };
// Methods used for the EarlGrey tests, related to UI. // Test methods that perform sign in actions on Chrome UI.
@interface SigninEarlGreyUI : NSObject @interface SigninEarlGreyUI : NSObject
// Calls [SigninEarlGreyUI signinWithFakeIdentity:fakeIdentity // Signs the account for |fakeIdentity| into Chrome through the Settings screen.
// isManagedAccount:NO]. // There will be a GREYAssert if the tools menus is open when calling this
// method or if the account is not successfully signed in.
+ (void)signinWithFakeIdentity:(FakeChromeIdentity*)fakeIdentity; + (void)signinWithFakeIdentity:(FakeChromeIdentity*)fakeIdentity;
// Adds the identity (if not already added), and perform a sign-in. if // Signs the primary account out of Chrome through the accounts list screen.
// |isManagedAccount| is true, |fakeIdentity| needs to be a managed account and // Taps the "Sign Out" button to begin flow. Note that managed accounts cannot
// the managed dialog is expected while signing in. // go through this flow. There will be a GREYAssert if the tools menus is open
+ (void)signinWithFakeIdentity:(FakeChromeIdentity*)fakeIdentity // when calling this method or if the account is not successfully signed out.
isManagedAccount:(BOOL)isManagedAccount; + (void)signOut;
// Signs the primary account out of Chrome through the accounts list screen.
// Taps the "Sign out and clear data from this device" button to begin flow.
// There will be a GREYAssert if the tools menus is open when calling this
// method or if the account is not successfully signed out.
+ (void)signOutAndClearDataFromDevice;
// Taps on the settings link in the sign-in view. The sign-in view has to be // Taps on the settings link in the sign-in view. The sign-in view has to be
// opened before calling this method. // opened before calling this method.
...@@ -38,9 +45,6 @@ typedef NS_ENUM(NSInteger, SignOutConfirmation) { ...@@ -38,9 +45,6 @@ typedef NS_ENUM(NSInteger, SignOutConfirmation) {
// is confirmed, but it doesn't validated the user consent page. // is confirmed, but it doesn't validated the user consent page.
+ (void)selectIdentityWithEmail:(NSString*)userEmail; + (void)selectIdentityWithEmail:(NSString*)userEmail;
// Confirms the managed account dialog with signing in.
+ (void)confirmSigninWithManagedAccount;
// Confirms the sign in confirmation page, scrolls first to make the OK button // Confirms the sign in confirmation page, scrolls first to make the OK button
// visible on short devices (e.g. iPhone 5s). // visible on short devices (e.g. iPhone 5s).
+ (void)confirmSigninConfirmationDialog; + (void)confirmSigninConfirmationDialog;
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#import "ios/chrome/test/earl_grey/chrome_matchers_app_interface.h" #import "ios/chrome/test/earl_grey/chrome_matchers_app_interface.h"
#import "ios/chrome/test/scoped_eg_synchronization_disabler.h" #import "ios/chrome/test/scoped_eg_synchronization_disabler.h"
#import "ios/public/provider/chrome/browser/signin/fake_chrome_identity.h" #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity.h"
#import "ios/public/provider/chrome/browser/signin/fake_chrome_identity_service.h"
#import "ios/testing/earl_grey/earl_grey_test.h" #import "ios/testing/earl_grey/earl_grey_test.h"
#include "ui/base/l10n/l10n_util_mac.h" #include "ui/base/l10n/l10n_util_mac.h"
...@@ -34,18 +35,13 @@ using chrome_test_util::SignOutAccountsButton; ...@@ -34,18 +35,13 @@ using chrome_test_util::SignOutAccountsButton;
@implementation SigninEarlGreyUI @implementation SigninEarlGreyUI
+ (void)signinWithFakeIdentity:(FakeChromeIdentity*)fakeIdentity { + (void)signinWithFakeIdentity:(FakeChromeIdentity*)fakeIdentity {
[self signinWithFakeIdentity:fakeIdentity isManagedAccount:NO];
}
+ (void)signinWithFakeIdentity:(FakeChromeIdentity*)fakeIdentity
isManagedAccount:(BOOL)isManagedAccount {
[SigninEarlGrey addFakeIdentity:fakeIdentity]; [SigninEarlGrey addFakeIdentity:fakeIdentity];
[ChromeEarlGreyUI openSettingsMenu]; [ChromeEarlGreyUI openSettingsMenu];
[ChromeEarlGreyUI [ChromeEarlGreyUI
tapSettingsMenuButton:chrome_test_util::SecondarySignInButton()]; tapSettingsMenuButton:chrome_test_util::SecondarySignInButton()];
[self selectIdentityWithEmail:fakeIdentity.userEmail]; [self selectIdentityWithEmail:fakeIdentity.userEmail];
[self confirmSigninConfirmationDialog]; [self confirmSigninConfirmationDialog];
if (isManagedAccount) { if ([fakeIdentity.userEmail hasSuffix:ios::kManagedIdentityEmailSuffix]) {
[self confirmSigninWithManagedAccount]; [self confirmSigninWithManagedAccount];
} }
[[EarlGrey selectElementWithMatcher:SettingsDoneButton()] [[EarlGrey selectElementWithMatcher:SettingsDoneButton()]
...@@ -53,6 +49,22 @@ using chrome_test_util::SignOutAccountsButton; ...@@ -53,6 +49,22 @@ using chrome_test_util::SignOutAccountsButton;
[SigninEarlGrey verifySignedInWithFakeIdentity:fakeIdentity]; [SigninEarlGrey verifySignedInWithFakeIdentity:fakeIdentity];
} }
+ (void)signOut {
NSString* primaryAccountEmail =
[SigninEarlGreyAppInterface primaryAccountEmail];
GREYAssert(![primaryAccountEmail hasSuffix:ios::kManagedIdentityEmailSuffix],
@"Managed account must clear data on signout");
[self signOutWithButton:SignOutAccountsButton()
confirmationLabelID:IDS_IOS_DISCONNECT_DIALOG_CONTINUE_BUTTON_MOBILE];
}
+ (void)signOutAndClearDataFromDevice {
[self signOutWithButton:
grey_accessibilityID(
kSettingsAccountsTableViewSignoutAndClearDataCellId)
confirmationLabelID:IDS_IOS_DISCONNECT_DIALOG_CONTINUE_AND_CLEAR_MOBILE];
}
+ (void)selectIdentityWithEmail:(NSString*)userEmail { + (void)selectIdentityWithEmail:(NSString*)userEmail {
// Assumes that the identity chooser is visible. // Assumes that the identity chooser is visible.
[[EarlGrey [[EarlGrey
...@@ -213,19 +225,6 @@ using chrome_test_util::SignOutAccountsButton; ...@@ -213,19 +225,6 @@ using chrome_test_util::SignOutAccountsButton;
break; break;
} }
} }
[ChromeEarlGreyUI tapAccountsMenuButton:signOutButtonMatcher];
id<GREYMatcher> confirmationButtonMatcher = [ChromeMatchersAppInterface
buttonWithAccessibilityLabelID:confirmationLabelID];
[[EarlGrey
selectElementWithMatcher:grey_allOf(confirmationButtonMatcher,
grey_not(signOutButtonMatcher), nil)]
performAction:grey_tap()];
// Wait until the user is signed out.
[ChromeEarlGreyUI waitForAppToIdle];
[[EarlGrey selectElementWithMatcher:SettingsDoneButton()]
performAction:grey_tap()];
[SigninEarlGrey verifySignedOut];
} }
+ (void)tapRemoveAccountFromDeviceWithFakeIdentity: + (void)tapRemoveAccountFromDeviceWithFakeIdentity:
...@@ -246,4 +245,24 @@ using chrome_test_util::SignOutAccountsButton; ...@@ -246,4 +245,24 @@ using chrome_test_util::SignOutAccountsButton;
[ChromeEarlGreyUI waitForAppToIdle]; [ChromeEarlGreyUI waitForAppToIdle];
} }
#pragma mark - Private
+ (void)signOutWithButton:(id<GREYMatcher>)buttonMatcher
confirmationLabelID:(int)confirmationLabelID {
[ChromeEarlGreyUI openSettingsMenu];
[ChromeEarlGreyUI tapSettingsMenuButton:SettingsAccountButton()];
[ChromeEarlGreyUI tapAccountsMenuButton:buttonMatcher];
id<GREYMatcher> confirmationButtonMatcher = [ChromeMatchersAppInterface
buttonWithAccessibilityLabelID:confirmationLabelID];
[[EarlGrey selectElementWithMatcher:grey_allOf(confirmationButtonMatcher,
grey_not(buttonMatcher), nil)]
performAction:grey_tap()];
// Wait until the user is signed out.
[ChromeEarlGreyUI waitForAppToIdle];
[[EarlGrey selectElementWithMatcher:SettingsDoneButton()]
performAction:grey_tap()];
[SigninEarlGrey verifySignedOut];
}
@end @end
...@@ -197,8 +197,7 @@ id<GREYMatcher> NoBookmarksLabel() { ...@@ -197,8 +197,7 @@ id<GREYMatcher> NoBookmarksLabel() {
[BookmarkEarlGrey setupStandardBookmarks]; [BookmarkEarlGrey setupStandardBookmarks];
// Sign out. // Sign out.
[SigninEarlGreyUI [SigninEarlGreyUI signOut];
signOutWithSignOutConfirmation:SignOutConfirmationNonManagedUser];
// Open the Bookmarks screen on the Tools menu. // Open the Bookmarks screen on the Tools menu.
[BookmarkEarlGreyUI openBookmarks]; [BookmarkEarlGreyUI openBookmarks];
...@@ -223,8 +222,7 @@ id<GREYMatcher> NoBookmarksLabel() { ...@@ -223,8 +222,7 @@ id<GREYMatcher> NoBookmarksLabel() {
[BookmarkEarlGrey setupStandardBookmarks]; [BookmarkEarlGrey setupStandardBookmarks];
// Sign out. // Sign out.
[SigninEarlGreyUI signOutWithSignOutConfirmation: [SigninEarlGreyUI signOutAndClearDataFromDevice];
SignOutConfirmationNonManagedUserWithClearedData];
// Open the Bookmarks screen on the Tools menu. // Open the Bookmarks screen on the Tools menu.
[BookmarkEarlGreyUI openBookmarks]; [BookmarkEarlGreyUI openBookmarks];
...@@ -237,10 +235,9 @@ id<GREYMatcher> NoBookmarksLabel() { ...@@ -237,10 +235,9 @@ id<GREYMatcher> NoBookmarksLabel() {
// Tests that signing out from a managed user account clears the user's data. // Tests that signing out from a managed user account clears the user's data.
- (void)testsSignOutFromManagedAccount { - (void)testsSignOutFromManagedAccount {
FakeChromeIdentity* fakeIdentity = [SigninEarlGrey fakeManagedIdentity]; // Sign In |fakeManagedIdentity|.
[SigninEarlGreyUI
// Sign In |fakeIdentity|. signinWithFakeIdentity:[SigninEarlGrey fakeManagedIdentity]];
[SigninEarlGreyUI signinWithFakeIdentity:fakeIdentity isManagedAccount:YES];
// Add a bookmark after sync is initialized. // Add a bookmark after sync is initialized.
[ChromeEarlGrey waitForSyncInitialized:YES syncTimeout:kSyncOperationTimeout]; [ChromeEarlGrey waitForSyncInitialized:YES syncTimeout:kSyncOperationTimeout];
...@@ -248,8 +245,7 @@ id<GREYMatcher> NoBookmarksLabel() { ...@@ -248,8 +245,7 @@ id<GREYMatcher> NoBookmarksLabel() {
[BookmarkEarlGrey setupStandardBookmarks]; [BookmarkEarlGrey setupStandardBookmarks];
// Sign out. // Sign out.
[SigninEarlGreyUI [SigninEarlGreyUI signOutAndClearDataFromDevice];
signOutWithSignOutConfirmation:SignOutConfirmationManagedUser];
// Open the Bookmarks screen on the Tools menu. // Open the Bookmarks screen on the Tools menu.
[BookmarkEarlGreyUI openBookmarks]; [BookmarkEarlGreyUI openBookmarks];
......
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