root_view_unittest.cc revision 116680a4aac90f2aa7413d9095a592090648e557
1424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 2424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// found in the LICENSE file. 4424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 5e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch#include "ui/views/widget/root_view.h" 6e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch 7e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch#include "ui/views/context_menu_controller.h" 8424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#include "ui/views/test/views_test_base.h" 9c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#include "ui/views/view_targeter.h" 10c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#include "ui/views/widget/root_view.h" 11424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 12424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)namespace views { 13424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)namespace test { 14424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 15424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)typedef ViewsTestBase RootViewTest; 16424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 17424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)class DeleteOnKeyEventView : public View { 18424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) public: 19424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) explicit DeleteOnKeyEventView(bool* set_on_key) : set_on_key_(set_on_key) {} 20424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) virtual ~DeleteOnKeyEventView() {} 21424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 22424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE { 23424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) *set_on_key_ = true; 24424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) delete this; 25424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return true; 26424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) } 27424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 28424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) private: 29424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // Set to true in OnKeyPressed(). 30424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) bool* set_on_key_; 31424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 32424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(DeleteOnKeyEventView); 33424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)}; 34424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 35c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch// Verifies deleting a View in OnKeyPressed() doesn't crash and that the 36c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch// target is marked as destroyed in the returned EventDispatchDetails. 37424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)TEST_F(RootViewTest, DeleteViewDuringKeyEventDispatch) { 38424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) Widget widget; 39424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) Widget::InitParams init_params = 40424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) CreateParams(Widget::InitParams::TYPE_POPUP); 41424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 42424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) widget.Init(init_params); 43424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 44424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) bool got_key_event = false; 45424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 46424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) View* content = new View; 47424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) widget.SetContentsView(content); 48424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 49424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) View* child = new DeleteOnKeyEventView(&got_key_event); 50424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) content->AddChildView(child); 51424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 52c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // Give focus to |child| so that it will be the target of the key event. 53c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch child->SetFocusable(true); 54c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch child->RequestFocus(); 55c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch 56c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch internal::RootView* root_view = 57c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch static_cast<internal::RootView*>(widget.GetRootView()); 58116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch ViewTargeter* view_targeter = new ViewTargeter(root_view); 59116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch root_view->SetEventTargeter(make_scoped_ptr(view_targeter)); 60c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch 61424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_ESCAPE, 0, false); 62c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch ui::EventDispatchDetails details = root_view->OnEventFromSource(&key_event); 63c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch EXPECT_TRUE(details.target_destroyed); 64c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch EXPECT_FALSE(details.dispatcher_destroyed); 65424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) EXPECT_TRUE(got_key_event); 66424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)} 67424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 68cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// Tracks whether a context menu is shown. 69e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochclass TestContextMenuController : public ContextMenuController { 70e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch public: 71e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch TestContextMenuController() 72e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch : show_context_menu_calls_(0), 73e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch menu_source_view_(NULL), 74e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch menu_source_type_(ui::MENU_SOURCE_NONE) { 75e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch } 76e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch virtual ~TestContextMenuController() {} 77e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch 78e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch int show_context_menu_calls() const { return show_context_menu_calls_; } 79e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch View* menu_source_view() const { return menu_source_view_; } 80e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch ui::MenuSourceType menu_source_type() const { return menu_source_type_; } 81e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch 82e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch void Reset() { 83e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch show_context_menu_calls_ = 0; 84e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch menu_source_view_ = NULL; 85e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch menu_source_type_ = ui::MENU_SOURCE_NONE; 86e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch } 87e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch 88e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch // ContextMenuController: 89e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch virtual void ShowContextMenuForView( 90e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch View* source, 91e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch const gfx::Point& point, 92e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch ui::MenuSourceType source_type) OVERRIDE { 93e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch show_context_menu_calls_++; 94e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch menu_source_view_ = source; 95e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch menu_source_type_ = source_type; 96e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch } 97e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch 98e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch private: 99e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch int show_context_menu_calls_; 100e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch View* menu_source_view_; 101e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch ui::MenuSourceType menu_source_type_; 102e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch 103e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch DISALLOW_COPY_AND_ASSIGN(TestContextMenuController); 104e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch}; 105e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch 106e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch// Tests that context menus are shown for certain key events (Shift+F10 107e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch// and VKEY_APPS) by the pre-target handler installed on RootView. 108e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen MurdochTEST_F(RootViewTest, ContextMenuFromKeyEvent) { 109e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch Widget widget; 110e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch Widget::InitParams init_params = 111e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch CreateParams(Widget::InitParams::TYPE_POPUP); 112e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 113e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch widget.Init(init_params); 114e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch internal::RootView* root_view = 115e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch static_cast<internal::RootView*>(widget.GetRootView()); 116e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch 117e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch TestContextMenuController controller; 118e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch View* focused_view = new View; 119e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch focused_view->set_context_menu_controller(&controller); 120e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch widget.SetContentsView(focused_view); 121e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch focused_view->SetFocusable(true); 122e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch focused_view->RequestFocus(); 123e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch 124e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch // No context menu should be shown for a keypress of 'A'. 125e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch ui::KeyEvent nomenu_key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, 0, true); 126e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch ui::EventDispatchDetails details = 127e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch root_view->OnEventFromSource(&nomenu_key_event); 128e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch EXPECT_FALSE(details.target_destroyed); 129e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch EXPECT_FALSE(details.dispatcher_destroyed); 130e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch EXPECT_EQ(0, controller.show_context_menu_calls()); 131e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch EXPECT_EQ(NULL, controller.menu_source_view()); 132e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch EXPECT_EQ(ui::MENU_SOURCE_NONE, controller.menu_source_type()); 133e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch controller.Reset(); 134e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch 135e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch // A context menu should be shown for a keypress of Shift+F10. 136e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch ui::KeyEvent menu_key_event( 137e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch ui::ET_KEY_PRESSED, ui::VKEY_F10, ui::EF_SHIFT_DOWN, false); 138e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch details = root_view->OnEventFromSource(&menu_key_event); 139e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch EXPECT_FALSE(details.target_destroyed); 140e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch EXPECT_FALSE(details.dispatcher_destroyed); 141e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch EXPECT_EQ(1, controller.show_context_menu_calls()); 142e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch EXPECT_EQ(focused_view, controller.menu_source_view()); 143e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch EXPECT_EQ(ui::MENU_SOURCE_KEYBOARD, controller.menu_source_type()); 144e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch controller.Reset(); 145e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch 146e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch // A context menu should be shown for a keypress of VKEY_APPS. 147e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch ui::KeyEvent menu_key_event2(ui::ET_KEY_PRESSED, ui::VKEY_APPS, 0, false); 148e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch details = root_view->OnEventFromSource(&menu_key_event2); 149e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch EXPECT_FALSE(details.target_destroyed); 150e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch EXPECT_FALSE(details.dispatcher_destroyed); 151e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch EXPECT_EQ(1, controller.show_context_menu_calls()); 152e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch EXPECT_EQ(focused_view, controller.menu_source_view()); 153e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch EXPECT_EQ(ui::MENU_SOURCE_KEYBOARD, controller.menu_source_type()); 154e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch controller.Reset(); 155e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch} 156e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch 157cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// View which handles all gesture events. 158cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)class GestureHandlingView : public View { 159cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) public: 160cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) GestureHandlingView() { 161cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) } 162cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 163cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) virtual ~GestureHandlingView() { 164cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) } 165cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 166cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { 167cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) event->SetHandled(); 168cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) } 169cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 170cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) private: 171cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(GestureHandlingView); 172cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)}; 173cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 174cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// Tests that context menus are shown for long press by the post-target handler 175cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// installed on the RootView only if the event is targetted at a view which can 176cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// show a context menu. 177cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)TEST_F(RootViewTest, ContextMenuFromLongPress) { 178cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) Widget widget; 179cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) Widget::InitParams init_params = 180cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) CreateParams(Widget::InitParams::TYPE_POPUP); 181cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 182cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) init_params.bounds = gfx::Rect(100,100); 183cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) widget.Init(init_params); 184cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) internal::RootView* root_view = 185cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) static_cast<internal::RootView*>(widget.GetRootView()); 186cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 187cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // Create a view capable of showing the context menu with two children one of 188cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // which handles all gesture events (e.g. a button). 189cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) TestContextMenuController controller; 190cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) View* parent_view = new View; 191cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) parent_view->set_context_menu_controller(&controller); 192cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) widget.SetContentsView(parent_view); 193cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 194cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) View* gesture_handling_child_view = new GestureHandlingView; 195cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) gesture_handling_child_view->SetBoundsRect(gfx::Rect(10,10)); 196cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) parent_view->AddChildView(gesture_handling_child_view); 197cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 198cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) View* other_child_view = new View; 199cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) other_child_view->SetBoundsRect(gfx::Rect(20, 0, 10,10)); 200cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) parent_view->AddChildView(other_child_view); 201cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 202cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // |parent_view| should not show a context menu as a result of a long press on 203cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // |gesture_handling_child_view|. 204116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch ui::GestureEvent begin1(5, 5, 0, base::TimeDelta(), 205116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch ui::GestureEventDetails(ui::ET_GESTURE_BEGIN, 0, 0)); 206cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) ui::EventDispatchDetails details = root_view->OnEventFromSource(&begin1); 207cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 208116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch ui::GestureEvent long_press1( 209116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 5, 210116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 5, 211116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 0, 212cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) base::TimeDelta(), 213116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch ui::GestureEventDetails(ui::ET_GESTURE_LONG_PRESS, 0, 0)); 214cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) details = root_view->OnEventFromSource(&long_press1); 215cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 216116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch ui::GestureEvent end1(5, 217116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 5, 218116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 0, 219116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch base::TimeDelta(), 220116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch ui::GestureEventDetails(ui::ET_GESTURE_END, 0, 0)); 221cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) details = root_view->OnEventFromSource(&end1); 222cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 223cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) EXPECT_FALSE(details.target_destroyed); 224cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) EXPECT_FALSE(details.dispatcher_destroyed); 225cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) EXPECT_EQ(0, controller.show_context_menu_calls()); 226cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 227cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // |parent_view| should show a context menu as a result of a long press on 228cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // |other_child_view|. 229116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch ui::GestureEvent begin2(25, 5, 0, base::TimeDelta(), 230116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch ui::GestureEventDetails(ui::ET_GESTURE_BEGIN, 0, 0)); 231cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) details = root_view->OnEventFromSource(&begin2); 232cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 233116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch ui::GestureEvent long_press2( 234116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 25, 235116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 5, 236116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 0, 237cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) base::TimeDelta(), 238116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch ui::GestureEventDetails(ui::ET_GESTURE_LONG_PRESS, 0, 0)); 239cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) details = root_view->OnEventFromSource(&long_press2); 240cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 241116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch ui::GestureEvent end2(25, 242116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 5, 243116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 0, 244116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch base::TimeDelta(), 245116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch ui::GestureEventDetails(ui::ET_GESTURE_END, 0, 0)); 246cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) details = root_view->OnEventFromSource(&end2); 247cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 248cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) EXPECT_FALSE(details.target_destroyed); 249cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) EXPECT_FALSE(details.dispatcher_destroyed); 250cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) EXPECT_EQ(1, controller.show_context_menu_calls()); 251cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)} 252cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 253424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)} // namespace test 254424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)} // namespace views 255