Commit 9d2e3f64 authored by Andrew Xu's avatar Andrew Xu Committed by Commit Bot

Fix the issue that AppList is dismissed when closing the notification

A recent CL allows to focus on the notification. As a result, when
notification gets the focus from AppList, AppList will be dismissed
because of losing the focus. This CL fixes the issue.

Bug: 948344
Change-Id: I0fd7d150548afc8e74d1ab406407fe3c1d7b2334
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1627701
Commit-Queue: Andrew Xu <andrewxu@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarRichard Knoll <knollr@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#663956}
parent 2629373c
......@@ -17,6 +17,7 @@
#include "ash/shelf/shelf.h"
#include "ash/shelf/shelf_widget.h"
#include "ash/shell.h"
#include "ash/system/unified/unified_system_tray_test_api.h"
#include "ash/test/ash_test_base.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "ash/wm/window_state.h"
......@@ -25,6 +26,8 @@
#include "base/strings/utf_string_conversions.h"
#include "base/test/metrics/histogram_tester.h"
#include "ui/events/test/event_generator.h"
#include "ui/message_center/message_center.h"
#include "ui/message_center/views/message_popup_view.h"
namespace ash {
......@@ -247,6 +250,47 @@ TEST_F(AppListControllerImplTest, CheckAppListViewBoundsWhenDismissVKeyboard) {
GetAppListViewNativeWindow()->bounds());
}
// Verifies that closing notification by gesture should not dismiss the AppList.
// (see https://crbug.com/948344)
TEST_F(AppListControllerImplTest, CloseNotificationWithAppListShown) {
ShowAppListNow();
// Add one notification.
ASSERT_EQ(
0u, message_center::MessageCenter::Get()->GetPopupNotifications().size());
const std::string notification_id("id");
const std::string notification_title("title");
message_center::MessageCenter::Get()->AddNotification(
std::make_unique<message_center::Notification>(
message_center::NOTIFICATION_TYPE_BASE_FORMAT, notification_id,
base::UTF8ToUTF16(notification_title),
base::UTF8ToUTF16("test message"), gfx::Image(),
base::string16() /* display_source */, GURL(),
message_center::NotifierId(), message_center::RichNotificationData(),
new message_center::NotificationDelegate()));
base::RunLoop().RunUntilIdle();
ASSERT_EQ(
1u, message_center::MessageCenter::Get()->GetPopupNotifications().size());
// Calculate the drag start point and end point.
UnifiedSystemTrayTestApi test_api(GetPrimaryUnifiedSystemTray());
message_center::MessagePopupView* popup_view =
test_api.GetPopupViewForNotificationID(notification_id);
ASSERT_TRUE(popup_view);
gfx::Rect bounds_in_screen = popup_view->GetBoundsInScreen();
const gfx::Point drag_start = bounds_in_screen.left_center();
const gfx::Point drag_end = bounds_in_screen.right_center();
// Swipe away notification by gesture. Verifies that AppListView still shows.
ui::test::EventGenerator* event_generator = GetEventGenerator();
event_generator->GestureScrollSequence(
drag_start, drag_end, base::TimeDelta::FromMicroseconds(500), 10);
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(GetAppListView());
EXPECT_EQ(
0u, message_center::MessageCenter::Get()->GetPopupNotifications().size());
}
class AppListControllerImplMetricsTest : public AshTestBase {
public:
AppListControllerImplMetricsTest() = default;
......
......@@ -57,6 +57,11 @@ class UnifiedSystemTray::UiDelegate : public MessageCenterUiDelegate {
void SetTrayBubbleHeight(int height) {
popup_alignment_delegate_->SetTrayBubbleHeight(height);
}
message_center::MessagePopupView* GetPopupViewForNotificationID(
const std::string& notification_id) {
return message_popup_collection_->GetPopupViewForNotificationID(
notification_id);
}
private:
std::unique_ptr<MessageCenterUiController> ui_controller_;
......@@ -327,4 +332,10 @@ void UnifiedSystemTray::UpdateNotificationAfterDelay() {
quiet_mode_view_->Update();
}
message_center::MessagePopupView*
UnifiedSystemTray::GetPopupViewForNotificationID(
const std::string& notification_id) {
return ui_delegate_->GetPopupViewForNotificationID(notification_id);
}
} // namespace ash
......@@ -12,6 +12,10 @@
#include "base/time/time.h"
#include "base/timer/timer.h"
namespace message_center {
class MessagePopupView;
} // namespace message_center
namespace ash {
namespace tray {
......@@ -119,6 +123,10 @@ class ASH_EXPORT UnifiedSystemTray : public TrayBackgroundView {
void UpdateNotificationInternal();
void UpdateNotificationAfterDelay();
// Forwarded to UiDelegate.
message_center::MessagePopupView* GetPopupViewForNotificationID(
const std::string& notification_id);
const std::unique_ptr<UiDelegate> ui_delegate_;
std::unique_ptr<UnifiedSystemTrayBubble> bubble_;
......
......@@ -84,6 +84,12 @@ bool UnifiedSystemTrayTestApi::Is24HourClock() {
return type == base::k24HourClock;
}
message_center::MessagePopupView*
UnifiedSystemTrayTestApi::GetPopupViewForNotificationID(
const std::string& notification_id) {
return tray_->GetPopupViewForNotificationID(notification_id);
}
views::View* UnifiedSystemTrayTestApi::GetBubbleView(int view_id) const {
return tray_->bubble_->bubble_view_->GetViewByID(view_id);
}
......
......@@ -18,6 +18,10 @@ namespace views {
class View;
} // namespace views
namespace message_center {
class MessagePopupView;
} // namespace message_center
namespace ash {
class UnifiedSystemTray;
......@@ -41,6 +45,9 @@ class UnifiedSystemTrayTestApi : public SystemTrayTestApi {
base::string16 GetBubbleViewTooltip(int view_id) override;
bool Is24HourClock() override;
message_center::MessagePopupView* GetPopupViewForNotificationID(
const std::string& notification_id);
private:
// Returns a view in the bubble menu (not the tray itself). Returns null if
// not found.
......
......@@ -197,6 +197,15 @@ void MessagePopupCollection::AnimationCanceled(
Update();
}
MessagePopupView* MessagePopupCollection::GetPopupViewForNotificationID(
const std::string& notification_id) {
for (const auto& item : popup_items_) {
if (item.id == notification_id)
return item.popup;
}
return nullptr;
}
MessagePopupView* MessagePopupCollection::CreatePopup(
const Notification& notification) {
return new MessagePopupView(notification, alignment_delegate_, this);
......
......@@ -58,6 +58,11 @@ class MESSAGE_CENTER_EXPORT MessagePopupCollection
void AnimationProgressed(const gfx::Animation* animation) override;
void AnimationCanceled(const gfx::Animation* animation) override;
// Find the message popup view for the given notification id. Return nullptr
// if it does not exist.
MessagePopupView* GetPopupViewForNotificationID(
const std::string& notification_id);
void set_inverse() { inverse_ = true; }
protected:
......
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