Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / ui / views / widget / root_view_unittest.cc
index 9def772..fcefb70 100644 (file)
@@ -4,7 +4,6 @@
 
 #include "ui/views/widget/root_view.h"
 
-#include "ui/events/event_targeter.h"
 #include "ui/views/context_menu_controller.h"
 #include "ui/views/test/views_test_base.h"
 #include "ui/views/view_targeter.h"
@@ -18,9 +17,9 @@ typedef ViewsTestBase RootViewTest;
 class DeleteOnKeyEventView : public View {
  public:
   explicit DeleteOnKeyEventView(bool* set_on_key) : set_on_key_(set_on_key) {}
-  virtual ~DeleteOnKeyEventView() {}
+  ~DeleteOnKeyEventView() override {}
 
-  virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE {
+  bool OnKeyPressed(const ui::KeyEvent& event) override {
     *set_on_key_ = true;
     delete this;
     return true;
@@ -54,12 +53,12 @@ TEST_F(RootViewTest, DeleteViewDuringKeyEventDispatch) {
   child->SetFocusable(true);
   child->RequestFocus();
 
-  ui::EventTargeter* targeter = new ViewTargeter();
   internal::RootView* root_view =
       static_cast<internal::RootView*>(widget.GetRootView());
-  root_view->SetEventTargeter(make_scoped_ptr(targeter));
+  ViewTargeter* view_targeter = new ViewTargeter(root_view);
+  root_view->SetEventTargeter(make_scoped_ptr(view_targeter));
 
-  ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_ESCAPE, 0, false);
+  ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_ESCAPE, ui::EF_NONE);
   ui::EventDispatchDetails details = root_view->OnEventFromSource(&key_event);
   EXPECT_TRUE(details.target_destroyed);
   EXPECT_FALSE(details.dispatcher_destroyed);
@@ -74,7 +73,7 @@ class TestContextMenuController : public ContextMenuController {
         menu_source_view_(NULL),
         menu_source_type_(ui::MENU_SOURCE_NONE) {
   }
-  virtual ~TestContextMenuController() {}
+  ~TestContextMenuController() override {}
 
   int show_context_menu_calls() const { return show_context_menu_calls_; }
   View* menu_source_view() const { return menu_source_view_; }
@@ -87,10 +86,9 @@ class TestContextMenuController : public ContextMenuController {
   }
 
   // ContextMenuController:
-  virtual void ShowContextMenuForView(
-      View* source,
-      const gfx::Point& point,
-      ui::MenuSourceType source_type) OVERRIDE {
+  void ShowContextMenuForView(View* source,
+                              const gfx::Point& point,
+                              ui::MenuSourceType source_type) override {
     show_context_menu_calls_++;
     menu_source_view_ = source;
     menu_source_type_ = source_type;
@@ -123,7 +121,7 @@ TEST_F(RootViewTest, ContextMenuFromKeyEvent) {
   focused_view->RequestFocus();
 
   // No context menu should be shown for a keypress of 'A'.
-  ui::KeyEvent nomenu_key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, 0, true);
+  ui::KeyEvent nomenu_key_event('a', ui::VKEY_A, ui::EF_NONE);
   ui::EventDispatchDetails details =
       root_view->OnEventFromSource(&nomenu_key_event);
   EXPECT_FALSE(details.target_destroyed);
@@ -135,7 +133,7 @@ TEST_F(RootViewTest, ContextMenuFromKeyEvent) {
 
   // A context menu should be shown for a keypress of Shift+F10.
   ui::KeyEvent menu_key_event(
-      ui::ET_KEY_PRESSED, ui::VKEY_F10, ui::EF_SHIFT_DOWN, false);
+      ui::ET_KEY_PRESSED, ui::VKEY_F10, ui::EF_SHIFT_DOWN);
   details = root_view->OnEventFromSource(&menu_key_event);
   EXPECT_FALSE(details.target_destroyed);
   EXPECT_FALSE(details.dispatcher_destroyed);
@@ -145,7 +143,7 @@ TEST_F(RootViewTest, ContextMenuFromKeyEvent) {
   controller.Reset();
 
   // A context menu should be shown for a keypress of VKEY_APPS.
-  ui::KeyEvent menu_key_event2(ui::ET_KEY_PRESSED, ui::VKEY_APPS, 0, false);
+  ui::KeyEvent menu_key_event2(ui::ET_KEY_PRESSED, ui::VKEY_APPS, ui::EF_NONE);
   details = root_view->OnEventFromSource(&menu_key_event2);
   EXPECT_FALSE(details.target_destroyed);
   EXPECT_FALSE(details.dispatcher_destroyed);
@@ -161,12 +159,9 @@ class GestureHandlingView : public View {
   GestureHandlingView() {
   }
 
-  virtual ~GestureHandlingView() {
-  }
+  ~GestureHandlingView() override {}
 
-  virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE {
-    event->SetHandled();
-  }
+  void OnGestureEvent(ui::GestureEvent* event) override { event->SetHandled(); }
 
  private:
   DISALLOW_COPY_AND_ASSIGN(GestureHandlingView);
@@ -180,7 +175,7 @@ TEST_F(RootViewTest, ContextMenuFromLongPress) {
   Widget::InitParams init_params =
       CreateParams(Widget::InitParams::TYPE_POPUP);
   init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
-  init_params.bounds = gfx::Rect(100,100);
+  init_params.bounds = gfx::Rect(100, 100);
   widget.Init(init_params);
   internal::RootView* root_view =
       static_cast<internal::RootView*>(widget.GetRootView());
@@ -193,50 +188,153 @@ TEST_F(RootViewTest, ContextMenuFromLongPress) {
   widget.SetContentsView(parent_view);
 
   View* gesture_handling_child_view = new GestureHandlingView;
-  gesture_handling_child_view->SetBoundsRect(gfx::Rect(10,10));
+  gesture_handling_child_view->SetBoundsRect(gfx::Rect(10, 10));
   parent_view->AddChildView(gesture_handling_child_view);
 
   View* other_child_view = new View;
-  other_child_view->SetBoundsRect(gfx::Rect(20, 0, 10,10));
+  other_child_view->SetBoundsRect(gfx::Rect(20, 0, 10, 10));
   parent_view->AddChildView(other_child_view);
 
   // |parent_view| should not show a context menu as a result of a long press on
   // |gesture_handling_child_view|.
-  ui::GestureEvent begin1(ui::ET_GESTURE_BEGIN, 5, 5, 0, base::TimeDelta(),
-      ui::GestureEventDetails(ui::ET_GESTURE_BEGIN, 0, 0), 1);
-  ui::EventDispatchDetails details = root_view->OnEventFromSource(&begin1);
-
-  ui::GestureEvent long_press1(ui::ET_GESTURE_LONG_PRESS, 5, 5, 0,
+  ui::GestureEvent long_press1(
+      5,
+      5,
+      0,
       base::TimeDelta(),
-      ui::GestureEventDetails(ui::ET_GESTURE_LONG_PRESS, 0, 0), 1);
-  details = root_view->OnEventFromSource(&long_press1);
+      ui::GestureEventDetails(ui::ET_GESTURE_LONG_PRESS));
+  ui::EventDispatchDetails details = root_view->OnEventFromSource(&long_press1);
 
-  ui::GestureEvent end1(ui::ET_GESTURE_END, 5, 5, 0, base::TimeDelta(),
-      ui::GestureEventDetails(ui::ET_GESTURE_END, 0, 0), 1);
+  ui::GestureEvent end1(
+      5, 5, 0, base::TimeDelta(), ui::GestureEventDetails(ui::ET_GESTURE_END));
   details = root_view->OnEventFromSource(&end1);
 
   EXPECT_FALSE(details.target_destroyed);
   EXPECT_FALSE(details.dispatcher_destroyed);
   EXPECT_EQ(0, controller.show_context_menu_calls());
+  controller.Reset();
 
   // |parent_view| should show a context menu as a result of a long press on
   // |other_child_view|.
-  ui::GestureEvent begin2(ui::ET_GESTURE_BEGIN, 25, 5, 0, base::TimeDelta(),
-      ui::GestureEventDetails(ui::ET_GESTURE_BEGIN, 0, 0), 1);
-  details = root_view->OnEventFromSource(&begin2);
-
-  ui::GestureEvent long_press2(ui::ET_GESTURE_LONG_PRESS, 25, 5, 0,
+  ui::GestureEvent long_press2(
+      25,
+      5,
+      0,
       base::TimeDelta(),
-      ui::GestureEventDetails(ui::ET_GESTURE_LONG_PRESS, 0, 0), 1);
+      ui::GestureEventDetails(ui::ET_GESTURE_LONG_PRESS));
   details = root_view->OnEventFromSource(&long_press2);
 
-  ui::GestureEvent end2(ui::ET_GESTURE_END, 25, 5, 0, base::TimeDelta(),
-      ui::GestureEventDetails(ui::ET_GESTURE_END, 0, 0), 1);
+  ui::GestureEvent end2(
+      25, 5, 0, base::TimeDelta(), ui::GestureEventDetails(ui::ET_GESTURE_END));
   details = root_view->OnEventFromSource(&end2);
 
   EXPECT_FALSE(details.target_destroyed);
   EXPECT_FALSE(details.dispatcher_destroyed);
   EXPECT_EQ(1, controller.show_context_menu_calls());
+  controller.Reset();
+
+  // |parent_view| should show a context menu as a result of a long press on
+  // itself.
+  ui::GestureEvent long_press3(
+      50,
+      50,
+      0,
+      base::TimeDelta(),
+      ui::GestureEventDetails(ui::ET_GESTURE_LONG_PRESS));
+  details = root_view->OnEventFromSource(&long_press3);
+
+  ui::GestureEvent end3(
+      25, 5, 0, base::TimeDelta(), ui::GestureEventDetails(ui::ET_GESTURE_END));
+  details = root_view->OnEventFromSource(&end3);
+
+  EXPECT_FALSE(details.target_destroyed);
+  EXPECT_FALSE(details.dispatcher_destroyed);
+  EXPECT_EQ(1, controller.show_context_menu_calls());
+}
+
+// Tests that context menus are not shown for disabled views on a long press.
+TEST_F(RootViewTest, ContextMenuFromLongPressOnDisabledView) {
+  Widget widget;
+  Widget::InitParams init_params =
+      CreateParams(Widget::InitParams::TYPE_POPUP);
+  init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
+  init_params.bounds = gfx::Rect(100, 100);
+  widget.Init(init_params);
+  internal::RootView* root_view =
+      static_cast<internal::RootView*>(widget.GetRootView());
+
+  // Create a view capable of showing the context menu with two children one of
+  // which handles all gesture events (e.g. a button). Also mark this view
+  // as disabled.
+  TestContextMenuController controller;
+  View* parent_view = new View;
+  parent_view->set_context_menu_controller(&controller);
+  parent_view->SetEnabled(false);
+  widget.SetContentsView(parent_view);
+
+  View* gesture_handling_child_view = new GestureHandlingView;
+  gesture_handling_child_view->SetBoundsRect(gfx::Rect(10, 10));
+  parent_view->AddChildView(gesture_handling_child_view);
+
+  View* other_child_view = new View;
+  other_child_view->SetBoundsRect(gfx::Rect(20, 0, 10, 10));
+  parent_view->AddChildView(other_child_view);
+
+  // |parent_view| should not show a context menu as a result of a long press on
+  // |gesture_handling_child_view|.
+  ui::GestureEvent long_press1(
+      5,
+      5,
+      0,
+      base::TimeDelta(),
+      ui::GestureEventDetails(ui::ET_GESTURE_LONG_PRESS));
+  ui::EventDispatchDetails details = root_view->OnEventFromSource(&long_press1);
+
+  ui::GestureEvent end1(
+      5, 5, 0, base::TimeDelta(), ui::GestureEventDetails(ui::ET_GESTURE_END));
+  details = root_view->OnEventFromSource(&end1);
+
+  EXPECT_FALSE(details.target_destroyed);
+  EXPECT_FALSE(details.dispatcher_destroyed);
+  EXPECT_EQ(0, controller.show_context_menu_calls());
+  controller.Reset();
+
+  // |parent_view| should not show a context menu as a result of a long press on
+  // |other_child_view|.
+  ui::GestureEvent long_press2(
+      25,
+      5,
+      0,
+      base::TimeDelta(),
+      ui::GestureEventDetails(ui::ET_GESTURE_LONG_PRESS));
+  details = root_view->OnEventFromSource(&long_press2);
+
+  ui::GestureEvent end2(
+      25, 5, 0, base::TimeDelta(), ui::GestureEventDetails(ui::ET_GESTURE_END));
+  details = root_view->OnEventFromSource(&end2);
+
+  EXPECT_FALSE(details.target_destroyed);
+  EXPECT_FALSE(details.dispatcher_destroyed);
+  EXPECT_EQ(0, controller.show_context_menu_calls());
+  controller.Reset();
+
+  // |parent_view| should not show a context menu as a result of a long press on
+  // itself.
+  ui::GestureEvent long_press3(
+      50,
+      50,
+      0,
+      base::TimeDelta(),
+      ui::GestureEventDetails(ui::ET_GESTURE_LONG_PRESS));
+  details = root_view->OnEventFromSource(&long_press3);
+
+  ui::GestureEvent end3(
+      25, 5, 0, base::TimeDelta(), ui::GestureEventDetails(ui::ET_GESTURE_END));
+  details = root_view->OnEventFromSource(&end3);
+
+  EXPECT_FALSE(details.target_destroyed);
+  EXPECT_FALSE(details.dispatcher_destroyed);
+  EXPECT_EQ(0, controller.show_context_menu_calls());
 }
 
 }  // namespace test