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

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: I4fda45961b684b877adf29a5bf0fee6e03f1ba8d
Reviewed-on: https://chromium-review.googlesource.com/594831Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Commit-Queue: Yuke Liao <liaoyuke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#490840}
parent 6c9464a6
...@@ -7,6 +7,12 @@ ...@@ -7,6 +7,12 @@
#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.
extern NSString* const kLanguagePickerCancelButtonId;
// The accessibility identifier of the done button on language picker view.
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];
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,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"
...@@ -107,20 +108,6 @@ NSString* GetTranslateInfobarSwitchLabel(const std::string& language) { ...@@ -107,20 +108,6 @@ NSString* GetTranslateInfobarSwitchLabel(const std::string& language) {
IDS_TRANSLATE_INFOBAR_ALWAYS_TRANSLATE, base::UTF8ToUTF16(language))); IDS_TRANSLATE_INFOBAR_ALWAYS_TRANSLATE, base::UTF8ToUTF16(language)));
} }
// Returns a matcher for the button with label "Cancel" in the language picker.
// TODO(crbug.com/750344): Change the matcher to use accessibility ID.
id<GREYMatcher> LanguagePickerCancelButton() {
return grey_allOf(chrome_test_util::ButtonWithAccessibilityLabel(@"Cancel"),
grey_userInteractionEnabled(), nil);
}
// Returns a matcher for the button with label "Done" in the language picker.
// TODO(crbug.com/750344): Change the matcher to use accessibility ID.
id<GREYMatcher> LanguagePickerDoneButton() {
return grey_allOf(chrome_test_util::ButtonWithAccessibilityLabel(@"Done"),
grey_userInteractionEnabled(), nil);
}
#pragma mark - TestResponseProvider #pragma mark - TestResponseProvider
// A ResponseProvider that provides html responses of texts in different // A ResponseProvider that provides html responses of texts in different
...@@ -615,9 +602,8 @@ using translate::LanguageDetectionController; ...@@ -615,9 +602,8 @@ 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 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(
// IDS_CANCEL here). kLanguagePickerCancelButtonId)]
[[EarlGrey selectElementWithMatcher:LanguagePickerCancelButton()]
assertWithMatcher:grey_notNil()]; assertWithMatcher:grey_notNil()];
// Change the language using the picker. // Change the language using the picker.
...@@ -628,7 +614,8 @@ using translate::LanguageDetectionController; ...@@ -628,7 +614,8 @@ using translate::LanguageDetectionController;
[[EarlGrey selectElementWithMatcher:languageMatcher] [[EarlGrey selectElementWithMatcher:languageMatcher]
performAction:grey_tap()]; performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:LanguagePickerDoneButton()] [[EarlGrey selectElementWithMatcher:grey_accessibilityID(
kLanguagePickerDoneButtonId)]
performAction:grey_tap()]; performAction:grey_tap()];
[[EarlGrey [[EarlGrey
selectElementWithMatcher:chrome_test_util::ButtonWithAccessibilityLabel( selectElementWithMatcher:chrome_test_util::ButtonWithAccessibilityLabel(
......
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