Commit 9d9c37b8 authored by Ahmed Mehfooz's avatar Ahmed Mehfooz Committed by Commit Bot

Fix system tray focus cycle crash

This CL fixes the check for the message center being visible.
Also adding a unit test to cover the case that caused the crash.

Change-Id: I37b82b4d3cd08c6c8823dab0b7ddd9342a3c7673
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1857378Reviewed-by: default avatarTim Song <tengs@chromium.org>
Commit-Queue: Ahmed Mehfooz <amehfooz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#705620}
parent 807c2182
...@@ -93,6 +93,10 @@ bool UnifiedMessageCenterBubble::FocusOut(bool reverse) { ...@@ -93,6 +93,10 @@ bool UnifiedMessageCenterBubble::FocusOut(bool reverse) {
return tray_->FocusQuickSettings(reverse); return tray_->FocusQuickSettings(reverse);
} }
bool UnifiedMessageCenterBubble::IsMessageCenterVisible() {
return message_center_view_->GetVisible();
}
TrayBackgroundView* UnifiedMessageCenterBubble::GetTray() const { TrayBackgroundView* UnifiedMessageCenterBubble::GetTray() const {
return tray_; return tray_;
} }
......
...@@ -38,6 +38,9 @@ class ASH_EXPORT UnifiedMessageCenterBubble : public TrayBubbleBase, ...@@ -38,6 +38,9 @@ class ASH_EXPORT UnifiedMessageCenterBubble : public TrayBubbleBase,
// Relinquish focus and transfer it to the quick settings widget. // Relinquish focus and transfer it to the quick settings widget.
bool FocusOut(bool reverse); bool FocusOut(bool reverse);
// Returns true if notifications are shown.
bool IsMessageCenterVisible();
// TrayBubbleBase: // TrayBubbleBase:
TrayBackgroundView* GetTray() const override; TrayBackgroundView* GetTray() const override;
TrayBubbleView* GetBubbleView() const override; TrayBubbleView* GetBubbleView() const override;
......
...@@ -249,4 +249,36 @@ TEST_F(UnifiedMessageCenterBubbleTest, ReverseFocusCycle) { ...@@ -249,4 +249,36 @@ TEST_F(UnifiedMessageCenterBubbleTest, ReverseFocusCycle) {
GetLastQuickSettingsFocusable()); GetLastQuickSettingsFocusable());
} }
TEST_F(UnifiedMessageCenterBubbleTest, FocusCycleWithNoNotifications) {
EnableMessageCenterRefactor();
GetPrimaryUnifiedSystemTray()->ShowBubble(true);
views::Widget* quick_settings_widget =
GetSystemTrayBubble()->GetBubbleWidget();
views::Widget* message_center_widget =
GetMessageCenterBubble()->GetBubbleWidget();
// First tab should focus the first element in the quick settings bubble.
DoTab();
EXPECT_TRUE(quick_settings_widget->IsActive());
EXPECT_FALSE(message_center_widget->IsActive());
EXPECT_EQ(quick_settings_widget->GetFocusManager()->GetFocusedView(),
GetFirstQuickSettingsFocusable());
// Keep tabbing until we reach the last focusable element in the quick
// settings bubble.
while (quick_settings_widget->GetFocusManager()->GetFocusedView() !=
GetLastQuickSettingsFocusable()) {
DoTab();
}
// Tab at the last element in the quick settings bubble should move focus to
// the first element in the quick settings bubble.
DoTab();
EXPECT_TRUE(quick_settings_widget->IsActive());
EXPECT_FALSE(message_center_widget->IsActive());
EXPECT_EQ(quick_settings_widget->GetFocusManager()->GetFocusedView(),
GetFirstQuickSettingsFocusable());
}
} // namespace ash } // namespace ash
...@@ -178,7 +178,7 @@ bool UnifiedSystemTray::IsSliderBubbleShown() const { ...@@ -178,7 +178,7 @@ bool UnifiedSystemTray::IsSliderBubbleShown() const {
bool UnifiedSystemTray::IsMessageCenterBubbleShown() const { bool UnifiedSystemTray::IsMessageCenterBubbleShown() const {
if (message_center_bubble_) if (message_center_bubble_)
return !!message_center_bubble_->GetBubbleWidget(); return message_center_bubble_->IsMessageCenterVisible();
return false; return 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