OLD | NEW |
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 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 EXPECT_TRUE(child->IsVisible()); | 305 EXPECT_TRUE(child->IsVisible()); |
306 EXPECT_TRUE(IsWindowStackedAbove(child, parent.get())); | 306 EXPECT_TRUE(IsWindowStackedAbove(child, parent.get())); |
307 EXPECT_FALSE(IsWindowStackedAbove(parent.get(), child)); // Sanity check. | 307 EXPECT_FALSE(IsWindowStackedAbove(parent.get(), child)); // Sanity check. |
308 | 308 |
309 WidgetAutoclosePtr popover(CreateTopLevelPlatformWidget()); | 309 WidgetAutoclosePtr popover(CreateTopLevelPlatformWidget()); |
310 popover->SetBounds(gfx::Rect(150, 90, 340, 240)); | 310 popover->SetBounds(gfx::Rect(150, 90, 340, 240)); |
311 popover->Show(); | 311 popover->Show(); |
312 | 312 |
313 // NOTE: for aura-mus-client stacking of top-levels is not maintained in the | 313 // NOTE: for aura-mus-client stacking of top-levels is not maintained in the |
314 // client, so z-order of top-levels can't be determined. | 314 // client, so z-order of top-levels can't be determined. |
315 const bool check_toplevel_z_order = !IsAuraMusClient(); | 315 const bool check_toplevel_z_order = !IsMus(); |
316 if (check_toplevel_z_order) | 316 if (check_toplevel_z_order) |
317 EXPECT_TRUE(IsWindowStackedAbove(popover.get(), child)); | 317 EXPECT_TRUE(IsWindowStackedAbove(popover.get(), child)); |
318 EXPECT_TRUE(IsWindowStackedAbove(child, parent.get())); | 318 EXPECT_TRUE(IsWindowStackedAbove(child, parent.get())); |
319 | 319 |
320 // Showing the parent again should raise it and its child above the popover. | 320 // Showing the parent again should raise it and its child above the popover. |
321 parent->Show(); | 321 parent->Show(); |
322 EXPECT_TRUE(IsWindowStackedAbove(child, parent.get())); | 322 EXPECT_TRUE(IsWindowStackedAbove(child, parent.get())); |
323 if (check_toplevel_z_order) | 323 if (check_toplevel_z_order) |
324 EXPECT_TRUE(IsWindowStackedAbove(parent.get(), popover.get())); | 324 EXPECT_TRUE(IsWindowStackedAbove(parent.get(), popover.get())); |
325 | 325 |
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
981 EXPECT_TRUE(child_observer.widget_closed()); | 981 EXPECT_TRUE(child_observer.widget_closed()); |
982 } | 982 } |
983 | 983 |
984 // Test behavior of NativeWidget*::GetWindowPlacement on the native desktop. | 984 // Test behavior of NativeWidget*::GetWindowPlacement on the native desktop. |
985 TEST_F(WidgetTest, GetWindowPlacement) { | 985 TEST_F(WidgetTest, GetWindowPlacement) { |
986 #if defined(OS_MACOSX) | 986 #if defined(OS_MACOSX) |
987 if (base::mac::IsOS10_10()) | 987 if (base::mac::IsOS10_10()) |
988 return; // Fails when swarmed. http://crbug.com/660582 | 988 return; // Fails when swarmed. http://crbug.com/660582 |
989 #endif | 989 #endif |
990 | 990 |
991 if (IsMus()) { | |
992 NOTIMPLEMENTED(); | |
993 return; | |
994 } | |
995 | |
996 WidgetAutoclosePtr widget; | 991 WidgetAutoclosePtr widget; |
997 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 992 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
998 // On desktop-Linux cheat and use non-desktop widgets. On X11, minimize is | 993 // On desktop-Linux cheat and use non-desktop widgets. On X11, minimize is |
999 // asynchronous. Also (harder) showing a window doesn't activate it without | 994 // asynchronous. Also (harder) showing a window doesn't activate it without |
1000 // user interaction (or extra steps only done for interactive ui tests). | 995 // user interaction (or extra steps only done for interactive ui tests). |
1001 // Without that, show_state remains in ui::SHOW_STATE_INACTIVE throughout. | 996 // Without that, show_state remains in ui::SHOW_STATE_INACTIVE throughout. |
1002 // TODO(tapted): Find a nice way to run this with desktop widgets on Linux. | 997 // TODO(tapted): Find a nice way to run this with desktop widgets on Linux. |
1003 widget.reset(CreateTopLevelPlatformWidget()); | 998 widget.reset(CreateTopLevelPlatformWidget()); |
1004 #else | 999 #else |
1005 widget.reset(CreateNativeDesktopWidget()); | 1000 widget.reset(CreateNativeDesktopWidget()); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1096 EXPECT_EQ(minimum_size, GetNativeWidgetMinimumContentSize(widget)); | 1091 EXPECT_EQ(minimum_size, GetNativeWidgetMinimumContentSize(widget)); |
1097 | 1092 |
1098 // Trying to resize smaller than the minimum size should restrict the content | 1093 // Trying to resize smaller than the minimum size should restrict the content |
1099 // size to the minimum size. | 1094 // size to the minimum size. |
1100 widget->SetBounds(gfx::Rect(smaller_size)); | 1095 widget->SetBounds(gfx::Rect(smaller_size)); |
1101 EXPECT_EQ(minimum_size, widget->GetClientAreaBoundsInScreen().size()); | 1096 EXPECT_EQ(minimum_size, widget->GetClientAreaBoundsInScreen().size()); |
1102 | 1097 |
1103 widget->SetSize(smaller_size); | 1098 widget->SetSize(smaller_size); |
1104 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 1099 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
1105 // TODO(tapted): Desktop Linux ignores size constraints for SetSize. Fix it. | 1100 // TODO(tapted): Desktop Linux ignores size constraints for SetSize. Fix it. |
1106 const bool use_small_size = IsMus() ? false : true; | 1101 const bool use_small_size = true; |
1107 #else | 1102 #else |
1108 const bool use_small_size = false; | 1103 const bool use_small_size = false; |
1109 #endif | 1104 #endif |
1110 EXPECT_EQ(use_small_size ? smaller_size : minimum_size, | 1105 EXPECT_EQ(use_small_size ? smaller_size : minimum_size, |
1111 widget->GetClientAreaBoundsInScreen().size()); | 1106 widget->GetClientAreaBoundsInScreen().size()); |
1112 } | 1107 } |
1113 | 1108 |
1114 // Tests that SetBounds() and GetWindowBoundsInScreen() is symmetric when the | 1109 // Tests that SetBounds() and GetWindowBoundsInScreen() is symmetric when the |
1115 // widget is visible and not maximized or fullscreen. | 1110 // widget is visible and not maximized or fullscreen. |
1116 TEST_F(WidgetTest, GetWindowBoundsInScreen) { | 1111 TEST_F(WidgetTest, GetWindowBoundsInScreen) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1172 // Disable on Linux because windows restore to the wrong bounds. | 1167 // Disable on Linux because windows restore to the wrong bounds. |
1173 // See http://crbug.com/515369. | 1168 // See http://crbug.com/515369. |
1174 #if defined(OS_CHROMEOS) || defined(OS_LINUX) | 1169 #if defined(OS_CHROMEOS) || defined(OS_LINUX) |
1175 #define MAYBE_GetRestoredBounds DISABLED_GetRestoredBounds | 1170 #define MAYBE_GetRestoredBounds DISABLED_GetRestoredBounds |
1176 #else | 1171 #else |
1177 #define MAYBE_GetRestoredBounds GetRestoredBounds | 1172 #define MAYBE_GetRestoredBounds GetRestoredBounds |
1178 #endif | 1173 #endif |
1179 | 1174 |
1180 // Test that GetRestoredBounds() returns the original bounds of the window. | 1175 // Test that GetRestoredBounds() returns the original bounds of the window. |
1181 TEST_F(WidgetTest, MAYBE_GetRestoredBounds) { | 1176 TEST_F(WidgetTest, MAYBE_GetRestoredBounds) { |
1182 if (IsMus()) { | |
1183 NOTIMPLEMENTED(); | |
1184 return; | |
1185 } | |
1186 | |
1187 WidgetAutoclosePtr toplevel(CreateNativeDesktopWidget()); | 1177 WidgetAutoclosePtr toplevel(CreateNativeDesktopWidget()); |
1188 toplevel->Show(); | 1178 toplevel->Show(); |
1189 // Initial restored bounds have non-zero size. | 1179 // Initial restored bounds have non-zero size. |
1190 EXPECT_FALSE(toplevel->GetRestoredBounds().IsEmpty()); | 1180 EXPECT_FALSE(toplevel->GetRestoredBounds().IsEmpty()); |
1191 | 1181 |
1192 const gfx::Rect bounds(100, 100, 200, 200); | 1182 const gfx::Rect bounds(100, 100, 200, 200); |
1193 toplevel->SetBounds(bounds); | 1183 toplevel->SetBounds(bounds); |
1194 EXPECT_EQ(bounds, toplevel->GetWindowBoundsInScreen()); | 1184 EXPECT_EQ(bounds, toplevel->GetWindowBoundsInScreen()); |
1195 EXPECT_EQ(bounds, toplevel->GetRestoredBounds()); | 1185 EXPECT_EQ(bounds, toplevel->GetRestoredBounds()); |
1196 | 1186 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1298 } | 1288 } |
1299 | 1289 |
1300 anchor->Hide(); | 1290 anchor->Hide(); |
1301 } | 1291 } |
1302 | 1292 |
1303 #if defined(OS_WIN) | 1293 #if defined(OS_WIN) |
1304 // Test to ensure that after minimize, view width is set to zero. This is only | 1294 // Test to ensure that after minimize, view width is set to zero. This is only |
1305 // the case for desktop widgets on Windows. Other platforms retain the window | 1295 // the case for desktop widgets on Windows. Other platforms retain the window |
1306 // size while minimized. | 1296 // size while minimized. |
1307 TEST_F(WidgetTest, TestViewWidthAfterMinimizingWidget) { | 1297 TEST_F(WidgetTest, TestViewWidthAfterMinimizingWidget) { |
1308 if (IsMus()) { | |
1309 // This test is testing behavior specific to DesktopWindowTreeHostWin. | |
1310 return; | |
1311 } | |
1312 // Create a widget. | 1298 // Create a widget. |
1313 Widget widget; | 1299 Widget widget; |
1314 Widget::InitParams init_params = | 1300 Widget::InitParams init_params = |
1315 CreateParams(Widget::InitParams::TYPE_WINDOW); | 1301 CreateParams(Widget::InitParams::TYPE_WINDOW); |
1316 init_params.show_state = ui::SHOW_STATE_NORMAL; | 1302 init_params.show_state = ui::SHOW_STATE_NORMAL; |
1317 gfx::Rect initial_bounds(0, 0, 300, 400); | 1303 gfx::Rect initial_bounds(0, 0, 300, 400); |
1318 init_params.bounds = initial_bounds; | 1304 init_params.bounds = initial_bounds; |
1319 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 1305 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
1320 init_params.native_widget = | 1306 init_params.native_widget = |
1321 CreatePlatformDesktopNativeWidgetImpl(init_params, &widget, nullptr); | 1307 CreatePlatformDesktopNativeWidgetImpl(init_params, &widget, nullptr); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1411 | 1397 |
1412 View* contents_view = new View; | 1398 View* contents_view = new View; |
1413 contents_view->SetFocusBehavior(View::FocusBehavior::ALWAYS); | 1399 contents_view->SetFocusBehavior(View::FocusBehavior::ALWAYS); |
1414 SetContentsView(contents_view); | 1400 SetContentsView(contents_view); |
1415 | 1401 |
1416 Show(); | 1402 Show(); |
1417 Activate(); | 1403 Activate(); |
1418 } | 1404 } |
1419 | 1405 |
1420 TEST_F(WidgetTest, DesktopNativeWidgetNoPaintAfterCloseTest) { | 1406 TEST_F(WidgetTest, DesktopNativeWidgetNoPaintAfterCloseTest) { |
1421 // TODO(sad): Desktop widgets do not work well in mus https://crbug.com/616551 | |
1422 if (IsMus()) | |
1423 return; | |
1424 DesktopAuraTestValidPaintWidget widget; | 1407 DesktopAuraTestValidPaintWidget widget; |
1425 widget.InitForTest(CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS)); | 1408 widget.InitForTest(CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS)); |
1426 widget.WaitUntilPaint(); | 1409 widget.WaitUntilPaint(); |
1427 EXPECT_TRUE(widget.ReadReceivedPaintAndReset()); | 1410 EXPECT_TRUE(widget.ReadReceivedPaintAndReset()); |
1428 widget.SchedulePaintInRect(widget.GetRestoredBounds()); | 1411 widget.SchedulePaintInRect(widget.GetRestoredBounds()); |
1429 widget.Close(); | 1412 widget.Close(); |
1430 RunPendingMessages(); | 1413 RunPendingMessages(); |
1431 EXPECT_FALSE(widget.ReadReceivedPaintAndReset()); | 1414 EXPECT_FALSE(widget.ReadReceivedPaintAndReset()); |
1432 EXPECT_FALSE(widget.received_paint_while_hidden()); | 1415 EXPECT_FALSE(widget.received_paint_while_hidden()); |
1433 } | 1416 } |
1434 | 1417 |
1435 TEST_F(WidgetTest, DesktopNativeWidgetNoPaintAfterHideTest) { | 1418 TEST_F(WidgetTest, DesktopNativeWidgetNoPaintAfterHideTest) { |
1436 // TODO(sad): Desktop widgets do not work well in mus https://crbug.com/616551 | |
1437 if (IsMus()) | |
1438 return; | |
1439 DesktopAuraTestValidPaintWidget widget; | 1419 DesktopAuraTestValidPaintWidget widget; |
1440 widget.InitForTest(CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS)); | 1420 widget.InitForTest(CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS)); |
1441 widget.WaitUntilPaint(); | 1421 widget.WaitUntilPaint(); |
1442 EXPECT_TRUE(widget.ReadReceivedPaintAndReset()); | 1422 EXPECT_TRUE(widget.ReadReceivedPaintAndReset()); |
1443 widget.SchedulePaintInRect(widget.GetRestoredBounds()); | 1423 widget.SchedulePaintInRect(widget.GetRestoredBounds()); |
1444 widget.Hide(); | 1424 widget.Hide(); |
1445 RunPendingMessages(); | 1425 RunPendingMessages(); |
1446 EXPECT_FALSE(widget.ReadReceivedPaintAndReset()); | 1426 EXPECT_FALSE(widget.ReadReceivedPaintAndReset()); |
1447 EXPECT_FALSE(widget.received_paint_while_hidden()); | 1427 EXPECT_FALSE(widget.received_paint_while_hidden()); |
1448 widget.Close(); | 1428 widget.Close(); |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1696 | 1676 |
1697 widget->Show(); | 1677 widget->Show(); |
1698 | 1678 |
1699 // SynthesizeMouseMoveEvent does nothing until the mouse is entered. | 1679 // SynthesizeMouseMoveEvent does nothing until the mouse is entered. |
1700 widget->SynthesizeMouseMoveEvent(); | 1680 widget->SynthesizeMouseMoveEvent(); |
1701 EXPECT_EQ(0, v1->GetEventCount(ui::ET_MOUSE_MOVED)); | 1681 EXPECT_EQ(0, v1->GetEventCount(ui::ET_MOUSE_MOVED)); |
1702 EXPECT_EQ(0, v2->GetEventCount(ui::ET_MOUSE_MOVED)); | 1682 EXPECT_EQ(0, v2->GetEventCount(ui::ET_MOUSE_MOVED)); |
1703 | 1683 |
1704 gfx::Point cursor_location(5, 5); | 1684 gfx::Point cursor_location(5, 5); |
1705 ui::test::EventGenerator generator( | 1685 ui::test::EventGenerator generator( |
1706 IsMus() || IsAuraMusClient() ? widget->GetNativeWindow() : GetContext(), | 1686 IsMus() ? widget->GetNativeWindow() : GetContext(), |
1707 widget->GetNativeWindow()); | 1687 widget->GetNativeWindow()); |
1708 generator.MoveMouseTo(cursor_location); | 1688 generator.MoveMouseTo(cursor_location); |
1709 | 1689 |
1710 EXPECT_EQ(1, v1->GetEventCount(ui::ET_MOUSE_MOVED)); | 1690 EXPECT_EQ(1, v1->GetEventCount(ui::ET_MOUSE_MOVED)); |
1711 EXPECT_EQ(0, v2->GetEventCount(ui::ET_MOUSE_MOVED)); | 1691 EXPECT_EQ(0, v2->GetEventCount(ui::ET_MOUSE_MOVED)); |
1712 | 1692 |
1713 // SynthesizeMouseMoveEvent dispatches an mousemove event. | 1693 // SynthesizeMouseMoveEvent dispatches an mousemove event. |
1714 widget->SynthesizeMouseMoveEvent(); | 1694 widget->SynthesizeMouseMoveEvent(); |
1715 EXPECT_EQ(2, v1->GetEventCount(ui::ET_MOUSE_MOVED)); | 1695 EXPECT_EQ(2, v1->GetEventCount(ui::ET_MOUSE_MOVED)); |
1716 | 1696 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1753 widget->SetSize(gfx::Size(300, 300)); | 1733 widget->SetSize(gfx::Size(300, 300)); |
1754 | 1734 |
1755 EventCountView* event_count_view = new EventCountView(); | 1735 EventCountView* event_count_view = new EventCountView(); |
1756 event_count_view->SetBounds(0, 0, 300, 300); | 1736 event_count_view->SetBounds(0, 0, 300, 300); |
1757 widget->GetRootView()->AddChildView(event_count_view); | 1737 widget->GetRootView()->AddChildView(event_count_view); |
1758 | 1738 |
1759 MousePressEventConsumer consumer; | 1739 MousePressEventConsumer consumer; |
1760 event_count_view->AddPostTargetHandler(&consumer); | 1740 event_count_view->AddPostTargetHandler(&consumer); |
1761 | 1741 |
1762 ui::test::EventGenerator generator( | 1742 ui::test::EventGenerator generator( |
1763 IsMus() || IsAuraMusClient() ? widget->GetNativeWindow() : GetContext(), | 1743 IsMus() ? widget->GetNativeWindow() : GetContext(), |
1764 widget->GetNativeWindow()); | 1744 widget->GetNativeWindow()); |
1765 generator.PressTouch(); | 1745 generator.PressTouch(); |
1766 generator.ClickLeftButton(); | 1746 generator.ClickLeftButton(); |
1767 | 1747 |
1768 EXPECT_EQ(1, event_count_view->GetEventCount(ui::ET_MOUSE_PRESSED)); | 1748 EXPECT_EQ(1, event_count_view->GetEventCount(ui::ET_MOUSE_PRESSED)); |
1769 EXPECT_EQ(1, event_count_view->GetEventCount(ui::ET_MOUSE_RELEASED)); | 1749 EXPECT_EQ(1, event_count_view->GetEventCount(ui::ET_MOUSE_RELEASED)); |
1770 | 1750 |
1771 // For mus it's important we destroy the widget before the EventGenerator. | 1751 // For mus it's important we destroy the widget before the EventGenerator. |
1772 widget->CloseNow(); | 1752 widget->CloseNow(); |
1773 } | 1753 } |
(...skipping 11 matching lines...) Expand all Loading... |
1785 event_count_view->SetBounds(0, 0, 300, 300); | 1765 event_count_view->SetBounds(0, 0, 300, 300); |
1786 widget->GetRootView()->AddChildView(event_count_view); | 1766 widget->GetRootView()->AddChildView(event_count_view); |
1787 | 1767 |
1788 // No capture has been set. | 1768 // No capture has been set. |
1789 EXPECT_EQ(nullptr, internal::NativeWidgetPrivate::GetGlobalCapture( | 1769 EXPECT_EQ(nullptr, internal::NativeWidgetPrivate::GetGlobalCapture( |
1790 widget->GetNativeView())); | 1770 widget->GetNativeView())); |
1791 | 1771 |
1792 MousePressEventConsumer consumer; | 1772 MousePressEventConsumer consumer; |
1793 event_count_view->AddPostTargetHandler(&consumer); | 1773 event_count_view->AddPostTargetHandler(&consumer); |
1794 ui::test::EventGenerator generator( | 1774 ui::test::EventGenerator generator( |
1795 IsMus() || IsAuraMusClient() ? widget->GetNativeWindow() : GetContext(), | 1775 IsMus() ? widget->GetNativeWindow() : GetContext(), |
1796 widget->GetNativeWindow()); | 1776 widget->GetNativeWindow()); |
1797 generator.PressLeftButton(); | 1777 generator.PressLeftButton(); |
1798 | 1778 |
1799 EXPECT_EQ(1, event_count_view->GetEventCount(ui::ET_MOUSE_PRESSED)); | 1779 EXPECT_EQ(1, event_count_view->GetEventCount(ui::ET_MOUSE_PRESSED)); |
1800 EXPECT_EQ( | 1780 EXPECT_EQ( |
1801 widget->GetNativeView(), | 1781 widget->GetNativeView(), |
1802 internal::NativeWidgetPrivate::GetGlobalCapture(widget->GetNativeView())); | 1782 internal::NativeWidgetPrivate::GetGlobalCapture(widget->GetNativeView())); |
1803 | 1783 |
1804 // For mus it's important we destroy the widget before the EventGenerator. | 1784 // For mus it's important we destroy the widget before the EventGenerator. |
1805 widget->CloseNow(); | 1785 widget->CloseNow(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1848 widget->GetRootView()->AddChildView(event_count_view); | 1828 widget->GetRootView()->AddChildView(event_count_view); |
1849 | 1829 |
1850 EXPECT_EQ(nullptr, internal::NativeWidgetPrivate::GetGlobalCapture( | 1830 EXPECT_EQ(nullptr, internal::NativeWidgetPrivate::GetGlobalCapture( |
1851 widget->GetNativeView())); | 1831 widget->GetNativeView())); |
1852 | 1832 |
1853 Widget* widget2 = CreateTopLevelNativeWidget(); | 1833 Widget* widget2 = CreateTopLevelNativeWidget(); |
1854 // Gives explicit capture to |widget2| | 1834 // Gives explicit capture to |widget2| |
1855 CaptureEventConsumer consumer(widget2); | 1835 CaptureEventConsumer consumer(widget2); |
1856 event_count_view->AddPostTargetHandler(&consumer); | 1836 event_count_view->AddPostTargetHandler(&consumer); |
1857 ui::test::EventGenerator generator( | 1837 ui::test::EventGenerator generator( |
1858 IsMus() || IsAuraMusClient() ? widget->GetNativeWindow() : GetContext(), | 1838 IsMus() ? widget->GetNativeWindow() : GetContext(), |
1859 widget->GetNativeWindow()); | 1839 widget->GetNativeWindow()); |
1860 // This event should implicitly give capture to |widget|, except that | 1840 // This event should implicitly give capture to |widget|, except that |
1861 // |consumer| will explicitly set capture on |widget2|. | 1841 // |consumer| will explicitly set capture on |widget2|. |
1862 generator.PressLeftButton(); | 1842 generator.PressLeftButton(); |
1863 | 1843 |
1864 EXPECT_EQ(1, event_count_view->GetEventCount(ui::ET_MOUSE_PRESSED)); | 1844 EXPECT_EQ(1, event_count_view->GetEventCount(ui::ET_MOUSE_PRESSED)); |
1865 EXPECT_NE( | 1845 EXPECT_NE( |
1866 widget->GetNativeView(), | 1846 widget->GetNativeView(), |
1867 internal::NativeWidgetPrivate::GetGlobalCapture(widget->GetNativeView())); | 1847 internal::NativeWidgetPrivate::GetGlobalCapture(widget->GetNativeView())); |
1868 EXPECT_EQ( | 1848 EXPECT_EQ( |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1933 // DesktopNativeWidget does not exist on non-Aura or on ChromeOS. | 1913 // DesktopNativeWidget does not exist on non-Aura or on ChromeOS. |
1934 #if !defined(OS_CHROMEOS) | 1914 #if !defined(OS_CHROMEOS) |
1935 TEST_F(WidgetWindowTitleTest, SetWindowTitleChanged_DesktopNativeWidget) { | 1915 TEST_F(WidgetWindowTitleTest, SetWindowTitleChanged_DesktopNativeWidget) { |
1936 // Override to use a DesktopNativeWidget. | 1916 // Override to use a DesktopNativeWidget. |
1937 bool desktop_native_widget = true; | 1917 bool desktop_native_widget = true; |
1938 RunTest(desktop_native_widget); | 1918 RunTest(desktop_native_widget); |
1939 } | 1919 } |
1940 #endif // !OS_CHROMEOS | 1920 #endif // !OS_CHROMEOS |
1941 | 1921 |
1942 TEST_F(WidgetTest, WidgetDeleted_InOnMousePressed) { | 1922 TEST_F(WidgetTest, WidgetDeleted_InOnMousePressed) { |
1943 // This test doesn't work in mus as it assumes widget and GetContext() | |
1944 // share an aura hierarchy. Test coverage of deletion from mouse pressed is | |
1945 // important though and should be added, hence the NOTIMPLEMENTED(). | |
1946 // http://crbug.com/594260. | |
1947 if (IsMus()) { | |
1948 NOTIMPLEMENTED(); | |
1949 return; | |
1950 } | |
1951 // TODO: test uses GetContext(), which is not applicable to aura-mus. | 1923 // TODO: test uses GetContext(), which is not applicable to aura-mus. |
1952 // http://crbug.com/663809. | 1924 // http://crbug.com/663809. |
1953 if (IsAuraMusClient()) | 1925 if (IsMus()) |
1954 return; | 1926 return; |
1955 | 1927 |
1956 Widget* widget = new Widget; | 1928 Widget* widget = new Widget; |
1957 Widget::InitParams params = | 1929 Widget::InitParams params = |
1958 CreateParams(views::Widget::InitParams::TYPE_POPUP); | 1930 CreateParams(views::Widget::InitParams::TYPE_POPUP); |
1959 widget->Init(params); | 1931 widget->Init(params); |
1960 | 1932 |
1961 widget->SetContentsView(new CloseWidgetView(ui::ET_MOUSE_PRESSED)); | 1933 widget->SetContentsView(new CloseWidgetView(ui::ET_MOUSE_PRESSED)); |
1962 | 1934 |
1963 widget->SetSize(gfx::Size(100, 100)); | 1935 widget->SetSize(gfx::Size(100, 100)); |
1964 widget->Show(); | 1936 widget->Show(); |
1965 | 1937 |
1966 ui::test::EventGenerator generator(GetContext(), widget->GetNativeWindow()); | 1938 ui::test::EventGenerator generator(GetContext(), widget->GetNativeWindow()); |
1967 | 1939 |
1968 WidgetDeletionObserver deletion_observer(widget); | 1940 WidgetDeletionObserver deletion_observer(widget); |
1969 generator.ClickLeftButton(); | 1941 generator.ClickLeftButton(); |
1970 EXPECT_FALSE(deletion_observer.IsWidgetAlive()); | 1942 EXPECT_FALSE(deletion_observer.IsWidgetAlive()); |
1971 | 1943 |
1972 // Yay we did not crash! | 1944 // Yay we did not crash! |
1973 } | 1945 } |
1974 | 1946 |
1975 // No touch on desktop Mac. Tracked in http://crbug.com/445520. | 1947 // No touch on desktop Mac. Tracked in http://crbug.com/445520. |
1976 #if !defined(OS_MACOSX) || defined(USE_AURA) | 1948 #if !defined(OS_MACOSX) || defined(USE_AURA) |
1977 | 1949 |
1978 TEST_F(WidgetTest, WidgetDeleted_InDispatchGestureEvent) { | 1950 TEST_F(WidgetTest, WidgetDeleted_InDispatchGestureEvent) { |
1979 // This test doesn't make sense for mus. | |
1980 if (IsMus()) | |
1981 return; | |
1982 // TODO: test uses GetContext(), which is not applicable to aura-mus. | 1951 // TODO: test uses GetContext(), which is not applicable to aura-mus. |
1983 // http://crbug.com/663809. | 1952 // http://crbug.com/663809. |
1984 if (IsAuraMusClient()) | 1953 if (IsMus()) |
1985 return; | 1954 return; |
1986 | 1955 |
1987 Widget* widget = new Widget; | 1956 Widget* widget = new Widget; |
1988 Widget::InitParams params = | 1957 Widget::InitParams params = |
1989 CreateParams(views::Widget::InitParams::TYPE_POPUP); | 1958 CreateParams(views::Widget::InitParams::TYPE_POPUP); |
1990 widget->Init(params); | 1959 widget->Init(params); |
1991 | 1960 |
1992 widget->SetContentsView(new CloseWidgetView(ui::ET_GESTURE_TAP_DOWN)); | 1961 widget->SetContentsView(new CloseWidgetView(ui::ET_GESTURE_TAP_DOWN)); |
1993 | 1962 |
1994 widget->SetSize(gfx::Size(100, 100)); | 1963 widget->SetSize(gfx::Size(100, 100)); |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2205 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); | 2174 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
2206 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 2175 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
2207 widget->Init(params); | 2176 widget->Init(params); |
2208 } | 2177 } |
2209 | 2178 |
2210 // Tests that we do not crash when a Widget is destroyed before it finishes | 2179 // Tests that we do not crash when a Widget is destroyed before it finishes |
2211 // processing of pending input events in the message loop. | 2180 // processing of pending input events in the message loop. |
2212 TEST_F(WidgetTest, NoCrashOnWidgetDeleteWithPendingEvents) { | 2181 TEST_F(WidgetTest, NoCrashOnWidgetDeleteWithPendingEvents) { |
2213 // TODO: test uses GetContext(), which is not applicable to aura-mus. | 2182 // TODO: test uses GetContext(), which is not applicable to aura-mus. |
2214 // http://crbug.com/663809. | 2183 // http://crbug.com/663809. |
2215 if (IsAuraMusClient()) | 2184 if (IsMus()) |
2216 return; | 2185 return; |
2217 | 2186 |
2218 std::unique_ptr<Widget> widget(new Widget); | 2187 std::unique_ptr<Widget> widget(new Widget); |
2219 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); | 2188 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); |
2220 params.bounds = gfx::Rect(0, 0, 200, 200); | 2189 params.bounds = gfx::Rect(0, 0, 200, 200); |
2221 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 2190 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
2222 widget->Init(params); | 2191 widget->Init(params); |
2223 widget->Show(); | 2192 widget->Show(); |
2224 | 2193 |
2225 ui::test::EventGenerator generator(GetContext(), widget->GetNativeWindow()); | 2194 ui::test::EventGenerator generator(GetContext(), widget->GetNativeWindow()); |
(...skipping 1024 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3250 | 3219 |
3251 parent_widget.CloseNow(); | 3220 parent_widget.CloseNow(); |
3252 } | 3221 } |
3253 #endif // !defined(OS_CHROMEOS) | 3222 #endif // !defined(OS_CHROMEOS) |
3254 | 3223 |
3255 // Tests that events propagate through from the dispatcher with the correct | 3224 // Tests that events propagate through from the dispatcher with the correct |
3256 // event type, and that the different platforms behave the same. | 3225 // event type, and that the different platforms behave the same. |
3257 TEST_F(WidgetTest, MouseEventTypesViaGenerator) { | 3226 TEST_F(WidgetTest, MouseEventTypesViaGenerator) { |
3258 // TODO: test uses GetContext(), which is not applicable to aura-mus. | 3227 // TODO: test uses GetContext(), which is not applicable to aura-mus. |
3259 // http://crbug.com/663809. | 3228 // http://crbug.com/663809. |
3260 if (IsAuraMusClient()) | 3229 if (IsMus()) |
3261 return; | 3230 return; |
3262 | 3231 |
3263 EventCountView* view = new EventCountView; | 3232 EventCountView* view = new EventCountView; |
3264 view->set_handle_mode(EventCountView::CONSUME_EVENTS); | 3233 view->set_handle_mode(EventCountView::CONSUME_EVENTS); |
3265 view->SetBounds(10, 10, 50, 40); | 3234 view->SetBounds(10, 10, 50, 40); |
3266 | 3235 |
3267 WidgetAutoclosePtr widget(CreateTopLevelFramelessPlatformWidget()); | 3236 WidgetAutoclosePtr widget(CreateTopLevelFramelessPlatformWidget()); |
3268 widget->GetRootView()->AddChildView(view); | 3237 widget->GetRootView()->AddChildView(view); |
3269 | 3238 |
3270 widget->SetBounds(gfx::Rect(0, 0, 100, 80)); | 3239 widget->SetBounds(gfx::Rect(0, 0, 100, 80)); |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3527 EXPECT_TRUE(subclass_helper.received_message(WM_NCLBUTTONDOWN)); | 3496 EXPECT_TRUE(subclass_helper.received_message(WM_NCLBUTTONDOWN)); |
3528 EXPECT_TRUE(subclass_helper.received_message(WM_SYSCOMMAND)); | 3497 EXPECT_TRUE(subclass_helper.received_message(WM_SYSCOMMAND)); |
3529 | 3498 |
3530 widget.CloseNow(); | 3499 widget.CloseNow(); |
3531 } | 3500 } |
3532 | 3501 |
3533 #endif | 3502 #endif |
3534 | 3503 |
3535 // Test that SetAlwaysOnTop and IsAlwaysOnTop are consistent. | 3504 // Test that SetAlwaysOnTop and IsAlwaysOnTop are consistent. |
3536 TEST_F(WidgetTest, AlwaysOnTop) { | 3505 TEST_F(WidgetTest, AlwaysOnTop) { |
3537 if (IsMus()) { | |
3538 NOTIMPLEMENTED(); | |
3539 return; | |
3540 } | |
3541 | |
3542 WidgetAutoclosePtr widget(CreateTopLevelNativeWidget()); | 3506 WidgetAutoclosePtr widget(CreateTopLevelNativeWidget()); |
3543 EXPECT_FALSE(widget->IsAlwaysOnTop()); | 3507 EXPECT_FALSE(widget->IsAlwaysOnTop()); |
3544 widget->SetAlwaysOnTop(true); | 3508 widget->SetAlwaysOnTop(true); |
3545 EXPECT_TRUE(widget->IsAlwaysOnTop()); | 3509 EXPECT_TRUE(widget->IsAlwaysOnTop()); |
3546 widget->SetAlwaysOnTop(false); | 3510 widget->SetAlwaysOnTop(false); |
3547 EXPECT_FALSE(widget->IsAlwaysOnTop()); | 3511 EXPECT_FALSE(widget->IsAlwaysOnTop()); |
3548 } | 3512 } |
3549 | 3513 |
3550 namespace { | 3514 namespace { |
3551 | 3515 |
(...skipping 14 matching lines...) Expand all Loading... |
3566 | 3530 |
3567 DISALLOW_COPY_AND_ASSIGN(ScaleFactorView); | 3531 DISALLOW_COPY_AND_ASSIGN(ScaleFactorView); |
3568 }; | 3532 }; |
3569 | 3533 |
3570 } | 3534 } |
3571 | 3535 |
3572 // Ensure scale factor changes are propagated from the native Widget. | 3536 // Ensure scale factor changes are propagated from the native Widget. |
3573 TEST_F(WidgetTest, OnDeviceScaleFactorChanged) { | 3537 TEST_F(WidgetTest, OnDeviceScaleFactorChanged) { |
3574 // This relies on the NativeWidget being the WindowDelegate, which is not the | 3538 // This relies on the NativeWidget being the WindowDelegate, which is not the |
3575 // case for aura-mus-client. | 3539 // case for aura-mus-client. |
3576 if (IsAuraMusClient()) | 3540 if (IsMus()) |
3577 return; | 3541 return; |
3578 | 3542 |
3579 // Automatically close the widget, but not delete it. | 3543 // Automatically close the widget, but not delete it. |
3580 WidgetAutoclosePtr widget(CreateTopLevelPlatformWidget()); | 3544 WidgetAutoclosePtr widget(CreateTopLevelPlatformWidget()); |
3581 ScaleFactorView* view = new ScaleFactorView; | 3545 ScaleFactorView* view = new ScaleFactorView; |
3582 widget->GetRootView()->AddChildView(view); | 3546 widget->GetRootView()->AddChildView(view); |
3583 float scale_factor = widget->GetLayer()->device_scale_factor(); | 3547 float scale_factor = widget->GetLayer()->device_scale_factor(); |
3584 EXPECT_NE(scale_factor, 0.f); | 3548 EXPECT_NE(scale_factor, 0.f); |
3585 | 3549 |
3586 // For views that are not layer-backed, adding the view won't notify the view | 3550 // For views that are not layer-backed, adding the view won't notify the view |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3676 widget2->client_view()->AddChildView(child); | 3640 widget2->client_view()->AddChildView(child); |
3677 EXPECT_TRUE(removals_observer.DidRemoveView(child)); | 3641 EXPECT_TRUE(removals_observer.DidRemoveView(child)); |
3678 | 3642 |
3679 widget->RemoveRemovalsObserver(&removals_observer); | 3643 widget->RemoveRemovalsObserver(&removals_observer); |
3680 } | 3644 } |
3681 | 3645 |
3682 // Test dispatch of ui::ET_MOUSEWHEEL. | 3646 // Test dispatch of ui::ET_MOUSEWHEEL. |
3683 TEST_F(WidgetTest, MouseWheelEvent) { | 3647 TEST_F(WidgetTest, MouseWheelEvent) { |
3684 // TODO: test uses GetContext(), which is not applicable to aura-mus. | 3648 // TODO: test uses GetContext(), which is not applicable to aura-mus. |
3685 // http://crbug.com/663809. | 3649 // http://crbug.com/663809. |
3686 if (IsAuraMusClient()) | 3650 if (IsMus()) |
3687 return; | 3651 return; |
3688 | 3652 |
3689 WidgetAutoclosePtr widget(CreateTopLevelPlatformWidget()); | 3653 WidgetAutoclosePtr widget(CreateTopLevelPlatformWidget()); |
3690 widget->SetBounds(gfx::Rect(0, 0, 600, 600)); | 3654 widget->SetBounds(gfx::Rect(0, 0, 600, 600)); |
3691 EventCountView* event_count_view = new EventCountView(); | 3655 EventCountView* event_count_view = new EventCountView(); |
3692 widget->GetContentsView()->AddChildView(event_count_view); | 3656 widget->GetContentsView()->AddChildView(event_count_view); |
3693 event_count_view->SetBounds(0, 0, 600, 600); | 3657 event_count_view->SetBounds(0, 0, 600, 600); |
3694 widget->Show(); | 3658 widget->Show(); |
3695 | 3659 |
3696 ui::test::EventGenerator event_generator(GetContext(), | 3660 ui::test::EventGenerator event_generator(GetContext(), |
(...skipping 21 matching lines...) Expand all Loading... |
3718 | 3682 |
3719 DISALLOW_COPY_AND_ASSIGN(ModalDialogDelegate); | 3683 DISALLOW_COPY_AND_ASSIGN(ModalDialogDelegate); |
3720 }; | 3684 }; |
3721 | 3685 |
3722 } // namespace | 3686 } // namespace |
3723 | 3687 |
3724 // Tests the case where an intervening owner popup window is destroyed out from | 3688 // Tests the case where an intervening owner popup window is destroyed out from |
3725 // under the currently active modal top-level window. In this instance, the | 3689 // under the currently active modal top-level window. In this instance, the |
3726 // remaining top-level windows should be re-enabled. | 3690 // remaining top-level windows should be re-enabled. |
3727 TEST_F(WidgetTest, WindowModalOwnerDestroyedEnabledTest) { | 3691 TEST_F(WidgetTest, WindowModalOwnerDestroyedEnabledTest) { |
3728 // Modality etc. are controlled by mus. | |
3729 if (IsMus()) | |
3730 return; | |
3731 // top_level_widget owns owner_dialog_widget which owns owned_dialog_widget. | 3692 // top_level_widget owns owner_dialog_widget which owns owned_dialog_widget. |
3732 Widget top_level_widget; | 3693 Widget top_level_widget; |
3733 Widget owner_dialog_widget; | 3694 Widget owner_dialog_widget; |
3734 Widget owned_dialog_widget; | 3695 Widget owned_dialog_widget; |
3735 // Create the top level widget. | 3696 // Create the top level widget. |
3736 Widget::InitParams init_params = | 3697 Widget::InitParams init_params = |
3737 CreateParams(Widget::InitParams::TYPE_WINDOW); | 3698 CreateParams(Widget::InitParams::TYPE_WINDOW); |
3738 init_params.show_state = ui::SHOW_STATE_NORMAL; | 3699 init_params.show_state = ui::SHOW_STATE_NORMAL; |
3739 gfx::Rect initial_bounds(0, 0, 500, 500); | 3700 gfx::Rect initial_bounds(0, 0, 500, 500); |
3740 init_params.bounds = initial_bounds; | 3701 init_params.bounds = initial_bounds; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3842 #elif defined(OS_WIN) | 3803 #elif defined(OS_WIN) |
3843 // Other widget types would require to create a parent window and the | 3804 // Other widget types would require to create a parent window and the |
3844 // the purpose of this test is mainly X11 in the first place. | 3805 // the purpose of this test is mainly X11 in the first place. |
3845 if (widget_type != Widget::InitParams::TYPE_WINDOW) | 3806 if (widget_type != Widget::InitParams::TYPE_WINDOW) |
3846 continue; | 3807 continue; |
3847 #endif | 3808 #endif |
3848 Widget widget; | 3809 Widget widget; |
3849 InitializeWidgetForOpacity(widget, CreateParams(widget_type), opacity); | 3810 InitializeWidgetForOpacity(widget, CreateParams(widget_type), opacity); |
3850 | 3811 |
3851 // Use NativeWidgetAura directly. | 3812 // Use NativeWidgetAura directly. |
3852 if (IsMus() && | 3813 if (widget_type == Widget::InitParams::TYPE_WINDOW_FRAMELESS || |
3853 (widget_type == Widget::InitParams::TYPE_WINDOW_FRAMELESS || | 3814 widget_type == Widget::InitParams::TYPE_CONTROL) |
3854 widget_type == Widget::InitParams::TYPE_CONTROL)) | |
3855 continue; | 3815 continue; |
3856 | 3816 |
3857 #if defined(OS_MACOSX) | 3817 #if defined(OS_MACOSX) |
3858 // Mac always always has a compositing window manager, but doesn't have | 3818 // Mac always always has a compositing window manager, but doesn't have |
3859 // transparent titlebars which is what ShouldWindowContentsBeTransparent() | 3819 // transparent titlebars which is what ShouldWindowContentsBeTransparent() |
3860 // is currently used for. Asking for transparency should get it. Note that | 3820 // is currently used for. Asking for transparency should get it. Note that |
3861 // TestViewsDelegate::use_transparent_windows_ determines the result of | 3821 // TestViewsDelegate::use_transparent_windows_ determines the result of |
3862 // INFER_OPACITY: assume it is false. | 3822 // INFER_OPACITY: assume it is false. |
3863 bool should_be_transparent = | 3823 bool should_be_transparent = |
3864 opacity == Widget::InitParams::TRANSLUCENT_WINDOW; | 3824 opacity == Widget::InitParams::TRANSLUCENT_WINDOW; |
3865 #else | 3825 #else |
3866 bool should_be_transparent = widget.ShouldWindowContentsBeTransparent(); | 3826 bool should_be_transparent = widget.ShouldWindowContentsBeTransparent(); |
3867 #endif | 3827 #endif |
3868 | 3828 |
3869 EXPECT_EQ(IsNativeWindowTransparent(widget.GetNativeWindow()), | 3829 EXPECT_EQ(IsNativeWindowTransparent(widget.GetNativeWindow()), |
3870 should_be_transparent); | 3830 should_be_transparent); |
3871 | 3831 |
3872 // When using the Mandoline UI Service, the translucency does not rely on | |
3873 // the widget type. | |
3874 if (IsMus()) | |
3875 continue; | |
3876 | |
3877 #if defined(USE_X11) | 3832 #if defined(USE_X11) |
3878 if (HasCompositingManager() && | 3833 if (HasCompositingManager() && |
3879 (widget_type == Widget::InitParams::TYPE_DRAG || | 3834 (widget_type == Widget::InitParams::TYPE_DRAG || |
3880 widget_type == Widget::InitParams::TYPE_WINDOW)) { | 3835 widget_type == Widget::InitParams::TYPE_WINDOW)) { |
3881 EXPECT_TRUE(widget.IsTranslucentWindowOpacitySupported()); | 3836 EXPECT_TRUE(widget.IsTranslucentWindowOpacitySupported()); |
3882 } else { | 3837 } else { |
3883 EXPECT_FALSE(widget.IsTranslucentWindowOpacitySupported()); | 3838 EXPECT_FALSE(widget.IsTranslucentWindowOpacitySupported()); |
3884 } | 3839 } |
3885 #endif | 3840 #endif |
3886 } | 3841 } |
(...skipping 17 matching lines...) Expand all Loading... |
3904 } | 3859 } |
3905 | 3860 |
3906 TEST_F(CompositingWidgetTest, Transparency_DesktopWidgetTranslucent) { | 3861 TEST_F(CompositingWidgetTest, Transparency_DesktopWidgetTranslucent) { |
3907 CheckAllWidgetsForOpacity(Widget::InitParams::TRANSLUCENT_WINDOW); | 3862 CheckAllWidgetsForOpacity(Widget::InitParams::TRANSLUCENT_WINDOW); |
3908 } | 3863 } |
3909 | 3864 |
3910 #endif // !defined(OS_CHROMEOS) | 3865 #endif // !defined(OS_CHROMEOS) |
3911 | 3866 |
3912 } // namespace test | 3867 } // namespace test |
3913 } // namespace views | 3868 } // namespace views |
OLD | NEW |