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") {
"//ios/chrome/test/earl_grey:eg_test_support+eg2",
"//ios/public/provider/chrome/browser/signin",
"//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/third_party/earl_grey2:test_lib",
"//ui/base",
......
......@@ -82,8 +82,7 @@ void ChooseImportOrKeepDataSepareteDialog(id<GREYMatcher> choiceButtonMatcher) {
// Sign in to |fakeIdentity1|.
[SigninEarlGreyUI signinWithFakeIdentity:fakeIdentity1];
[SigninEarlGreyUI
signOutWithSignOutConfirmation:SignOutConfirmationNonManagedUser];
[SigninEarlGreyUI signOut];
// Sign in with |fakeIdentity2|.
[ChromeEarlGreyUI openSettingsMenu];
......@@ -128,8 +127,6 @@ void ChooseImportOrKeepDataSepareteDialog(id<GREYMatcher> choiceButtonMatcher) {
- (void)testSignInOneUser {
// Set up a fake identity.
FakeChromeIdentity* fakeIdentity = [SigninEarlGrey fakeIdentity1];
[SigninEarlGrey addFakeIdentity:fakeIdentity];
[SigninEarlGreyUI signinWithFakeIdentity:fakeIdentity];
// Check |fakeIdentity| is signed-in.
......@@ -151,30 +148,21 @@ void ChooseImportOrKeepDataSepareteDialog(id<GREYMatcher> choiceButtonMatcher) {
// Tests that signing out from the Settings works correctly.
- (void)testSignInDisconnectFromChrome {
FakeChromeIdentity* fakeIdentity = [SigninEarlGrey fakeIdentity1];
[SigninEarlGrey addFakeIdentity:fakeIdentity];
// Sign in to |fakeIdentity|.
[SigninEarlGreyUI signinWithFakeIdentity:fakeIdentity];
// Sign out.
[SigninEarlGreyUI
signOutWithSignOutConfirmation:SignOutConfirmationNonManagedUser];
[SigninEarlGreyUI signOut];
}
// Tests that signing out of a managed account from the Settings works
// correctly.
- (void)testSignInDisconnectFromChromeManaged {
FakeChromeIdentity* fakeIdentity = [SigninEarlGrey fakeManagedIdentity];
// Sign-in with a managed account.
[SigninEarlGreyUI signinWithFakeIdentity:fakeIdentity isManagedAccount:YES];
FakeChromeIdentity* fakeIdentity = [SigninEarlGrey fakeManagedIdentity];
[SigninEarlGreyUI signinWithFakeIdentity:fakeIdentity];
// Sign out.
[SigninEarlGreyUI
signOutWithSignOutConfirmation:SignOutConfirmationManagedUser];
// Check that there is no signed in user.
[SigninEarlGrey verifySignedOut];
[SigninEarlGreyUI signOutAndClearDataFromDevice];
}
// Tests that signing in, tapping the Settings link on the confirmation screen
......@@ -253,8 +241,7 @@ void ChooseImportOrKeepDataSepareteDialog(id<GREYMatcher> choiceButtonMatcher) {
[SigninEarlGreyUI signinWithFakeIdentity:fakeIdentity2];
// Sign out.
[SigninEarlGreyUI
signOutWithSignOutConfirmation:SignOutConfirmationNonManagedUser];
[SigninEarlGreyUI signOut];
// Sign in with |fakeIdentity1|.
[ChromeEarlGreyUI openSettingsMenu];
[[EarlGrey selectElementWithMatcher:SecondarySignInButton()]
......
......@@ -32,8 +32,13 @@
+ (void)forgetFakeIdentity:(FakeChromeIdentity*)fakeIdentity;
// Returns the gaia ID of the signed-in account.
// If there is no signed-in account returns an empty string.
+ (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.
+ (BOOL)isSignedOut;
......
......@@ -41,7 +41,7 @@
}
+ (FakeChromeIdentity*)fakeManagedIdentity {
return [FakeChromeIdentity identityWithEmail:@"foo@managed.com"
return [FakeChromeIdentity identityWithEmail:@"foo@google.com"
gaiaID:@"fooManagedID"
name:@"Fake Managed"];
}
......@@ -57,20 +57,30 @@
}
+ (NSString*)primaryAccountGaiaID {
ChromeBrowserState* browser_state =
ChromeBrowserState* browserState =
chrome_test_util::GetOriginalBrowserState();
CoreAccountInfo info =
IdentityManagerFactory::GetForBrowserState(browser_state)
IdentityManagerFactory::GetForBrowserState(browserState)
->GetPrimaryAccountInfo();
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 {
ChromeBrowserState* browser_state =
ChromeBrowserState* browserState =
chrome_test_util::GetOriginalBrowserState();
return !IdentityManagerFactory::GetForBrowserState(browser_state)
return !IdentityManagerFactory::GetForBrowserState(browserState)
->HasPrimaryAccount();
}
......@@ -81,18 +91,18 @@
}
+ (BOOL)isAuthenticated {
ChromeBrowserState* browser_state =
ChromeBrowserState* browserState =
chrome_test_util::GetOriginalBrowserState();
AuthenticationService* authentication_service =
AuthenticationServiceFactory::GetForBrowserState(browser_state);
AuthenticationServiceFactory::GetForBrowserState(browserState);
return authentication_service->IsAuthenticated();
}
+ (void)signOut {
ChromeBrowserState* browser_state =
ChromeBrowserState* browserState =
chrome_test_util::GetOriginalBrowserState();
AuthenticationService* authentication_service =
AuthenticationServiceFactory::GetForBrowserState(browser_state);
AuthenticationServiceFactory::GetForBrowserState(browserState);
authentication_service->SignOut(signin_metrics::SIGNOUT_TEST,
/*force_clear_browsing_data=*/false, nil);
}
......
......@@ -17,18 +17,25 @@ typedef NS_ENUM(NSInteger, SignOutConfirmation) {
SignOutConfirmationNonManagedUserWithClearedData,
};
// Methods used for the EarlGrey tests, related to UI.
// Test methods that perform sign in actions on Chrome UI.
@interface SigninEarlGreyUI : NSObject
// Calls [SigninEarlGreyUI signinWithFakeIdentity:fakeIdentity
// isManagedAccount:NO].
// Signs the account for |fakeIdentity| into Chrome through the Settings screen.
// 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;
// Adds the identity (if not already added), and perform a sign-in. if
// |isManagedAccount| is true, |fakeIdentity| needs to be a managed account and
// the managed dialog is expected while signing in.
+ (void)signinWithFakeIdentity:(FakeChromeIdentity*)fakeIdentity
isManagedAccount:(BOOL)isManagedAccount;
// Signs the primary account out of Chrome through the accounts list screen.
// Taps the "Sign Out" button to begin flow. Note that managed accounts cannot
// go through this 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)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
// opened before calling this method.
......@@ -38,9 +45,6 @@ typedef NS_ENUM(NSInteger, SignOutConfirmation) {
// is confirmed, but it doesn't validated the user consent page.
+ (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
// visible on short devices (e.g. iPhone 5s).
+ (void)confirmSigninConfirmationDialog;
......
......@@ -17,6 +17,7 @@
#import "ios/chrome/test/earl_grey/chrome_matchers_app_interface.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_service.h"
#import "ios/testing/earl_grey/earl_grey_test.h"
#include "ui/base/l10n/l10n_util_mac.h"
......@@ -34,18 +35,13 @@ using chrome_test_util::SignOutAccountsButton;
@implementation SigninEarlGreyUI
+ (void)signinWithFakeIdentity:(FakeChromeIdentity*)fakeIdentity {
[self signinWithFakeIdentity:fakeIdentity isManagedAccount:NO];
}
+ (void)signinWithFakeIdentity:(FakeChromeIdentity*)fakeIdentity
isManagedAccount:(BOOL)isManagedAccount {
[SigninEarlGrey addFakeIdentity:fakeIdentity];
[ChromeEarlGreyUI openSettingsMenu];
[ChromeEarlGreyUI
tapSettingsMenuButton:chrome_test_util::SecondarySignInButton()];
[self selectIdentityWithEmail:fakeIdentity.userEmail];
[self confirmSigninConfirmationDialog];
if (isManagedAccount) {
if ([fakeIdentity.userEmail hasSuffix:ios::kManagedIdentityEmailSuffix]) {
[self confirmSigninWithManagedAccount];
}
[[EarlGrey selectElementWithMatcher:SettingsDoneButton()]
......@@ -53,6 +49,22 @@ using chrome_test_util::SignOutAccountsButton;
[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 {
// Assumes that the identity chooser is visible.
[[EarlGrey
......@@ -213,19 +225,6 @@ using chrome_test_util::SignOutAccountsButton;
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:
......@@ -246,4 +245,24 @@ using chrome_test_util::SignOutAccountsButton;
[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
......@@ -197,8 +197,7 @@ id<GREYMatcher> NoBookmarksLabel() {
[BookmarkEarlGrey setupStandardBookmarks];
// Sign out.
[SigninEarlGreyUI
signOutWithSignOutConfirmation:SignOutConfirmationNonManagedUser];
[SigninEarlGreyUI signOut];
// Open the Bookmarks screen on the Tools menu.
[BookmarkEarlGreyUI openBookmarks];
......@@ -223,8 +222,7 @@ id<GREYMatcher> NoBookmarksLabel() {
[BookmarkEarlGrey setupStandardBookmarks];
// Sign out.
[SigninEarlGreyUI signOutWithSignOutConfirmation:
SignOutConfirmationNonManagedUserWithClearedData];
[SigninEarlGreyUI signOutAndClearDataFromDevice];
// Open the Bookmarks screen on the Tools menu.
[BookmarkEarlGreyUI openBookmarks];
......@@ -237,10 +235,9 @@ id<GREYMatcher> NoBookmarksLabel() {
// Tests that signing out from a managed user account clears the user's data.
- (void)testsSignOutFromManagedAccount {
FakeChromeIdentity* fakeIdentity = [SigninEarlGrey fakeManagedIdentity];
// Sign In |fakeIdentity|.
[SigninEarlGreyUI signinWithFakeIdentity:fakeIdentity isManagedAccount:YES];
// Sign In |fakeManagedIdentity|.
[SigninEarlGreyUI
signinWithFakeIdentity:[SigninEarlGrey fakeManagedIdentity]];
// Add a bookmark after sync is initialized.
[ChromeEarlGrey waitForSyncInitialized:YES syncTimeout:kSyncOperationTimeout];
......@@ -248,8 +245,7 @@ id<GREYMatcher> NoBookmarksLabel() {
[BookmarkEarlGrey setupStandardBookmarks];
// Sign out.
[SigninEarlGreyUI
signOutWithSignOutConfirmation:SignOutConfirmationManagedUser];
[SigninEarlGreyUI signOutAndClearDataFromDevice];
// Open the Bookmarks screen on the Tools menu.
[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