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

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

Issue 2371113003: Do not give instant focus if a view's toplevelwidget is not active (Closed)
Patch Set: based on comments 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
« no previous file with comments | « ui/views/widget/native_widget_aura_interactive_uitest.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "ui/views/widget/root_view.h" 5 #include "ui/views/widget/root_view.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "ui/events/event_utils.h" 9 #include "ui/events/event_utils.h"
10 #include "ui/views/context_menu_controller.h" 10 #include "ui/views/context_menu_controller.h"
(...skipping 26 matching lines...) Expand all
37 }; 37 };
38 38
39 // Verifies deleting a View in OnKeyPressed() doesn't crash and that the 39 // Verifies deleting a View in OnKeyPressed() doesn't crash and that the
40 // target is marked as destroyed in the returned EventDispatchDetails. 40 // target is marked as destroyed in the returned EventDispatchDetails.
41 TEST_F(RootViewTest, DeleteViewDuringKeyEventDispatch) { 41 TEST_F(RootViewTest, DeleteViewDuringKeyEventDispatch) {
42 Widget widget; 42 Widget widget;
43 Widget::InitParams init_params = 43 Widget::InitParams init_params =
44 CreateParams(Widget::InitParams::TYPE_POPUP); 44 CreateParams(Widget::InitParams::TYPE_POPUP);
45 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 45 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
46 widget.Init(init_params); 46 widget.Init(init_params);
47 widget.Show();
47 48
48 bool got_key_event = false; 49 bool got_key_event = false;
49 50
50 View* content = new View; 51 View* content = new View;
51 widget.SetContentsView(content); 52 widget.SetContentsView(content);
52 53
53 View* child = new DeleteOnKeyEventView(&got_key_event); 54 View* child = new DeleteOnKeyEventView(&got_key_event);
54 content->AddChildView(child); 55 content->AddChildView(child);
55 56
56 // Give focus to |child| so that it will be the target of the key event. 57 // Give focus to |child| so that it will be the target of the key event.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 }; 108 };
108 109
109 // Tests that context menus are shown for certain key events (Shift+F10 110 // Tests that context menus are shown for certain key events (Shift+F10
110 // and VKEY_APPS) by the pre-target handler installed on RootView. 111 // and VKEY_APPS) by the pre-target handler installed on RootView.
111 TEST_F(RootViewTest, ContextMenuFromKeyEvent) { 112 TEST_F(RootViewTest, ContextMenuFromKeyEvent) {
112 Widget widget; 113 Widget widget;
113 Widget::InitParams init_params = 114 Widget::InitParams init_params =
114 CreateParams(Widget::InitParams::TYPE_POPUP); 115 CreateParams(Widget::InitParams::TYPE_POPUP);
115 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 116 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
116 widget.Init(init_params); 117 widget.Init(init_params);
118 widget.Show();
117 internal::RootView* root_view = 119 internal::RootView* root_view =
118 static_cast<internal::RootView*>(widget.GetRootView()); 120 static_cast<internal::RootView*>(widget.GetRootView());
119 121
120 TestContextMenuController controller; 122 TestContextMenuController controller;
121 View* focused_view = new View; 123 View* focused_view = new View;
122 focused_view->set_context_menu_controller(&controller); 124 focused_view->set_context_menu_controller(&controller);
123 widget.SetContentsView(focused_view); 125 widget.SetContentsView(focused_view);
124 focused_view->SetFocusBehavior(View::FocusBehavior::ALWAYS); 126 focused_view->SetFocusBehavior(View::FocusBehavior::ALWAYS);
125 focused_view->RequestFocus(); 127 focused_view->RequestFocus();
126 128
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 // mouse exit event to |subchild| and destroy the widget. This should not 535 // mouse exit event to |subchild| and destroy the widget. This should not
534 // crash when the mouse exit handler returns from |subchild|. 536 // crash when the mouse exit handler returns from |subchild|.
535 ui::MouseEvent move_event2(ui::ET_MOUSE_MOVED, gfx::Point(15, 15), 537 ui::MouseEvent move_event2(ui::ET_MOUSE_MOVED, gfx::Point(15, 15),
536 gfx::Point(15, 15), ui::EventTimeForNow(), 0, 0); 538 gfx::Point(15, 15), ui::EventTimeForNow(), 0, 0);
537 root_view->OnMouseMoved(move_event2); 539 root_view->OnMouseMoved(move_event2);
538 EXPECT_FALSE(widget_deletion_observer.IsWidgetAlive()); 540 EXPECT_FALSE(widget_deletion_observer.IsWidgetAlive());
539 } 541 }
540 542
541 } // namespace test 543 } // namespace test
542 } // namespace views 544 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/native_widget_aura_interactive_uitest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698