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

Unified Diff: components/mus/ws/event_dispatcher_unittest.cc

Issue 1414943003: Moves move logic into WM instead of WS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compile Created 5 years, 2 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 | « components/mus/ws/event_dispatcher_delegate.h ('k') | components/mus/ws/move_loop.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/mus/ws/event_dispatcher_unittest.cc
diff --git a/components/mus/ws/event_dispatcher_unittest.cc b/components/mus/ws/event_dispatcher_unittest.cc
index 607f4c25690b464a3f1c0410c1aab24f63b00d7a..91ce4b3a060404688ee4425b0b8a9ec0e5a9d760 100644
--- a/components/mus/ws/event_dispatcher_unittest.cc
+++ b/components/mus/ws/event_dispatcher_unittest.cc
@@ -22,7 +22,8 @@ class TestEventDispatcherDelegate : public EventDispatcherDelegate {
: root_(root),
focused_window_(nullptr),
last_target_(nullptr),
- last_accelerator_(0) {}
+ last_accelerator_(0),
+ last_in_nonclient_area_(false) {}
~TestEventDispatcherDelegate() override {}
mojo::EventPtr GetAndClearLastDispatchedEvent() {
@@ -37,6 +38,12 @@ class TestEventDispatcherDelegate : public EventDispatcherDelegate {
ServerWindow* last_target() { return last_target_; }
+ bool GetAndClearLastInNonclientArea() {
+ const bool result = last_in_nonclient_area_;
+ last_in_nonclient_area_ = false;
+ return result;
+ }
+
private:
// EventDispatcherDelegate:
void OnAccelerator(uint32_t accelerator, mojo::EventPtr event) override {
@@ -50,9 +57,11 @@ class TestEventDispatcherDelegate : public EventDispatcherDelegate {
return focused_window_;
}
void DispatchInputEventToWindow(ServerWindow* target,
+ bool in_nonclient_area,
mojo::EventPtr event) override {
last_target_ = target;
last_dispatched_event_ = event.Pass();
+ last_in_nonclient_area_ = in_nonclient_area;
}
ServerWindow* root_;
@@ -60,6 +69,7 @@ class TestEventDispatcherDelegate : public EventDispatcherDelegate {
ServerWindow* last_target_;
mojo::EventPtr last_dispatched_event_;
uint32_t last_accelerator_;
+ bool last_in_nonclient_area_;
DISALLOW_COPY_AND_ASSIGN(TestEventDispatcherDelegate);
};
@@ -90,6 +100,8 @@ void RunMouseEventTests(EventDispatcher* dispatcher,
dispatched_event_mojo.To<scoped_ptr<ui::Event>>());
ASSERT_TRUE(dispatched_event.get()) << "Test " << i << " failed.";
ASSERT_TRUE(dispatched_event->IsMouseEvent()) << "Test " << i << " failed.";
+ EXPECT_FALSE(dispatcher_delegate->GetAndClearLastInNonclientArea())
+ << "Test " << i << " failed.";
ui::MouseEvent* dispatched_mouse_event =
static_cast<ui::MouseEvent*>(dispatched_event.get());
EXPECT_EQ(test.expected_root_location,
@@ -268,7 +280,7 @@ TEST(EventDispatcherTest, CaptureMultipleMouseButtons) {
arraysize(tests));
}
-TEST(EventDispatcherTest, MoveWindow) {
+TEST(EventDispatcherTest, ClientAreaGoesToOwner) {
TestServerWindowDelegate window_delegate;
ServerWindow root(&window_delegate, WindowId(1, 2));
window_delegate.set_root_window(&root);
@@ -281,7 +293,6 @@ TEST(EventDispatcherTest, MoveWindow) {
root.SetBounds(gfx::Rect(0, 0, 100, 100));
child.SetBounds(gfx::Rect(10, 10, 20, 20));
- root.set_is_draggable_window_container(true);
child.SetClientArea(gfx::Rect(5, 5, 10, 10));
TestEventDispatcherDelegate event_dispatcher_delegate(&root);
@@ -295,20 +306,20 @@ TEST(EventDispatcherTest, MoveWindow) {
dispatcher.OnEvent(
mojo::Event::From(static_cast<const ui::Event&>(press_event)));
- // The event should not have been dispatched to the delegate.
- ASSERT_EQ(nullptr, event_dispatcher_delegate.last_target());
+ // Events should target child and be in the non-client area.
+ ASSERT_EQ(&child, event_dispatcher_delegate.last_target());
+ EXPECT_TRUE(event_dispatcher_delegate.GetAndClearLastInNonclientArea());
- // Move the mouse 5,6 pixels and verify window moved.
+ // Move the mouse 5,6 pixels and target is the same.
const ui::MouseEvent move_event(ui::ET_MOUSE_MOVED, gfx::PointF(17.f, 18.f),
gfx::PointF(17.f, 18.f), base::TimeDelta(),
ui::EF_LEFT_MOUSE_BUTTON, 0);
dispatcher.OnEvent(
mojo::Event::From(static_cast<const ui::Event&>(move_event)));
- // The event should not have been dispatched to the delegate.
- ASSERT_EQ(nullptr, event_dispatcher_delegate.last_target());
-
- EXPECT_EQ(gfx::Rect(15, 16, 20, 20), child.bounds());
+ // Still same target.
+ ASSERT_EQ(&child, event_dispatcher_delegate.last_target());
+ EXPECT_TRUE(event_dispatcher_delegate.GetAndClearLastInNonclientArea());
// Release the mouse.
const ui::MouseEvent release_event(
@@ -318,71 +329,17 @@ TEST(EventDispatcherTest, MoveWindow) {
mojo::Event::From(static_cast<const ui::Event&>(release_event)));
// The event should not have been dispatched to the delegate.
- ASSERT_EQ(nullptr, event_dispatcher_delegate.last_target());
-
- // Press in the client area and verify the window gets it.
- const ui::MouseEvent press_event2(
- ui::ET_MOUSE_PRESSED, gfx::PointF(21.f, 22.f), gfx::PointF(21.f, 22.f),
- base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON);
- dispatcher.OnEvent(
- mojo::Event::From(static_cast<const ui::Event&>(press_event2)));
ASSERT_EQ(&child, event_dispatcher_delegate.last_target());
-}
-
-TEST(EventDispatcherTest, DestroyWindowWhileMoving) {
- TestServerWindowDelegate window_delegate;
- ServerWindow root(&window_delegate, WindowId(1, 2));
- window_delegate.set_root_window(&root);
- root.SetVisible(true);
-
- scoped_ptr<ServerWindow> child(
- new ServerWindow(&window_delegate, WindowId(1, 3)));
- root.Add(child.get());
- child->SetVisible(true);
-
- root.SetBounds(gfx::Rect(0, 0, 100, 100));
- child->SetBounds(gfx::Rect(10, 10, 20, 20));
-
- root.set_is_draggable_window_container(true);
- child->SetClientArea(gfx::Rect(5, 5, 10, 10));
-
- TestEventDispatcherDelegate event_dispatcher_delegate(&root);
- EventDispatcher dispatcher(&event_dispatcher_delegate);
- dispatcher.set_root(&root);
-
- // Start move loop by sending mouse event over non-client area.
- const ui::MouseEvent press_event(
- ui::ET_MOUSE_PRESSED, gfx::PointF(12.f, 12.f), gfx::PointF(12.f, 12.f),
- base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON);
- dispatcher.OnEvent(
- mojo::Event::From(static_cast<const ui::Event&>(press_event)));
-
- // The event should not have been dispatched to the delegate.
- ASSERT_EQ(nullptr, event_dispatcher_delegate.last_target());
-
- // Destroy the child, no events should be propagated until after the release.
- child.reset();
-
- const ui::MouseEvent move_event(ui::ET_MOUSE_MOVED, gfx::PointF(17.f, 18.f),
- gfx::PointF(17.f, 18.f), base::TimeDelta(),
- ui::EF_LEFT_MOUSE_BUTTON, 0);
- dispatcher.OnEvent(
- mojo::Event::From(static_cast<const ui::Event&>(move_event)));
- ASSERT_EQ(nullptr, event_dispatcher_delegate.last_target());
-
- const ui::MouseEvent release_event(
- ui::ET_MOUSE_RELEASED, gfx::PointF(17.f, 18.f), gfx::PointF(17.f, 18.f),
- base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON);
- dispatcher.OnEvent(
- mojo::Event::From(static_cast<const ui::Event&>(release_event)));
- ASSERT_EQ(nullptr, event_dispatcher_delegate.last_target());
+ EXPECT_TRUE(event_dispatcher_delegate.GetAndClearLastInNonclientArea());
+ // Press in the client area and verify target/client area.
const ui::MouseEvent press_event2(
ui::ET_MOUSE_PRESSED, gfx::PointF(21.f, 22.f), gfx::PointF(21.f, 22.f),
base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON);
dispatcher.OnEvent(
mojo::Event::From(static_cast<const ui::Event&>(press_event2)));
- ASSERT_EQ(&root, event_dispatcher_delegate.last_target());
+ ASSERT_EQ(&child, event_dispatcher_delegate.last_target());
+ EXPECT_FALSE(event_dispatcher_delegate.GetAndClearLastInNonclientArea());
}
} // namespace ws
« no previous file with comments | « components/mus/ws/event_dispatcher_delegate.h ('k') | components/mus/ws/move_loop.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698