ui/views/view_targeter_unittest.cc
TEST_F(ViewTargeterTest, ViewTargeterForKeyEvents) {
  Widget widget;
  Widget::InitParams init_params =
      CreateParams(Widget::InitParams::TYPE_POPUP);
  init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
  widget.Init(init_params);

  View* content = new View;
  View* child = new View;
  View* grandchild = new View;

  widget.SetContentsView(content);
  content->AddChildView(child);
  child->AddChildView(grandchild);

  grandchild->SetFocusable(true);
  grandchild->RequestFocus();

  internal::RootView* root_view =
      static_cast<internal::RootView*>(widget.GetRootView());
  ViewTargeter* view_targeter = new ViewTargeter(root_view);
  ui::EventTargeter* targeter = view_targeter;
  root_view->SetEventTargeter(make_scoped_ptr(view_targeter));

  ui::KeyEvent key_event('a', ui::VKEY_A, ui::EF_NONE);

  // The focused view should be the initial target of the event.
  ui::EventTarget* current_target = targeter->FindTargetForEvent(root_view,
                                                                 &key_event);
  EXPECT_EQ(grandchild, static_cast<View*>(current_target));

  // Verify that FindNextBestTarget() will return the parent view of the
  // argument (and NULL if the argument has no parent view).
  current_target = targeter->FindNextBestTarget(grandchild, &key_event);
  EXPECT_EQ(child, static_cast<View*>(current_target));
  current_target = targeter->FindNextBestTarget(child, &key_event);
  EXPECT_EQ(content, static_cast<View*>(current_target));
  current_target = targeter->FindNextBestTarget(content, &key_event);
  EXPECT_EQ(widget.GetRootView(), static_cast<View*>(current_target));
  current_target = targeter->FindNextBestTarget(widget.GetRootView(),
                                                &key_event);
  EXPECT_EQ(NULL, static_cast<View*>(current_target));
}
// Verifies that the the functions ViewTargeter::FindTargetForEvent()
// and ViewTargeter::FindNextBestTarget() are implemented correctly
// for key events.
Verifies that the the functions ViewTargeter::FindTargetForEvent()
and ViewTargeter::FindNextBestTarget() are implemented correctly
for key events.
Verifies that the the functions ViewTargeter :: FindTargetForEvent () and ViewTargeter :: FindNextBestTarget () are implemented correctly for key events .
TEST_F(ViewTargeterTest, ViewTargeterForKeyEvents) {
  Widget widget;
  Widget::InitParams init_params =
      CreateParams(Widget::InitParams::TYPE_POPUP);
  init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
  widget.Init(init_params);
  View* content = new View;
  View* child = new View;
  View* grandchild = new View;
  widget.SetContentsView(content);
  content->AddChildView(child);
  child->AddChildView(grandchild);
  grandchild->SetFocusable(true);
  grandchild->RequestFocus();
  internal::RootView* root_view =
      static_cast<internal::RootView*>(widget.GetRootView());
  ViewTargeter* view_targeter = new ViewTargeter(root_view);
  ui::EventTargeter* targeter = view_targeter;
  root_view->SetEventTargeter(make_scoped_ptr(view_targeter));
  ui::KeyEvent key_event('a', ui::VKEY_A, ui::EF_NONE);
  ui::EventTarget* current_target = targeter->FindTargetForEvent(root_view,
                                                                 &key_event);
  EXPECT_EQ(grandchild, static_cast<View*>(current_target));
  current_target = targeter->FindNextBestTarget(grandchild, &key_event);
  EXPECT_EQ(child, static_cast<View*>(current_target));
  current_target = targeter->FindNextBestTarget(child, &key_event);
  EXPECT_EQ(content, static_cast<View*>(current_target));
  current_target = targeter->FindNextBestTarget(content, &key_event);
  EXPECT_EQ(widget.GetRootView(), static_cast<View*>(current_target));
  current_target = targeter->FindNextBestTarget(widget.GetRootView(),
                                                &key_event);
  EXPECT_EQ(NULL, static_cast<View*>(current_target));
}
TEST_F ( ViewTargeterTest , ViewTargeterForKeyEvents ) { Widget widget ; Widget :: InitParams init_params = CreateParams ( Widget :: InitParams :: TYPE_POPUP ) ; init_params . ownership = Widget :: InitParams :: WIDGET_OWNS_NATIVE_WIDGET ; widget . Init ( init_params ) ; View * content = new View ; View * child = new View ; View * grandchild = new View ; widget . SetContentsView ( content ) ; content -> AddChildView ( child ) ; child -> AddChildView ( grandchild ) ; grandchild -> SetFocusable ( true ) ; grandchild -> RequestFocus ( ) ; internal :: RootView * root_view = static_cast < internal :: RootView * > ( widget . GetRootView ( ) ) ; ViewTargeter * view_targeter = new ViewTargeter ( root_view ) ; ui :: EventTargeter * targeter = view_targeter ; root_view -> SetEventTargeter ( make_scoped_ptr ( view_targeter ) ) ; ui :: KeyEvent key_event ( ' ' , ui :: VKEY_A , ui :: EF_NONE ) ; ui :: EventTarget * current_target = targeter -> FindTargetForEvent ( root_view , & key_event ) ; EXPECT_EQ ( grandchild , static_cast < View * > ( current_target ) ) ; current_target = targeter -> FindNextBestTarget ( grandchild , & key_event ) ; EXPECT_EQ ( child , static_cast < View * > ( current_target ) ) ; current_target = targeter -> FindNextBestTarget ( child , & key_event ) ; EXPECT_EQ ( content , static_cast < View * > ( current_target ) ) ; current_target = targeter -> FindNextBestTarget ( content , & key_event ) ; EXPECT_EQ ( widget . GetRootView ( ) , static_cast < View * > ( current_target ) ) ; current_target = targeter -> FindNextBestTarget ( widget . GetRootView ( ) , & key_event ) ; EXPECT_EQ ( NULL , static_cast < View * > ( current_target ) ) ; }
Verifies that the the functions ViewTargeter::FindTargetForEvent()
and ViewTargeter::FindNextBestTarget() are implemented correctly
for key events.
Verifies that the the functions ViewTargeter :: FindTargetForEvent () and ViewTargeter :: FindNextBestTarget () are implemented correctly for key events .
// The focused view should be the initial target of the event. // Verify that FindNextBestTarget() will return the parent view of the // argument (and NULL if the argument has no parent view).