Commit be3e31b7 authored by Yuke Liao's avatar Yuke Liao Committed by Commit Bot

Reland"Add AX ID for Cancel and Done button on Translate Language Picker."

This reverts commit 6163e501.

The original CL's test fails on iPhone 5s, iOS 9.0 because the 
accessibility identifiers of the buttons are not set even though 
setAccessibilityIdentifier is called explicitly in the code, and it
looks like there is nothing we can do about it. This CL fixes the issue
by keeping using accessbilityLabel on iOS 9 and iOS 10, and switch to
use accessibilityID on iOS 11, and will clean this code up once the
support for iOS 10 is dropped.

Original change's description:
> Add AX ID for Cancel and Done button on Translate Language Picker.
> 
> Currently, the test uses the following matchers to find the cancel and
> done button on language picker:
> 
> grey_allOf(chrome_test_util::ButtonWithAccessibilityLabel(@"Cancel"),
>                     grey_userInteractionEnabled(), nil);
> 
> This is not bullet proof and may break any time, and this CL fixes the
> issue by adding AX ID to both the cancel and done buttons.

Bug: 750344
Change-Id: I57d1c716118049516d93853da77c25d85385aae0
Reviewed-on: https://chromium-review.googlesource.com/599124
Commit-Queue: Yuke Liao <liaoyuke@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#491774}
parent 6be7ecdc
...@@ -7,6 +7,14 @@ ...@@ -7,6 +7,14 @@
#include "ios/chrome/browser/infobars/infobar_controller.h" #include "ios/chrome/browser/infobars/infobar_controller.h"
// The accessibility identifier of the cancel button on language picker view.
// NOTE: this should not be used on iOS 9 for testing.
extern NSString* const kLanguagePickerCancelButtonId;
// The accessibility identifier of the done button on language picker view.
// NOTE: this should not be used on iOS 9 for testing.
extern NSString* const kLanguagePickerDoneButtonId;
@interface BeforeTranslateInfoBarController : InfoBarController @interface BeforeTranslateInfoBarController : InfoBarController
@end @end
......
...@@ -22,6 +22,9 @@ ...@@ -22,6 +22,9 @@
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
NSString* const kLanguagePickerCancelButtonId = @"LanguagePickerCancelButton";
NSString* const kLanguagePickerDoneButtonId = @"LanguagePickerDoneButton";
namespace { namespace {
CGFloat kNavigationBarHeight = 44; CGFloat kNavigationBarHeight = 44;
...@@ -302,10 +305,12 @@ NSTimeInterval kPickerAnimationDurationInSeconds = 0.2; ...@@ -302,10 +305,12 @@ NSTimeInterval kPickerAnimationDurationInSeconds = 0.2;
initWithBarButtonSystemItem:UIBarButtonSystemItemDone initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self target:self
action:@selector(languageSelectionDone)]; action:@selector(languageSelectionDone)];
[doneButton setAccessibilityIdentifier:kLanguagePickerDoneButtonId];
UIBarButtonItem* cancelButton = [[UIBarButtonItem alloc] UIBarButtonItem* cancelButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCancel initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
target:self target:self
action:@selector(dismissLanguageSelectionView)]; action:@selector(dismissLanguageSelectionView)];
[cancelButton setAccessibilityIdentifier:kLanguagePickerCancelButtonId];
UINavigationItem* item = [[UINavigationItem alloc] initWithTitle:@""]; UINavigationItem* item = [[UINavigationItem alloc] initWithTitle:@""];
[item setRightBarButtonItem:doneButton]; [item setRightBarButtonItem:doneButton];
[item setLeftBarButtonItem:cancelButton]; [item setLeftBarButtonItem:cancelButton];
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#import <XCTest/XCTest.h> #import <XCTest/XCTest.h>
#include "base/command_line.h" #include "base/command_line.h"
#include "base/ios/ios_util.h"
#include "base/mac/bind_objc_block.h" #include "base/mac/bind_objc_block.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
...@@ -19,6 +20,7 @@ ...@@ -19,6 +20,7 @@
#import "components/translate/ios/browser/js_translate_manager.h" #import "components/translate/ios/browser/js_translate_manager.h"
#import "components/translate/ios/browser/language_detection_controller.h" #import "components/translate/ios/browser/language_detection_controller.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h" #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/translate/before_translate_infobar_controller.h"
#include "ios/chrome/browser/translate/chrome_ios_translate_client.h" #include "ios/chrome/browser/translate/chrome_ios_translate_client.h"
#import "ios/chrome/test/app/chrome_test_util.h" #import "ios/chrome/test/app/chrome_test_util.h"
#import "ios/chrome/test/app/tab_test_util.h" #import "ios/chrome/test/app/tab_test_util.h"
...@@ -108,17 +110,23 @@ NSString* GetTranslateInfobarSwitchLabel(const std::string& language) { ...@@ -108,17 +110,23 @@ NSString* GetTranslateInfobarSwitchLabel(const std::string& language) {
} }
// Returns a matcher for the button with label "Cancel" in the language picker. // Returns a matcher for the button with label "Cancel" in the language picker.
// TODO(crbug.com/750344): Change the matcher to use accessibility ID. // The language picker uses the system accessibility labels, thus no IDS_CANCEL.
id<GREYMatcher> LanguagePickerCancelButton() { id<GREYMatcher> LanguagePickerCancelButton() {
return grey_allOf(chrome_test_util::ButtonWithAccessibilityLabel(@"Cancel"), // Setting A11y id on this button doesn't work on iOS 9.0.
grey_userInteractionEnabled(), nil); if (base::ios::IsRunningOnIOS10OrLater())
return grey_accessibilityID(kLanguagePickerCancelButtonId);
return chrome_test_util::ButtonWithAccessibilityLabel(@"Cancel");
} }
// Returns a matcher for the button with label "Done" in the language picker. // Returns a matcher for the button with label "Done" in the language picker.
// TODO(crbug.com/750344): Change the matcher to use accessibility ID. // The language picker uses the system accessibility labels, thus no IDS_DONE.
id<GREYMatcher> LanguagePickerDoneButton() { id<GREYMatcher> LanguagePickerDoneButton() {
return grey_allOf(chrome_test_util::ButtonWithAccessibilityLabel(@"Done"), // Setting A11y ID on this button doesn't work on iOS 9.0.
grey_userInteractionEnabled(), nil); if (base::ios::IsRunningOnIOS10OrLater())
return grey_accessibilityID(kLanguagePickerDoneButtonId);
return chrome_test_util::ButtonWithAccessibilityLabel(@"Done");
} }
#pragma mark - TestResponseProvider #pragma mark - TestResponseProvider
...@@ -615,8 +623,6 @@ using translate::LanguageDetectionController; ...@@ -615,8 +623,6 @@ using translate::LanguageDetectionController;
selectElementWithMatcher:chrome_test_util::ButtonWithAccessibilityLabel( selectElementWithMatcher:chrome_test_util::ButtonWithAccessibilityLabel(
kFrench)] performAction:grey_tap()]; kFrench)] performAction:grey_tap()];
// The language picker uses the system accessibility labels (thus no
// IDS_CANCEL here).
[[EarlGrey selectElementWithMatcher:LanguagePickerCancelButton()] [[EarlGrey selectElementWithMatcher:LanguagePickerCancelButton()]
assertWithMatcher:grey_notNil()]; assertWithMatcher:grey_notNil()];
......
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