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

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

Issue 25445002: Ensure that in Desktop AURA the WindowModalityController class is at the head of the event pre targ… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « ui/views/widget/desktop_aura/desktop_root_window_host_x11.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 <set> 6 #include <set>
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "ui/events/event_utils.h" 15 #include "ui/events/event_utils.h"
16 #include "ui/gfx/native_widget_types.h" 16 #include "ui/gfx/native_widget_types.h"
17 #include "ui/gfx/point.h" 17 #include "ui/gfx/point.h"
18 #include "ui/views/bubble/bubble_delegate.h" 18 #include "ui/views/bubble/bubble_delegate.h"
19 #include "ui/views/controls/textfield/textfield.h" 19 #include "ui/views/controls/textfield/textfield.h"
20 #include "ui/views/test/test_views_delegate.h" 20 #include "ui/views/test/test_views_delegate.h"
21 #include "ui/views/test/widget_test.h" 21 #include "ui/views/test/widget_test.h"
22 #include "ui/views/views_delegate.h" 22 #include "ui/views/views_delegate.h"
23 #include "ui/views/widget/native_widget_delegate.h" 23 #include "ui/views/widget/native_widget_delegate.h"
24 #include "ui/views/widget/root_view.h" 24 #include "ui/views/widget/root_view.h"
25 #include "ui/views/window/dialog_delegate.h"
25 #include "ui/views/window/native_frame_view.h" 26 #include "ui/views/window/native_frame_view.h"
26 27
27 #if defined(USE_AURA) 28 #if defined(USE_AURA)
28 #include "ui/aura/client/aura_constants.h" 29 #include "ui/aura/client/aura_constants.h"
29 #include "ui/aura/root_window.h" 30 #include "ui/aura/root_window.h"
30 #include "ui/aura/test/test_window_delegate.h" 31 #include "ui/aura/test/test_window_delegate.h"
31 #include "ui/aura/window.h" 32 #include "ui/aura/window.h"
32 #include "ui/views/widget/native_widget_aura.h" 33 #include "ui/views/widget/native_widget_aura.h"
33 #if !defined(OS_CHROMEOS) 34 #if !defined(OS_CHROMEOS)
34 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" 35 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
(...skipping 1925 matching lines...) Expand 10 before | Expand all | Expand 10 after
1960 RunDestroyChildWidgetsTest(true, true); 1961 RunDestroyChildWidgetsTest(true, true);
1961 } 1962 }
1962 #endif 1963 #endif
1963 #endif 1964 #endif
1964 1965
1965 // See description of RunDestroyChildWidgetsTest(). 1966 // See description of RunDestroyChildWidgetsTest().
1966 TEST_F(WidgetChildDestructionTest, DestroyChildWidgetsInOrder) { 1967 TEST_F(WidgetChildDestructionTest, DestroyChildWidgetsInOrder) {
1967 RunDestroyChildWidgetsTest(false, false); 1968 RunDestroyChildWidgetsTest(false, false);
1968 } 1969 }
1969 1970
1971 #if defined(USE_AURA) && !defined(OS_CHROMEOS)
1972 // Provides functionality to create a window modal dialog.
1973 class ModalDialogDelegate : public DialogDelegateView {
1974 public:
1975 ModalDialogDelegate() {}
1976 virtual ~ModalDialogDelegate() {}
1977
1978 // WidgetDelegate overrides.
1979 virtual ui::ModalType GetModalType() const OVERRIDE {
1980 return ui::MODAL_TYPE_WINDOW;
1981 }
1982
1983 private:
1984 DISALLOW_COPY_AND_ASSIGN(ModalDialogDelegate);
1985 };
1986
1987 // This test verifies that whether mouse events when a modal dialog is
1988 // displayed are eaten or recieved by the dialog.
1989 TEST_F(WidgetTest, WindowMouseModalityTest) {
1990 // Create a top level widget.
1991 Widget top_level_widget;
1992 Widget::InitParams init_params =
1993 CreateParams(Widget::InitParams::TYPE_WINDOW);
1994 init_params.show_state = ui::SHOW_STATE_NORMAL;
1995 gfx::Rect initial_bounds(0, 0, 500, 500);
1996 init_params.bounds = initial_bounds;
1997 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
1998 init_params.native_widget = new DesktopNativeWidgetAura(&top_level_widget);
1999 top_level_widget.Init(init_params);
2000 top_level_widget.Show();
2001 EXPECT_TRUE(top_level_widget.IsVisible());
2002
2003 // Create a view and validate that a mouse moves makes it to the view.
2004 EventCountView* widget_view = new EventCountView();
2005 widget_view->SetBounds(0, 0, 10, 10);
2006 top_level_widget.GetRootView()->AddChildView(widget_view);
2007
2008 gfx::Point cursor_location_main(5, 5);
2009 ui::MouseEvent move_main(ui::ET_MOUSE_MOVED,
2010 cursor_location_main,
2011 cursor_location_main,
2012 ui::EF_NONE);
2013 top_level_widget.GetNativeView()->GetRootWindow()->
2014 AsRootWindowHostDelegate()->OnHostMouseEvent(&move_main);
2015
2016 EXPECT_EQ(1, widget_view->GetEventCount(ui::ET_MOUSE_ENTERED));
2017 widget_view->ResetCounts();
2018
2019 // Create a modal dialog and validate that a mouse down message makes it to
2020 // the main view within the dialog.
2021
2022 // This instance will be destroyed when the dialog is destroyed.
2023 ModalDialogDelegate* dialog_delegate = new ModalDialogDelegate;
2024
2025 Widget* modal_dialog_widget = views::DialogDelegate::CreateDialogWidget(
2026 dialog_delegate, NULL, top_level_widget.GetNativeWindow());
2027 modal_dialog_widget->SetBounds(gfx::Rect(100, 100, 200, 200));
2028 EventCountView* dialog_widget_view = new EventCountView();
2029 dialog_widget_view->SetBounds(0, 0, 50, 50);
2030 modal_dialog_widget->GetRootView()->AddChildView(dialog_widget_view);
2031 modal_dialog_widget->Show();
2032 EXPECT_TRUE(modal_dialog_widget->IsVisible());
2033
2034 gfx::Point cursor_location_dialog(100, 100);
2035 ui::MouseEvent mouse_down_dialog(ui::ET_MOUSE_PRESSED,
2036 cursor_location_dialog,
2037 cursor_location_dialog,
2038 ui::EF_NONE);
2039 top_level_widget.GetNativeView()->GetRootWindow()->
2040 AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_down_dialog);
2041 EXPECT_EQ(1, dialog_widget_view->GetEventCount(ui::ET_MOUSE_PRESSED));
2042
2043 // Send a mouse move message to the main window. It should not be received by
2044 // the main window as the modal dialog is still active.
2045 gfx::Point cursor_location_main2(6, 6);
2046 ui::MouseEvent mouse_down_main(ui::ET_MOUSE_MOVED,
2047 cursor_location_main2,
2048 cursor_location_main2,
2049 ui::EF_NONE);
2050 top_level_widget.GetNativeView()->GetRootWindow()->
2051 AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_down_main);
2052 EXPECT_EQ(0, widget_view->GetEventCount(ui::ET_MOUSE_MOVED));
2053
2054 modal_dialog_widget->CloseNow();
2055 top_level_widget.CloseNow();
2056 }
2057 #endif
2058
1970 } // namespace test 2059 } // namespace test
1971 } // namespace views 2060 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/desktop_aura/desktop_root_window_host_x11.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698