Commit 4fcce6d7 authored by Chris Lu's avatar Chris Lu Committed by Commit Bot

[ios] Fix BadgeViewController interpretation of badgeState

Since BadgeState is a mask, a direct equality comparison to
BadgeState values for the BadgeItem properties is not the correct
way to assess if a badge is accepted.

To add testing support for this case, accepted a11y identifiers
for BadgeButtons are created, and they will be properly set
in setAccepted: in BadgeButton.

Bug: 976901, 1016793
Change-Id: Id17eb82e0764fbbf80b871df0b974fe148c2339f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1872938
Commit-Queue: Chris Lu <thegreenfrog@chromium.org>
Reviewed-by: default avatarPeter Lee <pkl@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709037}
parent d812bc5c
......@@ -4,6 +4,8 @@
#import "ios/chrome/browser/ui/badges/badge_button.h"
#import "base/logging.h"
#import "ios/chrome/browser/ui/badges/badge_constants.h"
#import "ios/chrome/browser/ui/util/uikit_ui_util.h"
#import "ios/chrome/common/colors/semantic_color_names.h"
......@@ -45,6 +47,7 @@ const CGFloat kButtonCircularCornerRadiusDivisor = 2.0;
self.accepted = accepted;
void (^changeTintColor)() = ^{
self.tintColor = accepted ? nil : [UIColor colorNamed:kToolbarButtonColor];
self.accessibilityIdentifier = [self getAccessibilityIdentifier:accepted];
};
if (animated) {
[UIView animateWithDuration:kButtonAnimationDuration
......@@ -73,6 +76,31 @@ const CGFloat kButtonCircularCornerRadiusDivisor = 2.0;
#pragma mark - Private
- (NSString*)getAccessibilityIdentifier:(BOOL)accepted {
switch (self.badgeType) {
case BadgeType::kBadgeTypeNone:
NOTREACHED() << "A badge should not have kBadgeTypeNone";
return nil;
case BadgeType::kBadgeTypePasswordSave:
return accepted ? kBadgeButtonSavePasswordAcceptedAccessibilityIdentifier
: kBadgeButtonSavePasswordAccessibilityIdentifier;
case BadgeType::kBadgeTypePasswordUpdate:
return accepted
? kBadgeButtonUpdatePasswordAccpetedAccessibilityIdentifier
: kBadgeButtonUpdatePasswordAccessibilityIdentifier;
case BadgeType::kBadgeTypeIncognito:
return kBadgeButtonIncognitoAccessibilityIdentifier;
case BadgeType::kBadgeTypeOverflow:
return kBadgeButtonOverflowAccessibilityIdentifier;
case BadgeType::kBadgeTypeSaveCard:
return accepted ? kBadgeButtonSaveCardAcceptedAccessibilityIdentifier
: kBadgeButtonSaveCardAccessibilityIdentifier;
case BadgeType::kBadgeTypeTranslate:
return accepted ? kBadgeButtonTranslateAcceptedAccessibilityIdentifier
: kBadgeButtonTranslateAccessibilityIdentifier;
}
}
- (void)configureImage {
if (self.fullScreenOn && self.fullScreenImage) {
[self setImage:self.fullScreenImage forState:UIControlStateNormal];
......
......@@ -9,11 +9,16 @@
// A11y identifiers so that automation can tap on BadgeButtons
extern NSString* const kBadgeButtonSavePasswordAccessibilityIdentifier;
extern NSString* const kBadgeButtonSavePasswordAcceptedAccessibilityIdentifier;
extern NSString* const kBadgeButtonUpdatePasswordAccessibilityIdentifier;
extern NSString* const
kBadgeButtonUpdatePasswordAccpetedAccessibilityIdentifier;
extern NSString* const kBadgeButtonIncognitoAccessibilityIdentifier;
extern NSString* const kBadgeButtonOverflowAccessibilityIdentifier;
extern NSString* const kBadgeButtonSaveCardAccessibilityIdentifier;
extern NSString* const kBadgeButtonSaveCardAcceptedAccessibilityIdentifier;
extern NSString* const kBadgeButtonTranslateAccessibilityIdentifier;
extern NSString* const kBadgeButtonTranslateAcceptedAccessibilityIdentifier;
// A11y identifier for the Badge Popup Menu Table View.
extern NSString* const kBadgePopupMenuTableViewAccessibilityIdentifier;
......
......@@ -11,9 +11,15 @@
NSString* const kBadgeButtonSavePasswordAccessibilityIdentifier =
@"badgeButtonSavePasswordAXID";
NSString* const kBadgeButtonSavePasswordAcceptedAccessibilityIdentifier =
@"badgeButtonSavePasswordAcceptedAXID";
NSString* const kBadgeButtonUpdatePasswordAccessibilityIdentifier =
@"badgeButtonUpdatePasswordAXID";
NSString* const kBadgeButtonUpdatePasswordAccpetedAccessibilityIdentifier =
@"badgeButtonUpdatePasswordAcceptedAXID";
NSString* const kBadgeButtonIncognitoAccessibilityIdentifier =
@"badgeButtonIncognitoAXID";
......@@ -23,9 +29,15 @@ NSString* const kBadgeButtonOverflowAccessibilityIdentifier =
NSString* const kBadgeButtonSaveCardAccessibilityIdentifier =
@"badgeButtonSaveCardAXID";
NSString* const kBadgeButtonSaveCardAcceptedAccessibilityIdentifier =
@"badgeButtonSaveCardAcceptedAXID";
NSString* const kBadgeButtonTranslateAccessibilityIdentifier =
@"badgeButtonTranslateAXID";
NSString* const kBadgeButtonTranslateAcceptedAccessibilityIdentifier =
@"badgeButtonTranslateAcceptedAXID";
NSString* const kBadgePopupMenuTableViewAccessibilityIdentifier =
@"badgePopupMenuOverflowAXID";
......
......@@ -89,7 +89,7 @@ const CGFloat kUnreadIndicatorViewHeight = 6.0;
if (displayedBadgeItem) {
BadgeButton* newButton = [self.buttonFactory
getBadgeButtonForBadgeType:displayedBadgeItem.badgeType];
[newButton setAccepted:displayedBadgeItem.badgeState == BadgeStateAccepted
[newButton setAccepted:displayedBadgeItem.badgeState & BadgeStateAccepted
animated:NO];
self.displayedBadge = newButton;
}
......@@ -116,12 +116,12 @@ const CGFloat kUnreadIndicatorViewHeight = 6.0;
if (self.displayedBadge &&
self.displayedBadge.badgeType == displayedBadgeItem.badgeType) {
[self.displayedBadge
setAccepted:displayedBadgeItem.badgeState == BadgeStateAccepted
setAccepted:displayedBadgeItem.badgeState & BadgeStateAccepted
animated:YES];
} else {
BadgeButton* newButton = [self.buttonFactory
getBadgeButtonForBadgeType:displayedBadgeItem.badgeType];
[newButton setAccepted:displayedBadgeItem.badgeState == BadgeStateAccepted
[newButton setAccepted:displayedBadgeItem.badgeState & BadgeStateAccepted
animated:NO];
self.displayedBadge = newButton;
}
......
......@@ -17,9 +17,7 @@
// successfully. If it returns NO no Modal should be presented.
- (BOOL)configureModalViewController;
// Returns YES if the Infobar action was completed successfully. Useful for
// Infobar actions that finish asynchronously to delay marking the Infobar as
// accepted.
// Returns YES if the Infobar Accept action was completed successfully.
- (BOOL)isInfobarAccepted;
// Performs any actions related to an Infobar Banner presentation.
......
......@@ -65,8 +65,7 @@
- (void)translateInfoBarDelegate:(translate::TranslateInfoBarDelegate*)delegate
didChangeTranslateStep:(translate::TranslateStep)step
withErrorType:(translate::TranslateErrors::Type)errorType {
// TODO(crbug.com/1014959): Update currentStep and call
// infobarWasAccepted:forWebState: if translate finished.
// TODO(crbug.com/1014959): implement
}
- (BOOL)translateInfoBarDelegateDidDismissWithoutInteraction:
......
......@@ -9,7 +9,10 @@
// A11y identifier for button that will replace the displayed badge with the
// overflow badge button.
extern NSString* const kSCDisplayedBadgeToggleButton;
extern NSString* const kSCShowOverflowDisplayedBadgeButton;
// A11y identifier for button that will show an accepted displayed button.
extern NSString* const kSCShowAcceptedDisplayedBadgeButton;
@interface SCBadgeCoordinator : NSObject <NavigationCoordinator>
......
......@@ -20,8 +20,11 @@
#error "This file requires ARC support."
#endif
NSString* const kSCDisplayedBadgeToggleButton =
@"kSCDisplayedBadgeToggleButtonAXID";
NSString* const kSCShowOverflowDisplayedBadgeButton =
@"kSCShowOverflowDisplayedBadgeButtonAXID";
NSString* const kSCShowAcceptedDisplayedBadgeButton =
@"kSCShowAcceptedDisplayedBadgeButtonAXID";
@interface BadgeContainerViewController : UIViewController
@property(nonatomic, strong) BadgeViewController* centeredChildViewController;
......@@ -54,13 +57,27 @@ NSString* const kSCDisplayedBadgeToggleButton =
constraintEqualToConstant:100]
]];
UIButton* button = [UIButton buttonWithType:UIButtonTypeSystem];
button.accessibilityIdentifier = kSCDisplayedBadgeToggleButton;
[button setTitle:@"Show Overflow badge" forState:UIControlStateNormal];
[button addTarget:self
action:@selector(addSecondBadge:)
forControlEvents:UIControlEventTouchUpInside];
[stackView addArrangedSubview:button];
UIButton* showAcceptedBadgeButton =
[UIButton buttonWithType:UIButtonTypeSystem];
showAcceptedBadgeButton.accessibilityIdentifier =
kSCShowAcceptedDisplayedBadgeButton;
[showAcceptedBadgeButton setTitle:@"Show Accepted Badge"
forState:UIControlStateNormal];
[showAcceptedBadgeButton addTarget:self
action:@selector(showAcceptedDisplayedBadge)
forControlEvents:UIControlEventTouchUpInside];
[stackView addArrangedSubview:showAcceptedBadgeButton];
UIButton* showOverflowBadgeButton =
[UIButton buttonWithType:UIButtonTypeSystem];
showOverflowBadgeButton.accessibilityIdentifier =
kSCShowOverflowDisplayedBadgeButton;
[showOverflowBadgeButton setTitle:@"Show Overflow badge"
forState:UIControlStateNormal];
[showOverflowBadgeButton addTarget:self
action:@selector(addSecondBadge:)
forControlEvents:UIControlEventTouchUpInside];
[stackView addArrangedSubview:showOverflowBadgeButton];
UIView* containerView = self.view;
containerView.backgroundColor = [UIColor whiteColor];
......@@ -70,6 +87,17 @@ NSString* const kSCDisplayedBadgeToggleButton =
initWithBadgeType:BadgeType::kBadgeTypeIncognito];
InfobarBadgeModel* passwordBadgeItem = [[InfobarBadgeModel alloc]
initWithInfobarType:InfobarType::kInfobarTypePasswordSave];
passwordBadgeItem.badgeState = BadgeStateRead;
[self.consumer setupWithDisplayedBadge:passwordBadgeItem
fullScreenBadge:incognitoItem];
}
- (void)showAcceptedDisplayedBadge {
BadgeStaticItem* incognitoItem = [[BadgeStaticItem alloc]
initWithBadgeType:BadgeType::kBadgeTypeIncognito];
InfobarBadgeModel* passwordBadgeItem = [[InfobarBadgeModel alloc]
initWithInfobarType:InfobarType::kInfobarTypePasswordSave];
passwordBadgeItem.badgeState = BadgeStateRead | BadgeStateAccepted;
[self.consumer setupWithDisplayedBadge:passwordBadgeItem
fullScreenBadge:incognitoItem];
}
......
......@@ -43,11 +43,23 @@ using ::showcase_utils::Close;
kBadgeButtonSavePasswordAccessibilityIdentifier),
grey_sufficientlyVisible(), nil)]
assertWithMatcher:grey_sufficientlyVisible()];
// Tap on button to show the accepted badge.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
kSCShowAcceptedDisplayedBadgeButton)]
performAction:grey_tap()];
[[EarlGrey
selectElementWithMatcher:
grey_allOf(grey_accessibilityID(
kBadgeButtonSavePasswordAccessibilityIdentifier),
grey_sufficientlyVisible(), nil)]
grey_allOf(
grey_accessibilityID(
kBadgeButtonSavePasswordAcceptedAccessibilityIdentifier),
grey_sufficientlyVisible(), nil)]
assertWithMatcher:grey_sufficientlyVisible()];
[[EarlGrey selectElementWithMatcher:
grey_allOf(grey_accessibilityID(
kBadgeButtonIncognitoAccessibilityIdentifier),
grey_sufficientlyVisible(), nil)]
assertWithMatcher:grey_sufficientlyVisible()];
}
......@@ -56,7 +68,7 @@ using ::showcase_utils::Close;
- (void)testOverflowbadge {
// Tap on button to show the overflow badge.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
kSCDisplayedBadgeToggleButton)]
kSCShowOverflowDisplayedBadgeButton)]
performAction:grey_tap()];
// Assert that overflow badge and the unread indicator is shown and tap on it.
......@@ -87,7 +99,7 @@ using ::showcase_utils::Close;
// badge is sufficient here. Assert that the unread indicator is not there
// anymore.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
kSCDisplayedBadgeToggleButton)]
kSCShowOverflowDisplayedBadgeButton)]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:
grey_allOf(grey_accessibilityID(
......
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