| 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..a5ffeb7a12fda4f8b8fe0d64f058054284856b35 100644
|
| --- a/ui/views/widget/native_widget_mac_unittest.mm
|
| +++ b/ui/views/widget/native_widget_mac_unittest.mm
|
| @@ -16,12 +16,14 @@
|
| #include "base/strings/utf_string_conversions.h"
|
| #include "base/test/test_timeouts.h"
|
| #include "base/threading/thread_task_runner_handle.h"
|
| +#include "testing/gmock/include/gmock/gmock.h"
|
| #import "testing/gtest_mac.h"
|
| #include "third_party/skia/include/core/SkBitmap.h"
|
| #include "third_party/skia/include/core/SkCanvas.h"
|
| #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"
|
| @@ -642,6 +644,139 @@ void WaitForPaintCount(int target) {
|
| widget->CloseNow();
|
| }
|
|
|
| +class MockView : public View {
|
| + public:
|
| + MockView() {}
|
| +
|
| + MOCK_METHOD1(OnMousePressed, bool(const ui::MouseEvent& event));
|
| + MOCK_METHOD1(OnMouseReleased, void(const ui::MouseEvent& event));
|
| + MOCK_METHOD1(OnMouseDragged, bool(const ui::MouseEvent& event));
|
| + MOCK_METHOD1(OnMouseMoved, void(const ui::MouseEvent& event));
|
| + MOCK_METHOD1(OnMouseEntered, void(const ui::MouseEvent& event));
|
| + MOCK_METHOD1(OnMouseExited, void(const ui::MouseEvent& event));
|
| + MOCK_METHOD1(OnMouseWheel, bool(const ui::MouseWheelEvent& event));
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(MockView);
|
| +};
|
| +
|
| +// 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));
|
| + MockView* mock_view = new MockView();
|
| + 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());
|
| +
|
| + EXPECT_CALL(*mock_view, OnMouseEntered(::testing::_)).Times(1);
|
| + EXPECT_CALL(*mock_view, OnMouseMoved(::testing::_)).Times(1);
|
| + event_generator.MoveMouseTo(gfx::Point(50, 50));
|
| + ::testing::Mock::VerifyAndClear(mock_view);
|
| +
|
| + EXPECT_CALL(*mock_view, OnMouseExited(::testing::_)).Times(1);
|
| + event_generator.MoveMouseTo(gfx::Point(-50, -50));
|
| + ::testing::Mock::VerifyAndClear(mock_view);
|
| +
|
| + 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));
|
| + MockView* mock_view = new MockView();
|
| + 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());
|
| +
|
| + EXPECT_CALL(*mock_view, OnMouseEntered(::testing::_)).Times(1);
|
| + EXPECT_CALL(*mock_view, OnMouseMoved(::testing::_)).Times(1);
|
| + event_generator.MoveMouseTo(gfx::Point(50, 50));
|
| + ::testing::Mock::VerifyAndClear(mock_view);
|
| +
|
| + EXPECT_CALL(*mock_view, OnMousePressed(::testing::_)).Times(1);
|
| + ON_CALL(*mock_view, OnMousePressed(::testing::_))
|
| + .WillByDefault(::testing::Return(true));
|
| +
|
| + event_generator.PressLeftButton();
|
| + ::testing::Mock::VerifyAndClear(mock_view);
|
| +
|
| + EXPECT_TRUE(widget->HasCapture());
|
| +
|
| + // The mouse exit event should not be received, if we have capture.
|
| + EXPECT_CALL(*mock_view, OnMouseExited(::testing::_)).Times(0);
|
| + EXPECT_CALL(*mock_view, OnMouseDragged(::testing::_)).Times(1);
|
| + ON_CALL(*mock_view, OnMouseDragged(::testing::_))
|
| + .WillByDefault(::testing::Return(true));
|
| + event_generator.MoveMouseTo(gfx::Point(-50, -50));
|
| + ::testing::Mock::VerifyAndClear(mock_view);
|
| +
|
| + EXPECT_CALL(*mock_view, OnMouseReleased(::testing::_)).Times(1);
|
| + EXPECT_CALL(*mock_view, OnMouseExited(::testing::_)).Times(1);
|
| + event_generator.ReleaseLeftButton();
|
| + ::testing::Mock::VerifyAndClear(mock_view);
|
| +
|
| + 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));
|
| + MockView* mock_view = new MockView();
|
| + widget->GetContentsView()->AddChildView(mock_view);
|
| + mock_view->SetBounds(0, 0, 300, 300);
|
| + widget->Show();
|
| +
|
| + ui::test::EventGenerator event_generator(GetContext(),
|
| + widget->GetNativeWindow());
|
| +
|
| + EXPECT_CALL(*mock_view, OnMouseEntered(::testing::_)).Times(1);
|
| + EXPECT_CALL(*mock_view, OnMouseMoved(::testing::_)).Times(1);
|
| + event_generator.MoveMouseTo(gfx::Point(50, 50));
|
| + ::testing::Mock::VerifyAndClear(mock_view);
|
| +
|
| + EXPECT_CALL(*mock_view, OnMouseExited(::testing::_)).Times(1);
|
| + event_generator.SendMouseExit();
|
| + ::testing::Mock::VerifyAndClear(mock_view);
|
| +
|
| + widget->CloseNow();
|
| +}
|
| +
|
| +TEST_F(NativeWidgetMacTest, MouseWheelEvent) {
|
| + Widget* widget = CreateTopLevelPlatformWidget();
|
| + widget->SetBounds(gfx::Rect(0, 0, 600, 600));
|
| + MockView* mock_view = new MockView();
|
| + widget->GetContentsView()->AddChildView(mock_view);
|
| + mock_view->SetBounds(0, 0, 600, 600);
|
| + widget->Show();
|
| +
|
| + ui::test::EventGenerator event_generator(GetContext(),
|
| + widget->GetNativeWindow());
|
| + EXPECT_CALL(*mock_view, OnMouseWheel(::testing::_)).Times(1);
|
| + event_generator.MoveMouseWheel(1, 1);
|
| + ::testing::Mock::VerifyAndClear(mock_view);
|
| +
|
| + 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) {
|
|
|