| 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 0cb895ab493dbb7afa6b1c3ff07d3713d02e1c0f..110f0d1944dafbe460c83ac96272c0247a594afb 100644
|
| --- a/ui/aura/mus/window_tree_client_unittest.cc
|
| +++ b/ui/aura/mus/window_tree_client_unittest.cc
|
| @@ -22,6 +22,7 @@
|
| #include "ui/aura/client/focus_client.h"
|
| #include "ui/aura/client/transient_window_client.h"
|
| #include "ui/aura/mus/capture_synchronizer.h"
|
| +#include "ui/aura/mus/mus_types.h"
|
| #include "ui/aura/mus/property_converter.h"
|
| #include "ui/aura/mus/window_mus.h"
|
| #include "ui/aura/mus/window_tree_client_delegate.h"
|
| @@ -541,7 +542,8 @@ class InputEventBasicTestWindowDelegate : public test::TestWindowDelegate {
|
|
|
| class InputEventBasicTestEventHandler : public ui::test::TestEventHandler {
|
| public:
|
| - InputEventBasicTestEventHandler() {}
|
| + explicit InputEventBasicTestEventHandler(Window* target_window)
|
| + : target_window_(target_window) {}
|
| ~InputEventBasicTestEventHandler() override {}
|
|
|
| bool got_move() const { return got_move_; }
|
| @@ -550,10 +552,12 @@ class InputEventBasicTestEventHandler : public ui::test::TestEventHandler {
|
|
|
| // ui::test::TestEventHandler overrides.
|
| void OnMouseEvent(ui::MouseEvent* event) override {
|
| - if (event->type() == ui::ET_MOUSE_MOVED)
|
| - got_move_ = true;
|
| - last_event_location_ = event->location();
|
| - event->SetHandled();
|
| + if (event->target() == target_window_) {
|
| + if (event->type() == ui::ET_MOUSE_MOVED)
|
| + got_move_ = true;
|
| + last_event_location_ = event->location();
|
| + event->SetHandled();
|
| + }
|
| }
|
|
|
| void reset() {
|
| @@ -563,6 +567,7 @@ class InputEventBasicTestEventHandler : public ui::test::TestEventHandler {
|
| }
|
|
|
| private:
|
| + Window* target_window_ = nullptr;
|
| bool got_move_ = false;
|
| gfx::Point last_event_location_;
|
| uint32_t event_id_ = 0;
|
| @@ -816,7 +821,7 @@ TEST_F(WindowTreeClientClientTest, InputEventCaptureWindow) {
|
| TEST_F(WindowTreeClientClientTest, InputEventRootWindow) {
|
| WindowTreeHostMus window_tree_host(window_tree_client_impl());
|
| Window* top_level = window_tree_host.window();
|
| - InputEventBasicTestEventHandler root_handler;
|
| + InputEventBasicTestEventHandler root_handler(top_level);
|
| top_level->AddPreTargetHandler(&root_handler);
|
| const gfx::Rect bounds(0, 0, 100, 100);
|
| window_tree_host.SetBoundsInPixels(bounds);
|
| @@ -854,6 +859,104 @@ TEST_F(WindowTreeClientClientTest, InputEventRootWindow) {
|
| EXPECT_EQ(gfx::Point(), child_delegate.last_event_location());
|
| }
|
|
|
| +TEST_F(WindowTreeClientClientTest, InputEventNoWindow) {
|
| + WindowTreeHostMus window_tree_host(window_tree_client_impl());
|
| + Window* top_level = window_tree_host.window();
|
| + InputEventBasicTestEventHandler root_handler(top_level);
|
| + top_level->AddPreTargetHandler(&root_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 child_delegate1(window_tree());
|
| + Window child1(&child_delegate1);
|
| + child1.Init(ui::LAYER_NOT_DRAWN);
|
| + top_level->AddChild(&child1);
|
| + child1.SetBounds(gfx::Rect(25, 25, 100, 100));
|
| + child1.Show();
|
| + InputEventBasicTestWindowDelegate child_delegate2(window_tree());
|
| + Window child2(&child_delegate2);
|
| + child2.Init(ui::LAYER_NOT_DRAWN);
|
| + top_level->AddChild(&child2);
|
| + child2.SetBounds(gfx::Rect(40, 40, 100, 100));
|
| + child2.Show();
|
| + EXPECT_FALSE(root_handler.got_move());
|
| + EXPECT_FALSE(child_delegate1.got_move());
|
| + EXPECT_FALSE(child_delegate2.got_move());
|
| +
|
| + const gfx::Point event_location(40, 50);
|
| + const gfx::Point event_root_location(10, 10);
|
| + uint32_t event_id = 1;
|
| + root_handler.set_event_id(event_id);
|
| + child_delegate1.set_event_id(event_id);
|
| + child_delegate2.set_event_id(event_id);
|
| + std::unique_ptr<ui::Event> ui_event(new ui::MouseEvent(
|
| + ui::ET_MOUSE_MOVED, event_location, event_root_location,
|
| + ui::EventTimeForNow(), ui::EF_NONE, 0));
|
| + window_tree_client()->OnWindowInputEvent(
|
| + event_id, kInvalidServerId, window_tree_host.display_id(),
|
| + ui::Event::Clone(*ui_event.get()), 0);
|
| + // WindowTreeClient::OnWindowInputEvent cannot find a target window with
|
| + // kInvalidServerId but should use the display_id to find the window_tree_host
|
| + // for event dispatching and dispatch the event to |top_level| since it's in
|
| + // the space for |top_level|.
|
| + EXPECT_TRUE(window_tree()->WasEventAcked(event_id));
|
| + EXPECT_EQ(ui::mojom::EventResult::HANDLED,
|
| + window_tree()->GetEventResult(event_id));
|
| + EXPECT_TRUE(root_handler.got_move());
|
| + EXPECT_EQ(event_root_location, root_handler.last_event_location());
|
| + EXPECT_FALSE(child_delegate1.got_move());
|
| + EXPECT_FALSE(child_delegate2.got_move());
|
| + root_handler.reset();
|
| + child_delegate1.reset();
|
| + child_delegate2.reset();
|
| +
|
| + const gfx::Point event_root_location1(30, 30);
|
| + event_id = 2;
|
| + root_handler.set_event_id(event_id);
|
| + child_delegate1.set_event_id(event_id);
|
| + child_delegate2.set_event_id(event_id);
|
| + std::unique_ptr<ui::Event> ui_event1(new ui::MouseEvent(
|
| + ui::ET_MOUSE_MOVED, event_location, event_root_location1,
|
| + ui::EventTimeForNow(), ui::EF_NONE, 0));
|
| + window_tree_client()->OnWindowInputEvent(
|
| + event_id, kInvalidServerId, window_tree_host.display_id(),
|
| + ui::Event::Clone(*ui_event1.get()), 0);
|
| + // |child1| should get the event since it's in the space for |child1|.
|
| + EXPECT_TRUE(window_tree()->WasEventAcked(event_id));
|
| + EXPECT_EQ(ui::mojom::EventResult::HANDLED,
|
| + window_tree()->GetEventResult(event_id));
|
| + EXPECT_FALSE(root_handler.got_move());
|
| + EXPECT_TRUE(child_delegate1.got_move());
|
| + EXPECT_EQ(gfx::Point(5, 5), child_delegate1.last_event_location());
|
| + EXPECT_FALSE(child_delegate2.got_move());
|
| + root_handler.reset();
|
| + child_delegate1.reset();
|
| + child_delegate2.reset();
|
| +
|
| + const gfx::Point event_root_location2(60, 60);
|
| + event_id = 3;
|
| + root_handler.set_event_id(event_id);
|
| + child_delegate1.set_event_id(event_id);
|
| + child_delegate2.set_event_id(event_id);
|
| + std::unique_ptr<ui::Event> ui_event2(new ui::MouseEvent(
|
| + ui::ET_MOUSE_MOVED, event_location, event_root_location2,
|
| + ui::EventTimeForNow(), ui::EF_NONE, 0));
|
| + window_tree_client()->OnWindowInputEvent(
|
| + event_id, kInvalidServerId, window_tree_host.display_id(),
|
| + ui::Event::Clone(*ui_event2.get()), 0);
|
| + // |child2| should get the event since it's in the space for |child2|.
|
| + EXPECT_TRUE(window_tree()->WasEventAcked(event_id));
|
| + EXPECT_EQ(ui::mojom::EventResult::HANDLED,
|
| + window_tree()->GetEventResult(event_id));
|
| + EXPECT_FALSE(root_handler.got_move());
|
| + EXPECT_FALSE(child_delegate1.got_move());
|
| + EXPECT_TRUE(child_delegate2.got_move());
|
| + EXPECT_EQ(gfx::Point(20, 20), child_delegate2.last_event_location());
|
| +}
|
| +
|
| class WindowTreeClientPointerObserverTest : public WindowTreeClientClientTest {
|
| public:
|
| WindowTreeClientPointerObserverTest() {}
|
|
|