Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Unified Diff: ui/views/widget/native_widget_mac_unittest.mm

Issue 2448173002: Fix processing of mouse events on MacViews.
Patch Set: Fix review issues. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/test/event_generator_delegate_mac.mm ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/widget/native_widget_mac_unittest.mm
diff --git a/ui/views/widget/native_widget_mac_unittest.mm b/ui/views/widget/native_widget_mac_unittest.mm
index 0dec9ded50095c597488f9b4f621fe55f2e16cf5..5bdd65ce1d464d4154dac55d6e26950ae9ae866d 100644
--- a/ui/views/widget/native_widget_mac_unittest.mm
+++ b/ui/views/widget/native_widget_mac_unittest.mm
@@ -22,6 +22,7 @@
#import "ui/base/cocoa/constrained_window/constrained_window_animation.h"
#import "ui/base/cocoa/window_size_constants.h"
#import "ui/base/test/scoped_fake_full_keyboard_access.h"
+#import "ui/events/cocoa/cocoa_event_utils.h"
#import "ui/events/test/cocoa_test_event_utils.h"
#include "ui/events/test/event_generator.h"
#import "ui/gfx/mac/coordinate_conversion.h"
@@ -34,6 +35,7 @@
#include "ui/views/controls/native/native_view_host.h"
#include "ui/views/native_cursor.h"
#include "ui/views/test/native_widget_factory.h"
+#include "ui/views/test/test_views.h"
#include "ui/views/test/test_widget_observer.h"
#include "ui/views/test/widget_test.h"
#include "ui/views/widget/native_widget_mac.h"
@@ -642,6 +644,126 @@ void WaitForPaintCount(int target) {
widget->CloseNow();
}
+// Tests that when no mouse drag is in progress the Entered / Moved / Exited
+// notifications are sent normally.
+TEST_F(NativeWidgetMacTest, MouseEnterExit) {
+ Widget* widget = CreateTopLevelPlatformWidget();
+ widget->SetBounds(gfx::Rect(0, 0, 300, 300));
+ EventCountView* mock_view = new EventCountView();
+ widget->GetContentsView()->AddChildView(mock_view);
+ mock_view->SetBounds(0, 0, 300, 300);
+ widget->Show();
+
+ // Use an event generator to ask views code to set the cursor. However, note
+ // that this does not cause Cocoa to generate tracking rectangle updates.
+ ui::test::EventGenerator event_generator(GetContext(),
+ widget->GetNativeWindow());
+
+
+ event_generator.MoveMouseTo(gfx::Point(50, 50));
+ EXPECT_EQ(1, mock_view->GetEventCount(ui::ET_MOUSE_ENTERED));
+ EXPECT_EQ(1, mock_view->GetEventCount(ui::ET_MOUSE_MOVED));
+ mock_view->ResetCounts();
+
+ event_generator.MoveMouseTo(gfx::Point(-50, -50));
+ EXPECT_EQ(1, mock_view->GetEventCount(ui::ET_MOUSE_EXITED));
+ mock_view->ResetCounts();
+
+ widget->CloseNow();
+}
+
+// Tests that we don't get Exited notification when we're handling the dragging
+// operation. When we stop the drag outside of Widget's bounds we should get the
+// Exited notification when the mouse capture will be released.
+TEST_F(NativeWidgetMacTest, MouseEnterExitWithCapture) {
+ Widget* widget = CreateTopLevelNativeWidget();
+ widget->SetBounds(gfx::Rect(0, 0, 300, 300));
+ EventCountView* mock_view = new EventCountView();
+ widget->GetContentsView()->AddChildView(mock_view);
+ mock_view->SetBounds(0, 0, 300, 300);
+ widget->Show();
+
+ // Use an event generator to ask views code to set the cursor. However, note
+ // that this does not cause Cocoa to generate tracking rectangle updates.
+ ui::test::EventGenerator event_generator(GetContext(),
+ widget->GetNativeWindow());
+
+ event_generator.MoveMouseTo(gfx::Point(50, 50));
+ EXPECT_EQ(1, mock_view->GetEventCount(ui::ET_MOUSE_ENTERED));
+ EXPECT_EQ(1, mock_view->GetEventCount(ui::ET_MOUSE_MOVED));
+ mock_view->ResetCounts();
+
+
+ mock_view->set_handle_mode(EventCountView::CONSUME_EVENTS);
+ event_generator.PressLeftButton();
+ EXPECT_EQ(1, mock_view->GetEventCount(ui::ET_MOUSE_PRESSED));
+ mock_view->set_handle_mode(EventCountView::PROPAGATE_EVENTS);
+ mock_view->ResetCounts();
+
+ EXPECT_TRUE(widget->HasCapture());
+
+ mock_view->set_handle_mode(EventCountView::CONSUME_EVENTS);
+ event_generator.MoveMouseTo(gfx::Point(-50, -50));
+ // The mouse exit event should not be received, if we have capture.
+ EXPECT_EQ(0, mock_view->GetEventCount(ui::ET_MOUSE_EXITED));
+ EXPECT_EQ(1, mock_view->GetEventCount(ui::ET_MOUSE_DRAGGED));
+ mock_view->set_handle_mode(EventCountView::PROPAGATE_EVENTS);
+ mock_view->ResetCounts();
+
+ event_generator.ReleaseLeftButton();
+ EXPECT_EQ(1, mock_view->GetEventCount(ui::ET_MOUSE_RELEASED));
+ EXPECT_EQ(1, mock_view->GetEventCount(ui::ET_MOUSE_EXITED));
+ mock_view->ResetCounts();
+
+ EXPECT_FALSE(widget->HasCapture());
+
+ widget->CloseNow();
+}
+
+// Tests that when exited event have location inside Widget, it will be
+// processed.
+// TODO(art-snake): Fix ui::test::EventGenerator::SendMouseExit method.
+TEST_F(NativeWidgetMacTest, MouseExitInsideWidget) {
+ Widget* widget = CreateTopLevelPlatformWidget();
+ widget->SetBounds(gfx::Rect(0, 0, 300, 300));
+ EventCountView* mock_view = new EventCountView();
+ widget->GetContentsView()->AddChildView(mock_view);
+ mock_view->SetBounds(0, 0, 300, 300);
+ widget->Show();
+
+ ui::test::EventGenerator event_generator(GetContext(),
+ widget->GetNativeWindow());
+
+ event_generator.MoveMouseTo(gfx::Point(50, 50));
+ EXPECT_EQ(1, mock_view->GetEventCount(ui::ET_MOUSE_ENTERED));
+ EXPECT_EQ(1, mock_view->GetEventCount(ui::ET_MOUSE_MOVED));
+ mock_view->ResetCounts();
+
+ event_generator.SendMouseExit();
+ EXPECT_EQ(1, mock_view->GetEventCount(ui::ET_MOUSE_EXITED));
+ mock_view->ResetCounts();
+
+ widget->CloseNow();
+}
+
+TEST_F(NativeWidgetMacTest, MouseWheelEvent) {
+ Widget* widget = CreateTopLevelPlatformWidget();
+ widget->SetBounds(gfx::Rect(0, 0, 600, 600));
+ EventCountView* mock_view = new EventCountView();
+ widget->GetContentsView()->AddChildView(mock_view);
+ mock_view->SetBounds(0, 0, 600, 600);
+ widget->Show();
+
+ ui::test::EventGenerator event_generator(GetContext(),
+ widget->GetNativeWindow());
+
+ event_generator.MoveMouseWheel(1, 1);
+ EXPECT_EQ(1, mock_view->GetEventCount(ui::ET_MOUSEWHEEL));
+ mock_view->ResetCounts();
+
+ widget->CloseNow();
+}
+
// Tests that an accessibility request from the system makes its way through to
// a views::Label filling the window.
TEST_F(NativeWidgetMacTest, AccessibilityIntegration) {
« no previous file with comments | « ui/views/test/event_generator_delegate_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698