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

Unified Diff: mojo/services/window_manager/view_targeter_unittest.cc

Issue 737913002: Dispatch key events to the currently focused window. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Redo FocusController storage so that it is a local property on a view. Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/services/window_manager/view_targeter.cc ('k') | mojo/services/window_manager/window_manager_app.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/services/window_manager/view_targeter_unittest.cc
diff --git a/mojo/services/window_manager/view_targeter_unittest.cc b/mojo/services/window_manager/view_targeter_unittest.cc
index d97c5a1ef95cb5c86b6a41e7f6ff7ded849cd5f5..6d080affe522e563606758c5768a21856ae377d5 100644
--- a/mojo/services/window_manager/view_targeter_unittest.cc
+++ b/mojo/services/window_manager/view_targeter_unittest.cc
@@ -4,6 +4,8 @@
#include "mojo/services/window_manager/view_targeter.h"
+#include "mojo/services/window_manager/basic_focus_rules.h"
+#include "mojo/services/window_manager/focus_controller.h"
#include "mojo/services/window_manager/view_event_dispatcher.h"
#include "mojo/services/window_manager/window_manager_test_util.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -59,4 +61,46 @@ TEST_F(ViewTargeterTest, Basic) {
one.target()->RemovePreTargetHandler(&handler);
}
+TEST_F(ViewTargeterTest, KeyTest) {
+ // The dispatcher will take ownership of the tree root.
+ TestView root(1, gfx::Rect(0, 0, 100, 100));
+ ViewTarget* root_target = root.target();
+ root_target->SetEventTargeter(scoped_ptr<ViewTargeter>(new ViewTargeter()));
+ view_event_dispatcher_->SetRootViewTarget(root_target);
+
+ TestView one(2, gfx::Rect(0, 0, 500, 100));
+ TestView two(3, gfx::Rect(501, 0, 500, 1000));
+
+ root.AddChild(&one);
+ root.AddChild(&two);
+
+ ui::test::TestEventHandler one_handler;
+ one.target()->AddPreTargetHandler(&one_handler);
+
+ ui::test::TestEventHandler two_handler;
+ two.target()->AddPreTargetHandler(&two_handler);
+
+ FocusController focus_controller(scoped_ptr<mojo::FocusRules>(
+ new mojo::BasicFocusRules(&root)));
+ SetFocusController(&root, &focus_controller);
+
+ // Focus |one|. Then test that it receives a key event.
+ focus_controller.FocusView(&one);
+ ui::KeyEvent key_event_one(ui::ET_KEY_PRESSED, ui::VKEY_A, 0);
+ ui::EventDispatchDetails details =
+ view_event_dispatcher_->OnEventFromSource(&key_event_one);
+ ASSERT_FALSE(details.dispatcher_destroyed);
+ EXPECT_EQ(1, one_handler.num_key_events());
+
+ // Focus |two|. Then test that it receives a key event.
+ focus_controller.FocusView(&two);
+ ui::KeyEvent key_event_two(ui::ET_KEY_PRESSED, ui::VKEY_A, 0);
+ details = view_event_dispatcher_->OnEventFromSource(&key_event_two);
+ ASSERT_FALSE(details.dispatcher_destroyed);
+ EXPECT_EQ(1, two_handler.num_key_events());
+
+ two.target()->RemovePreTargetHandler(&two_handler);
+ one.target()->RemovePreTargetHandler(&one_handler);
+}
+
} // namespace mojo
« no previous file with comments | « mojo/services/window_manager/view_targeter.cc ('k') | mojo/services/window_manager/window_manager_app.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698