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

[iOS] Add animation parameter to cancelAndDismiss in AuthenticationFlow.

Fixed: 1056634
Change-Id: I18e13be1bbee5449b865745719a9f38ea1432096
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2387765Reviewed-by: default avatarJérôme Lebel <jlebel@chromium.org>
Commit-Queue: Nohemi Fernandez <fernandex@chromium.org>
Cr-Commit-Position: refs/heads/master@{#803816}
parent 89a048b0
...@@ -62,10 +62,10 @@ class Browser; ...@@ -62,10 +62,10 @@ class Browser;
- (void)startSignInWithCompletion:(signin_ui::CompletionCallback)completion; - (void)startSignInWithCompletion:(signin_ui::CompletionCallback)completion;
// Cancels the current sign-in operation (if any) and dismiss any UI presented // Cancels the current sign-in operation (if any) and dismiss any UI presented
// by this authentication flow. Calls the completion callback with the sign-in // by this authentication flow with animation if |animated|. Calls the
// flag set to NO. // completion callback with the sign-in flag set to NO. Does nothing if the sign
// Does nothing if the sign in flow is already done. // in flow is already done.
- (void)cancelAndDismiss; - (void)cancelAndDismissAnimated:(BOOL)animated;
// The dispatcher used to clear browsing data. // The dispatcher used to clear browsing data.
@property(nonatomic, weak) id<BrowsingDataCommands> dispatcher; @property(nonatomic, weak) id<BrowsingDataCommands> dispatcher;
......
...@@ -142,11 +142,11 @@ NSError* IdentityMissingError() { ...@@ -142,11 +142,11 @@ NSError* IdentityMissingError() {
[self continueSignin]; [self continueSignin];
} }
- (void)cancelAndDismiss { - (void)cancelAndDismissAnimated:(BOOL)animated {
if (_state == DONE) if (_state == DONE)
return; return;
[_performer cancelAndDismiss]; [_performer cancelAndDismissAnimated:animated];
if (_state != DONE) { if (_state != DONE) {
// The performer might not have been able to continue the flow if it was // The performer might not have been able to continue the flow if it was
// waiting for a callback (e.g. waiting for AccountReconcilor). In this // waiting for a callback (e.g. waiting for AccountReconcilor). In this
......
...@@ -27,8 +27,9 @@ class ChromeBrowserState; ...@@ -27,8 +27,9 @@ class ChromeBrowserState;
- (instancetype)init NS_UNAVAILABLE; - (instancetype)init NS_UNAVAILABLE;
// Cancels any outstanding work and dismisses an alert view (if shown). // Cancels any outstanding work and dismisses an alert view (if shown) using
- (void)cancelAndDismiss; // animation if |animated| is true.
- (void)cancelAndDismissAnimated:(BOOL)animated;
// Starts sync for |browserState|. // Starts sync for |browserState|.
- (void)commitSyncForBrowserState:(ChromeBrowserState*)browserState; - (void)commitSyncForBrowserState:(ChromeBrowserState*)browserState;
......
...@@ -91,13 +91,13 @@ const int64_t kAuthenticationFlowTimeoutSeconds = 10; ...@@ -91,13 +91,13 @@ const int64_t kAuthenticationFlowTimeoutSeconds = 10;
return self; return self;
} }
- (void)cancelAndDismiss { - (void)cancelAndDismissAnimated:(BOOL)animated {
[_alertCoordinator executeCancelHandler]; [_alertCoordinator executeCancelHandler];
[_alertCoordinator stop]; [_alertCoordinator stop];
if (_navigationController) { if (_navigationController) {
[_navigationController cleanUpSettings]; [_navigationController cleanUpSettings];
_navigationController = nil; _navigationController = nil;
[_delegate dismissPresentingViewControllerAnimated:NO completion:nil]; [_delegate dismissPresentingViewControllerAnimated:animated completion:nil];
} }
[self stopWatchdogTimer]; [self stopWatchdogTimer];
} }
......
...@@ -236,12 +236,12 @@ TEST_F(AuthenticationFlowTest, TestCancel) { ...@@ -236,12 +236,12 @@ TEST_F(AuthenticationFlowTest, TestCancel) {
browserState:browser_state_.get()]; browserState:browser_state_.get()];
[[[performer_ expect] andDo:^(NSInvocation*) { [[[performer_ expect] andDo:^(NSInvocation*) {
[authentication_flow_ cancelAndDismiss]; [authentication_flow_ cancelAndDismissAnimated:NO];
}] promptMergeCaseForIdentity:identity1_ }] promptMergeCaseForIdentity:identity1_
browser:browser_.get() browser:browser_.get()
viewController:view_controller_]; viewController:view_controller_];
[[performer_ expect] cancelAndDismiss]; [[performer_ expect] cancelAndDismissAnimated:NO];
[authentication_flow_ startSignInWithCompletion:sign_in_completion_]; [authentication_flow_ startSignInWithCompletion:sign_in_completion_];
......
...@@ -459,7 +459,6 @@ const CGFloat kFadeOutAnimationDuration = 0.16f; ...@@ -459,7 +459,6 @@ const CGFloat kFadeOutAnimationDuration = 0.16f;
DCHECK(self.unifiedConsentCoordinator); DCHECK(self.unifiedConsentCoordinator);
DCHECK(!self.addAccountSigninCoordinator); DCHECK(!self.addAccountSigninCoordinator);
DCHECK(!self.advancedSettingsSigninCoordinator); DCHECK(!self.advancedSettingsSigninCoordinator);
[self.mediator cancelAndDismissAuthenticationFlow];
__weak UserSigninCoordinator* weakSelf = self; __weak UserSigninCoordinator* weakSelf = self;
ProceduralBlock runCompletionCallback = ^{ ProceduralBlock runCompletionCallback = ^{
[weakSelf [weakSelf
...@@ -473,15 +472,18 @@ const CGFloat kFadeOutAnimationDuration = 0.16f; ...@@ -473,15 +472,18 @@ const CGFloat kFadeOutAnimationDuration = 0.16f;
}; };
switch (action) { switch (action) {
case SigninCoordinatorInterruptActionNoDismiss: { case SigninCoordinatorInterruptActionNoDismiss: {
[self.mediator cancelAndDismissAuthenticationFlowAnimated:NO];
runCompletionCallback(); runCompletionCallback();
break; break;
} }
case SigninCoordinatorInterruptActionDismissWithAnimation: { case SigninCoordinatorInterruptActionDismissWithAnimation: {
[self.mediator cancelAndDismissAuthenticationFlowAnimated:YES];
[self.viewController dismissViewControllerAnimated:YES [self.viewController dismissViewControllerAnimated:YES
completion:runCompletionCallback]; completion:runCompletionCallback];
break; break;
} }
case SigninCoordinatorInterruptActionDismissWithoutAnimation: { case SigninCoordinatorInterruptActionDismissWithoutAnimation: {
[self.mediator cancelAndDismissAuthenticationFlowAnimated:NO];
[self.viewController dismissViewControllerAnimated:NO [self.viewController dismissViewControllerAnimated:NO
completion:runCompletionCallback]; completion:runCompletionCallback];
break; break;
......
...@@ -78,8 +78,9 @@ class UnifiedConsentService; ...@@ -78,8 +78,9 @@ class UnifiedConsentService;
// Reverts the sign-in operation. // Reverts the sign-in operation.
- (void)cancelSignin; - (void)cancelSignin;
// Cancels and dismisses the authentication flow if sign-in is in progress. // Cancels and dismisses with animation if |animated| the authentication flow
- (void)cancelAndDismissAuthenticationFlow; // when sign-in is in progress.
- (void)cancelAndDismissAuthenticationFlowAnimated:(BOOL)animated;
@end @end
......
...@@ -75,20 +75,19 @@ ...@@ -75,20 +75,19 @@
- (void)cancelSignin { - (void)cancelSignin {
if (self.isAuthenticationInProgress) { if (self.isAuthenticationInProgress) {
[self cancelAndDismissAuthenticationFlow]; [self cancelAndDismissAuthenticationFlowAnimated:NO];
} else { } else {
[self.delegate userSigninMediatorSigninFinishedWithResult: [self.delegate userSigninMediatorSigninFinishedWithResult:
SigninCoordinatorResultCanceledByUser]; SigninCoordinatorResultCanceledByUser];
} }
} }
- (void)cancelAndDismissAuthenticationFlow { - (void)cancelAndDismissAuthenticationFlowAnimated:(BOOL)animated {
if (!self.isAuthenticationInProgress) { if (!self.isAuthenticationInProgress) {
return; return;
} }
// TODO(crbug.com/1056634): Support cancelAndDismiss with animation parameter. [self.authenticationFlow cancelAndDismissAnimated:animated];
[self.authenticationFlow cancelAndDismiss];
self.authenticationService->SignOut(signin_metrics::ABORT_SIGNIN, self.authenticationService->SignOut(signin_metrics::ABORT_SIGNIN,
/*force_clear_browsing_data=*/false, nil); /*force_clear_browsing_data=*/false, nil);
} }
......
...@@ -168,9 +168,9 @@ class UserSigninMediatorTest : public PlatformTest { ...@@ -168,9 +168,9 @@ class UserSigninMediatorTest : public PlatformTest {
}); });
} }
// Sets up the expectations for cancelAndDismiss in the // Sets up the expectations for cancelAndDismissAnimated in the
// AuthenticationFlowPerformer. // AuthenticationFlowPerformer.
void SetPerformerCancelAndDismissExpectations() { void SetPerformerCancelAndDismissExpectations(BOOL animated) {
OCMExpect([performer_mock_ fetchManagedStatus:browser_state_.get() OCMExpect([performer_mock_ fetchManagedStatus:browser_state_.get()
forIdentity:identity_]) forIdentity:identity_])
.andDo(^(NSInvocation*) { .andDo(^(NSInvocation*) {
...@@ -184,7 +184,7 @@ class UserSigninMediatorTest : public PlatformTest { ...@@ -184,7 +184,7 @@ class UserSigninMediatorTest : public PlatformTest {
promptMergeCaseForIdentity:identity_ promptMergeCaseForIdentity:identity_
browser:browser_.get() browser:browser_.get()
viewController:presenting_view_controller_mock_]); viewController:presenting_view_controller_mock_]);
OCMExpect([performer_mock_ cancelAndDismiss]); OCMExpect([performer_mock_ cancelAndDismissAnimated:animated]);
} }
void ExpectNoConsent() { void ExpectNoConsent() {
...@@ -344,7 +344,7 @@ TEST_F(UserSigninMediatorTest, CancelAuthenticationNotInProgress) { ...@@ -344,7 +344,7 @@ TEST_F(UserSigninMediatorTest, CancelAuthenticationNotInProgress) {
// Tests a user sign-in operation cancel when authentication is in progress. // Tests a user sign-in operation cancel when authentication is in progress.
TEST_F(UserSigninMediatorTest, CancelWithAuthenticationInProgress) { TEST_F(UserSigninMediatorTest, CancelWithAuthenticationInProgress) {
SetPerformerCancelAndDismissExpectations(); SetPerformerCancelAndDismissExpectations(/*animated=*/NO);
// Unsuccessful sign-in completion updates the primary button. // Unsuccessful sign-in completion updates the primary button.
OCMExpect([mediator_delegate_mock_ userSigninMediatorSigninFailed]); OCMExpect([mediator_delegate_mock_ userSigninMediatorSigninFailed]);
...@@ -358,20 +358,36 @@ TEST_F(UserSigninMediatorTest, CancelWithAuthenticationInProgress) { ...@@ -358,20 +358,36 @@ TEST_F(UserSigninMediatorTest, CancelWithAuthenticationInProgress) {
// Tests a user sign-in operation cancel and dismiss when authentication has not // Tests a user sign-in operation cancel and dismiss when authentication has not
// begun. // begun.
TEST_F(UserSigninMediatorTest, CancelAndDismissAuthenticationNotInProgress) { TEST_F(UserSigninMediatorTest, CancelAndDismissAuthenticationNotInProgress) {
[mediator_ cancelAndDismissAuthenticationFlow]; [mediator_ cancelAndDismissAuthenticationFlowAnimated:NO];
ExpectNoConsent(); ExpectNoConsent();
} }
// Tests a user sign-in operation cancel and dismiss when authentication is in // Tests a user sign-in operation cancel and dismiss with animation when
// progress. // authentication is in progress.
TEST_F(UserSigninMediatorTest, CancelAndDismissAuthenticationInProgress) { TEST_F(UserSigninMediatorTest,
SetPerformerCancelAndDismissExpectations(); CancelAndDismissAuthenticationInProgressWithAnimation) {
SetPerformerCancelAndDismissExpectations(/*animated=*/YES);
// Unsuccessful sign-in completion updates the primary button. // Unsuccessful sign-in completion updates the primary button.
OCMExpect([mediator_delegate_mock_ userSigninMediatorSigninFailed]); OCMExpect([mediator_delegate_mock_ userSigninMediatorSigninFailed]);
[mediator_ authenticateWithIdentity:identity_ [mediator_ authenticateWithIdentity:identity_
authenticationFlow:authentication_flow_]; authenticationFlow:authentication_flow_];
[mediator_ cancelAndDismissAuthenticationFlow]; [mediator_ cancelAndDismissAuthenticationFlowAnimated:YES];
ExpectNoConsent();
}
// Tests a user sign-in operation cancel and dismiss without animation when
// authentication is in progress.
TEST_F(UserSigninMediatorTest,
CancelAndDismissAuthenticationInProgressWithoutAnimation) {
SetPerformerCancelAndDismissExpectations(/*animated=*/NO);
// Unsuccessful sign-in completion updates the primary button.
OCMExpect([mediator_delegate_mock_ userSigninMediatorSigninFailed]);
[mediator_ authenticateWithIdentity:identity_
authenticationFlow:authentication_flow_];
[mediator_ cancelAndDismissAuthenticationFlowAnimated:NO];
ExpectNoConsent(); ExpectNoConsent();
} }
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