Commit e5f935fc authored by Sebastien Lalancette's avatar Sebastien Lalancette Committed by Commit Bot

[ActivityService] Cleaned-up Usage of Alert

I realized no code-path will ever trigger the error alert pop-up in
the activity service component. I think it actually makes sense given
that our activities are in fact commands - the command should handle
reporting its failing state. Cleaned-up that scenario.

Bug: 1068606
Change-Id: I677746f7216cbc975a0382d2fc98cec05a75a7b5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2165849Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Commit-Queue: Sebastien Lalancette <seblalancette@chromium.org>
Cr-Commit-Position: refs/heads/master@{#762816}
parent b7e7f2b3
...@@ -67,7 +67,6 @@ source_set("coordinator") { ...@@ -67,7 +67,6 @@ source_set("coordinator") {
"//ios/chrome/browser/main:public", "//ios/chrome/browser/main:public",
"//ios/chrome/browser/tabs", "//ios/chrome/browser/tabs",
"//ios/chrome/browser/ui/activity_services/requirements", "//ios/chrome/browser/ui/activity_services/requirements",
"//ios/chrome/browser/ui/alert_coordinator",
"//ios/chrome/browser/ui/commands", "//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/coordinators:chrome_coordinators", "//ios/chrome/browser/ui/coordinators:chrome_coordinators",
"//ios/chrome/browser/web_state_list", "//ios/chrome/browser/web_state_list",
......
...@@ -15,26 +15,6 @@ class ChromeBrowserState; ...@@ -15,26 +15,6 @@ class ChromeBrowserState;
@class ShareToData; @class ShareToData;
@protocol SnackbarCommands; @protocol SnackbarCommands;
namespace ShareTo {
// Provides the result of a sharing event.
enum ShareResult {
// The share was successful.
SHARE_SUCCESS,
// The share was cancelled by either the user or by the service.
SHARE_CANCEL,
// The share was attempted, but failed due to a network-related error.
SHARE_NETWORK_FAILURE,
// The share was attempted, but failed because of user authentication error.
SHARE_SIGN_IN_FAILURE,
// The share was attempted, but failed with an unspecified error.
SHARE_ERROR,
// The share was attempted, and the result is unknown.
SHARE_UNKNOWN_RESULT,
};
} // namespace ShareTo
// Snackbar ID for any services that wish to show snackbars. // Snackbar ID for any services that wish to show snackbars.
extern NSString* const kActivityServicesSnackbarCategory; extern NSString* const kActivityServicesSnackbarCategory;
......
...@@ -206,18 +206,14 @@ NSString* const kActivityServicesSnackbarCategory = ...@@ -206,18 +206,14 @@ NSString* const kActivityServicesSnackbarCategory =
DCHECK(_presentationProvider); DCHECK(_presentationProvider);
if (activityType) { if (activityType) {
ShareTo::ShareResult shareResult = completed
? ShareTo::ShareResult::SHARE_SUCCESS
: ShareTo::ShareResult::SHARE_CANCEL;
activity_type_util::ActivityType type = activity_type_util::ActivityType type =
activity_type_util::TypeFromString(activityType); activity_type_util::TypeFromString(activityType);
activity_type_util::RecordMetricForActivity(type); activity_type_util::RecordMetricForActivity(type);
NSString* completionMessage = NSString* completionMessage =
activity_type_util::CompletionMessageForActivity(type); activity_type_util::CompletionMessageForActivity(type);
[self shareDidComplete:shareResult completionMessage:completionMessage]; [self shareDidComplete:completed completionMessage:completionMessage];
} else { } else {
[self shareDidComplete:ShareTo::ShareResult::SHARE_CANCEL [self shareDidComplete:NO completionMessage:nil];
completionMessage:nil];
} }
[self resetUserInterface]; [self resetUserInterface];
...@@ -317,32 +313,15 @@ NSString* const kActivityServicesSnackbarCategory = ...@@ -317,32 +313,15 @@ NSString* const kActivityServicesSnackbarCategory =
return applicationActivities; return applicationActivities;
} }
- (void)shareDidComplete:(ShareTo::ShareResult)shareStatus - (void)shareDidComplete:(BOOL)isSuccess completionMessage:(NSString*)message {
completionMessage:(NSString*)message { if (isSuccess) {
switch (shareStatus) { if ([message length]) {
case ShareTo::SHARE_SUCCESS: TriggerHapticFeedbackForNotification(UINotificationFeedbackTypeSuccess);
if ([message length]) { [self showSnackbar:message];
TriggerHapticFeedbackForNotification(UINotificationFeedbackTypeSuccess); }
[self showSnackbar:message]; } else {
} // Share action was cancelled.
break; base::RecordAction(base::UserMetricsAction("MobileShareMenuCancel"));
case ShareTo::SHARE_ERROR:
[self showErrorAlert:IDS_IOS_SHARE_TO_ERROR_ALERT_TITLE
message:IDS_IOS_SHARE_TO_ERROR_ALERT];
break;
case ShareTo::SHARE_NETWORK_FAILURE:
[self showErrorAlert:IDS_IOS_SHARE_TO_NETWORK_ERROR_ALERT_TITLE
message:IDS_IOS_SHARE_TO_NETWORK_ERROR_ALERT];
break;
case ShareTo::SHARE_SIGN_IN_FAILURE:
[self showErrorAlert:IDS_IOS_SHARE_TO_SIGN_IN_ERROR_ALERT_TITLE
message:IDS_IOS_SHARE_TO_SIGN_IN_ERROR_ALERT];
break;
case ShareTo::SHARE_CANCEL:
base::RecordAction(base::UserMetricsAction("MobileShareMenuCancel"));
break;
case ShareTo::SHARE_UNKNOWN_RESULT:
break;
} }
// The shareTo dialog dismisses itself instead of through // The shareTo dialog dismisses itself instead of through
...@@ -351,13 +330,6 @@ NSString* const kActivityServicesSnackbarCategory = ...@@ -351,13 +330,6 @@ NSString* const kActivityServicesSnackbarCategory =
[_presentationProvider activityServiceDidEndPresenting]; [_presentationProvider activityServiceDidEndPresenting];
} }
- (void)showErrorAlert:(int)titleMessageId message:(int)messageId {
NSString* title = l10n_util::GetNSString(titleMessageId);
NSString* message = l10n_util::GetNSString(messageId);
[_presentationProvider showActivityServiceErrorAlertWithStringTitle:title
message:message];
}
- (void)showSnackbar:(NSString*)text { - (void)showSnackbar:(NSString*)text {
MDCSnackbarMessage* message = [MDCSnackbarMessage messageWithText:text]; MDCSnackbarMessage* message = [MDCSnackbarMessage messageWithText:text];
message.accessibilityLabel = text; message.accessibilityLabel = text;
......
...@@ -58,8 +58,7 @@ ...@@ -58,8 +58,7 @@
prefService:(PrefService*)prefService prefService:(PrefService*)prefService
canSendTabToSelf:(BOOL)canSendTabToSelf; canSendTabToSelf:(BOOL)canSendTabToSelf;
- (void)shareDidComplete:(ShareTo::ShareResult)shareStatus - (void)shareDidComplete:(BOOL)isSuccess completionMessage:(NSString*)message;
completionMessage:(NSString*)message;
// Setter function for mocking during testing // Setter function for mocking during testing
- (void)setProvidersForTesting:(id<ActivityServicePresentation>)provider - (void)setProvidersForTesting:(id<ActivityServicePresentation>)provider
...@@ -80,8 +79,6 @@ ...@@ -80,8 +79,6 @@
BOOL activityServiceDidEndPresentingWasCalled; BOOL activityServiceDidEndPresentingWasCalled;
// Stores the latest values that were passed to the associated provider methods. // Stores the latest values that were passed to the associated provider methods.
@property(nonatomic, readonly, copy) NSString* latestErrorAlertTitle;
@property(nonatomic, readonly, copy) NSString* latestErrorAlertMessage;
@property(nonatomic, readonly, copy) NSString* latestSnackbarMessage; @property(nonatomic, readonly, copy) NSString* latestSnackbarMessage;
@property(nonatomic, readonly, copy) NSString* latestContextMenuTitle; @property(nonatomic, readonly, copy) NSString* latestContextMenuTitle;
...@@ -113,12 +110,6 @@ ...@@ -113,12 +110,6 @@
_activityServiceDidEndPresentingWasCalled = YES; _activityServiceDidEndPresentingWasCalled = YES;
} }
- (void)showActivityServiceErrorAlertWithStringTitle:(NSString*)title
message:(NSString*)message {
_latestErrorAlertTitle = [title copy];
_latestErrorAlertMessage = [message copy];
}
#pragma mark - ActivityServicePositioner #pragma mark - ActivityServicePositioner
- (UIView*)shareButtonView { - (UIView*)shareButtonView {
...@@ -521,15 +512,13 @@ TEST_F(ActivityServiceControllerTest, TestShareDidCompleteWithSuccess) { ...@@ -521,15 +512,13 @@ TEST_F(ActivityServiceControllerTest, TestShareDidCompleteWithSuccess) {
[controller setProvidersForTesting:provider dispatcher:provider]; [controller setProvidersForTesting:provider dispatcher:provider];
NSString* completion_message = @"Completion!"; NSString* completion_message = @"Completion!";
[controller shareDidComplete:ShareTo::SHARE_SUCCESS [controller shareDidComplete:YES completionMessage:completion_message];
completionMessage:completion_message];
EXPECT_TRUE(provider.activityServiceDidEndPresentingWasCalled); EXPECT_TRUE(provider.activityServiceDidEndPresentingWasCalled);
EXPECT_NSEQ(completion_message, provider.latestSnackbarMessage); EXPECT_NSEQ(completion_message, provider.latestSnackbarMessage);
} }
// Verifies that the snackbar and error alert providers are not invoked for a // Verifies that the snackbar is not invoked for a cancelled share.
// cancelled share.
TEST_F(ActivityServiceControllerTest, TestShareDidCompleteWithCancellation) { TEST_F(ActivityServiceControllerTest, TestShareDidCompleteWithCancellation) {
ActivityServiceController* controller = ActivityServiceController* controller =
[[ActivityServiceController alloc] init]; [[ActivityServiceController alloc] init];
...@@ -538,32 +527,8 @@ TEST_F(ActivityServiceControllerTest, TestShareDidCompleteWithCancellation) { ...@@ -538,32 +527,8 @@ TEST_F(ActivityServiceControllerTest, TestShareDidCompleteWithCancellation) {
initWithParentViewController:nil]; initWithParentViewController:nil];
[controller setProvidersForTesting:provider dispatcher:provider]; [controller setProvidersForTesting:provider dispatcher:provider];
[controller shareDidComplete:ShareTo::SHARE_CANCEL [controller shareDidComplete:NO completionMessage:@"dummy"];
completionMessage:@"dummy"];
EXPECT_TRUE(provider.activityServiceDidEndPresentingWasCalled); EXPECT_TRUE(provider.activityServiceDidEndPresentingWasCalled);
EXPECT_FALSE(provider.latestErrorAlertTitle);
EXPECT_FALSE(provider.latestErrorAlertMessage);
EXPECT_FALSE(provider.latestSnackbarMessage);
}
// Verifies that the error alert provider is invoked with the proper error
// message upon receiving a -shareDidComplete callback for a failed share.
TEST_F(ActivityServiceControllerTest, TestShareDidCompleteWithError) {
ActivityServiceController* controller =
[[ActivityServiceController alloc] init];
FakeActivityServiceControllerTestProvider* provider =
[[FakeActivityServiceControllerTestProvider alloc]
initWithParentViewController:nil];
[controller setProvidersForTesting:provider dispatcher:provider];
[controller shareDidComplete:ShareTo::SHARE_ERROR completionMessage:@"dummy"];
NSString* error_title =
l10n_util::GetNSString(IDS_IOS_SHARE_TO_ERROR_ALERT_TITLE);
NSString* error_message =
l10n_util::GetNSString(IDS_IOS_SHARE_TO_ERROR_ALERT);
EXPECT_NSEQ(error_title, provider.latestErrorAlertTitle);
EXPECT_NSEQ(error_message, provider.latestErrorAlertMessage);
EXPECT_FALSE(provider.latestSnackbarMessage); EXPECT_FALSE(provider.latestSnackbarMessage);
} }
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#import "ios/chrome/browser/ui/activity_services/requirements/activity_service_presentation.h" #import "ios/chrome/browser/ui/activity_services/requirements/activity_service_presentation.h"
#import "ios/chrome/browser/ui/activity_services/share_to_data.h" #import "ios/chrome/browser/ui/activity_services/share_to_data.h"
#import "ios/chrome/browser/ui/activity_services/share_to_data_builder.h" #import "ios/chrome/browser/ui/activity_services/share_to_data_builder.h"
#import "ios/chrome/browser/ui/alert_coordinator/alert_coordinator.h"
#import "ios/chrome/browser/ui/commands/activity_service_commands.h" #import "ios/chrome/browser/ui/commands/activity_service_commands.h"
#import "ios/chrome/browser/ui/commands/command_dispatcher.h" #import "ios/chrome/browser/ui/commands/command_dispatcher.h"
#import "ios/chrome/browser/web_state_list/web_state_list.h" #import "ios/chrome/browser/web_state_list/web_state_list.h"
...@@ -41,9 +40,6 @@ const char kSharePageLatencyHistogram[] = "IOS.SharePageLatency"; ...@@ -41,9 +40,6 @@ const char kSharePageLatencyHistogram[] = "IOS.SharePageLatency";
// The time when the Share Page operation started. // The time when the Share Page operation started.
@property(nonatomic, assign) base::TimeTicks sharePageStartTime; @property(nonatomic, assign) base::TimeTicks sharePageStartTime;
// Coordinator used to display error messages when activities fail.
@property(nonatomic, strong) AlertCoordinator* alertCoordinator;
@end @end
@implementation ActivityServiceCoordinator @implementation ActivityServiceCoordinator
...@@ -65,9 +61,6 @@ const char kSharePageLatencyHistogram[] = "IOS.SharePageLatency"; ...@@ -65,9 +61,6 @@ const char kSharePageLatencyHistogram[] = "IOS.SharePageLatency";
- (void)stop { - (void)stop {
[[ActivityServiceController sharedInstance] cancelShareAnimated:NO]; [[ActivityServiceController sharedInstance] cancelShareAnimated:NO];
[self.alertCoordinator stop];
self.alertCoordinator = nil;
} }
#pragma mark - ActivityServicePresentation #pragma mark - ActivityServicePresentation
...@@ -79,32 +72,9 @@ const char kSharePageLatencyHistogram[] = "IOS.SharePageLatency"; ...@@ -79,32 +72,9 @@ const char kSharePageLatencyHistogram[] = "IOS.SharePageLatency";
} }
- (void)activityServiceDidEndPresenting { - (void)activityServiceDidEndPresenting {
if ([self.alertCoordinator isVisible]) {
return;
}
[self.handler hideActivityView]; [self.handler hideActivityView];
} }
- (void)showActivityServiceErrorAlertWithStringTitle:(NSString*)title
message:(NSString*)message {
self.alertCoordinator = [[AlertCoordinator alloc]
initWithBaseViewController:self.baseViewController
browser:self.browser
title:title
message:message];
// Add OK button.
__weak __typeof(self) weakSelf = self;
ProceduralBlock action = ^{
[weakSelf alertDismissed];
};
[self.alertCoordinator addItemWithTitle:l10n_util::GetNSString(IDS_APP_OK)
action:action
style:UIAlertActionStyleDefault];
[self.alertCoordinator start];
}
#pragma mark - Private Methods #pragma mark - Private Methods
// Shares the current page using the |canonicalURL|. // Shares the current page using the |canonicalURL|.
...@@ -134,9 +104,4 @@ const char kSharePageLatencyHistogram[] = "IOS.SharePageLatency"; ...@@ -134,9 +104,4 @@ const char kSharePageLatencyHistogram[] = "IOS.SharePageLatency";
presentationProvider:self]; presentationProvider:self];
} }
// Cleans up the alert's components.
- (void)alertDismissed {
[self.handler hideActivityView];
}
@end @end
...@@ -18,11 +18,6 @@ ...@@ -18,11 +18,6 @@
// to perform cleanup after the UI is gone. // to perform cleanup after the UI is gone.
- (void)activityServiceDidEndPresenting; - (void)activityServiceDidEndPresenting;
// Asks the implementor to show an error alert with the given |title| and
// |message|.
- (void)showActivityServiceErrorAlertWithStringTitle:(NSString*)title
message:(NSString*)message;
@end @end
#endif // IOS_CHROME_BROWSER_UI_ACTIVITY_SERVICES_REQUIREMENTS_ACTIVITY_SERVICE_PRESENTATION_H_ #endif // IOS_CHROME_BROWSER_UI_ACTIVITY_SERVICES_REQUIREMENTS_ACTIVITY_SERVICE_PRESENTATION_H_
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