Commit 4e09a866 authored by sczs's avatar sczs Committed by Commit Bot

[ios clean] Adds toolbar accessibility support and showcase egtests

-Adds accessibility labels for all ToolbarButtons.
-Creates Showcase EG tests for the ToolbarVC.

BUG=683793

Review-Url: https://codereview.chromium.org/2936773003
Cr-Commit-Position: refs/heads/master@{#481100}
parent 897ac00a
...@@ -1426,6 +1426,9 @@ Your data was encrypted with your sync passphrase on <ph name="TIME">$2<ex>Sept ...@@ -1426,6 +1426,9 @@ Your data was encrypted with your sync passphrase on <ph name="TIME">$2<ex>Sept
<message name="IDS_IOS_TOOLBAR_SHOW_TABS" desc="The accessibility label for the toolbar show tabs button [iOS only]."> <message name="IDS_IOS_TOOLBAR_SHOW_TABS" desc="The accessibility label for the toolbar show tabs button [iOS only].">
Show Tabs Show Tabs
</message> </message>
<message name="IDS_IOS_TOOLBAR_SHOW_TAB_GRID" desc="The accessibility label for the toolbar show tab grid button [iOS only].">
Show Tab Grid
</message>
<message name="IDS_IOS_TOOLS_MENU" desc="The accessibility label for the iOS tools menu [iOS only]"> <message name="IDS_IOS_TOOLS_MENU" desc="The accessibility label for the iOS tools menu [iOS only]">
Tools Menu Tools Menu
</message> </message>
......
...@@ -59,8 +59,11 @@ source_set("toolbar_components_ui") { ...@@ -59,8 +59,11 @@ source_set("toolbar_components_ui") {
] ]
deps = [ deps = [
"//base", "//base",
"//components/strings",
"//ios/chrome/app/strings",
"//ios/chrome/app/theme", "//ios/chrome/app/theme",
"//ios/chrome/browser/ui", "//ios/chrome/browser/ui",
"//ui/base",
] ]
libs = [ "UIKit.framework" ] libs = [ "UIKit.framework" ]
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
......
...@@ -4,9 +4,12 @@ ...@@ -4,9 +4,12 @@
#import "ios/clean/chrome/browser/ui/toolbar/toolbar_button+factory.h" #import "ios/clean/chrome/browser/ui/toolbar/toolbar_button+factory.h"
#include "components/strings/grit/components_strings.h"
#import "ios/chrome/browser/ui/rtl_geometry.h" #import "ios/chrome/browser/ui/rtl_geometry.h"
#import "ios/chrome/browser/ui/uikit_ui_util.h" #import "ios/chrome/browser/ui/uikit_ui_util.h"
#include "ios/chrome/grit/ios_strings.h"
#include "ios/chrome/grit/ios_theme_resources.h" #include "ios/chrome/grit/ios_theme_resources.h"
#include "ui/base/l10n/l10n_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support." #error "This file requires ARC support."
...@@ -26,6 +29,7 @@ ...@@ -26,6 +29,7 @@
imageForDisabledState: imageForDisabledState:
NativeReversableImage( NativeReversableImage(
IDR_IOS_TOOLBAR_LIGHT_BACK_DISABLED, YES)]; IDR_IOS_TOOLBAR_LIGHT_BACK_DISABLED, YES)];
backButton.accessibilityLabel = l10n_util::GetNSString(IDS_ACCNAME_BACK);
return backButton; return backButton;
} }
...@@ -40,6 +44,8 @@ ...@@ -40,6 +44,8 @@
imageForDisabledState: imageForDisabledState:
NativeReversableImage( NativeReversableImage(
IDR_IOS_TOOLBAR_LIGHT_FORWARD_DISABLED, YES)]; IDR_IOS_TOOLBAR_LIGHT_FORWARD_DISABLED, YES)];
forwardButton.accessibilityLabel =
l10n_util::GetNSString(IDS_ACCNAME_FORWARD);
return forwardButton; return forwardButton;
} }
...@@ -51,6 +57,8 @@ ...@@ -51,6 +57,8 @@
NativeImage(IDR_IOS_TOOLBAR_LIGHT_OVERVIEW_PRESSED) NativeImage(IDR_IOS_TOOLBAR_LIGHT_OVERVIEW_PRESSED)
imageForDisabledState: imageForDisabledState:
NativeImage(IDR_IOS_TOOLBAR_LIGHT_OVERVIEW_DISABLED)]; NativeImage(IDR_IOS_TOOLBAR_LIGHT_OVERVIEW_DISABLED)];
tabSwitcherStripButton.accessibilityLabel =
l10n_util::GetNSString(IDS_IOS_TOOLBAR_SHOW_TABS);
return tabSwitcherStripButton; return tabSwitcherStripButton;
} }
...@@ -60,6 +68,8 @@ ...@@ -60,6 +68,8 @@
[UIImage imageNamed:@"tabswitcher_tab_switcher_button"] [UIImage imageNamed:@"tabswitcher_tab_switcher_button"]
imageForHighlightedState:nil imageForHighlightedState:nil
imageForDisabledState:nil]; imageForDisabledState:nil];
tabSwitcherGridButton.accessibilityLabel =
l10n_util::GetNSString(IDS_IOS_TOOLBAR_SHOW_TAB_GRID);
return tabSwitcherGridButton; return tabSwitcherGridButton;
} }
...@@ -71,6 +81,8 @@ ...@@ -71,6 +81,8 @@
NativeImage(IDR_IOS_TOOLBAR_LIGHT_TOOLS_PRESSED) NativeImage(IDR_IOS_TOOLBAR_LIGHT_TOOLS_PRESSED)
imageForDisabledState:nil]; imageForDisabledState:nil];
[toolsMenuButton setImageEdgeInsets:UIEdgeInsetsMakeDirected(0, -3, 0, 0)]; [toolsMenuButton setImageEdgeInsets:UIEdgeInsetsMakeDirected(0, -3, 0, 0)];
toolsMenuButton.accessibilityLabel =
l10n_util::GetNSString(IDS_IOS_TOOLBAR_SETTINGS);
return toolsMenuButton; return toolsMenuButton;
} }
...@@ -82,6 +94,8 @@ ...@@ -82,6 +94,8 @@
NativeImage(IDR_IOS_TOOLBAR_LIGHT_SHARE_PRESSED) NativeImage(IDR_IOS_TOOLBAR_LIGHT_SHARE_PRESSED)
imageForDisabledState: imageForDisabledState:
NativeImage(IDR_IOS_TOOLBAR_LIGHT_SHARE_DISABLED)]; NativeImage(IDR_IOS_TOOLBAR_LIGHT_SHARE_DISABLED)];
shareButton.accessibilityLabel =
l10n_util::GetNSString(IDS_IOS_TOOLS_MENU_SHARE);
return shareButton; return shareButton;
} }
...@@ -96,6 +110,8 @@ ...@@ -96,6 +110,8 @@
imageForDisabledState: imageForDisabledState:
NativeReversableImage( NativeReversableImage(
IDR_IOS_TOOLBAR_LIGHT_RELOAD_DISABLED, YES)]; IDR_IOS_TOOLBAR_LIGHT_RELOAD_DISABLED, YES)];
reloadButton.accessibilityLabel =
l10n_util::GetNSString(IDS_IOS_ACCNAME_RELOAD);
return reloadButton; return reloadButton;
} }
...@@ -107,6 +123,7 @@ ...@@ -107,6 +123,7 @@
NativeImage(IDR_IOS_TOOLBAR_LIGHT_STOP_PRESSED) NativeImage(IDR_IOS_TOOLBAR_LIGHT_STOP_PRESSED)
imageForDisabledState: imageForDisabledState:
NativeImage(IDR_IOS_TOOLBAR_LIGHT_STOP_DISABLED)]; NativeImage(IDR_IOS_TOOLBAR_LIGHT_STOP_DISABLED)];
stopButton.accessibilityLabel = l10n_util::GetNSString(IDS_IOS_ACCNAME_STOP);
return stopButton; return stopButton;
} }
...@@ -117,6 +134,7 @@ ...@@ -117,6 +134,7 @@
imageForHighlightedState: imageForHighlightedState:
NativeImage(IDR_IOS_TOOLBAR_LIGHT_STAR_PRESSED) NativeImage(IDR_IOS_TOOLBAR_LIGHT_STAR_PRESSED)
imageForDisabledState:nil]; imageForDisabledState:nil];
starButton.accessibilityLabel = l10n_util::GetNSString(IDS_TOOLTIP_STAR);
return starButton; return starButton;
} }
......
...@@ -60,6 +60,7 @@ ios_eg_test("ios_showcase_egtests") { ...@@ -60,6 +60,7 @@ ios_eg_test("ios_showcase_egtests") {
"//ios/showcase/root:eg_tests", "//ios/showcase/root:eg_tests",
"//ios/showcase/tab:eg_tests", "//ios/showcase/tab:eg_tests",
"//ios/showcase/tab_grid:eg_tests", "//ios/showcase/tab_grid:eg_tests",
"//ios/showcase/toolbar:eg_tests",
# All shared libraries must have the sanitizer deps to properly link in # All shared libraries must have the sanitizer deps to properly link in
# asan mode (this target will be empty in other cases). # asan mode (this target will be empty in other cases).
......
...@@ -15,3 +15,20 @@ source_set("toolbar") { ...@@ -15,3 +15,20 @@ source_set("toolbar") {
libs = [ "UIKit.framework" ] libs = [ "UIKit.framework" ]
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
} }
source_set("eg_tests") {
testonly = true
sources = [
"sc_toolbar_egtest.mm",
]
deps = [
"//components/strings",
"//ios/chrome/app/strings",
"//ios/chrome/browser/ui",
"//ios/chrome/test/earl_grey:test_support",
"//ios/showcase/test",
"//ios/third_party/earl_grey",
"//ui/base",
]
configs += [ "//build/config/compiler:enable_arc" ]
}
...@@ -44,11 +44,11 @@ CGFloat kToolbarHeight = 50.0f; ...@@ -44,11 +44,11 @@ CGFloat kToolbarHeight = 50.0f;
containerView.backgroundColor = [UIColor redColor]; containerView.backgroundColor = [UIColor redColor];
containerView.translatesAutoresizingMaskIntoConstraints = NO; containerView.translatesAutoresizingMaskIntoConstraints = NO;
ToolbarViewController* toolbarViewController = id dispatcher =
[[ToolbarViewController alloc] init];
toolbarViewController.dispatcher =
static_cast<id<NavigationCommands, TabGridCommands, TabStripCommands, static_cast<id<NavigationCommands, TabGridCommands, TabStripCommands,
ToolsMenuCommands>>(self.alerter); ToolsMenuCommands>>(self.alerter);
ToolbarViewController* toolbarViewController =
[[ToolbarViewController alloc] initWithDispatcher:dispatcher];
[containerViewController addChildViewController:toolbarViewController]; [containerViewController addChildViewController:toolbarViewController];
toolbarViewController.view.frame = containerView.frame; toolbarViewController.view.frame = containerView.frame;
[containerView addSubview:toolbarViewController.view]; [containerView addSubview:toolbarViewController.view];
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import <EarlGrey/EarlGrey.h>
#include "components/strings/grit/components_strings.h"
#import "ios/chrome/browser/ui/uikit_ui_util.h"
#include "ios/chrome/grit/ios_strings.h"
#import "ios/chrome/test/earl_grey/accessibility_util.h"
#import "ios/showcase/test/showcase_eg_utils.h"
#import "ios/showcase/test/showcase_test_case.h"
#include "ui/base/l10n/l10n_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
using ::showcase_utils::Open;
using ::showcase_utils::Close;
}
// Tests for the toolbar view controller.
@interface SCToolbarTestCase : ShowcaseTestCase
@end
@implementation SCToolbarTestCase
- (void)setUp {
[super setUp];
Open(@"ToolbarViewController");
}
- (void)tearDown {
Close();
if ([UIDevice currentDevice].orientation != UIDeviceOrientationPortrait) {
[EarlGrey rotateDeviceToOrientation:UIDeviceOrientationPortrait
errorOrNil:nil];
}
[super tearDown];
}
// Tests if the Toolbar buttons have the right accessibility labels and
// commands.
- (void)testVerifyToolbarButtonsLabelAndAction {
// Buttons displayed in both Regular and Compact SizeClasses.
// Back Button.
[[EarlGrey
selectElementWithMatcher:grey_accessibilityLabel(
l10n_util::GetNSString(IDS_ACCNAME_BACK))]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"goBack")]
assertWithMatcher:grey_notNil()];
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(
@"protocol_alerter_done")]
performAction:grey_tap()];
// Forward Button.
[[EarlGrey
selectElementWithMatcher:grey_accessibilityLabel(
l10n_util::GetNSString(IDS_ACCNAME_FORWARD))]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"goForward")]
assertWithMatcher:grey_notNil()];
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(
@"protocol_alerter_done")]
performAction:grey_tap()];
// ShowTabStrip Button.
[[EarlGrey
selectElementWithMatcher:grey_accessibilityLabel(l10n_util::GetNSString(
IDS_IOS_TOOLBAR_SHOW_TABS))]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"showTabStrip")]
assertWithMatcher:grey_notNil()];
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(
@"protocol_alerter_done")]
performAction:grey_tap()];
// Menu Button.
[[EarlGrey
selectElementWithMatcher:grey_accessibilityLabel(l10n_util::GetNSString(
IDS_IOS_TOOLBAR_SETTINGS))]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"showToolsMenu")]
assertWithMatcher:grey_notNil()];
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(
@"protocol_alerter_done")]
performAction:grey_tap()];
// Buttons displayed only in Regular SizeClass.
if (!IsCompact()) {
// Share Button.
[[EarlGrey
selectElementWithMatcher:grey_accessibilityLabel(l10n_util::GetNSString(
IDS_IOS_TOOLS_MENU_SHARE))]
assertWithMatcher:grey_notNil()];
// Reload Button.
[[EarlGrey
selectElementWithMatcher:grey_accessibilityLabel(l10n_util::GetNSString(
IDS_IOS_ACCNAME_RELOAD))]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"reloadPage")]
assertWithMatcher:grey_notNil()];
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(
@"protocol_alerter_done")]
performAction:grey_tap()];
// Stop Button.
[[EarlGrey
selectElementWithMatcher:grey_accessibilityLabel(l10n_util::GetNSString(
IDS_IOS_ACCNAME_STOP))]
performAction:grey_tap()];
[[EarlGrey
selectElementWithMatcher:grey_accessibilityLabel(@"stopLoadingPage")]
assertWithMatcher:grey_notNil()];
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(
@"protocol_alerter_done")]
performAction:grey_tap()];
}
}
// Tests that the Menu will be closed on rotation from portrait to landscape and
// viceversa.
- (void)testRotation {
// TODO(crbug.com/652464): Enable the test for iPad when rotation bug is
// fixed.
if (IsIPadIdiom()) {
EARL_GREY_TEST_DISABLED(@"Disabled for iPad due to device rotation bug.");
}
// Rotate from portrait to landscape.
if ([EarlGrey rotateDeviceToOrientation:UIDeviceOrientationLandscapeRight
errorOrNil:nil]) {
[[EarlGrey
selectElementWithMatcher:grey_accessibilityLabel(@"closeToolsMenu")]
assertWithMatcher:grey_notNil()];
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(
@"protocol_alerter_done")]
performAction:grey_tap()];
// If successful rotate back from landscape to portrait.
if ([EarlGrey rotateDeviceToOrientation:UIDeviceOrientationPortrait
errorOrNil:nil]) {
[[EarlGrey
selectElementWithMatcher:grey_accessibilityLabel(@"closeToolsMenu")]
assertWithMatcher:grey_notNil()];
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(
@"protocol_alerter_done")]
performAction:grey_tap()];
}
}
}
// Tests that the Regular SizeClass buttons appear when a rotation causes a
// SizeClass change from Compact to Regular. E.g. iPhone Plus rotation from
// portrait to landscape and viceversa.
- (void)testRotationSizeClassChange {
// TODO(crbug.com/652464): Enable the test for iPad when rotation bug is
// fixed.
if (IsIPadIdiom()) {
EARL_GREY_TEST_DISABLED(@"Disabled for iPad due to device rotation bug.");
}
// If currently on compact rotate to check if SizeClass changes to regular.
if (IsCompact()) {
if ([EarlGrey rotateDeviceToOrientation:UIDeviceOrientationLandscapeRight
errorOrNil:nil]) {
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(
@"protocol_alerter_done")]
performAction:grey_tap()];
// If SizeClass is not compact after rotation, confirm that some
// ToolbarButtons are now visible.
if (!IsCompact()) {
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(
l10n_util::GetNSString(
IDS_IOS_TOOLS_MENU_SHARE))]
assertWithMatcher:grey_notNil()];
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(
l10n_util::GetNSString(
IDS_IOS_ACCNAME_RELOAD))]
assertWithMatcher:grey_notNil()];
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(
l10n_util::GetNSString(
IDS_IOS_ACCNAME_STOP))]
assertWithMatcher:grey_notNil()];
// Going back to Compact Width.
if ([EarlGrey rotateDeviceToOrientation:UIDeviceOrientationPortrait
errorOrNil:nil]) {
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(
@"protocol_alerter_done")]
performAction:grey_tap()];
[[EarlGrey
selectElementWithMatcher:grey_accessibilityLabel(
l10n_util::GetNSString(
IDS_IOS_TOOLS_MENU_SHARE))]
assertWithMatcher:grey_nil()];
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(
l10n_util::GetNSString(
IDS_IOS_ACCNAME_RELOAD))]
assertWithMatcher:grey_nil()];
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(
l10n_util::GetNSString(
IDS_IOS_ACCNAME_STOP))]
assertWithMatcher:grey_nil()];
}
}
}
}
}
@end
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