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

Side by Side Diff: ui/views/widget/widget_unittest.cc

Issue 2456903003: Send mouse exited event after mouse release outside view.
Patch Set: Created 4 years, 1 month 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 unified diff | Download patch
« ui/views/widget/root_view.cc ('K') | « ui/views/widget/root_view.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <algorithm> 5 #include <algorithm>
6 #include <memory> 6 #include <memory>
7 #include <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 3609 matching lines...) Expand 10 before | Expand all | Expand 10 after
3620 EXPECT_FALSE(removals_observer.DidRemoveView(child)); 3620 EXPECT_FALSE(removals_observer.DidRemoveView(child));
3621 3621
3622 // Moving the child to a different widget should call the removals observer. 3622 // Moving the child to a different widget should call the removals observer.
3623 WidgetAutoclosePtr widget2(CreateTopLevelPlatformWidget()); 3623 WidgetAutoclosePtr widget2(CreateTopLevelPlatformWidget());
3624 widget2->client_view()->AddChildView(child); 3624 widget2->client_view()->AddChildView(child);
3625 EXPECT_TRUE(removals_observer.DidRemoveView(child)); 3625 EXPECT_TRUE(removals_observer.DidRemoveView(child));
3626 3626
3627 widget->RemoveRemovalsObserver(&removals_observer); 3627 widget->RemoveRemovalsObserver(&removals_observer);
3628 } 3628 }
3629 3629
3630 // Tests that we don't get Exited notification when we're handling the dragging
3631 // operation. When we stop the drag outside of Widget's bounds we should get the
3632 // Exited notification when the mouse capture will be released.
3633 TEST_F(WidgetTest, MouseExitOnMouseReleaseOutsideView) {
3634 Widget* widget = CreateTopLevelNativeWidget();
3635 widget->SetBounds(gfx::Rect(0, 0, 300, 300));
3636 EventCountView* mock_view = new EventCountView();
3637 widget->GetContentsView()->AddChildView(mock_view);
3638 mock_view->SetBounds(0, 0, 300, 300);
3639 widget->Show();
3640
3641 // Use an event generator to ask views code to set the cursor. However, note
3642 // that this does not cause Cocoa to generate tracking rectangle updates.
3643 ui::test::EventGenerator event_generator(GetContext(),
3644 widget->GetNativeWindow());
3645
3646 event_generator.MoveMouseTo(gfx::Point(50, 50));
3647 EXPECT_EQ(1, mock_view->GetEventCount(ui::ET_MOUSE_ENTERED));
3648 EXPECT_EQ(1, mock_view->GetEventCount(ui::ET_MOUSE_MOVED));
3649 mock_view->ResetCounts();
3650
3651
3652 mock_view->set_handle_mode(EventCountView::CONSUME_EVENTS);
3653 event_generator.PressLeftButton();
3654 EXPECT_EQ(1, mock_view->GetEventCount(ui::ET_MOUSE_PRESSED));
3655 mock_view->set_handle_mode(EventCountView::PROPAGATE_EVENTS);
3656 mock_view->ResetCounts();
3657
3658 EXPECT_TRUE(widget->HasCapture());
3659
3660 mock_view->set_handle_mode(EventCountView::CONSUME_EVENTS);
3661 event_generator.MoveMouseTo(gfx::Point(-50, -50));
3662 // The mouse exited event should not be received, if we have capture.
3663 EXPECT_EQ(0, mock_view->GetEventCount(ui::ET_MOUSE_EXITED));
3664 EXPECT_EQ(1, mock_view->GetEventCount(ui::ET_MOUSE_DRAGGED));
3665 mock_view->set_handle_mode(EventCountView::PROPAGATE_EVENTS);
3666 mock_view->ResetCounts();
3667
3668 event_generator.ReleaseLeftButton();
3669 EXPECT_EQ(1, mock_view->GetEventCount(ui::ET_MOUSE_RELEASED));
3670 // The mouse exited event should be received, after mouse released
3671 // outside view bounds.
3672 EXPECT_EQ(1, mock_view->GetEventCount(ui::ET_MOUSE_EXITED));
3673 mock_view->ResetCounts();
3674
3675 EXPECT_FALSE(widget->HasCapture());
3676
3677 widget->CloseNow();
3678 }
3679
3630 #if defined(OS_WIN) 3680 #if defined(OS_WIN)
3631 3681
3632 namespace { 3682 namespace {
3633 3683
3634 // Provides functionality to create a window modal dialog. 3684 // Provides functionality to create a window modal dialog.
3635 class ModalDialogDelegate : public DialogDelegateView { 3685 class ModalDialogDelegate : public DialogDelegateView {
3636 public: 3686 public:
3637 explicit ModalDialogDelegate(ui::ModalType type) : type_(type) {} 3687 explicit ModalDialogDelegate(ui::ModalType type) : type_(type) {}
3638 ~ModalDialogDelegate() override {} 3688 ~ModalDialogDelegate() override {}
3639 3689
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
3827 Transparency_DesktopWidgetTranslucent 3877 Transparency_DesktopWidgetTranslucent
3828 #endif 3878 #endif
3829 TEST_F(CompositingWidgetTest, MAYBE_Transparency_DesktopWidgetTranslucent) { 3879 TEST_F(CompositingWidgetTest, MAYBE_Transparency_DesktopWidgetTranslucent) {
3830 CheckAllWidgetsForOpacity(Widget::InitParams::TRANSLUCENT_WINDOW); 3880 CheckAllWidgetsForOpacity(Widget::InitParams::TRANSLUCENT_WINDOW);
3831 } 3881 }
3832 3882
3833 #endif // !defined(OS_CHROMEOS) 3883 #endif // !defined(OS_CHROMEOS)
3834 3884
3835 } // namespace test 3885 } // namespace test
3836 } // namespace views 3886 } // namespace views
OLDNEW
« ui/views/widget/root_view.cc ('K') | « ui/views/widget/root_view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698