From f37a3059fa303908154679d86046b431c53130c4 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 20 Mar 2019 10:56:45 -0400 Subject: [PATCH] Add accessibility identifiers to debug log popups. --- .../PrivacySettingsTableViewController.m | 20 ++-- Signal/src/util/Pastelog.m | 96 ++++++++++++------- SignalMessaging/categories/UIView+OWS.h | 11 +++ SignalMessaging/categories/UIView+OWS.m | 21 +++- 4 files changed, 104 insertions(+), 44 deletions(-) diff --git a/Signal/src/ViewControllers/AppSettings/PrivacySettingsTableViewController.m b/Signal/src/ViewControllers/AppSettings/PrivacySettingsTableViewController.m index 7c9a286d9..1f9d32835 100644 --- a/Signal/src/ViewControllers/AppSettings/PrivacySettingsTableViewController.m +++ b/Signal/src/ViewControllers/AppSettings/PrivacySettingsTableViewController.m @@ -555,16 +555,22 @@ static NSString *const kSealedSenderInfoURL = @"https://signal.org/blog/sealed-s uint32_t screenLockTimeout = (uint32_t)round(timeoutValue.doubleValue); NSString *screenLockTimeoutString = [self formatScreenLockTimeout:screenLockTimeout useShortFormat:NO]; - [controller addAction:[UIAlertAction actionWithTitle:screenLockTimeoutString - style:UIAlertActionStyleDefault - handler:^(UIAlertAction *action) { - [OWSScreenLock.sharedManager - setScreenLockTimeout:screenLockTimeout]; - }]]; + UIAlertAction *action = + [UIAlertAction actionWithTitle:screenLockTimeoutString + style:UIAlertActionStyleDefault + handler:^(UIAlertAction *ignore) { + [OWSScreenLock.sharedManager setScreenLockTimeout:screenLockTimeout]; + }]; + action.accessibilityIdentifier = [NSString stringWithFormat:@"settings.privacy.timeout.%@", timeoutValue]; + [controller addAction:action]; } [controller addAction:[OWSAlerts cancelAction]]; UIViewController *fromViewController = [[UIApplication sharedApplication] frontmostViewController]; - [fromViewController presentViewController:controller animated:YES completion:nil]; + [fromViewController presentViewController:controller + animated:YES + completion:^{ + [controller applyAccessibilityIdentifiers]; + }]; } - (NSString *)formatScreenLockTimeout:(NSInteger)value useShortFormat:(BOOL)useShortFormat diff --git a/Signal/src/util/Pastelog.m b/Signal/src/util/Pastelog.m index c1b1809c6..c5e987cb5 100644 --- a/Signal/src/util/Pastelog.m +++ b/Signal/src/util/Pastelog.m @@ -319,17 +319,20 @@ typedef void (^DebugLogUploadFailure)(DebugLogUploader *uploader, NSError *error alertControllerWithTitle:NSLocalizedString(@"DEBUG_LOG_ALERT_TITLE", @"Title of the debug log alert.") message:NSLocalizedString(@"DEBUG_LOG_ALERT_MESSAGE", @"Message of the debug log alert.") preferredStyle:UIAlertControllerStyleAlert]; - [alert addAction:[UIAlertAction - actionWithTitle:NSLocalizedString(@"DEBUG_LOG_ALERT_OPTION_EMAIL", - @"Label for the 'email debug log' option of the debug log alert.") - style:UIAlertActionStyleDefault - handler:^(UIAlertAction *action) { - [Pastelog.sharedManager submitEmail:url]; - - completion(); - }]]; + [alert + addAction:[UIAlertAction + actionWithTitle:NSLocalizedString(@"DEBUG_LOG_ALERT_OPTION_EMAIL", + @"Label for the 'email debug log' option of the debug log alert.") + accessibilityIdentifier:SUBVIEW_ACCESSIBILITY_IDENTIFIER(self, @"send_email") + style:UIAlertActionStyleDefault + handler:^(UIAlertAction *action) { + [Pastelog.sharedManager submitEmail:url]; + + completion(); + }]]; [alert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"DEBUG_LOG_ALERT_OPTION_COPY_LINK", @"Label for the 'copy link' option of the debug log alert.") + accessibilityIdentifier:SUBVIEW_ACCESSIBILITY_IDENTIFIER(self, @"copy_link") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { UIPasteboard *pb = [UIPasteboard generalPasteboard]; @@ -341,27 +344,32 @@ typedef void (^DebugLogUploadFailure)(DebugLogUploader *uploader, NSError *error [alert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"DEBUG_LOG_ALERT_OPTION_SEND_TO_SELF", @"Label for the 'send to self' option of the debug log alert.") + accessibilityIdentifier:SUBVIEW_ACCESSIBILITY_IDENTIFIER(self, @"send_to_self") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { [Pastelog.sharedManager sendToSelf:url]; }]]; - [alert addAction:[UIAlertAction - actionWithTitle:NSLocalizedString(@"DEBUG_LOG_ALERT_OPTION_SEND_TO_LAST_THREAD", - @"Label for the 'send to last thread' option of the debug log alert.") - style:UIAlertActionStyleDefault - handler:^(UIAlertAction *action) { - [Pastelog.sharedManager sendToMostRecentThread:url]; - }]]; + [alert addAction:[UIAlertAction actionWithTitle: + NSLocalizedString(@"DEBUG_LOG_ALERT_OPTION_SEND_TO_LAST_THREAD", + @"Label for the 'send to last thread' option of the debug log alert.") + accessibilityIdentifier:SUBVIEW_ACCESSIBILITY_IDENTIFIER(self, @"send_to_last_thread") + style:UIAlertActionStyleDefault + handler:^(UIAlertAction *action) { + [Pastelog.sharedManager sendToMostRecentThread:url]; + }]]; #endif - [alert addAction:[UIAlertAction - actionWithTitle:NSLocalizedString(@"DEBUG_LOG_ALERT_OPTION_BUG_REPORT", - @"Label for the 'Open a Bug Report' option of the debug log alert.") - style:UIAlertActionStyleDefault - handler:^(UIAlertAction *action) { - [Pastelog.sharedManager prepareRedirection:url completion:completion]; - }]]; + [alert + addAction: + [UIAlertAction actionWithTitle:NSLocalizedString(@"DEBUG_LOG_ALERT_OPTION_BUG_REPORT", + @"Label for the 'Open a Bug Report' option of the debug log alert.") + accessibilityIdentifier:SUBVIEW_ACCESSIBILITY_IDENTIFIER(self, @"submit_bug_report") + style:UIAlertActionStyleDefault + handler:^(UIAlertAction *action) { + [Pastelog.sharedManager prepareRedirection:url completion:completion]; + }]]; [alert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"DEBUG_LOG_ALERT_OPTION_SHARE", @"Label for the 'Share' option of the debug log alert.") + accessibilityIdentifier:SUBVIEW_ACCESSIBILITY_IDENTIFIER(self, @"share") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { [AttachmentSharing showShareUIForText:url.absoluteString @@ -370,7 +378,11 @@ typedef void (^DebugLogUploadFailure)(DebugLogUploader *uploader, NSError *error [alert addAction:[OWSAlerts cancelAction]]; UIViewController *presentingViewController = UIApplication.sharedApplication.frontmostViewControllerIgnoringAlerts; - [presentingViewController presentViewController:alert animated:NO completion:nil]; + [presentingViewController presentViewController:alert + animated:NO + completion:^{ + [alert applyAccessibilityIdentifiers]; + }]; }]; } @@ -507,10 +519,15 @@ typedef void (^DebugLogUploadFailure)(DebugLogUploader *uploader, NSError *error message:message preferredStyle:UIAlertControllerStyleAlert]; [alert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"OK", @"") + accessibilityIdentifier:SUBVIEW_ACCESSIBILITY_IDENTIFIER(self, @"ok") style:UIAlertActionStyleDefault handler:nil]]; UIViewController *presentingViewController = UIApplication.sharedApplication.frontmostViewControllerIgnoringAlerts; - [presentingViewController presentViewController:alert animated:NO completion:nil]; + [presentingViewController presentViewController:alert + animated:NO + completion:^{ + [alert applyAccessibilityIdentifiers]; + }]; } #pragma mark Logs submission @@ -561,18 +578,25 @@ typedef void (^DebugLogUploadFailure)(DebugLogUploader *uploader, NSError *error message:NSLocalizedString(@"DEBUG_LOG_GITHUB_ISSUE_ALERT_MESSAGE", @"Message of the alert before redirecting to GitHub Issues.") preferredStyle:UIAlertControllerStyleAlert]; - [alert addAction:[UIAlertAction - actionWithTitle:NSLocalizedString(@"OK", @"") - style:UIAlertActionStyleDefault - handler:^(UIAlertAction *action) { - [UIApplication.sharedApplication - openURL:[NSURL URLWithString:[[NSBundle mainBundle] - objectForInfoDictionaryKey:@"LOGS_URL"]]]; - - completion(); - }]]; + [alert + addAction:[UIAlertAction + actionWithTitle:NSLocalizedString(@"OK", @"") + accessibilityIdentifier:SUBVIEW_ACCESSIBILITY_IDENTIFIER(self, @"ok") + style:UIAlertActionStyleDefault + handler:^(UIAlertAction *action) { + [UIApplication.sharedApplication + openURL:[NSURL + URLWithString:[[NSBundle mainBundle] + objectForInfoDictionaryKey:@"LOGS_URL"]]]; + + completion(); + }]]; UIViewController *presentingViewController = UIApplication.sharedApplication.frontmostViewControllerIgnoringAlerts; - [presentingViewController presentViewController:alert animated:NO completion:nil]; + [presentingViewController presentViewController:alert + animated:NO + completion:^{ + [alert applyAccessibilityIdentifiers]; + }]; } - (void)sendToSelf:(NSURL *)url diff --git a/SignalMessaging/categories/UIView+OWS.h b/SignalMessaging/categories/UIView+OWS.h index 7a775e6ef..6ca66a471 100644 --- a/SignalMessaging/categories/UIView+OWS.h +++ b/SignalMessaging/categories/UIView+OWS.h @@ -156,6 +156,17 @@ CGFloat ScaleFromIPhone5(CGFloat iPhone5Value); @end +#pragma mark - + +@interface UIAlertAction (OWS) + ++ (instancetype)actionWithTitle:(nullable NSString *)title + accessibilityIdentifier:(nullable NSString *)accessibilityIdentifier + style:(UIAlertActionStyle)style + handler:(void (^__nullable)(UIAlertAction *action))handler; + +@end + #pragma mark - Macros CGFloat CGHairlineWidth(void); diff --git a/SignalMessaging/categories/UIView+OWS.m b/SignalMessaging/categories/UIView+OWS.m index 8bdc03c17..e58f9354f 100644 --- a/SignalMessaging/categories/UIView+OWS.m +++ b/SignalMessaging/categories/UIView+OWS.m @@ -2,9 +2,10 @@ // Copyright (c) 2019 Open Whisper Systems. All rights reserved. // -#import "UIView+OWS.h" #import "OWSMath.h" +#import "UIView+OWS.h" #import +#import #import NS_ASSUME_NONNULL_BEGIN @@ -594,6 +595,24 @@ CGFloat ScaleFromIPhone5(CGFloat iPhone5Value) @end +#pragma mark - + +@implementation UIAlertAction (OWS) + ++ (instancetype)actionWithTitle:(nullable NSString *)title + accessibilityIdentifier:(nullable NSString *)accessibilityIdentifier + style:(UIAlertActionStyle)style + handler:(void (^__nullable)(UIAlertAction *action))handler +{ + UIAlertAction *action = [UIAlertAction actionWithTitle:title style:style handler:handler]; + action.accessibilityIdentifier = accessibilityIdentifier; + return action; +} + +@end + +#pragma mark - + CGFloat CGHairlineWidth() { return 1.f / UIScreen.mainScreen.scale;