Chromium Code Reviews| 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 76dcf10e58846047070855359b207796cb78cc4d..c4e37c6f3c516ed1c4deabc5ed866bad80dd8907 100644 |
| --- a/ui/aura/mus/window_tree_client_unittest.cc |
| +++ b/ui/aura/mus/window_tree_client_unittest.cc |
| @@ -31,7 +31,9 @@ |
| #include "ui/aura/test/mus/test_window_tree.h" |
| #include "ui/aura/test/mus/window_tree_client_private.h" |
| #include "ui/aura/test/test_window_delegate.h" |
| +#include "ui/aura/test/test_window_targeter.h" |
| #include "ui/aura/window.h" |
| +#include "ui/aura/window_targeter.h" |
| #include "ui/aura/window_tracker.h" |
| #include "ui/aura/window_tree_host_observer.h" |
| #include "ui/base/class_property.h" |
| @@ -493,8 +495,6 @@ namespace { |
| class InputEventBasicTestWindowDelegate : public test::TestWindowDelegate { |
| public: |
| - static uint32_t constexpr kEventId = 1; |
| - |
| explicit InputEventBasicTestWindowDelegate(TestWindowTree* test_window_tree) |
| : test_window_tree_(test_window_tree) {} |
| ~InputEventBasicTestWindowDelegate() override {} |
| @@ -502,21 +502,30 @@ class InputEventBasicTestWindowDelegate : public test::TestWindowDelegate { |
| 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; } |
| // TestWindowDelegate:: |
| void OnMouseEvent(ui::MouseEvent* event) override { |
| - was_acked_ = test_window_tree_->WasEventAcked(kEventId); |
| + 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; |
| bool got_move_ = false; |
| gfx::Point last_event_location_; |
| + uint32_t event_id_ = 0; |
| DISALLOW_COPY_AND_ASSIGN(InputEventBasicTestWindowDelegate); |
| }; |
| @@ -541,22 +550,196 @@ TEST_F(WindowTreeClientClientTest, InputEventBasic) { |
| EXPECT_FALSE(window_delegate.got_move()); |
| EXPECT_FALSE(window_delegate.was_acked()); |
| const gfx::Point event_location_in_child(2, 3); |
| + const uint32_t event_id = 1; |
| + 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( |
| - InputEventBasicTestWindowDelegate::kEventId, server_id(&child), |
| - window_tree_host.display_id(), ui::Event::Clone(*ui_event.get()), 0); |
| - EXPECT_TRUE(window_tree()->WasEventAcked( |
| - InputEventBasicTestWindowDelegate::kEventId)); |
| + event_id, server_id(&child), 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( |
| - InputEventBasicTestWindowDelegate::kEventId)); |
| + window_tree()->GetEventResult(event_id)); |
| EXPECT_TRUE(window_delegate.got_move()); |
| EXPECT_FALSE(window_delegate.was_acked()); |
| EXPECT_EQ(event_location_in_child, window_delegate.last_event_location()); |
| } |
| +TEST_F(WindowTreeClientClientTest, InputEventFindTargetAndConversion) { |
| + WindowTreeHostMus window_tree_host(window_tree_client_impl()); |
| + Window* top_level = window_tree_host.window(); |
| + 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_delegate1(window_tree()); |
| + Window child1(&window_delegate1); |
| + child1.Init(ui::LAYER_NOT_DRAWN); |
| + child1.SetEventTargeter(base::MakeUnique<WindowTargeter>()); |
| + top_level->AddChild(&child1); |
| + child1.SetBounds(gfx::Rect(10, 10, 100, 100)); |
| + child1.Show(); |
| + InputEventBasicTestWindowDelegate window_delegate2(window_tree()); |
| + Window child2(&window_delegate2); |
| + child2.Init(ui::LAYER_NOT_DRAWN); |
| + child1.AddChild(&child2); |
| + child2.SetBounds(gfx::Rect(20, 30, 100, 100)); |
| + child2.Show(); |
| + |
| + EXPECT_FALSE(window_delegate1.got_move()); |
| + EXPECT_FALSE(window_delegate1.was_acked()); |
| + EXPECT_FALSE(window_delegate2.got_move()); |
| + EXPECT_FALSE(window_delegate2.was_acked()); |
| + |
| + // child1 has a targeter set and event_location is (50, 60), child2 |
| + // should get the event even though mus-ws wants to send to child1. |
| + const gfx::Point event_location(50, 60); |
| + uint32_t event_id = 1; |
| + window_delegate1.set_event_id(event_id); |
| + window_delegate2.set_event_id(event_id); |
| + std::unique_ptr<ui::Event> ui_event( |
| + new ui::MouseEvent(ui::ET_MOUSE_MOVED, event_location, gfx::Point(), |
| + ui::EventTimeForNow(), ui::EF_NONE, 0)); |
| + window_tree_client()->OnWindowInputEvent( |
| + event_id, server_id(&child1), 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_FALSE(window_delegate1.got_move()); |
| + EXPECT_FALSE(window_delegate1.was_acked()); |
| + EXPECT_TRUE(window_delegate2.got_move()); |
| + EXPECT_FALSE(window_delegate2.was_acked()); |
| + EXPECT_EQ(gfx::Point(30, 30), window_delegate2.last_event_location()); |
| + window_delegate1.reset(); |
| + window_delegate2.reset(); |
| + |
| + // Keep the event location in child2's space. Remove the targeter for |
| + // child1 and specify the event to go to child1. However, since there's |
| + // no targeter set for the root target returned by |
| + // EventProcessor::GetRootForEvent, we fall back to use default targeter |
| + // which will send the event to child2. |
|
sadrul
2017/02/14 21:40:10
Because mus-ws sends the event to client1, and non
riajiang
2017/02/15 18:09:27
Changed the logic in EventProcessor and updated th
|
| + child1.SetEventTargeter(nullptr); |
| + const gfx::Point event_location1(45, 50); |
| + event_id = 2; |
| + window_delegate1.set_event_id(event_id); |
| + window_delegate2.set_event_id(event_id); |
| + std::unique_ptr<ui::Event> ui_event1( |
| + new ui::MouseEvent(ui::ET_MOUSE_MOVED, event_location1, gfx::Point(), |
| + ui::EventTimeForNow(), ui::EF_NONE, 0)); |
| + window_tree_client()->OnWindowInputEvent( |
| + event_id, server_id(&child1), window_tree_host.display_id(), |
| + ui::Event::Clone(*ui_event1.get()), 0); |
| + EXPECT_TRUE(window_tree()->WasEventAcked(event_id)); |
| + EXPECT_EQ(ui::mojom::EventResult::HANDLED, |
| + window_tree()->GetEventResult(event_id)); |
| + EXPECT_FALSE(window_delegate1.got_move()); |
| + EXPECT_FALSE(window_delegate1.was_acked()); |
| + EXPECT_TRUE(window_delegate2.got_move()); |
| + EXPECT_FALSE(window_delegate2.was_acked()); |
| + EXPECT_EQ(gfx::Point(25, 20), window_delegate2.last_event_location()); |
| + window_delegate1.reset(); |
| + window_delegate2.reset(); |
| + |
| + // Change the location to be in child1's space and child1 should get the |
| + // event this time. |
| + const gfx::Point event_location2(10, 15); |
| + event_id = 3; |
| + window_delegate1.set_event_id(event_id); |
| + window_delegate2.set_event_id(event_id); |
| + std::unique_ptr<ui::Event> ui_event2( |
| + new ui::MouseEvent(ui::ET_MOUSE_MOVED, event_location2, gfx::Point(), |
| + ui::EventTimeForNow(), ui::EF_NONE, 0)); |
| + window_tree_client()->OnWindowInputEvent( |
| + event_id, server_id(&child1), window_tree_host.display_id(), |
| + ui::Event::Clone(*ui_event2.get()), 0); |
| + EXPECT_TRUE(window_tree()->WasEventAcked(event_id)); |
| + EXPECT_EQ(ui::mojom::EventResult::HANDLED, |
| + window_tree()->GetEventResult(event_id)); |
| + EXPECT_TRUE(window_delegate1.got_move()); |
| + EXPECT_FALSE(window_delegate1.was_acked()); |
| + EXPECT_FALSE(window_delegate2.got_move()); |
| + EXPECT_FALSE(window_delegate2.was_acked()); |
| + EXPECT_EQ(gfx::Point(10, 15), window_delegate1.last_event_location()); |
| +} |
| + |
| +TEST_F(WindowTreeClientClientTest, InputEventCustomWindowTargeter) { |
| + WindowTreeHostMus window_tree_host(window_tree_client_impl()); |
| + Window* top_level = window_tree_host.window(); |
| + 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_delegate1(window_tree()); |
| + Window child1(&window_delegate1); |
| + child1.Init(ui::LAYER_NOT_DRAWN); |
| + child1.SetEventTargeter(base::MakeUnique<test::TestWindowTargeter>()); |
| + top_level->AddChild(&child1); |
| + child1.SetBounds(gfx::Rect(10, 10, 100, 100)); |
| + child1.Show(); |
| + InputEventBasicTestWindowDelegate window_delegate2(window_tree()); |
| + Window child2(&window_delegate2); |
| + child2.Init(ui::LAYER_NOT_DRAWN); |
| + child1.AddChild(&child2); |
| + child2.SetBounds(gfx::Rect(20, 30, 100, 100)); |
| + child2.Show(); |
| + |
| + EXPECT_FALSE(window_delegate1.got_move()); |
| + EXPECT_FALSE(window_delegate1.was_acked()); |
| + EXPECT_FALSE(window_delegate2.got_move()); |
| + EXPECT_FALSE(window_delegate2.was_acked()); |
| + |
| + // child1 has a custom targeter set which would always return itself as the |
| + // target window therefore event should go to child1 unlike |
| + // WindowTreeClientClientTest.InputEventFindTargetAndConversion. |
| + const gfx::Point event_location(50, 60); |
| + uint32_t event_id = 1; |
| + window_delegate1.set_event_id(event_id); |
| + window_delegate2.set_event_id(event_id); |
| + std::unique_ptr<ui::Event> ui_event( |
| + new ui::MouseEvent(ui::ET_MOUSE_MOVED, event_location, gfx::Point(), |
| + ui::EventTimeForNow(), ui::EF_NONE, 0)); |
| + window_tree_client()->OnWindowInputEvent( |
| + event_id, server_id(&child1), 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(window_delegate1.got_move()); |
| + EXPECT_FALSE(window_delegate1.was_acked()); |
| + EXPECT_FALSE(window_delegate2.got_move()); |
| + EXPECT_FALSE(window_delegate2.was_acked()); |
| + EXPECT_EQ(gfx::Point(50, 60), window_delegate1.last_event_location()); |
| + window_delegate1.reset(); |
| + window_delegate2.reset(); |
| + |
| + // child1 should get the event even though mus-ws specifies child2 and it's |
| + // actually in child2's space. Event location will be transformed. |
| + const gfx::Point event_location1(50, 60); |
| + event_id = 2; |
| + window_delegate1.set_event_id(event_id); |
| + window_delegate2.set_event_id(event_id); |
| + std::unique_ptr<ui::Event> ui_event1( |
| + new ui::MouseEvent(ui::ET_MOUSE_MOVED, event_location1, gfx::Point(), |
| + ui::EventTimeForNow(), ui::EF_NONE, 0)); |
| + window_tree_client()->OnWindowInputEvent( |
| + event_id, server_id(&child2), window_tree_host.display_id(), |
| + ui::Event::Clone(*ui_event1.get()), 0); |
| + EXPECT_TRUE(window_tree()->WasEventAcked(event_id)); |
| + EXPECT_EQ(ui::mojom::EventResult::HANDLED, |
| + window_tree()->GetEventResult(event_id)); |
| + EXPECT_TRUE(window_delegate1.got_move()); |
| + EXPECT_FALSE(window_delegate1.was_acked()); |
| + EXPECT_FALSE(window_delegate2.got_move()); |
| + EXPECT_FALSE(window_delegate2.was_acked()); |
| + EXPECT_EQ(gfx::Point(70, 90), window_delegate1.last_event_location()); |
| +} |
| + |
| class WindowTreeClientPointerObserverTest : public WindowTreeClientClientTest { |
| public: |
| WindowTreeClientPointerObserverTest() {} |