0

[views-ax] Set a11y name in ctor of TrayBackgroundView derived classes

This CL is the first of a multi-CL set that will migrate how
TrayBackgroundView and its derived classes set their accessible names.
This initial CL takes care of the simple cases in which each View's
accessible name is a static string. This CL updates each View to set
its accessible name in its constructor.

This CL also changes TrayBackgroundView::GetAccessibleNameForTray from
being a pure virtual function to just a virtual function, meaning it
can be overridden in derived classes but isn't required to be. The base
class implementation for now returns an empty string, and will be
removed in a future CL. The derived classes in this CL have their
callers deleted.

This CL sets up these Views in preparation for a future CL where
TrayBackgroundView::GetAccessibleNodeData and GetAccessibleNameForTray
will be deleted.

As part of the ViewsAX project (link below), we are removing
GetAccessibleNodeData from Views across chromium. This is so that
we can move towards updating Views' accessibility properties whenever
they change ("push" system) instead of just calculating them by
request in GetAccessibleNodeData ("pull" system).

This CL adds relevant test for each View that was updated.

Future CLs will handle more complex cases where the accessible
name for the derived class needs to be updated dynamically.
The final CL will remove TrayBackgroundView::GetAccessibleNodeData
entirely.

This change is part of the ViewsAX project:
https://docs.google.com/document/d/1Ku7HOyDsiZem1yaV6ccZ-tz3lO2XR2NEcm8HjR6d-VY/edit

Bug: 325137417, 379818907
Change-Id: Idad44ee220a25b960ab74bb814c2d8f6f6f6db58
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6026351
Reviewed-by: Mitsuru Oshima <oshima@chromium.org>
Commit-Queue: Evelynn Kaplan <evelynn.kaplan@microsoft.com>
Cr-Commit-Position: refs/heads/main@{#1385408}
This commit is contained in:
Evelynn Kaplan
2024-11-20 02:44:04 +00:00
committed by Chromium LUCI CQ
parent 754e5905f7
commit ab794b583e
50 changed files with 346 additions and 154 deletions

@ -4328,6 +4328,7 @@ test("ash_unittests") {
"system/phonehub/quick_actions_view_unittest.cc",
"system/phonehub/silence_phone_quick_action_controller_unittest.cc",
"system/phonehub/task_continuation_view_unittest.cc",
"system/pods_overflow_tray_unittest.cc",
"system/power/adaptive_charging_controller_unittest.cc",
"system/power/adaptive_charging_notification_controller_unittest.cc",
"system/power/backlights_forced_off_setter_unittest.cc",

@ -4936,6 +4936,25 @@ TEST_F(CaptureModeTest, KeyboardShortcutTest) {
EndRecordingReason::kKeyboardShortcut, 1);
}
TEST_F(CaptureModeTest, StopRecordingButtonTrayAccessibleName) {
ash::CaptureModeTestApi test_api;
test_api.StartForFullscreen(/*for_video=*/true);
test_api.PerformCapture();
test_api.FlushRecordingServiceForTesting();
auto* stop_recording_button = Shell::GetPrimaryRootWindowController()
->GetStatusAreaWidget()
->stop_recording_button_tray();
EXPECT_TRUE(stop_recording_button->visible_preferred());
ui::AXNodeData tray_data;
stop_recording_button->GetViewAccessibility().GetAccessibleNodeData(
&tray_data);
EXPECT_EQ(tray_data.GetString16Attribute(ax::mojom::StringAttribute::kName),
l10n_util::GetStringUTF16(
IDS_ASH_STATUS_AREA_STOP_RECORDING_BUTTON_ACCESSIBLE_NAME));
}
namespace {
// -----------------------------------------------------------------------------

@ -17,6 +17,7 @@
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/controls/image_view.h"
namespace ash {
@ -33,7 +34,10 @@ StopRecordingButtonTray::StopRecordingButtonTray(Shelf* shelf)
CaptureModeController::Get()->EndVideoRecording(
EndRecordingReason::kStopRecordingButton);
}));
image_view_->SetTooltipText(GetAccessibleNameForTray());
GetViewAccessibility().SetName(l10n_util::GetStringUTF16(
IDS_ASH_STATUS_AREA_STOP_RECORDING_BUTTON_ACCESSIBLE_NAME));
image_view_->SetTooltipText(l10n_util::GetStringUTF16(
IDS_ASH_STATUS_AREA_STOP_RECORDING_BUTTON_ACCESSIBLE_NAME));
image_view_->SetHorizontalAlignment(views::ImageView::Alignment::kCenter);
image_view_->SetVerticalAlignment(views::ImageView::Alignment::kCenter);
image_view_->SetPreferredSize(gfx::Size(kTrayItemSize, kTrayItemSize));
@ -41,11 +45,6 @@ StopRecordingButtonTray::StopRecordingButtonTray(Shelf* shelf)
StopRecordingButtonTray::~StopRecordingButtonTray() = default;
std::u16string StopRecordingButtonTray::GetAccessibleNameForTray() {
return l10n_util::GetStringUTF16(
IDS_ASH_STATUS_AREA_STOP_RECORDING_BUTTON_ACCESSIBLE_NAME);
}
void StopRecordingButtonTray::OnThemeChanged() {
TrayBackgroundView::OnThemeChanged();
image_view_->SetImage(gfx::CreateVectorIcon(

@ -31,12 +31,14 @@ class StopRecordingButtonTray : public TrayBackgroundView {
~StopRecordingButtonTray() override;
private:
FRIEND_TEST_ALL_PREFIXES(CaptureModeTest,
StopRecordingButtonTrayAccessibleName);
// TrayBackgroundView:
void ClickedOutsideBubble(const ui::LocatedEvent& event) override {}
// No need to override since this view doesn't have an active/inactive state
// Clicking on it will stop the recording and make this view disappear.
void UpdateTrayItemColor(bool is_active) override {}
std::u16string GetAccessibleNameForTray() override;
void HandleLocaleChange() override {}
void HideBubbleWithView(const TrayBubbleView* bubble_view) override {}
void OnThemeChanged() override;

@ -30,6 +30,7 @@
#include "ui/color/color_id.h"
#include "ui/compositor/layer.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/border.h"
#include "ui/views/controls/image_view.h"
@ -89,6 +90,9 @@ DictationButtonTray::DictationButtonTray(
shell->accessibility_controller()->AddObserver(this);
shell->session_controller()->AddObserver(this);
shell->window_tree_host_manager()->input_method()->AddObserver(this);
GetViewAccessibility().SetName(
l10n_util::GetStringUTF16(IDS_ASH_DICTATION_BUTTON_ACCESSIBLE_NAME));
}
DictationButtonTray::~DictationButtonTray() {
@ -149,10 +153,6 @@ void DictationButtonTray::UpdateTrayItemColor(bool is_active) {
}
}
std::u16string DictationButtonTray::GetAccessibleNameForTray() {
return l10n_util::GetStringUTF16(IDS_ASH_DICTATION_BUTTON_ACCESSIBLE_NAME);
}
void DictationButtonTray::HandleLocaleChange() {
icon_->SetTooltipText(
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ACCESSIBILITY_DICTATION));

@ -60,7 +60,6 @@ class ASH_EXPORT DictationButtonTray : public TrayBackgroundView,
void Initialize() override;
void ClickedOutsideBubble(const ui::LocatedEvent& event) override;
void UpdateTrayItemColor(bool is_active) override;
std::u16string GetAccessibleNameForTray() override;
void HandleLocaleChange() override;
void HideBubbleWithView(const TrayBubbleView* bubble_view) override;
void OnThemeChanged() override;

@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "ash/system/accessibility/dictation_button_tray.h"
#include <memory>
#include "ash/accessibility/accessibility_controller.h"
@ -16,6 +17,7 @@
#include "ash/rotator/screen_rotation_animator.h"
#include "ash/session/session_controller_impl.h"
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/style/ash_color_id.h"
#include "ash/system/progress_indicator/progress_indicator.h"
#include "ash/system/status_area_widget.h"
@ -43,6 +45,7 @@
#include "ui/base/ime/ash/input_method_ash.h"
#include "ui/base/ime/fake_text_input_client.h"
#include "ui/base/ime/text_input_type.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
#include "ui/display/display_switches.h"
#include "ui/display/manager/display_manager.h"
@ -52,6 +55,7 @@
#include "ui/gfx/color_palette.h"
#include "ui/gfx/image/image_unittest_util.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/controls/image_view.h"
#include "ui/wm/core/window_util.h"
@ -140,13 +144,19 @@ class DictationButtonTrayTest : public AshTestBase {
};
// Ensures that creation doesn't cause any crashes and adds the image icon.
// Also checks that the tray is visible.
// Also checks that the tray is visible and has an accessible name.
TEST_F(DictationButtonTrayTest, BasicConstruction) {
AccessibilityController* controller =
Shell::Get()->accessibility_controller();
controller->dictation().SetEnabled(true);
EXPECT_TRUE(GetImageView(GetTray()));
EXPECT_TRUE(GetTray()->GetVisible());
ui::AXNodeData tray_data;
GetTray()->GetViewAccessibility().GetAccessibleNodeData(&tray_data);
EXPECT_EQ(
tray_data.GetString16Attribute(ax::mojom::StringAttribute::kName),
l10n_util::GetStringUTF16(IDS_ASH_DICTATION_BUTTON_ACCESSIBLE_NAME));
}
// Test that clicking the button activates dictation.

@ -21,6 +21,7 @@
#include "ui/base/models/image_model.h"
#include "ui/color/color_id.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/border.h"
#include "ui/views/controls/image_view.h"
@ -58,6 +59,9 @@ MouseKeysTray::MouseKeysTray(Shelf* shelf,
// Observe the accessibility controller state changes to know when mouse keys
// state is updated or when it is disabled/enabled.
Shell::Get()->accessibility_controller()->AddObserver(this);
GetViewAccessibility().SetName(
l10n_util::GetStringUTF16(IDS_ASH_MOUSE_KEYS_TRAY_ACCESSIBLE_NAME));
}
MouseKeysTray::~MouseKeysTray() {
@ -79,10 +83,6 @@ void MouseKeysTray::Initialize() {
HandleLocaleChange();
}
std::u16string MouseKeysTray::GetAccessibleNameForTray() {
return l10n_util::GetStringUTF16(IDS_ASH_MOUSE_KEYS_TRAY_ACCESSIBLE_NAME);
}
void MouseKeysTray::HandleLocaleChange() {
GetIcon()->SetTooltipText(
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ACCESSIBILITY_MOUSE_KEYS));

@ -5,8 +5,6 @@
#ifndef ASH_SYSTEM_ACCESSIBILITY_MOUSE_KEYS_MOUSE_KEYS_TRAY_H_
#define ASH_SYSTEM_ACCESSIBILITY_MOUSE_KEYS_MOUSE_KEYS_TRAY_H_
#include <string>
#include "ash/accessibility/accessibility_observer.h"
#include "ash/ash_export.h"
#include "ash/constants/tray_background_view_catalog.h"
@ -37,7 +35,6 @@ class ASH_EXPORT MouseKeysTray : public TrayBackgroundView,
// TrayBackgroundView:
void Initialize() override;
std::u16string GetAccessibleNameForTray() override;
void HandleLocaleChange() override;
void HideBubbleWithView(const TrayBubbleView* bubble_view) override {}
void HideBubble(const TrayBubbleView* bubble_view) override {}

@ -6,12 +6,15 @@
#include "ash/accessibility/accessibility_controller.h"
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/system/status_area_widget.h"
#include "ash/system/status_area_widget_test_helper.h"
#include "ash/test/ash_test_base.h"
#include "base/test/scoped_feature_list.h"
#include "ui/accessibility/accessibility_features.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/events/base_event_utils.h"
#include "ui/views/accessibility/view_accessibility.h"
namespace ash {
@ -73,6 +76,14 @@ TEST_F(MouseKeysTrayTest, OverriddenFunctionsDoNothing) {
GetTray()->ClickedOutsideBubble(event);
}
// Tests that the accessible name is set correctly in the accessibility cache.
TEST_F(MouseKeysTrayTest, AccessibleName) {
ui::AXNodeData tray_data;
GetTray()->GetViewAccessibility().GetAccessibleNodeData(&tray_data);
EXPECT_EQ(tray_data.GetString16Attribute(ax::mojom::StringAttribute::kName),
l10n_util::GetStringUTF16(IDS_ASH_MOUSE_KEYS_TRAY_ACCESSIBLE_NAME));
}
using MouseKeysTrayTestFeatureDisabled = AshTestBase;
TEST_F(MouseKeysTrayTestFeatureDisabled, TrayHidden) {

@ -21,6 +21,7 @@
#include "ui/base/models/image_model.h"
#include "ui/color/color_id.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/border.h"
#include "ui/views/controls/image_view.h"
@ -101,6 +102,9 @@ SelectToSpeakTray::SelectToSpeakTray(Shelf* shelf,
// Observe the accessibility controller state changes to know when Select to
// Speak state is updated or when it is disabled/enabled.
Shell::Get()->accessibility_controller()->AddObserver(this);
GetViewAccessibility().SetName(
l10n_util::GetStringUTF16(IDS_ASH_SELECT_TO_SPEAK_TRAY_ACCESSIBLE_NAME));
}
SelectToSpeakTray::~SelectToSpeakTray() {
@ -121,11 +125,6 @@ void SelectToSpeakTray::Initialize() {
UpdateUXOnCurrentStatus();
}
std::u16string SelectToSpeakTray::GetAccessibleNameForTray() {
return l10n_util::GetStringUTF16(
IDS_ASH_SELECT_TO_SPEAK_TRAY_ACCESSIBLE_NAME);
}
void SelectToSpeakTray::HandleLocaleChange() {
const auto select_to_speak_state =
Shell::Get()->accessibility_controller()->GetSelectToSpeakState();

@ -35,7 +35,6 @@ class ASH_EXPORT SelectToSpeakTray : public TrayBackgroundView,
// TrayBackgroundView:
void Initialize() override;
std::u16string GetAccessibleNameForTray() override;
void HandleLocaleChange() override;
void OnThemeChanged() override;
// The SelectToSpeakTray does not have a bubble, so these functions are

@ -28,6 +28,7 @@
#include "ui/events/event.h"
#include "ui/gfx/image/image_unittest_util.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
@ -92,10 +93,16 @@ class SelectToSpeakTrayTest : public AshTestBase {
};
// Ensures that creation doesn't cause any crashes and adds the image icon.
// Also checks that the tray is visible.
// Also checks that the tray is visible and has an accessible name.
TEST_F(SelectToSpeakTrayTest, BasicConstruction) {
EXPECT_TRUE(GetImageView());
EXPECT_TRUE(IsVisible());
ui::AXNodeData tray_data;
GetTray()->GetViewAccessibility().GetAccessibleNodeData(&tray_data);
EXPECT_EQ(
tray_data.GetString16Attribute(ax::mojom::StringAttribute::kName),
l10n_util::GetStringUTF16(IDS_ASH_SELECT_TO_SPEAK_TRAY_ACCESSIBLE_NAME));
}
// Tests the icon disapears when select-to-speak is disabled and re-appears

@ -72,6 +72,7 @@
#include "ui/gfx/text_constants.h"
#include "ui/gfx/vector_icon_types.h"
#include "ui/strings/grit/ui_strings.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/border.h"
#include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/button/image_button_factory.h"
@ -228,12 +229,14 @@ EcheTray::EcheTray(Shelf* shelf)
// Observers setup
// Note: `ScreenLayoutObserver` starts observing at its constructor.
observed_session_.Observe(Shell::Get()->session_controller());
icon_->SetTooltipText(GetAccessibleNameForTray());
icon_->SetTooltipText(GetAccessibleName());
UpdateTrayItemColor(is_active());
shelf_observation_.Observe(shelf);
shell_observer_.Observe(Shell::Get());
keyboard_observation_.Observe(keyboard::KeyboardUIController::Get());
GetViewAccessibility().SetName(GetAccessibleName());
}
EcheTray::~EcheTray() {
@ -261,14 +264,8 @@ void EcheTray::UpdateTrayItemColor(bool is_active) {
: cros_tokens::kCrosSysOnSurface));
}
std::u16string EcheTray::GetAccessibleNameForTray() {
// TODO(nayebi): Change this based on the final model of interaction
// between phone hub and Eche.
return l10n_util::GetStringUTF16(IDS_ASH_PHONE_HUB_TRAY_ACCESSIBLE_NAME);
}
void EcheTray::HandleLocaleChange() {
icon_->SetTooltipText(GetAccessibleNameForTray());
icon_->SetTooltipText(GetAccessibleName());
}
void EcheTray::HideBubbleWithView(const TrayBubbleView* bubble_view) {
@ -354,7 +351,7 @@ bool EcheTray::CacheBubbleViewForHide() const {
}
std::u16string EcheTray::GetAccessibleNameForBubble() {
return GetAccessibleNameForTray();
return GetAccessibleName();
}
bool EcheTray::ShouldEnableExtraKeyboardAccessibility() {
@ -856,6 +853,12 @@ views::ImageButton* EcheTray::GetIcon() {
return phone_hub_tray->eche_icon_view();
}
std::u16string EcheTray::GetAccessibleName() {
// TODO(nayebi): Change this based on the final model of interaction
// between phone hub and Eche.
return l10n_util::GetStringUTF16(IDS_ASH_PHONE_HUB_TRAY_ACCESSIBLE_NAME);
}
void EcheTray::ResizeIcon(int offset_dip) {
views::ImageButton* icon_view = GetIcon();
if (icon_view) {

@ -139,7 +139,6 @@ class ASH_EXPORT EcheTray
// TrayBackgroundView:
void ClickedOutsideBubble(const ui::LocatedEvent& event) override;
void UpdateTrayItemColor(bool is_active) override;
std::u16string GetAccessibleNameForTray() override;
void HandleLocaleChange() override;
void HideBubbleWithView(const TrayBubbleView* bubble_view) override;
void AnchorUpdated() override;
@ -271,6 +270,8 @@ class ASH_EXPORT EcheTray
}
views::ImageButton* GetIcon();
std::u16string GetAccessibleName();
private:
FRIEND_TEST_ALL_PREFIXES(EcheTrayTest, EcheTrayCreatesBubbleButHideFirst);
FRIEND_TEST_ALL_PREFIXES(EcheTrayTest, EcheTrayOnDisplayConfigurationChanged);

@ -649,7 +649,16 @@ TEST_F(EcheTrayTest, OnConnectionStatusChanged) {
EXPECT_TRUE(eche_tray()->get_initializer_webview_for_test());
}
TEST_F(EcheTrayTest, BubbleViewAccessibleName) {
TEST_F(EcheTrayTest, AccessibleNames) {
ASSERT_TRUE(eche_tray());
{
ui::AXNodeData node_data;
eche_tray()->GetViewAccessibility().GetAccessibleNodeData(&node_data);
EXPECT_EQ(node_data.GetString16Attribute(ax::mojom::StringAttribute::kName),
eche_tray()->GetAccessibleName());
}
eche_tray()->LoadBubble(
GURL("http://google.com"), CreateTestImage(), u"app 1", u"your phone",
eche_app::mojom::ConnectionStatus::kConnectionStatusDisconnected,
@ -658,10 +667,12 @@ TEST_F(EcheTrayTest, BubbleViewAccessibleName) {
auto* bubble_view = eche_tray()->get_bubble_wrapper_for_test()->bubble_view();
EXPECT_TRUE(bubble_view->GetVisible());
ui::AXNodeData node_data;
bubble_view->GetViewAccessibility().GetAccessibleNodeData(&node_data);
EXPECT_EQ(node_data.GetString16Attribute(ax::mojom::StringAttribute::kName),
eche_tray()->GetAccessibleNameForBubble());
{
ui::AXNodeData node_data;
bubble_view->GetViewAccessibility().GetAccessibleNodeData(&node_data);
EXPECT_EQ(node_data.GetString16Attribute(ax::mojom::StringAttribute::kName),
eche_tray()->GetAccessibleNameForBubble());
}
}
} // namespace ash

@ -54,6 +54,7 @@
#include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/gfx/geometry/transform_util.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/animation/animation_builder.h"
#include "ui/views/animation/ink_drop.h"
#include "ui/views/controls/image_view.h"
@ -272,6 +273,10 @@ HoldingSpaceTray::HoldingSpaceTray(Shelf* shelf)
// Enable context menu, which supports an action to toggle item previews.
SetContextMenuEnabled(true);
GetViewAccessibility().SetName(l10n_util::GetStringFUTF16(
IDS_ASH_HOLDING_SPACE_A11Y_NAME,
l10n_util::GetStringUTF16(IDS_ASH_HOLDING_SPACE_TITLE)));
}
HoldingSpaceTray::~HoldingSpaceTray() = default;
@ -297,12 +302,6 @@ void HoldingSpaceTray::ClickedOutsideBubble(const ui::LocatedEvent& event) {
CloseBubble();
}
std::u16string HoldingSpaceTray::GetAccessibleNameForTray() {
return l10n_util::GetStringFUTF16(
IDS_ASH_HOLDING_SPACE_A11Y_NAME,
l10n_util::GetStringUTF16(IDS_ASH_HOLDING_SPACE_TITLE));
}
views::View* HoldingSpaceTray::GetTooltipHandlerForPoint(
const gfx::Point& point) {
// Tooltip events should be handled top level, not by descendents.
@ -528,7 +527,9 @@ void HoldingSpaceTray::FirePreviewsUpdateTimerIfRunningForTesting() {
}
std::u16string HoldingSpaceTray::GetAccessibleNameForBubble() {
return GetAccessibleNameForTray();
return l10n_util::GetStringFUTF16(
IDS_ASH_HOLDING_SPACE_A11Y_NAME,
l10n_util::GetStringUTF16(IDS_ASH_HOLDING_SPACE_TITLE));
}
bool HoldingSpaceTray::ShouldEnableExtraKeyboardAccessibility() {

@ -67,7 +67,6 @@ class ASH_EXPORT HoldingSpaceTray : public TrayBackgroundView,
// TrayBackgroundView:
void Initialize() override;
void ClickedOutsideBubble(const ui::LocatedEvent& event) override;
std::u16string GetAccessibleNameForTray() override;
views::View* GetTooltipHandlerForPoint(const gfx::Point& point) override;
std::u16string GetTooltipText(const gfx::Point& point) const override;
void HandleLocaleChange() override;

@ -2189,13 +2189,6 @@ TEST_F(HoldingSpaceTrayTest, HasExpectedBubbleTreatment) {
EXPECT_EQ(bubble->layer()->rounded_corner_radii(), gfx::RoundedCornersF(0.f));
}
TEST_F(HoldingSpaceTrayTest, CheckTrayAccessibilityText) {
StartSession(/*pre_mark_time_of_first_add=*/true);
GetTray()->FirePreviewsUpdateTimerIfRunningForTesting();
EXPECT_EQ(GetTray()->GetAccessibleNameForTray(),
u"Tote: recent screen captures, downloads, and pinned files");
}
TEST_F(HoldingSpaceTrayTest, TrayButtonWithRefreshIcon) {
StartSession(/*pre_mark_time_of_first_add=*/true);
GetTray()->FirePreviewsUpdateTimerIfRunningForTesting();
@ -2214,17 +2207,27 @@ TEST_F(HoldingSpaceTrayTest, CheckTrayTooltipText) {
EXPECT_EQ(GetTray()->GetTooltipText(gfx::Point()), u"Tote");
}
TEST_F(HoldingSpaceTrayTest, BubbleViewAccessibleName) {
TEST_F(HoldingSpaceTrayTest, AccessibleNames) {
StartSession();
{
ui::AXNodeData node_data;
GetTray()->GetViewAccessibility().GetAccessibleNodeData(&node_data);
EXPECT_EQ(node_data.GetString16Attribute(ax::mojom::StringAttribute::kName),
l10n_util::GetStringFUTF16(
IDS_ASH_HOLDING_SPACE_A11Y_NAME,
l10n_util::GetStringUTF16(IDS_ASH_HOLDING_SPACE_TITLE)));
}
test_api()->Show();
views::View* bubble = test_api()->GetBubble();
ASSERT_TRUE(bubble);
ui::AXNodeData node_data;
bubble->GetViewAccessibility().GetAccessibleNodeData(&node_data);
EXPECT_EQ(node_data.GetString16Attribute(ax::mojom::StringAttribute::kName),
test_api()->GetAccessibleNameForBubble());
{
ui::AXNodeData node_data;
bubble->GetViewAccessibility().GetAccessibleNodeData(&node_data);
EXPECT_EQ(node_data.GetString16Attribute(ax::mojom::StringAttribute::kName),
test_api()->GetAccessibleNameForBubble());
}
}
using HoldingSpacePreviewsTrayTest = HoldingSpaceTrayTestBase;

@ -55,6 +55,7 @@
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/range/range.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/border.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
@ -396,6 +397,9 @@ ImeMenuTray::ImeMenuTray(Shelf* shelf)
// Show the tray even if virtual keyboard is shown. (Other tray buttons will
// be hidden).
set_show_with_virtual_keyboard(true);
GetViewAccessibility().SetName(
l10n_util::GetStringUTF16(IDS_ASH_IME_MENU_ACCESSIBLE_NAME));
}
ImeMenuTray::~ImeMenuTray() {
@ -488,10 +492,6 @@ void ImeMenuTray::OnThemeChanged() {
UpdateTrayLabel();
}
std::u16string ImeMenuTray::GetAccessibleNameForTray() {
return l10n_util::GetStringUTF16(IDS_ASH_IME_MENU_ACCESSIBLE_NAME);
}
void ImeMenuTray::HandleLocaleChange() {
if (image_view_) {
image_view_->SetTooltipText(

@ -54,7 +54,6 @@ class ASH_EXPORT ImeMenuTray : public TrayBackgroundView,
// TrayBackgroundView:
void OnThemeChanged() override;
std::u16string GetAccessibleNameForTray() override;
void HandleLocaleChange() override;
void HideBubbleWithView(const TrayBubbleView* bubble_view) override;
void ClickedOutsideBubble(const ui::LocatedEvent& event) override;

@ -13,6 +13,7 @@
#include "ash/public/cpp/ime_info.h"
#include "ash/session/session_controller_impl.h"
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/system/ime_menu/ime_list_view.h"
#include "ash/system/status_area_widget.h"
#include "ash/system/status_area_widget_test_helper.h"
@ -28,6 +29,7 @@
#include "ui/base/emoji/emoji_panel_helper.h"
#include "ui/base/ime/ash/ime_bridge.h"
#include "ui/base/ime/text_input_flags.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/display/test/display_manager_test_api.h"
#include "ui/events/devices/device_data_manager_test_api.h"
#include "ui/events/devices/input_device.h"
@ -616,19 +618,28 @@ TEST_F(ImeMenuTrayTest, ImeMenuHasBottomInsetsOnLockScreen) {
EXPECT_GT(container_margins->bottom(), 0);
}
TEST_F(ImeMenuTrayTest, BubbleViewAccessibleName) {
TEST_F(ImeMenuTrayTest, AccessibleNames) {
Shell::Get()->ime_controller()->SetExtraInputOptionsEnabledState(
/*is_extra_input_options_enabled=*/true, /*is_emoji_enabled=*/true,
/*is_handwriting_enabled=*/true, /*is_voice_enabled=*/true);
{
ui::AXNodeData node_data;
GetTray()->GetViewAccessibility().GetAccessibleNodeData(&node_data);
EXPECT_EQ(node_data.GetString16Attribute(ax::mojom::StringAttribute::kName),
l10n_util::GetStringUTF16(IDS_ASH_IME_MENU_ACCESSIBLE_NAME));
}
// Show IME tray bubble.
GetTray()->ShowBubble();
TrayBubbleView* bubble_view = GetTray()->GetBubbleView();
ui::AXNodeData node_data;
bubble_view->GetViewAccessibility().GetAccessibleNodeData(&node_data);
EXPECT_EQ(node_data.GetString16Attribute(ax::mojom::StringAttribute::kName),
GetTray()->GetAccessibleNameForBubble());
{
ui::AXNodeData node_data;
bubble_view->GetViewAccessibility().GetAccessibleNodeData(&node_data);
EXPECT_EQ(node_data.GetString16Attribute(ax::mojom::StringAttribute::kName),
GetTray()->GetAccessibleNameForBubble());
}
}
} // namespace ash

@ -41,6 +41,7 @@
#include "ui/display/manager/managed_display_info.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/border.h"
#include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/image_view.h"
@ -218,6 +219,8 @@ MediaTray::MediaTray(Shelf* shelf)
IDS_ASH_GLOBAL_MEDIA_CONTROLS_BUTTON_TOOLTIP_TEXT));
icon_ = tray_container()->AddChildView(std::move(icon));
UpdateTrayItemColor(is_active());
GetViewAccessibility().SetName(l10n_util::GetStringUTF16(
IDS_ASH_GLOBAL_MEDIA_CONTROLS_BUTTON_TOOLTIP_TEXT));
}
MediaTray::~MediaTray() {
@ -244,11 +247,6 @@ void MediaTray::OnNotificationListViewSizeChanged() {
GetBubbleView()->UpdateBubble();
}
std::u16string MediaTray::GetAccessibleNameForTray() {
return l10n_util::GetStringUTF16(
IDS_ASH_GLOBAL_MEDIA_CONTROLS_BUTTON_TOOLTIP_TEXT);
}
void MediaTray::HideBubble(const TrayBubbleView* bubble_view) {
CloseBubble();
}

@ -69,7 +69,6 @@ class ASH_EXPORT MediaTray : public MediaNotificationProviderObserver,
void OnNotificationListViewSizeChanged() override;
// TrayBackgroundView:
std::u16string GetAccessibleNameForTray() override;
void UpdateAfterLoginStatusChange() override;
void HandleLocaleChange() override;
views::Widget* GetBubbleWidget() const override;

@ -6,6 +6,7 @@
#include "ash/constants/tray_background_view_catalog.h"
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/system/media/media_notification_provider.h"
#include "ash/system/media/mock_media_notification_provider.h"
#include "ash/system/status_area_widget.h"
@ -15,6 +16,7 @@
#include "base/memory/raw_ptr.h"
#include "components/media_message_center/media_notification_view_impl.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/events/event.h"
#include "ui/views/accessibility/view_accessibility.h"
@ -259,15 +261,25 @@ TEST_F(MediaTrayTest, CloseBubbleIsNoopWhenNoBubble) {
media_tray()->CloseBubble();
}
TEST_F(MediaTrayTest, BubbleViewAccessibleName) {
TEST_F(MediaTrayTest, AccessibleNames) {
{
ui::AXNodeData node_data;
media_tray()->GetViewAccessibility().GetAccessibleNodeData(&node_data);
EXPECT_EQ(node_data.GetString16Attribute(ax::mojom::StringAttribute::kName),
l10n_util::GetStringUTF16(
IDS_ASH_GLOBAL_MEDIA_CONTROLS_BUTTON_TOOLTIP_TEXT));
}
media_tray()->ShowBubble();
ASSERT_TRUE(media_tray()->GetBubbleView());
ui::AXNodeData node_data;
media_tray()->GetBubbleView()->GetViewAccessibility().GetAccessibleNodeData(
&node_data);
EXPECT_EQ(node_data.GetString16Attribute(ax::mojom::StringAttribute::kName),
GetAccessibleNameForBubble());
{
ui::AXNodeData node_data;
media_tray()->GetBubbleView()->GetViewAccessibility().GetAccessibleNodeData(
&node_data);
EXPECT_EQ(node_data.GetString16Attribute(ax::mojom::StringAttribute::kName),
GetAccessibleNameForBubble());
}
}
} // namespace ash

@ -30,6 +30,7 @@
#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/animation/ink_drop.h"
#include "ui/views/border.h"
#include "ui/views/controls/image_view.h"
@ -83,6 +84,9 @@ OverviewButtonTray::OverviewButtonTray(Shelf* shelf)
Shell::Get()->overview_controller()->AddObserver(this);
Shell::Get()->tablet_mode_controller()->AddObserver(this);
Shell::Get()->shelf_config()->AddObserver(this);
GetViewAccessibility().SetName(
l10n_util::GetStringUTF16(IDS_ASH_OVERVIEW_BUTTON_ACCESSIBLE_NAME));
}
OverviewButtonTray::~OverviewButtonTray() {
@ -140,10 +144,6 @@ void OverviewButtonTray::UpdateTrayItemColor(bool is_active) {
icon_->SetImage(GetIconImage());
}
std::u16string OverviewButtonTray::GetAccessibleNameForTray() {
return l10n_util::GetStringUTF16(IDS_ASH_OVERVIEW_BUTTON_ACCESSIBLE_NAME);
}
void OverviewButtonTray::HandleLocaleChange() {}
void OverviewButtonTray::HideBubbleWithView(const TrayBubbleView* bubble_view) {

@ -78,7 +78,6 @@ class ASH_EXPORT OverviewButtonTray : public TrayBackgroundView,
void UpdateAfterLoginStatusChange() override;
void ClickedOutsideBubble(const ui::LocatedEvent& event) override;
void UpdateTrayItemColor(bool is_active) override;
std::u16string GetAccessibleNameForTray() override;
void HandleLocaleChange() override;
void HideBubbleWithView(const TrayBubbleView* bubble_view) override;
void OnThemeChanged() override;

@ -14,6 +14,7 @@
#include "ash/rotator/screen_rotation_animator.h"
#include "ash/session/session_controller_impl.h"
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/system/status_area_widget.h"
#include "ash/system/status_area_widget_test_helper.h"
#include "ash/test/ash_test_base.h"
@ -32,6 +33,7 @@
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/client/window_types.h"
#include "ui/aura/window.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/mojom/ui_base_types.mojom-shared.h"
#include "ui/compositor/layer_tree_owner.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
@ -44,6 +46,7 @@
#include "ui/events/event.h"
#include "ui/events/gestures/gesture_types.h"
#include "ui/events/types/event_type.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/controls/image_view.h"
#include "ui/wm/core/window_util.h"
@ -115,8 +118,14 @@ class OverviewButtonTrayTest : public AshTestBase {
};
// Ensures that creation doesn't cause any crashes and adds the image icon.
// Ensures that the accessible name gets set on construction.
TEST_F(OverviewButtonTrayTest, BasicConstruction) {
EXPECT_TRUE(GetImageView(GetTray()));
ui::AXNodeData node_data;
GetTray()->GetViewAccessibility().GetAccessibleNodeData(&node_data);
EXPECT_EQ(node_data.GetString16Attribute(ax::mojom::StringAttribute::kName),
l10n_util::GetStringUTF16(IDS_ASH_OVERVIEW_BUTTON_ACCESSIBLE_NAME));
}
// Test that tablet mode toggle changes visibility.

@ -58,6 +58,7 @@
#include "ui/events/devices/stylus_state.h"
#include "ui/events/event_constants.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/border.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
@ -212,6 +213,9 @@ PaletteTray::PaletteTray(Shelf* shelf)
Shell::Get()->display_manager()->AddDisplayManagerObserver(this);
shelf->AddObserver(this);
GetViewAccessibility().SetName(
l10n_util::GetStringUTF16(IDS_ASH_STYLUS_TOOLS_TITLE));
}
PaletteTray::~PaletteTray() {
@ -397,10 +401,6 @@ void PaletteTray::OnThemeChanged() {
UpdateTrayIcon();
}
std::u16string PaletteTray::GetAccessibleNameForTray() {
return l10n_util::GetStringUTF16(IDS_ASH_STYLUS_TOOLS_TITLE);
}
void PaletteTray::HandleLocaleChange() {
icon_->SetTooltipText(l10n_util::GetStringUTF16(IDS_ASH_STYLUS_TOOLS_TITLE));
}
@ -467,7 +467,7 @@ void PaletteTray::BubbleViewDestroyed() {
}
std::u16string PaletteTray::GetAccessibleNameForBubble() {
return GetAccessibleNameForTray();
return l10n_util::GetStringUTF16(IDS_ASH_STYLUS_TOOLS_TITLE);
}
bool PaletteTray::ShouldEnableExtraKeyboardAccessibility() {

@ -103,7 +103,6 @@ class ASH_EXPORT PaletteTray : public TrayBackgroundView,
void ClickedOutsideBubble(const ui::LocatedEvent& event) override;
void UpdateTrayItemColor(bool is_active) override;
void OnThemeChanged() override;
std::u16string GetAccessibleNameForTray() override;
void HandleLocaleChange() override;
void HideBubbleWithView(const TrayBubbleView* bubble_view) override;
void AnchorUpdated() override;

@ -16,6 +16,7 @@
#include "ash/session/session_controller_impl.h"
#include "ash/session/test_session_controller_client.h"
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/system/palette/palette_tray_test_api.h"
#include "ash/system/palette/palette_utils.h"
#include "ash/system/palette/palette_welcome_bubble.h"
@ -32,6 +33,7 @@
#include "base/test/simple_test_tick_clock.h"
#include "components/prefs/pref_service.h"
#include "components/session_manager/session_manager_types.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
#include "ui/display/manager/display_manager.h"
#include "ui/display/test/display_manager_test_api.h"
@ -480,20 +482,29 @@ TEST_F(PaletteTrayTestWithInternalStylus, PaletteBubbleShownOnEject) {
PaletteToolId::LASER_POINTER));
}
// Verify that palette bubble is shown/hidden on stylus eject/insert iff the
// auto open palette setting is true.
TEST_F(PaletteTrayTestWithInternalStylus, PaletteBubbleViewAccessibleName) {
// Verify that palette tray and bubble view have the correct accessible names.
TEST_F(PaletteTrayTestWithInternalStylus, AccessibleNames) {
active_user_pref_service()->SetBoolean(prefs::kEnableStylusTools, true);
{
ui::AXNodeData node_data;
palette_tray_->GetViewAccessibility().GetAccessibleNodeData(&node_data);
EXPECT_EQ(node_data.GetString16Attribute(ax::mojom::StringAttribute::kName),
l10n_util::GetStringUTF16(IDS_ASH_STYLUS_TOOLS_TITLE));
}
// Removing the stylus shows the bubble.
EjectStylus();
ASSERT_TRUE(palette_tray_->GetBubbleView());
ui::AXNodeData node_data;
palette_tray_->GetBubbleView()->GetViewAccessibility().GetAccessibleNodeData(
&node_data);
EXPECT_EQ(node_data.GetString16Attribute(ax::mojom::StringAttribute::kName),
test_api_->GetAccessibleNameForBubble());
{
ui::AXNodeData node_data;
palette_tray_->GetBubbleView()
->GetViewAccessibility()
.GetAccessibleNodeData(&node_data);
EXPECT_EQ(node_data.GetString16Attribute(ax::mojom::StringAttribute::kName),
test_api_->GetAccessibleNameForBubble());
}
}
// Base class for tests that need to simulate an internal stylus, and need to

@ -58,6 +58,7 @@
#include "ui/events/event.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/border.h"
#include "ui/views/controls/button/button_controller.h"
#include "ui/views/controls/image_view.h"
@ -158,6 +159,9 @@ PhoneHubTray::PhoneHubTray(Shelf* shelf)
: nullptr;
Shell::Get()->display_manager()->AddDisplayManagerObserver(this);
GetViewAccessibility().SetName(
l10n_util::GetStringUTF16(IDS_ASH_PHONE_HUB_TRAY_ACCESSIBLE_NAME));
}
PhoneHubTray::~PhoneHubTray() {
@ -204,10 +208,6 @@ void PhoneHubTray::UpdateTrayItemColor(bool is_active) {
: cros_tokens::kCrosSysOnSurface));
}
std::u16string PhoneHubTray::GetAccessibleNameForTray() {
return l10n_util::GetStringUTF16(IDS_ASH_PHONE_HUB_TRAY_ACCESSIBLE_NAME);
}
void PhoneHubTray::HandleLocaleChange() {
icon_->SetTooltipText(
l10n_util::GetStringUTF16(IDS_ASH_PHONE_HUB_TRAY_ACCESSIBLE_NAME));
@ -219,7 +219,7 @@ void PhoneHubTray::HideBubbleWithView(const TrayBubbleView* bubble_view) {
}
std::u16string PhoneHubTray::GetAccessibleNameForBubble() {
return GetAccessibleNameForTray();
return l10n_util::GetStringUTF16(IDS_ASH_PHONE_HUB_TRAY_ACCESSIBLE_NAME);
}
bool PhoneHubTray::ShouldEnableExtraKeyboardAccessibility() {

@ -71,7 +71,6 @@ class ASH_EXPORT PhoneHubTray : public TrayBackgroundView,
// TrayBackgroundView:
void ClickedOutsideBubble(const ui::LocatedEvent& event) override;
void UpdateTrayItemColor(bool is_active) override;
std::u16string GetAccessibleNameForTray() override;
void HandleLocaleChange() override;
void HideBubbleWithView(const TrayBubbleView* bubble_view) override;
void AnchorUpdated() override;
@ -132,7 +131,7 @@ class ASH_EXPORT PhoneHubTray : public TrayBackgroundView,
FRIEND_TEST_ALL_PREFIXES(PhoneHubTrayTest, EcheIconActivatesCallback);
FRIEND_TEST_ALL_PREFIXES(PhoneHubTrayTest, SafeAccessToHeaderView);
FRIEND_TEST_ALL_PREFIXES(PhoneHubTrayTest, TrayPressedMetrics);
FRIEND_TEST_ALL_PREFIXES(PhoneHubTrayTest, BubbleViewAccessibleName);
FRIEND_TEST_ALL_PREFIXES(PhoneHubTrayTest, AccessibleNames);
// TrayBubbleView::Delegate:
std::u16string GetAccessibleNameForBubble() override;

@ -832,7 +832,15 @@ TEST_F(PhoneHubTrayTest, TrayPressedMetrics) {
histogram_tester.ExpectTotalCount(kTrayBackgroundViewHistogramName, 3);
}
TEST_F(PhoneHubTrayTest, BubbleViewAccessibleName) {
TEST_F(PhoneHubTrayTest, AccessibleNames) {
{
ui::AXNodeData node_data;
phone_hub_tray_->GetViewAccessibility().GetAccessibleNodeData(&node_data);
EXPECT_EQ(
node_data.GetString16Attribute(ax::mojom::StringAttribute::kName),
l10n_util::GetStringUTF16(IDS_ASH_PHONE_HUB_TRAY_ACCESSIBLE_NAME));
}
Shell::Get()->focus_cycler()->FocusWidget(phone_hub_tray_->GetWidget());
phone_hub_tray_->RequestFocus();
PressAndReleaseKey(ui::KeyboardCode::VKEY_RETURN);
@ -846,10 +854,12 @@ TEST_F(PhoneHubTrayTest, BubbleViewAccessibleName) {
EXPECT_TRUE(phone_hub_tray_->is_active());
ASSERT_TRUE(bubble_view());
ui::AXNodeData node_data;
bubble_view()->GetViewAccessibility().GetAccessibleNodeData(&node_data);
EXPECT_EQ(node_data.GetString16Attribute(ax::mojom::StringAttribute::kName),
phone_hub_tray()->GetAccessibleNameForBubble());
{
ui::AXNodeData node_data;
bubble_view()->GetViewAccessibility().GetAccessibleNodeData(&node_data);
EXPECT_EQ(node_data.GetString16Attribute(ax::mojom::StringAttribute::kName),
phone_hub_tray()->GetAccessibleNameForBubble());
}
}
} // namespace ash

@ -26,6 +26,7 @@
#include "ui/compositor/layer.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/layout/box_layout_view.h"
@ -61,6 +62,9 @@ PodsOverflowTray::PodsOverflowTray(Shelf* shelf)
// TODO(b/337925759): Make visible only when pods overflow on the shelf.
TrayBackgroundView::SetVisiblePreferred(true);
// TODO(crbug.com/337963043): Update a11y strings.
GetViewAccessibility().SetName(u"Pods overflow tray");
}
PodsOverflowTray::~PodsOverflowTray() {
@ -69,11 +73,6 @@ PodsOverflowTray::~PodsOverflowTray() {
}
}
std::u16string PodsOverflowTray::GetAccessibleNameForTray() {
// TODO(b/337963043): Update a11y strings.
return u"Pods overflow tray";
}
void PodsOverflowTray::HandleLocaleChange() {
TooltipTextChanged();
}

@ -35,7 +35,6 @@ class ASH_EXPORT PodsOverflowTray : public TrayBackgroundView {
views::Widget* GetBubbleWidget() const override;
void CloseBubbleInternal() override;
void ShowBubble() override;
std::u16string GetAccessibleNameForTray() override;
void HandleLocaleChange() override;
void HideBubbleWithView(const TrayBubbleView* bubble_view) override;
void ClickedOutsideBubble(const ui::LocatedEvent& event) override;

@ -0,0 +1,53 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/system/pods_overflow_tray.h"
#include "ash/constants/ash_features.h"
#include "ash/system/status_area_widget.h"
#include "ash/system/status_area_widget_test_helper.h"
#include "ash/test/ash_test_base.h"
#include "base/test/scoped_feature_list.h"
#include "ui/events/base_event_utils.h"
#include "ui/views/accessibility/view_accessibility.h"
namespace ash {
namespace {
class PodsOverflowTrayTest : public AshTestBase {
public:
PodsOverflowTrayTest() = default;
PodsOverflowTrayTest(const PodsOverflowTrayTest&) = delete;
PodsOverflowTrayTest& operator=(const PodsOverflowTrayTest&) = delete;
~PodsOverflowTrayTest() override = default;
// AshtestBase:
void SetUp() override {
scoped_feature_list_.InitAndEnableFeature(features::kScalableShelfPods);
AshTestBase::SetUp();
}
PodsOverflowTray* GetTray() {
return StatusAreaWidgetTestHelper::GetStatusAreaWidget()
->pods_overflow_tray();
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
};
} // namespace
// Tests that the accessible name is set correctly in the accessibility cache.
TEST_F(PodsOverflowTrayTest, AccessibleName) {
ui::AXNodeData tray_data;
GetTray()->GetViewAccessibility().GetAccessibleNodeData(&tray_data);
EXPECT_EQ(tray_data.GetString16Attribute(ax::mojom::StringAttribute::kName),
u"Pods overflow tray");
}
} // namespace ash

@ -532,6 +532,10 @@ void TrayBackgroundView::UpdateAfterLockStateChange(bool locked) {
}
}
std::u16string TrayBackgroundView::GetAccessibleNameForTray() {
return std::u16string();
}
void TrayBackgroundView::OnVisibilityAnimationFinished(
bool should_log_visible_pod_count,
bool aborted) {
@ -596,7 +600,9 @@ void TrayBackgroundView::GetAccessibleNodeData(ui::AXNodeData* node_data) {
// Override the name set in `LabelButton::SetText`.
// TODO(crbug.com/325137417): Remove this once the accessible name is set in
// the cache as soon as the name is updated.
GetViewAccessibility().SetName(GetAccessibleNameForTray());
if (!GetAccessibleNameForTray().empty()) {
GetViewAccessibility().SetName(GetAccessibleNameForTray());
}
}
void TrayBackgroundView::ChildPreferredSizeChanged(views::View* child) {

@ -145,8 +145,9 @@ class ASH_EXPORT TrayBackgroundView : public views::Button,
// Called when the anchor (tray or bubble) may have moved or changed.
virtual void AnchorUpdated() {}
// Called from GetAccessibleNodeData, must return a valid accessible name.
virtual std::u16string GetAccessibleNameForTray() = 0;
// TODO(crbug.com/379818907): In process of deprecation; derived classes that
// override this use it to set their accessible names.
virtual std::u16string GetAccessibleNameForTray();
// Called when a locale change is detected. It should reload any strings the
// view may be using. Note that the locale is not expected to change after the

@ -47,9 +47,6 @@ class TestTrayBackgroundView : public TrayBackgroundView,
// TrayBackgroundView:
void ClickedOutsideBubble(const ui::LocatedEvent& event) override {}
void UpdateTrayItemColor(bool is_active) override {}
std::u16string GetAccessibleNameForTray() override {
return u"TestTrayBackgroundView";
}
void HandleLocaleChange() override {}

@ -63,9 +63,6 @@ class TestTrayBackgroundView : public TrayBackgroundView {
}
void UpdateTrayItemColor(bool is_active) override {}
std::u16string GetAccessibleNameForTray() override {
return u"TestTrayBackgroundView";
}
void HandleLocaleChange() override {}

@ -315,6 +315,9 @@ VideoConferenceTray::VideoConferenceTray(Shelf* shelf)
tray_container()->children().size())
<< "Icons must be updated here in case a media session begins prior to "
"connecting a secondary display.";
GetViewAccessibility().SetName(
l10n_util::GetStringUTF16(IDS_ASH_VIDEO_CONFERENCE_ACCESSIBLE_NAME));
}
VideoConferenceTray::~VideoConferenceTray() {
@ -339,12 +342,8 @@ views::Widget* VideoConferenceTray::GetBubbleWidget() const {
return bubble_ ? bubble_->bubble_widget() : nullptr;
}
std::u16string VideoConferenceTray::GetAccessibleNameForTray() {
return l10n_util::GetStringUTF16(IDS_ASH_VIDEO_CONFERENCE_ACCESSIBLE_NAME);
}
std::u16string VideoConferenceTray::GetAccessibleNameForBubble() {
return GetAccessibleNameForTray();
return l10n_util::GetStringUTF16(IDS_ASH_VIDEO_CONFERENCE_ACCESSIBLE_NAME);
}
void VideoConferenceTray::HideBubbleWithView(

@ -134,7 +134,6 @@ class ASH_EXPORT VideoConferenceTray
void CloseBubbleInternal() override;
TrayBubbleView* GetBubbleView() override;
views::Widget* GetBubbleWidget() const override;
std::u16string GetAccessibleNameForTray() override;
std::u16string GetAccessibleNameForBubble() override;
void HideBubbleWithView(const TrayBubbleView* bubble_view) override;
void HideBubble(const TrayBubbleView* bubble_view) override;

@ -1108,16 +1108,28 @@ TEST_F(VideoConferenceTrayTest, BubbleWithOnlyLinuxApps) {
bubble_view->GetID());
}
TEST_F(VideoConferenceTrayTest, BubbleViewAccessibleName) {
TEST_F(VideoConferenceTrayTest, AccessibleNames) {
SetTrayAndButtonsVisible();
ASSERT_TRUE(video_conference_tray());
{
ui::AXNodeData node_data;
video_conference_tray()->GetViewAccessibility().GetAccessibleNodeData(
&node_data);
EXPECT_EQ(
node_data.GetString16Attribute(ax::mojom::StringAttribute::kName),
l10n_util::GetStringUTF16(IDS_ASH_VIDEO_CONFERENCE_ACCESSIBLE_NAME));
}
LeftClickOn(toggle_bubble_button());
auto* bubble_view = video_conference_tray()->GetBubbleView();
ASSERT_TRUE(bubble_view);
ui::AXNodeData node_data;
bubble_view->GetViewAccessibility().GetAccessibleNodeData(&node_data);
EXPECT_EQ(node_data.GetString16Attribute(ax::mojom::StringAttribute::kName),
video_conference_tray()->GetAccessibleNameForBubble());
{
ui::AXNodeData node_data;
bubble_view->GetViewAccessibility().GetAccessibleNodeData(&node_data);
EXPECT_EQ(node_data.GetString16Attribute(ax::mojom::StringAttribute::kName),
video_conference_tray()->GetAccessibleNameForBubble());
}
}
// Tests the tray when there's a delay in `GetMediaApps()`.

@ -24,6 +24,7 @@
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/events/event.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/border.h"
#include "ui/views/controls/image_view.h"
@ -64,6 +65,9 @@ VirtualKeyboardTray::VirtualKeyboardTray(
Shell::Get()->AddShellObserver(this);
keyboard::KeyboardUIController::Get()->AddObserver(this);
}
GetViewAccessibility().SetName(
l10n_util::GetStringUTF16(IDS_ASH_VIRTUAL_KEYBOARD_TRAY_ACCESSIBLE_NAME));
}
VirtualKeyboardTray::~VirtualKeyboardTray() {
@ -109,11 +113,6 @@ void VirtualKeyboardTray::Initialize() {
Shell::Get()->accessibility_controller()->virtual_keyboard().enabled());
}
std::u16string VirtualKeyboardTray::GetAccessibleNameForTray() {
return l10n_util::GetStringUTF16(
IDS_ASH_VIRTUAL_KEYBOARD_TRAY_ACCESSIBLE_NAME);
}
void VirtualKeyboardTray::HandleLocaleChange() {
icon_->SetTooltipText(l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_ACCESSIBILITY_VIRTUAL_KEYBOARD));

@ -38,7 +38,6 @@ class VirtualKeyboardTray : public TrayBackgroundView,
// TrayBackgroundView:
void Initialize() override;
std::u16string GetAccessibleNameForTray() override;
void HandleLocaleChange() override;
void HideBubbleWithView(const TrayBubbleView* bubble_view) override;
void ClickedOutsideBubble(const ui::LocatedEvent& event) override;

@ -8,12 +8,15 @@
#include "ash/keyboard/ui/keyboard_util.h"
#include "ash/keyboard/ui/test/keyboard_test_util.h"
#include "ash/public/cpp/keyboard/keyboard_switches.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/system/status_area_widget.h"
#include "ash/system/status_area_widget_test_helper.h"
#include "ash/test/ash_test_base.h"
#include "base/command_line.h"
#include "base/functional/callback_helpers.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/views/accessibility/view_accessibility.h"
namespace ash {
@ -55,4 +58,16 @@ TEST_F(VirtualKeyboardTrayTest, PerformActionTogglesVirtualKeyboard) {
ASSERT_TRUE(keyboard::test::WaitUntilHidden());
}
TEST_F(VirtualKeyboardTrayTest, AccessibleName) {
StatusAreaWidget* status = StatusAreaWidgetTestHelper::GetStatusAreaWidget();
VirtualKeyboardTray* tray = status->virtual_keyboard_tray_for_testing();
ASSERT_TRUE(tray);
ui::AXNodeData node_data;
tray->GetViewAccessibility().GetAccessibleNodeData(&node_data);
EXPECT_EQ(
node_data.GetString16Attribute(ax::mojom::StringAttribute::kName),
l10n_util::GetStringUTF16(IDS_ASH_VIRTUAL_KEYBOARD_TRAY_ACCESSIBLE_NAME));
}
} // namespace ash

@ -19,6 +19,7 @@
#include "ui/events/event.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/controls/image_view.h"
namespace ash {
@ -38,7 +39,10 @@ WmModeButtonTray::WmModeButtonTray(Shelf* shelf)
SetCallback(base::BindRepeating(
[](const ui::Event& event) { WmModeController::Get()->Toggle(); }));
image_view_->SetTooltipText(GetAccessibleNameForTray());
// TODO(crbug.com/252558235): Localize once approved.
GetViewAccessibility().SetName(u"WM Mode");
image_view_->SetTooltipText(u"WM Mode");
image_view_->SetHorizontalAlignment(views::ImageView::Alignment::kCenter);
image_view_->SetVerticalAlignment(views::ImageView::Alignment::kCenter);
image_view_->SetPreferredSize(gfx::Size(kTrayItemSize, kTrayItemSize));
@ -68,11 +72,6 @@ void WmModeButtonTray::UpdateAfterLoginStatusChange() {
UpdateButtonVisibility();
}
std::u16string WmModeButtonTray::GetAccessibleNameForTray() {
// TODO(crbug.com/1366034): Localize once approved.
return u"WM Mode";
}
void WmModeButtonTray::OnSessionStateChanged(
session_manager::SessionState state) {
UpdateButtonVisibility();

@ -36,7 +36,6 @@ class WmModeButtonTray : public TrayBackgroundView, public SessionObserver {
// TrayBackgroundView:
void OnThemeChanged() override;
void UpdateAfterLoginStatusChange() override;
std::u16string GetAccessibleNameForTray() override;
void HandleLocaleChange() override {}
void HideBubbleWithView(const TrayBubbleView* bubble_view) override {}
void ClickedOutsideBubble(const ui::LocatedEvent& event) override {}

@ -22,6 +22,7 @@
#include "ui/compositor/layer.h"
#include "ui/display/manager/display_manager.h"
#include "ui/gfx/geometry/vector2d.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/controls/image_view.h"
namespace ash {
@ -357,4 +358,15 @@ TEST_F(WmModeTests, MoveWindowToDeskFromPieMenu) {
EXPECT_FALSE(controller->pie_menu_widget()->IsVisible());
}
TEST_F(WmModeTests, AccessibleName) {
WmModeButtonTray* tray =
GetWmModeButtonTrayForRoot(Shell::GetPrimaryRootWindow());
ASSERT_TRUE(tray);
ui::AXNodeData node_data;
tray->GetViewAccessibility().GetAccessibleNodeData(&node_data);
EXPECT_EQ(node_data.GetString16Attribute(ax::mojom::StringAttribute::kName),
u"WM Mode");
}
} // namespace ash