Commit 3a054147 authored by dewittj@chromium.org's avatar dewittj@chromium.org

Make toasts notice when they're hidden and send the mouse-out event.

A recent change in Views causes the mouse move trackers to be
removed when visibility changes, causing the mouseexited event never
to happen if a window is closed underneath the mouse.

BUG=282117
R=mukai@chromium.org

Review URL: https://codereview.chromium.org/23764003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@220691 0039d316-1c4b-4281-b951-d872f2087c98
parent 486e6f50
...@@ -100,6 +100,8 @@ MessagePopupCollection::~MessagePopupCollection() { ...@@ -100,6 +100,8 @@ MessagePopupCollection::~MessagePopupCollection() {
} }
void MessagePopupCollection::RemoveToast(ToastContentsView* toast) { void MessagePopupCollection::RemoveToast(ToastContentsView* toast) {
OnMouseExited(toast);
for (Toasts::iterator iter = toasts_.begin(); iter != toasts_.end(); ++iter) { for (Toasts::iterator iter = toasts_.begin(); iter != toasts_.end(); ++iter) {
if ((*iter) == toast) { if ((*iter) == toast) {
toasts_.erase(iter); toasts_.erase(iter);
......
...@@ -36,7 +36,6 @@ FORWARD_DECLARE_TEST(WebNotificationTrayTest, ManyPopupNotifications); ...@@ -36,7 +36,6 @@ FORWARD_DECLARE_TEST(WebNotificationTrayTest, ManyPopupNotifications);
namespace message_center { namespace message_center {
namespace test { namespace test {
class MessagePopupCollectionTest; class MessagePopupCollectionTest;
class MessagePopupCollectionWidgetsTest;
} }
class MessageCenter; class MessageCenter;
...@@ -109,7 +108,6 @@ class MESSAGE_CENTER_EXPORT MessagePopupCollection ...@@ -109,7 +108,6 @@ class MESSAGE_CENTER_EXPORT MessagePopupCollection
FRIEND_TEST_ALL_PREFIXES(ash::WebNotificationTrayTest, FRIEND_TEST_ALL_PREFIXES(ash::WebNotificationTrayTest,
ManyPopupNotifications); ManyPopupNotifications);
friend class test::MessagePopupCollectionTest; friend class test::MessagePopupCollectionTest;
friend class test::MessagePopupCollectionWidgetsTest;
friend class ash::WebNotificationTrayTest; friend class ash::WebNotificationTrayTest;
typedef std::list<ToastContentsView*> Toasts; typedef std::list<ToastContentsView*> Toasts;
......
...@@ -10,12 +10,15 @@ ...@@ -10,12 +10,15 @@
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/events/event.h"
#include "ui/base/events/event_constants.h"
#include "ui/gfx/display.h" #include "ui/gfx/display.h"
#include "ui/gfx/rect.h" #include "ui/gfx/rect.h"
#include "ui/message_center/fake_message_center.h" #include "ui/message_center/fake_message_center.h"
#include "ui/message_center/views/toast_contents_view.h" #include "ui/message_center/views/toast_contents_view.h"
#include "ui/views/test/views_test_base.h" #include "ui/views/test/views_test_base.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"
namespace message_center { namespace message_center {
namespace test { namespace test {
...@@ -51,6 +54,10 @@ class MessagePopupCollectionTest : public views::ViewsTestBase { ...@@ -51,6 +54,10 @@ class MessagePopupCollectionTest : public views::ViewsTestBase {
return collection_->toasts_.size(); return collection_->toasts_.size();
} }
bool MouseInCollection() {
return collection_->latest_toast_entered_ != NULL;
}
bool IsToastShown(const std::string& id) { bool IsToastShown(const std::string& id) {
views::Widget* widget = collection_->GetWidgetForTest(id); views::Widget* widget = collection_->GetWidgetForTest(id);
return widget && widget->IsVisible(); return widget && widget->IsVisible();
...@@ -335,6 +342,39 @@ TEST_F(MessagePopupCollectionTest, LeftPositioningWithLeftTaskbar) { ...@@ -335,6 +342,39 @@ TEST_F(MessagePopupCollectionTest, LeftPositioningWithLeftTaskbar) {
gfx::Rect(0, 0, 600, 400)); // Display-bounds. gfx::Rect(0, 0, 600, 400)); // Display-bounds.
} }
TEST_F(MessagePopupCollectionTest, DetectMouseHover) {
std::string id0 = AddNotification();
std::string id1 = AddNotification();
WaitForTransitionsDone();
views::WidgetDelegateView* toast0 = GetToast(id0);
EXPECT_TRUE(toast0 != NULL);
views::WidgetDelegateView* toast1 = GetToast(id1);
EXPECT_TRUE(toast1 != NULL);
ui::MouseEvent event(ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(), 0);
// Test that mouse detection logic works in presence of out-of-order events.
toast0->OnMouseEntered(event);
EXPECT_TRUE(MouseInCollection());
toast1->OnMouseEntered(event);
EXPECT_TRUE(MouseInCollection());
toast0->OnMouseExited(event);
EXPECT_TRUE(MouseInCollection());
toast1->OnMouseExited(event);
EXPECT_FALSE(MouseInCollection());
// Test that mouse detection logic works in presence of WindowClosing events.
toast0->OnMouseEntered(event);
EXPECT_TRUE(MouseInCollection());
toast1->OnMouseEntered(event);
EXPECT_TRUE(MouseInCollection());
toast0->WindowClosing();
EXPECT_TRUE(MouseInCollection());
toast1->WindowClosing();
EXPECT_FALSE(MouseInCollection());
}
// TODO(dimich): Test repositioning - both normal one and when user is closing // TODO(dimich): Test repositioning - both normal one and when user is closing
// the toasts. // the toasts.
......
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