Commit b4da5cc8 authored by Eric Aleshire's avatar Eric Aleshire Committed by Commit Bot

Creates AppInterface for SignInEarlGreyUtils, preparing it for EG2.

This follows the model of ChromeEarlGrey by:
* Creating an AppInterface class that handles all the app interaction,
and calling the AppInterface from the original SignInEarlGreyUtils class,
which will live test-side in EG2.

* Inheriting from BaseEGTestHelperImpl and asserting failures inside the
helpers, always returning nil instead of returning NSError* on failure.
In a follow-up CL, these methods will be converted to void and the
callsites modified to remove the NSError* check.

This CL does NOT create EG2 app and test support targets for auth, but
does confirm that the AppInterface works for EG1.

Change-Id: I083ea7397b0ad787611d91ab5f6901971bca2486
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1656058
Commit-Queue: ericale <ericale@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#670257}
parent 1cbf3b53
......@@ -146,6 +146,7 @@ source_set("unit_tests") {
}
source_set("eg_test_support") {
defines = [ "CHROME_EARL_GREY_1" ]
configs += [ "//build/config/compiler:enable_arc" ]
testonly = true
sources = [
......@@ -153,6 +154,8 @@ source_set("eg_test_support") {
"signin_earl_grey_ui.mm",
"signin_earlgrey_utils.h",
"signin_earlgrey_utils.mm",
"signin_earlgrey_utils_app_interface.h",
"signin_earlgrey_utils_app_interface.mm",
]
deps = [
":authentication",
......@@ -171,6 +174,7 @@ source_set("eg_test_support") {
"//ios/chrome/test/earl_grey:test_support",
"//ios/public/provider/chrome/browser/signin",
"//ios/public/provider/chrome/browser/signin:test_support",
"//ios/testing/earl_grey:earl_grey_support",
"//ios/third_party/earl_grey:earl_grey+link",
"//services/identity/public/cpp",
]
......
......@@ -6,28 +6,34 @@
#define IOS_CHROME_BROWSER_UI_AUTHENTICATION_SIGNIN_EARLGREY_UTILS_H_
#import <Foundation/Foundation.h>
#include "base/compiler_specific.h"
#import "ios/testing/earl_grey/base_eg_test_helper_impl.h"
@class ChromeIdentity;
#define SigninEarlGreyUtils \
[SigninEarlGreyUtilsImpl invokedFromFile:@"" __FILE__ lineNumber:__LINE__]
// Methods used for the EarlGrey tests.
@interface SigninEarlGreyUtils : NSObject
// TODO(crbug.com/974833): Consider moving these into ChromeEarlGrey.
@interface SigninEarlGreyUtilsImpl : BaseEGTestHelperImpl
// Returns a fake identity.
+ (ChromeIdentity*)fakeIdentity1;
- (ChromeIdentity*)fakeIdentity1;
// Returns a second fake identity.
+ (ChromeIdentity*)fakeIdentity2;
- (ChromeIdentity*)fakeIdentity2;
// Returns a fake managed identity.
+ (ChromeIdentity*)fakeManagedIdentity;
- (ChromeIdentity*)fakeManagedIdentity;
// Checks that |identity| is actually signed in to the active profile.
+ (NSError*)checkSignedInWithIdentity:(ChromeIdentity*)identity
- (NSError*)checkSignedInWithIdentity:(ChromeIdentity*)identity
WARN_UNUSED_RESULT;
// Checks that no identity is signed in.
+ (NSError*)checkSignedOut WARN_UNUSED_RESULT;
- (NSError*)checkSignedOut WARN_UNUSED_RESULT;
@end
......
......@@ -6,82 +6,67 @@
#import <EarlGrey/EarlGrey.h>
#include "base/strings/sys_string_conversions.h"
#include "components/signin/core/browser/account_info.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/signin/identity_manager_factory.h"
#import "ios/chrome/test/app/chrome_test_util.h"
#import "ios/chrome/browser/ui/authentication/signin_earlgrey_utils_app_interface.h"
#import "ios/public/provider/chrome/browser/signin/fake_chrome_identity.h"
#import "ios/testing/nserror_util.h"
#include "services/identity/public/cpp/identity_manager.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@implementation SigninEarlGreyUtils
#if defined(CHROME_EARL_GREY_2)
GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(SigninEarlGreyUtilsAppInterface)
#endif // defined(CHROME_EARL_GREY_2)
+ (ChromeIdentity*)fakeIdentity1 {
@implementation SigninEarlGreyUtilsImpl
- (ChromeIdentity*)fakeIdentity1 {
return [FakeChromeIdentity identityWithEmail:@"foo1@gmail.com"
gaiaID:@"foo1ID"
name:@"Fake Foo 1"];
}
+ (ChromeIdentity*)fakeIdentity2 {
- (ChromeIdentity*)fakeIdentity2 {
return [FakeChromeIdentity identityWithEmail:@"foo2@gmail.com"
gaiaID:@"foo2ID"
name:@"Fake Foo 2"];
}
+ (ChromeIdentity*)fakeManagedIdentity {
- (ChromeIdentity*)fakeManagedIdentity {
return [FakeChromeIdentity identityWithEmail:@"foo@managed.com"
gaiaID:@"fooManagedID"
name:@"Fake Managed"];
}
+ (NSError*)checkSignedInWithIdentity:(ChromeIdentity*)identity {
if (identity == nil) {
return testing::NSErrorWithLocalizedDescription(
@"Need to give an identity");
}
- (NSError*)checkSignedInWithIdentity:(ChromeIdentity*)identity {
BOOL identityIsNonNil = identity != nil;
EG_TEST_HELPER_ASSERT_TRUE(identityIsNonNil, @"Need to give an identity");
// Required to avoid any problem since the following test is not dependant
// to UI, and the previous action has to be totally finished before going
// through the assert.
[[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
ios::ChromeBrowserState* browser_state =
chrome_test_util::GetOriginalBrowserState();
CoreAccountInfo info =
IdentityManagerFactory::GetForBrowserState(browser_state)
->GetPrimaryAccountInfo();
if (base::SysNSStringToUTF8(identity.gaiaID) != info.gaia) {
NSString* errorStr =
[NSString stringWithFormat:
@"Unexpected Gaia ID of the signed in user [expected = "
@"\"%@\", actual = \"%s\"]",
identity.gaiaID, info.gaia.c_str()];
return testing::NSErrorWithLocalizedDescription(errorStr);
}
NSString* primaryAccountGaiaID =
[SignInEarlGreyUtilsAppInterface primaryAccountGaiaID];
NSString* errorStr = [NSString
stringWithFormat:@"Unexpected Gaia ID of the signed in user [expected = "
@"\"%@\", actual = \"%@\"]",
identity.gaiaID, primaryAccountGaiaID];
EG_TEST_HELPER_ASSERT_TRUE(
[identity.gaiaID isEqualToString:primaryAccountGaiaID], errorStr);
return nil;
}
+ (NSError*)checkSignedOut {
- (NSError*)checkSignedOut {
// Required to avoid any problem since the following test is not dependant to
// UI, and the previous action has to be totally finished before going through
// the assert.
[[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
ios::ChromeBrowserState* browser_state =
chrome_test_util::GetOriginalBrowserState();
if (IdentityManagerFactory::GetForBrowserState(browser_state)
->HasPrimaryAccount()) {
return testing::NSErrorWithLocalizedDescription(
@"Unexpected signed in user");
}
EG_TEST_HELPER_ASSERT_TRUE([SignInEarlGreyUtilsAppInterface isSignedOut],
@"Unexpected signed in user");
return nil;
}
......
// 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_AUTHENTICATION_SIGNIN_EARLGREY_UTILS_APP_INTERFACE_H_
#define IOS_CHROME_BROWSER_UI_AUTHENTICATION_SIGNIN_EARLGREY_UTILS_APP_INTERFACE_H_
#import <Foundation/Foundation.h>
@class ChromeIdentity;
// SignInEarlGreyAppInterface contains the app-side implementation for helpers
// that primarily work via direct model access. These helpers are compiled into
// the app binary and can be called from either app or test code.
@interface SignInEarlGreyUtilsAppInterface : NSObject
// Returns the gaia ID of the signed-in account.
+ (NSString*)primaryAccountGaiaID;
// Checks that no identity is signed in.
+ (BOOL)isSignedOut;
@end
#endif // IOS_CHROME_BROWSER_UI_AUTHENTICATION_SIGNIN_EARLGREY_UTILS_APP_INTERFACE_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/authentication/signin_earlgrey_utils_app_interface.h"
#include "base/strings/sys_string_conversions.h"
#include "components/signin/core/browser/account_info.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/signin/identity_manager_factory.h"
#import "ios/chrome/test/app/chrome_test_util.h"
#import "ios/public/provider/chrome/browser/signin/fake_chrome_identity.h"
#include "services/identity/public/cpp/identity_manager.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@implementation SignInEarlGreyUtilsAppInterface
+ (NSString*)primaryAccountGaiaID {
ios::ChromeBrowserState* browser_state =
chrome_test_util::GetOriginalBrowserState();
CoreAccountInfo info =
IdentityManagerFactory::GetForBrowserState(browser_state)
->GetPrimaryAccountInfo();
return base::SysUTF8ToNSString(info.gaia);
}
+ (BOOL)isSignedOut {
ios::ChromeBrowserState* browser_state =
chrome_test_util::GetOriginalBrowserState();
return !IdentityManagerFactory::GetForBrowserState(browser_state)
->HasPrimaryAccount();
}
@end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment