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

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

Issue 1953753002: Turn RootWindowController Menus Async (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 unified diff | Download patch
« no previous file with comments | « ui/views/widget/widget.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 1683 matching lines...) Expand 10 before | Expand all | Expand 10 after
1694 1694
1695 delete v1; 1695 delete v1;
1696 EXPECT_EQ(0, v2->GetEventCount(ui::ET_MOUSE_MOVED)); 1696 EXPECT_EQ(0, v2->GetEventCount(ui::ET_MOUSE_MOVED));
1697 v2->SetBounds(5, 5, 10, 10); 1697 v2->SetBounds(5, 5, 10, 10);
1698 EXPECT_EQ(0, v2->GetEventCount(ui::ET_MOUSE_MOVED)); 1698 EXPECT_EQ(0, v2->GetEventCount(ui::ET_MOUSE_MOVED));
1699 1699
1700 widget->SynthesizeMouseMoveEvent(); 1700 widget->SynthesizeMouseMoveEvent();
1701 EXPECT_EQ(1, v2->GetEventCount(ui::ET_MOUSE_MOVED)); 1701 EXPECT_EQ(1, v2->GetEventCount(ui::ET_MOUSE_MOVED));
1702 } 1702 }
1703 1703
1704 // No touch on desktop Mac. Tracked in http://crbug.com/445520.
1705 #if !defined(OS_MACOSX) || defined(USE_AURA)
1706
1707 namespace { 1704 namespace {
1708 1705
1709 // ui::EventHandler which handles all mouse press events. 1706 // ui::EventHandler which handles all mouse press events.
1710 class MousePressEventConsumer : public ui::EventHandler { 1707 class MousePressEventConsumer : public ui::EventHandler {
1711 public: 1708 public:
1712 MousePressEventConsumer() {} 1709 MousePressEventConsumer() {}
1713 1710
1714 private: 1711 private:
1715 // ui::EventHandler: 1712 // ui::EventHandler:
1716 void OnMouseEvent(ui::MouseEvent* event) override { 1713 void OnMouseEvent(ui::MouseEvent* event) override {
1717 if (event->type() == ui::ET_MOUSE_PRESSED) 1714 if (event->type() == ui::ET_MOUSE_PRESSED)
1718 event->SetHandled(); 1715 event->SetHandled();
1719 } 1716 }
1720 1717
1721 DISALLOW_COPY_AND_ASSIGN(MousePressEventConsumer); 1718 DISALLOW_COPY_AND_ASSIGN(MousePressEventConsumer);
1722 }; 1719 };
1723 1720
1724 } // namespace 1721 } // namespace
1725 1722
1723 // No touch on desktop Mac. Tracked in http://crbug.com/445520.
1724 #if !defined(OS_MACOSX) || defined(USE_AURA)
1725
1726 // Test that mouse presses and mouse releases are dispatched normally when a 1726 // Test that mouse presses and mouse releases are dispatched normally when a
1727 // touch is down. 1727 // touch is down.
1728 TEST_F(WidgetTest, MouseEventDispatchWhileTouchIsDown) { 1728 TEST_F(WidgetTest, MouseEventDispatchWhileTouchIsDown) {
1729 Widget* widget = CreateTopLevelNativeWidget(); 1729 Widget* widget = CreateTopLevelNativeWidget();
1730 widget->Show(); 1730 widget->Show();
1731 widget->SetSize(gfx::Size(300, 300)); 1731 widget->SetSize(gfx::Size(300, 300));
1732 1732
1733 EventCountView* event_count_view = new EventCountView(); 1733 EventCountView* event_count_view = new EventCountView();
1734 event_count_view->SetBounds(0, 0, 300, 300); 1734 event_count_view->SetBounds(0, 0, 300, 300);
1735 widget->GetRootView()->AddChildView(event_count_view); 1735 widget->GetRootView()->AddChildView(event_count_view);
(...skipping 10 matching lines...) Expand all
1746 1746
1747 EXPECT_EQ(1, event_count_view->GetEventCount(ui::ET_MOUSE_PRESSED)); 1747 EXPECT_EQ(1, event_count_view->GetEventCount(ui::ET_MOUSE_PRESSED));
1748 EXPECT_EQ(1, event_count_view->GetEventCount(ui::ET_MOUSE_RELEASED)); 1748 EXPECT_EQ(1, event_count_view->GetEventCount(ui::ET_MOUSE_RELEASED));
1749 1749
1750 // For mus it's important we destroy the widget before the EventGenerator. 1750 // For mus it's important we destroy the widget before the EventGenerator.
1751 widget->CloseNow(); 1751 widget->CloseNow();
1752 } 1752 }
1753 1753
1754 #endif // !defined(OS_MACOSX) || defined(USE_AURA) 1754 #endif // !defined(OS_MACOSX) || defined(USE_AURA)
1755 1755
1756 // Tests that when there is no active capture, that a mouse press causes capture
1757 // to be set.
1758 TEST_F(WidgetTest, MousePressCausesCapture) {
1759 Widget* widget = CreateTopLevelNativeWidget();
1760 widget->Show();
1761 widget->SetSize(gfx::Size(300, 300));
1762
1763 EventCountView* event_count_view = new EventCountView();
1764 event_count_view->SetBounds(0, 0, 300, 300);
1765 widget->GetRootView()->AddChildView(event_count_view);
1766
1767 // No capture has been set.
1768 EXPECT_EQ(nullptr, internal::NativeWidgetPrivate::GetGlobalCapture(
1769 widget->GetNativeView()));
1770
1771 MousePressEventConsumer consumer;
1772 event_count_view->AddPostTargetHandler(&consumer);
1773 std::unique_ptr<ui::test::EventGenerator> generator(
1774 new ui::test::EventGenerator(
1775 IsMus() ? widget->GetNativeWindow() : GetContext(),
1776 widget->GetNativeWindow()));
1777 generator->PressLeftButton();
1778
1779 EXPECT_EQ(1, event_count_view->GetEventCount(ui::ET_MOUSE_PRESSED));
1780 EXPECT_EQ(
1781 widget->GetNativeView(),
1782 internal::NativeWidgetPrivate::GetGlobalCapture(widget->GetNativeView()));
1783
1784 // For mus it's important we destroy the widget before the EventGenerator.
1785 widget->CloseNow();
1786 }
1787
1788 namespace {
1789
1790 // An EventHandler which shows a Wiget upon receiving a mouse event. The Widget
1791 // proceeds to take capture.
1792 class CaptureEventConsumer : public ui::EventHandler {
1793 public:
1794 CaptureEventConsumer(Widget* widget)
1795 : event_count_view_(new EventCountView()), widget_(widget) {}
1796 ~CaptureEventConsumer() override { widget_->CloseNow(); }
1797
1798 private:
1799 // ui::EventHandler:
1800 void OnMouseEvent(ui::MouseEvent* event) override {
1801 if (event->type() == ui::ET_MOUSE_PRESSED) {
1802 event->SetHandled();
1803 widget_->Show();
1804 widget_->SetSize(gfx::Size(200, 200));
1805
1806 event_count_view_->SetBounds(0, 0, 200, 200);
1807 widget_->GetRootView()->AddChildView(event_count_view_);
1808 widget_->SetCapture(event_count_view_);
1809 }
1810 }
1811
1812 EventCountView* event_count_view_;
1813 Widget* widget_;
1814 DISALLOW_COPY_AND_ASSIGN(CaptureEventConsumer);
1815 };
1816
1817 } // namespace
1818
1819 // Tests that if explicit capture occurs during a mouse press, that implicit
1820 // capture is not applied.
1821 TEST_F(WidgetTest, CaptureDuringMousePressNotOverridden) {
1822 Widget* widget = CreateTopLevelNativeWidget();
1823 widget->Show();
1824 widget->SetSize(gfx::Size(300, 300));
1825
1826 EventCountView* event_count_view = new EventCountView();
1827 event_count_view->SetBounds(0, 0, 300, 300);
1828 widget->GetRootView()->AddChildView(event_count_view);
1829
1830 EXPECT_EQ(nullptr, internal::NativeWidgetPrivate::GetGlobalCapture(
1831 widget->GetNativeView()));
1832
1833 Widget* widget2 = CreateTopLevelNativeWidget();
1834 // Gives explicit capture to |widget2|
1835 CaptureEventConsumer consumer(widget2);
1836 event_count_view->AddPostTargetHandler(&consumer);
1837 std::unique_ptr<ui::test::EventGenerator> generator(
1838 new ui::test::EventGenerator(
1839 IsMus() ? widget->GetNativeWindow() : GetContext(),
1840 widget->GetNativeWindow()));
1841 // This event should implicitly give capture to |widget|, except that
1842 // |consumer| will explicitly set capture on |widget2|.
1843 generator->PressLeftButton();
1844
1845 EXPECT_EQ(1, event_count_view->GetEventCount(ui::ET_MOUSE_PRESSED));
1846 EXPECT_NE(
1847 widget->GetNativeView(),
1848 internal::NativeWidgetPrivate::GetGlobalCapture(widget->GetNativeView()));
1849 EXPECT_EQ(
1850 widget2->GetNativeView(),
1851 internal::NativeWidgetPrivate::GetGlobalCapture(widget->GetNativeView()));
1852
1853 // For mus it's important we destroy the widget before the EventGenerator.
1854 widget->CloseNow();
1855 }
1856
1756 // Verifies WindowClosing() is invoked correctly on the delegate when a Widget 1857 // Verifies WindowClosing() is invoked correctly on the delegate when a Widget
1757 // is closed. 1858 // is closed.
1758 TEST_F(WidgetTest, SingleWindowClosing) { 1859 TEST_F(WidgetTest, SingleWindowClosing) {
1759 TestDesktopWidgetDelegate delegate; 1860 TestDesktopWidgetDelegate delegate;
1760 delegate.InitWidget(CreateParams(Widget::InitParams::TYPE_WINDOW)); 1861 delegate.InitWidget(CreateParams(Widget::InitParams::TYPE_WINDOW));
1761 EXPECT_EQ(0, delegate.window_closing_count()); 1862 EXPECT_EQ(0, delegate.window_closing_count());
1762 delegate.GetWidget()->CloseNow(); 1863 delegate.GetWidget()->CloseNow();
1763 EXPECT_EQ(1, delegate.window_closing_count()); 1864 EXPECT_EQ(1, delegate.window_closing_count());
1764 } 1865 }
1765 1866
(...skipping 1749 matching lines...) Expand 10 before | Expand all | Expand 10 after
3515 // Moving the child to a different widget should call the removals observer. 3616 // Moving the child to a different widget should call the removals observer.
3516 WidgetAutoclosePtr widget2(CreateTopLevelPlatformWidget()); 3617 WidgetAutoclosePtr widget2(CreateTopLevelPlatformWidget());
3517 widget2->client_view()->AddChildView(child); 3618 widget2->client_view()->AddChildView(child);
3518 EXPECT_TRUE(removals_observer.DidRemoveView(child)); 3619 EXPECT_TRUE(removals_observer.DidRemoveView(child));
3519 3620
3520 widget->RemoveRemovalsObserver(&removals_observer); 3621 widget->RemoveRemovalsObserver(&removals_observer);
3521 } 3622 }
3522 3623
3523 } // namespace test 3624 } // namespace test
3524 } // namespace views 3625 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/widget.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698