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

Unified Diff: ui/aura/mus/window_tree_client_unittest.cc

Issue 2730903005: Start with event_target in for loop to avoid GetEventTargeter crash. (Closed)
Patch Set: test Created 3 years, 10 months 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 | « no previous file | ui/aura/window_event_dispatcher.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/aura/mus/window_tree_client_unittest.cc
diff --git a/ui/aura/mus/window_tree_client_unittest.cc b/ui/aura/mus/window_tree_client_unittest.cc
index c15f3b7cb840f3e81b4e1c07d807f2709328eef6..a17f71809f6d6af60e2fc0f1c83b62b4a2a8f020 100644
--- a/ui/aura/mus/window_tree_client_unittest.cc
+++ b/ui/aura/mus/window_tree_client_unittest.cc
@@ -43,6 +43,7 @@
#include "ui/display/screen.h"
#include "ui/events/event.h"
#include "ui/events/event_utils.h"
+#include "ui/events/test/test_event_handler.h"
#include "ui/gfx/geometry/dip_util.h"
#include "ui/gfx/geometry/rect.h"
@@ -536,6 +537,43 @@ class InputEventBasicTestWindowDelegate : public test::TestWindowDelegate {
DISALLOW_COPY_AND_ASSIGN(InputEventBasicTestWindowDelegate);
};
+class InputEventBasicTestEventHandler : public ui::test::TestEventHandler {
+ public:
+ explicit InputEventBasicTestEventHandler(TestWindowTree* test_window_tree)
+ : test_window_tree_(test_window_tree) {}
+ ~InputEventBasicTestEventHandler() override {}
+
+ bool got_move() const { return got_move_; }
+ bool was_acked() const { return was_acked_; }
+ const gfx::Point& last_event_location() const { return last_event_location_; }
+ void set_event_id(uint32_t event_id) { event_id_ = event_id; }
+
+ // ui::test::TestEventHandler overrides.
+ void OnMouseEvent(ui::MouseEvent* event) override {
+ was_acked_ = test_window_tree_->WasEventAcked(event_id_);
+ if (event->type() == ui::ET_MOUSE_MOVED)
+ got_move_ = true;
+ last_event_location_ = event->location();
+ event->SetHandled();
+ }
+
+ void reset() {
+ was_acked_ = false;
+ got_move_ = false;
+ last_event_location_ = gfx::Point();
+ event_id_ = 0;
+ }
+
+ private:
+ TestWindowTree* test_window_tree_;
+ bool was_acked_ = false;
sadrul 2017/03/04 02:44:00 Can you get rid of this?
riajiang 2017/03/04 21:34:20 Done.
+ bool got_move_ = false;
+ gfx::Point last_event_location_;
+ uint32_t event_id_ = 0;
+
+ DISALLOW_COPY_AND_ASSIGN(InputEventBasicTestEventHandler);
+};
+
} // namespace
TEST_F(WindowTreeClientClientTest, InputEventBasic) {
@@ -779,6 +817,47 @@ TEST_F(WindowTreeClientClientTest, InputEventCaptureWindow) {
capture_client.reset();
}
+TEST_F(WindowTreeClientClientTest, InputEventRootWindow) {
+ WindowTreeHostMus window_tree_host(window_tree_client_impl());
+ Window* top_level = window_tree_host.window();
+ InputEventBasicTestEventHandler event_handler(window_tree());
sadrul 2017/03/04 02:44:00 Call this root_handler (or top_level_handler)
riajiang 2017/03/04 21:34:20 Done.
+ top_level->AddPreTargetHandler(&event_handler);
+ const gfx::Rect bounds(0, 0, 100, 100);
+ window_tree_host.SetBoundsInPixels(bounds);
+ window_tree_host.InitHost();
+ window_tree_host.Show();
+ EXPECT_EQ(bounds, top_level->bounds());
+ EXPECT_EQ(bounds, window_tree_host.GetBoundsInPixels());
+ InputEventBasicTestWindowDelegate window_delegate(window_tree());
sadrul 2017/03/04 02:44:00 Call this child_delegate
riajiang 2017/03/04 21:34:20 Done.
+ Window child(&window_delegate);
+ child.Init(ui::LAYER_NOT_DRAWN);
+ top_level->AddChild(&child);
+ child.SetBounds(gfx::Rect(10, 10, 100, 100));
+ child.Show();
+
+ EXPECT_FALSE(event_handler.got_move());
+ EXPECT_FALSE(window_delegate.got_move());
+
+ const gfx::Point event_location_in_child(20, 30);
+ const uint32_t event_id = 1;
+ event_handler.set_event_id(event_id);
+ window_delegate.set_event_id(event_id);
+ std::unique_ptr<ui::Event> ui_event(
+ new ui::MouseEvent(ui::ET_MOUSE_MOVED, event_location_in_child,
+ gfx::Point(), ui::EventTimeForNow(), ui::EF_NONE, 0));
+ window_tree_client()->OnWindowInputEvent(
+ event_id, server_id(top_level), window_tree_host.display_id(),
+ ui::Event::Clone(*ui_event.get()), 0);
+
+ EXPECT_TRUE(window_tree()->WasEventAcked(event_id));
+ EXPECT_EQ(ui::mojom::EventResult::HANDLED,
+ window_tree()->GetEventResult(event_id));
+ EXPECT_TRUE(event_handler.got_move());
+ EXPECT_EQ(gfx::Point(20, 30), event_handler.last_event_location());
+ EXPECT_FALSE(window_delegate.got_move());
+ EXPECT_EQ(gfx::Point(), window_delegate.last_event_location());
+}
+
class WindowTreeClientPointerObserverTest : public WindowTreeClientClientTest {
public:
WindowTreeClientPointerObserverTest() {}
« no previous file with comments | « no previous file | ui/aura/window_event_dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698