| 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) {
|
|
|