Commit a35e0ef6 authored by Meilin Wang's avatar Meilin Wang Committed by Commit Bot

[CrOS PhoneHub] Fix bubble can't grab focus in a11y mode.

Screenshot: https://screenshot.googleplex.com/77SePNbWg2gvy53.png

BUG=1106937,1126208
TEST=unittested.

Change-Id: I75974a008dae69e282d34091202c0887c34e4ce0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2464087Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Reviewed-by: default avatarTim Song <tengs@chromium.org>
Commit-Queue: Meilin Wang <meilinw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#816799}
parent 5c4e4d0e
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "ash/system/phonehub/phone_hub_tray.h" #include "ash/system/phonehub/phone_hub_tray.h"
#include "ash/accessibility/accessibility_controller_impl.h" #include "ash/accessibility/accessibility_controller_impl.h"
#include "ash/focus_cycler.h"
#include "ash/resources/vector_icons/vector_icons.h" #include "ash/resources/vector_icons/vector_icons.h"
#include "ash/shelf/shelf.h" #include "ash/shelf/shelf.h"
#include "ash/shell.h" #include "ash/shell.h"
...@@ -187,6 +188,14 @@ void PhoneHubTray::ShowBubble(bool show_by_click) { ...@@ -187,6 +188,14 @@ void PhoneHubTray::ShowBubble(bool show_by_click) {
false /* is_persistent */); false /* is_persistent */);
SetIsActive(true); SetIsActive(true);
// Only focus the widget if it's opened by the keyboard.
if (!show_by_click) {
views::Widget* widget = bubble_->GetBubbleWidget();
widget->widget_delegate()->SetCanActivate(true);
Shell::Get()->focus_cycler()->FocusWidget(widget);
widget->Activate();
}
} }
TrayBubbleView* PhoneHubTray::GetBubbleView() { TrayBubbleView* PhoneHubTray::GetBubbleView() {
......
...@@ -75,6 +75,12 @@ class PhoneHubTrayTest : public AshTestBase { ...@@ -75,6 +75,12 @@ class PhoneHubTrayTest : public AshTestBase {
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
} }
void PressReturnKeyOnTrayButton() {
const ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_RETURN,
ui::EF_NONE);
phone_hub_tray_->PerformAction(key_event);
}
void ClickTrayButton() { ClickOnAndWait(phone_hub_tray_); } void ClickTrayButton() { ClickOnAndWait(phone_hub_tray_); }
MockNewWindowDelegate& new_window_delegate() { return new_window_delegate_; } MockNewWindowDelegate& new_window_delegate() { return new_window_delegate_; }
...@@ -138,11 +144,22 @@ TEST_F(PhoneHubTrayTest, ClickTrayButton) { ...@@ -138,11 +144,22 @@ TEST_F(PhoneHubTrayTest, ClickTrayButton) {
ClickTrayButton(); ClickTrayButton();
EXPECT_TRUE(phone_hub_tray_->is_active()); EXPECT_TRUE(phone_hub_tray_->is_active());
// We only want to focus the bubble widget when it's opened by keyboard.
EXPECT_FALSE(phone_hub_tray_->GetBubbleView()->GetWidget()->IsActive());
ClickTrayButton(); ClickTrayButton();
EXPECT_FALSE(phone_hub_tray_->is_active()); EXPECT_FALSE(phone_hub_tray_->is_active());
} }
TEST_F(PhoneHubTrayTest, FocusBubbleWhenOpenedByKeyboard) {
EXPECT_TRUE(phone_hub_tray_->GetVisible());
PressReturnKeyOnTrayButton();
// The bubble widget should get focus when it's opened by keyboard.
EXPECT_TRUE(phone_hub_tray_->is_active());
EXPECT_TRUE(phone_hub_tray_->GetBubbleView()->GetWidget()->IsActive());
}
TEST_F(PhoneHubTrayTest, ShowNotificationOptInViewWhenAccessNotGranted) { TEST_F(PhoneHubTrayTest, ShowNotificationOptInViewWhenAccessNotGranted) {
GetNotificationAccessManager()->SetHasAccessBeenGrantedInternal(false); GetNotificationAccessManager()->SetHasAccessBeenGrantedInternal(false);
......
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