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

[iOS] Add unit tests for the add account sign-in mediator.

This CL is part of a series of refactors to move the existing sign-in
architecture to the Coordinator-Mediator design paradigm.

Fore more information, see go/chrome-ios-signin-migration.

Bug: 971989
Change-Id: I3131d6f20fa230b1c55cf9f979d3ed34aa38ccc4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2047249
Commit-Queue: Nohemi Fernandez <fernandex@chromium.org>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Reviewed-by: default avatarJérôme Lebel <jlebel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#742155}
parent 7a6a4983
...@@ -27,3 +27,24 @@ source_set("add_account_signin") { ...@@ -27,3 +27,24 @@ source_set("add_account_signin") {
public_deps = public_deps =
[ "//ios/chrome/browser/ui/authentication/signin:signin_headers" ] [ "//ios/chrome/browser/ui/authentication/signin:signin_headers" ]
} }
source_set("unit_tests") {
configs += [ "//build/config/compiler:enable_arc" ]
testonly = true
sources = [ "add_account_signin_mediator_unittest.mm" ]
deps = [
":add_account_signin",
"//base/test:test_support",
"//components/prefs",
"//components/prefs:test_support",
"//ios/chrome/browser/browser_state:test_support",
"//ios/chrome/browser/signin",
"//ios/public/provider/chrome/browser/signin",
"//ios/public/provider/chrome/browser/signin:fake_chrome_identity",
"//ios/public/provider/chrome/browser/signin:test_support",
"//ios/web/public/test",
"//testing/gmock",
"//testing/gtest",
"//third_party/ocmock",
]
}
...@@ -148,26 +148,13 @@ using signin_metrics::PromoAction; ...@@ -148,26 +148,13 @@ using signin_metrics::PromoAction;
#pragma mark - AddAccountSigninMediatorDelegate #pragma mark - AddAccountSigninMediatorDelegate
- (void)handleUserConsentForIdentity:(ChromeIdentity*)identity { - (void)addAccountSigninMediatorFailedWith:(NSError*)error {
// The UserSigninViewController is presented on top of the currently displayed
// view controller.
self.userSigninCoordinator = [SigninCoordinator
userSigninCoordinatorWithBaseViewController:self.baseViewController
.presentedViewController
browser:self.browser
identity:identity
accessPoint:self.accessPoint
promoAction:self.promoAction];
[self.userSigninCoordinator start];
}
- (void)showAlertWithError:(NSError*)error identity:(ChromeIdentity*)identity {
DCHECK(error); DCHECK(error);
__weak AddAccountSigninCoordinator* weakSelf = self; __weak AddAccountSigninCoordinator* weakSelf = self;
ProceduralBlock dismissAction = ^{ ProceduralBlock dismissAction = ^{
[weakSelf runCompletionCallbackWithSigninResult: [weakSelf addAccountSigninMediatorFinishedWith:
SigninCoordinatorResultCanceledByUser SigninCoordinatorResultCanceledByUser
identity:identity]; identity:nil];
}; };
self.alertCoordinator = self.alertCoordinator =
...@@ -175,9 +162,20 @@ using signin_metrics::PromoAction; ...@@ -175,9 +162,20 @@ using signin_metrics::PromoAction;
[self.alertCoordinator start]; [self.alertCoordinator start];
} }
- (void)runCompletionCallbackWithSigninResult: - (void)addAccountSigninMediatorFinishedWith:
(SigninCoordinatorResult)signinResult (SigninCoordinatorResult)signinResult
identity:(ChromeIdentity*)identity { identity:(ChromeIdentity*)identity {
switch (self.signinIntent) {
case SigninIntentReauth: {
// Show the user consent screen to finish the sign-in operation.
[self handleUserConsentForIdentity:identity];
return;
}
case SigninIntentAddAccount: {
break;
}
}
// Cleaning up and calling the |signinCompletion| should be done last. // Cleaning up and calling the |signinCompletion| should be done last.
self.identityInteractionManager = nil; self.identityInteractionManager = nil;
DCHECK(!self.alertCoordinator); DCHECK(!self.alertCoordinator);
...@@ -193,4 +191,19 @@ using signin_metrics::PromoAction; ...@@ -193,4 +191,19 @@ using signin_metrics::PromoAction;
} }
} }
#pragma mark - Private
- (void)handleUserConsentForIdentity:(ChromeIdentity*)identity {
// The UserSigninViewController is presented on top of the currently displayed
// view controller.
self.userSigninCoordinator = [SigninCoordinator
userSigninCoordinatorWithBaseViewController:self.baseViewController
.presentedViewController
browser:self.browser
identity:identity
accessPoint:self.accessPoint
promoAction:self.promoAction];
[self.userSigninCoordinator start];
}
@end @end
...@@ -20,21 +20,16 @@ class IdentityManager; ...@@ -20,21 +20,16 @@ class IdentityManager;
// flows. // flows.
@protocol AddAccountSigninMediatorDelegate @protocol AddAccountSigninMediatorDelegate
// Handles the flow for obtaining user consent for the selected Chrome identity. // Shows alert modal dialog and interrupts sign-in operation.
// |identity| is the identity of the consenting account.
- (void)handleUserConsentForIdentity:(ChromeIdentity*)identity;
// Shows alert modal dialog.
// |error| is the error to be displayed. // |error| is the error to be displayed.
// |identity| is the identity of the added account. - (void)addAccountSigninMediatorFailedWith:(NSError*)error;
- (void)showAlertWithError:(NSError*)error identity:(ChromeIdentity*)identity;
// Runs the sign-in completion callback. // Completes the sign-in operation.
// |signinResult| is the state of sign-in at add account flow completion. // |signinResult| is the state of sign-in at add account flow completion.
// |identity| is the identity of the added account. // |identity| is the identity of the added account.
- (void)runCompletionCallbackWithSigninResult: - (void)addAccountSigninMediatorFinishedWith:
(SigninCoordinatorResult)signinResult (SigninCoordinatorResult)signinResult
identity:(ChromeIdentity*)identity; identity:(ChromeIdentity*)identity;
@end @end
......
...@@ -70,31 +70,26 @@ using signin_metrics::PromoAction; ...@@ -70,31 +70,26 @@ using signin_metrics::PromoAction;
} }
} }
#pragma mark - Utility methods #pragma mark - Private
// Completes the add account flow including handling any errors that have not // Completes the add account flow including handling any errors that have not
// been handled internally by ChromeIdentity. Will return YES if the sign-in // been handled internally by ChromeIdentity. Will return the sign-in status of
// flow should be interrupted following this step. |identity| is the identity of // the user.
// the added account. |error| is an error reported by the SSOAuth following // |identity| is the identity of the added account.
// adding an account. // |error| is an error reported by the SSOAuth following adding an account.
- (BOOL)shouldInterruptSigninForIdentity:(ChromeIdentity*)identity - (SigninCoordinatorResult)signinStateWithIdentity:(ChromeIdentity*)identity
error:(NSError*)error { error:(NSError*)error {
if (!self.identityInteractionManager) { DCHECK(self.identityInteractionManager);
return YES;
}
if (error) { if (error) {
DCHECK(!identity);
// Filter out errors handled internally by ChromeIdentity. // Filter out errors handled internally by ChromeIdentity.
if (!ShouldHandleSigninError(error)) { if (ShouldHandleSigninError(error)) {
[self.delegate runCompletionCallbackWithSigninResult: return SigninCoordinatorResultInterrupted;
SigninCoordinatorResultCanceledByUser
identity:identity];
return YES;
} }
return SigninCoordinatorResultCanceledByUser;
[self.delegate showAlertWithError:error identity:identity];
} }
return error; DCHECK(identity);
return SigninCoordinatorResultSuccess;
} }
// Handles the reauthentication operation for a user from the screen to enter // Handles the reauthentication operation for a user from the screen to enter
...@@ -125,20 +120,31 @@ using signin_metrics::PromoAction; ...@@ -125,20 +120,31 @@ using signin_metrics::PromoAction;
email:base::SysUTF8ToNSString(email) email:base::SysUTF8ToNSString(email)
completion:^(ChromeIdentity* chromeIdentity, completion:^(ChromeIdentity* chromeIdentity,
NSError* error) { NSError* error) {
__typeof(self) strongSelf = weakSelf; [weakSelf operationCompletedWithIdentity:chromeIdentity
if (!strongSelf) { error:error];
return;
}
if ([strongSelf
shouldInterruptSigninForIdentity:chromeIdentity
error:error]) {
return;
}
[strongSelf.delegate
handleUserConsentForIdentity:chromeIdentity];
}]; }];
} }
// Handles the reauthentication or add account operation if the flow has not
// been interrupted by a sign-in error.
- (void)operationCompletedWithIdentity:(ChromeIdentity*)identity
error:(NSError*)error {
SigninCoordinatorResult signinResult = [self signinStateWithIdentity:identity
error:error];
switch (signinResult) {
case SigninCoordinatorResultSuccess:
case SigninCoordinatorResultCanceledByUser: {
[self.delegate addAccountSigninMediatorFinishedWith:signinResult
identity:identity];
break;
}
case SigninCoordinatorResultInterrupted: {
[self.delegate addAccountSigninMediatorFailedWith:error];
break;
}
}
}
// Handles the add account operation for a user. Presents the screen to enter // Handles the add account operation for a user. Presents the screen to enter
// credentials for the added account. In the case of a sign-in error will // credentials for the added account. In the case of a sign-in error will
// display a modal alert and abort the add account flow. // display a modal alert and abort the add account flow.
...@@ -146,17 +152,7 @@ using signin_metrics::PromoAction; ...@@ -146,17 +152,7 @@ using signin_metrics::PromoAction;
__weak AddAccountSigninMediator* weakSelf = self; __weak AddAccountSigninMediator* weakSelf = self;
[self.identityInteractionManager [self.identityInteractionManager
addAccountWithCompletion:^(ChromeIdentity* identity, NSError* error) { addAccountWithCompletion:^(ChromeIdentity* identity, NSError* error) {
__typeof(self) strongSelf = weakSelf; [weakSelf operationCompletedWithIdentity:identity error:error];
if (!strongSelf) {
return;
}
if ([strongSelf shouldInterruptSigninForIdentity:identity
error:error]) {
return;
}
[strongSelf.delegate
runCompletionCallbackWithSigninResult:SigninCoordinatorResultSuccess
identity:identity];
}]; }];
} }
......
// Copyright 2020 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/add_account_signin/add_account_signin_mediator.h"
#import <UIKit/UIKit.h>
#import "base/test/task_environment.h"
#import "components/prefs/pref_registry_simple.h"
#import "components/prefs/testing_pref_service.h"
#import "components/signin/public/base/signin_pref_names.h"
#import "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
#import "ios/chrome/browser/signin/identity_manager_factory.h"
#import "ios/public/provider/chrome/browser/signin/fake_chrome_identity.h"
#import "ios/public/provider/chrome/browser/signin/fake_chrome_identity_interaction_manager.h"
#import "ios/public/provider/chrome/browser/signin/fake_chrome_identity_service.h"
#import "testing/platform_test.h"
#import "third_party/ocmock/OCMock/OCMock.h"
#import "third_party/ocmock/gtest_support.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// Constants for configuring a FakeChromeIdentity.
const char kTestGaiaID[] = "fooID";
const char kTestEmail[] = "foo@gmail.com";
} // namespace
// Fake implementation of ChromeIdentityInteractionManagerDelegate that calls
// completion callback.
@interface FakeChromeIdentityInteractionManagerDelegate
: NSObject <ChromeIdentityInteractionManagerDelegate>
@end
@implementation FakeChromeIdentityInteractionManagerDelegate
- (void)interactionManager:(ChromeIdentityInteractionManager*)interactionManager
presentViewController:(UIViewController*)viewController
animated:(BOOL)animated
completion:(ProceduralBlock)completion {
if (completion) {
completion();
}
}
- (void)interactionManager:(ChromeIdentityInteractionManager*)interactionManager
dismissViewControllerAnimated:(BOOL)animated
completion:(ProceduralBlock)completion {
if (completion) {
completion();
}
}
@end
class AddAccountSigninMediatorTest : public PlatformTest {
public:
AddAccountSigninMediatorTest()
: browser_state_(TestChromeBrowserState::Builder().Build()),
identity_service_(
ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()) {
manager_delegate_ =
[[FakeChromeIdentityInteractionManagerDelegate alloc] init];
identity_interaction_manager_ = GetIdentityInteractionManager();
}
FakeChromeIdentityInteractionManager* GetIdentityInteractionManager() {
FakeChromeIdentityInteractionManager* identity_interaction_manager =
ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()
->CreateFakeChromeIdentityInteractionManager(browser_state_.get(),
manager_delegate_);
fake_identity_ = [FakeChromeIdentity
identityWithEmail:[NSString stringWithUTF8String:kTestEmail]
gaiaID:[NSString stringWithUTF8String:kTestGaiaID]
name:@"Foo"];
identity_interaction_manager.fakeIdentity = fake_identity_;
return identity_interaction_manager;
}
signin::IdentityManager* GetIdentityManager() {
return IdentityManagerFactory::GetForBrowserState(browser_state_.get());
}
// Registers account preferences that will be used in reauthentication.
PrefService* GetPrefService() {
TestingPrefServiceSimple* prefs = new TestingPrefServiceSimple();
PrefRegistrySimple* registry = prefs->registry();
registry->RegisterStringPref(prefs::kGoogleServicesLastUsername,
kTestEmail);
registry->RegisterStringPref(prefs::kGoogleServicesLastAccountId,
kTestGaiaID);
return prefs;
}
protected:
void SetUp() override {
mediator_ = [[AddAccountSigninMediator alloc]
initWithIdentityInteractionManager:identity_interaction_manager_
prefService:GetPrefService()
identityManager:GetIdentityManager()];
mediator_delegate_ =
OCMProtocolMock(@protocol(AddAccountSigninMediatorDelegate));
mediator_.delegate = mediator_delegate_;
}
void TearDown() override { EXPECT_OCMOCK_VERIFY(mediator_delegate_); }
// Needed for test browser state created by TestChromeBrowserState().
base::test::TaskEnvironment environment_;
std::unique_ptr<TestChromeBrowserState> browser_state_;
AddAccountSigninMediator* mediator_ = nil;
id mediator_delegate_ = nil;
id<ChromeIdentityInteractionManagerDelegate> manager_delegate_ = nil;
ios::FakeChromeIdentityService* identity_service_ = nil;
FakeChromeIdentityInteractionManager* identity_interaction_manager_ = nil;
FakeChromeIdentity* fake_identity_ = nil;
};
// Verifies the following state in the successful add account flow:
// - Account is added to the identity service
// - Completion callback is called with success state
TEST_F(AddAccountSigninMediatorTest, AddAccountIntent) {
// Verify that completion was called with success state.
[[mediator_delegate_ expect]
addAccountSigninMediatorFinishedWith:SigninCoordinatorResultSuccess
identity:fake_identity_];
[mediator_
handleSigninIntent:SigninIntentAddAccount
accessPoint:signin_metrics::AccessPoint::ACCESS_POINT_SETTINGS
promoAction:signin_metrics::PromoAction::
PROMO_ACTION_WITH_DEFAULT];
[identity_interaction_manager_ addAccountViewControllerDidTapSignIn];
// Account added.
EXPECT_TRUE(identity_service_->IsValidIdentity(fake_identity_));
}
// Verifies the following state in the add account flow with a user cancel:
// - Account is not added to the identity service
// - Completion callback is called with user cancel state
TEST_F(AddAccountSigninMediatorTest, AddAccountIntentWithUserCancel) {
// Verify that completion was called with canceled result state.
[[mediator_delegate_ expect]
addAccountSigninMediatorFinishedWith:SigninCoordinatorResultCanceledByUser
identity:nil];
[[mediator_delegate_ reject] addAccountSigninMediatorFailedWith:[OCMArg any]];
[mediator_
handleSigninIntent:SigninIntentAddAccount
accessPoint:signin_metrics::AccessPoint::ACCESS_POINT_SETTINGS
promoAction:signin_metrics::PromoAction::
PROMO_ACTION_WITH_DEFAULT];
[identity_interaction_manager_ addAccountViewControllerDidTapCancel];
// No account is present.
EXPECT_FALSE(identity_service_->HasIdentities());
}
// Verifies the following state in the add account flow with an error handled by
// the mediator:
// - Account is not added to the identity service
// - Completion callback is called with user cancel state
TEST_F(AddAccountSigninMediatorTest,
AddAccountIntentWithErrorHandledByMediator) {
// Verify that completion was called with canceled result state and an error
// is shown.
[[mediator_delegate_ expect] addAccountSigninMediatorFailedWith:[OCMArg any]];
[mediator_
handleSigninIntent:SigninIntentAddAccount
accessPoint:signin_metrics::AccessPoint::ACCESS_POINT_SETTINGS
promoAction:signin_metrics::PromoAction::
PROMO_ACTION_WITH_DEFAULT];
[identity_interaction_manager_
addAccountViewControllerDidThrowUnhandledError];
// No account is present.
EXPECT_FALSE(identity_service_->HasIdentities());
}
// TODO(crbug.com/971989): Add the ReauthIntent test.
// Verifies the following state in the successful reauth flow:
// - Account is added to the identity service
// - Completion callback is called with success state
// Verifies the following state in the reauth flow with a user cancel:
// - Account is not added to the identity service
// - Completion callback is called with user cancel state
TEST_F(AddAccountSigninMediatorTest, ReauthIntentWithUserCancel) {
// Verify that completion was called with canceled result state.
[[mediator_delegate_ expect]
addAccountSigninMediatorFinishedWith:SigninCoordinatorResultCanceledByUser
identity:nil];
[[mediator_delegate_ reject] addAccountSigninMediatorFailedWith:[OCMArg any]];
[mediator_
handleSigninIntent:SigninIntentReauth
accessPoint:signin_metrics::AccessPoint::ACCESS_POINT_SETTINGS
promoAction:signin_metrics::PromoAction::
PROMO_ACTION_WITH_DEFAULT];
[identity_interaction_manager_ addAccountViewControllerDidTapCancel];
// No account is present.
EXPECT_FALSE(identity_service_->HasIdentities());
}
// Verifies the following state in the reauth flow with an error handled by the
// mediator:
// - Account is not added to the identity service
// - Completion callback is called with user cancel state
TEST_F(AddAccountSigninMediatorTest, ReauthIntentWithErrorHandledByMediator) {
// Verify that completion was called with canceled result state and an error
// is shown.
[[mediator_delegate_ expect] addAccountSigninMediatorFailedWith:[OCMArg any]];
[mediator_
handleSigninIntent:SigninIntentReauth
accessPoint:signin_metrics::AccessPoint::ACCESS_POINT_SETTINGS
promoAction:signin_metrics::PromoAction::
PROMO_ACTION_WITH_DEFAULT];
[identity_interaction_manager_
addAccountViewControllerDidThrowUnhandledError];
// No account is present.
EXPECT_FALSE(identity_service_->HasIdentities());
}
...@@ -224,6 +224,7 @@ test("ios_chrome_unittests") { ...@@ -224,6 +224,7 @@ test("ios_chrome_unittests") {
"//ios/chrome/browser/ui/app_launcher:unit_tests", "//ios/chrome/browser/ui/app_launcher:unit_tests",
"//ios/chrome/browser/ui/authentication:unit_tests", "//ios/chrome/browser/ui/authentication:unit_tests",
"//ios/chrome/browser/ui/authentication/cells:unit_tests", "//ios/chrome/browser/ui/authentication/cells:unit_tests",
"//ios/chrome/browser/ui/authentication/signin/add_account_signin:unit_tests",
"//ios/chrome/browser/ui/autofill/cells:unit_tests", "//ios/chrome/browser/ui/autofill/cells:unit_tests",
"//ios/chrome/browser/ui/autofill/manual_fill:unit_tests", "//ios/chrome/browser/ui/autofill/manual_fill:unit_tests",
"//ios/chrome/browser/ui/badges:unit_tests", "//ios/chrome/browser/ui/badges:unit_tests",
......
...@@ -41,6 +41,7 @@ source_set("test_support") { ...@@ -41,6 +41,7 @@ source_set("test_support") {
"//ios/public/provider/chrome/browser/images:test_support", "//ios/public/provider/chrome/browser/images:test_support",
"//ios/public/provider/chrome/browser/mailto:test_support", "//ios/public/provider/chrome/browser/mailto:test_support",
"//ios/public/provider/chrome/browser/omaha:test_support", "//ios/public/provider/chrome/browser/omaha:test_support",
"//ios/public/provider/chrome/browser/signin",
"//ios/public/provider/chrome/browser/signin:test_support", "//ios/public/provider/chrome/browser/signin:test_support",
"//ios/public/provider/chrome/browser/spotlight:test_support", "//ios/public/provider/chrome/browser/spotlight:test_support",
"//ios/public/provider/chrome/browser/ui", "//ios/public/provider/chrome/browser/ui",
......
...@@ -14,6 +14,15 @@ ...@@ -14,6 +14,15 @@
// Fake identity that will be returned by the add account method. // Fake identity that will be returned by the add account method.
@property(nonatomic, weak) ChromeIdentity* fakeIdentity; @property(nonatomic, weak) ChromeIdentity* fakeIdentity;
// Simulates a user tapping the sign-in button.
- (void)addAccountViewControllerDidTapSignIn;
// Simulates a user tapping the cancel button.
- (void)addAccountViewControllerDidTapCancel;
// Simulates the user encountering an error not handled by ChromeIdentity.
- (void)addAccountViewControllerDidThrowUnhandledError;
@end @end
#endif // IOS_PUBLIC_PROVIDER_CHROME_BROWSER_SIGNIN_FAKE_CHROME_IDENTITY_INTERACTION_MANAGER_H_ #endif // IOS_PUBLIC_PROVIDER_CHROME_BROWSER_SIGNIN_FAKE_CHROME_IDENTITY_INTERACTION_MANAGER_H_
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base/mac/scoped_block.h" #include "base/mac/scoped_block.h"
#import "ios/public/provider/chrome/browser/chrome_browser_provider.h" #import "ios/public/provider/chrome/browser/chrome_browser_provider.h"
#import "ios/public/provider/chrome/browser/signin/chrome_identity_interaction_manager.h"
#import "ios/public/provider/chrome/browser/signin/fake_chrome_identity_interaction_manager_constants.h" #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity_interaction_manager_constants.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"
#include "ios/public/provider/chrome/browser/signin/signin_error_provider.h" #include "ios/public/provider/chrome/browser/signin/signin_error_provider.h"
...@@ -27,10 +28,6 @@ ...@@ -27,10 +28,6 @@
BOOL _isCanceling; BOOL _isCanceling;
} }
- (void)addAccountViewControllerDidTapSignIn:(FakeAddAccountViewController*)vc;
- (void)addAccountViewControllerDidTapCancel:(FakeAddAccountViewController*)vc;
@end @end
@implementation FakeAddAccountViewController @implementation FakeAddAccountViewController
...@@ -89,11 +86,11 @@ ...@@ -89,11 +86,11 @@
} }
- (void)didTapSignIn:(id)sender { - (void)didTapSignIn:(id)sender {
[_manager addAccountViewControllerDidTapSignIn:self]; [_manager addAccountViewControllerDidTapSignIn];
} }
- (void)didTapCancel:(id)sender { - (void)didTapCancel:(id)sender {
[_manager addAccountViewControllerDidTapCancel:self]; [_manager addAccountViewControllerDidTapCancel];
} }
@end @end
...@@ -129,17 +126,22 @@ ...@@ -129,17 +126,22 @@
_isCanceling = NO; _isCanceling = NO;
} }
- (void)addAccountViewControllerDidTapSignIn:(FakeAddAccountViewController*)vc { - (void)addAccountViewControllerDidTapSignIn {
ios::FakeChromeIdentityService::GetInstanceFromChromeProvider() ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()
->AddIdentity(_fakeIdentity); ->AddIdentity(_fakeIdentity);
[self dismissAndRunCompletionCallbackWithError:nil animated:YES]; [self dismissAndRunCompletionCallbackWithError:nil animated:YES];
} }
- (void)addAccountViewControllerDidTapCancel:(FakeAddAccountViewController*)vc { - (void)addAccountViewControllerDidTapCancel {
[self dismissAndRunCompletionCallbackWithError:[self canceledError] [self dismissAndRunCompletionCallbackWithError:[self canceledError]
animated:YES]; animated:YES];
} }
- (void)addAccountViewControllerDidThrowUnhandledError {
[self dismissAndRunCompletionCallbackWithError:[self unhandledError]
animated:YES];
}
#pragma mark Helper #pragma mark Helper
- (void)dismissAndRunCompletionCallbackWithError:(NSError*)error - (void)dismissAndRunCompletionCallbackWithError:(NSError*)error
...@@ -174,4 +176,8 @@ ...@@ -174,4 +176,8 @@
userInfo:nil]; userInfo:nil];
} }
- (NSError*)unhandledError {
return [NSError errorWithDomain:@"" code:-1 userInfo:nil];
}
@end @end
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
@class FakeChromeIdentityInteractionManager;
@class NSMutableArray; @class NSMutableArray;
namespace ios { namespace ios {
...@@ -31,6 +32,10 @@ class FakeChromeIdentityService : public ChromeIdentityService { ...@@ -31,6 +32,10 @@ class FakeChromeIdentityService : public ChromeIdentityService {
ChromeIdentityInteractionManager* CreateChromeIdentityInteractionManager( ChromeIdentityInteractionManager* CreateChromeIdentityInteractionManager(
ChromeBrowserState* browser_state, ChromeBrowserState* browser_state,
id<ChromeIdentityInteractionManagerDelegate> delegate) const override; id<ChromeIdentityInteractionManagerDelegate> delegate) const override;
FakeChromeIdentityInteractionManager*
CreateFakeChromeIdentityInteractionManager(
ChromeBrowserState* browser_state,
id<ChromeIdentityInteractionManagerDelegate> delegate) const;
bool IsValidIdentity(ChromeIdentity* identity) const override; bool IsValidIdentity(ChromeIdentity* identity) const override;
ChromeIdentity* GetIdentityWithGaiaID( ChromeIdentity* GetIdentityWithGaiaID(
......
...@@ -129,7 +129,14 @@ ChromeIdentityInteractionManager* ...@@ -129,7 +129,14 @@ ChromeIdentityInteractionManager*
FakeChromeIdentityService::CreateChromeIdentityInteractionManager( FakeChromeIdentityService::CreateChromeIdentityInteractionManager(
ChromeBrowserState* browser_state, ChromeBrowserState* browser_state,
id<ChromeIdentityInteractionManagerDelegate> delegate) const { id<ChromeIdentityInteractionManagerDelegate> delegate) const {
ChromeIdentityInteractionManager* manager = return CreateFakeChromeIdentityInteractionManager(browser_state, delegate);
}
FakeChromeIdentityInteractionManager*
FakeChromeIdentityService::CreateFakeChromeIdentityInteractionManager(
ChromeBrowserState* browser_state,
id<ChromeIdentityInteractionManagerDelegate> delegate) const {
FakeChromeIdentityInteractionManager* manager =
[[FakeChromeIdentityInteractionManager alloc] init]; [[FakeChromeIdentityInteractionManager alloc] init];
manager.delegate = delegate; manager.delegate = delegate;
return manager; return manager;
......
...@@ -22,6 +22,7 @@ class TestChromeBrowserProvider : public ChromeBrowserProvider { ...@@ -22,6 +22,7 @@ class TestChromeBrowserProvider : public ChromeBrowserProvider {
// ChromeBrowserProvider: // ChromeBrowserProvider:
SigninResourcesProvider* GetSigninResourcesProvider() override; SigninResourcesProvider* GetSigninResourcesProvider() override;
SigninErrorProvider* GetSigninErrorProvider() override;
void SetChromeIdentityServiceForTesting( void SetChromeIdentityServiceForTesting(
std::unique_ptr<ChromeIdentityService> service) override; std::unique_ptr<ChromeIdentityService> service) override;
ChromeIdentityService* GetChromeIdentityService() override; ChromeIdentityService* GetChromeIdentityService() override;
...@@ -40,6 +41,7 @@ class TestChromeBrowserProvider : public ChromeBrowserProvider { ...@@ -40,6 +41,7 @@ class TestChromeBrowserProvider : public ChromeBrowserProvider {
std::unique_ptr<BrandedImageProvider> branded_image_provider_; std::unique_ptr<BrandedImageProvider> branded_image_provider_;
std::unique_ptr<ChromeIdentityService> chrome_identity_service_; std::unique_ptr<ChromeIdentityService> chrome_identity_service_;
std::unique_ptr<OmahaServiceProvider> omaha_service_provider_; std::unique_ptr<OmahaServiceProvider> omaha_service_provider_;
std::unique_ptr<SigninErrorProvider> signin_error_provider_;
std::unique_ptr<SigninResourcesProvider> signin_resources_provider_; std::unique_ptr<SigninResourcesProvider> signin_resources_provider_;
std::unique_ptr<VoiceSearchProvider> voice_search_provider_; std::unique_ptr<VoiceSearchProvider> voice_search_provider_;
std::unique_ptr<UserFeedbackProvider> user_feedback_provider_; std::unique_ptr<UserFeedbackProvider> user_feedback_provider_;
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "ios/public/provider/chrome/browser/mailto/test_mailto_handler_provider.h" #include "ios/public/provider/chrome/browser/mailto/test_mailto_handler_provider.h"
#include "ios/public/provider/chrome/browser/omaha/test_omaha_service_provider.h" #include "ios/public/provider/chrome/browser/omaha/test_omaha_service_provider.h"
#include "ios/public/provider/chrome/browser/signin/fake_chrome_identity_service.h" #include "ios/public/provider/chrome/browser/signin/fake_chrome_identity_service.h"
#include "ios/public/provider/chrome/browser/signin/signin_error_provider.h"
#include "ios/public/provider/chrome/browser/signin/test_signin_resources_provider.h" #include "ios/public/provider/chrome/browser/signin/test_signin_resources_provider.h"
#import "ios/public/provider/chrome/browser/spotlight/test_spotlight_provider.h" #import "ios/public/provider/chrome/browser/spotlight/test_spotlight_provider.h"
#import "ios/public/provider/chrome/browser/ui/fullscreen_provider.h" #import "ios/public/provider/chrome/browser/ui/fullscreen_provider.h"
...@@ -30,6 +31,7 @@ TestChromeBrowserProvider::TestChromeBrowserProvider() ...@@ -30,6 +31,7 @@ TestChromeBrowserProvider::TestChromeBrowserProvider()
std::make_unique<TestAppDistributionProvider>()), std::make_unique<TestAppDistributionProvider>()),
branded_image_provider_(std::make_unique<TestBrandedImageProvider>()), branded_image_provider_(std::make_unique<TestBrandedImageProvider>()),
omaha_service_provider_(std::make_unique<TestOmahaServiceProvider>()), omaha_service_provider_(std::make_unique<TestOmahaServiceProvider>()),
signin_error_provider_(std::make_unique<SigninErrorProvider>()),
signin_resources_provider_( signin_resources_provider_(
std::make_unique<TestSigninResourcesProvider>()), std::make_unique<TestSigninResourcesProvider>()),
voice_search_provider_(std::make_unique<TestVoiceSearchProvider>()), voice_search_provider_(std::make_unique<TestVoiceSearchProvider>()),
...@@ -57,6 +59,10 @@ void TestChromeBrowserProvider::SetChromeIdentityServiceForTesting( ...@@ -57,6 +59,10 @@ void TestChromeBrowserProvider::SetChromeIdentityServiceForTesting(
chrome_identity_service_.swap(service); chrome_identity_service_.swap(service);
} }
SigninErrorProvider* TestChromeBrowserProvider::GetSigninErrorProvider() {
return signin_error_provider_.get();
}
ChromeIdentityService* TestChromeBrowserProvider::GetChromeIdentityService() { ChromeIdentityService* TestChromeBrowserProvider::GetChromeIdentityService() {
if (!chrome_identity_service_) { if (!chrome_identity_service_) {
chrome_identity_service_.reset(new FakeChromeIdentityService()); chrome_identity_service_.reset(new FakeChromeIdentityService());
......
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