| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "mash/wm/frame/move_loop.h" | 5 #include "mash/wm/frame/move_loop.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "components/mus/public/cpp/tests/test_window.h" | 10 #include "components/mus/public/cpp/tests/test_window.h" |
| 11 #include "mojo/converters/input_events/input_events_type_converters.h" | 11 #include "mojo/converters/input_events/input_events_type_converters.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "ui/base/hit_test.h" | 13 #include "ui/base/hit_test.h" |
| 14 #include "ui/events/event.h" | 14 #include "ui/events/event.h" |
| 15 #include "ui/gfx/geometry/point.h" | 15 #include "ui/gfx/geometry/point.h" |
| 16 #include "ui/gfx/geometry/rect.h" | 16 #include "ui/gfx/geometry/rect.h" |
| 17 | 17 |
| 18 using MoveLoopTest = testing::Test; | 18 using MoveLoopTest = testing::Test; |
| 19 | 19 |
| 20 namespace mash { | 20 namespace mash { |
| 21 namespace wm { | 21 namespace wm { |
| 22 | 22 |
| 23 namespace { | |
| 24 | |
| 25 mus::mojom::EventPtr CreatePointerDownEvent(const gfx::Point& location) { | |
| 26 const ui::TouchEvent event(ui::ET_TOUCH_PRESSED, location, 1, | |
| 27 base::TimeDelta()); | |
| 28 return mus::mojom::Event::From(static_cast<const ui::Event&>(event)); | |
| 29 } | |
| 30 | |
| 31 mus::mojom::EventPtr CreatePointerMove(const gfx::Point& location) { | |
| 32 const ui::TouchEvent event(ui::ET_TOUCH_MOVED, location, 1, | |
| 33 base::TimeDelta()); | |
| 34 return mus::mojom::Event::From(static_cast<const ui::Event&>(event)); | |
| 35 } | |
| 36 | |
| 37 } // namespace | |
| 38 | |
| 39 TEST_F(MoveLoopTest, Move) { | 23 TEST_F(MoveLoopTest, Move) { |
| 40 struct TestData { | 24 struct TestData { |
| 41 // One of the HitTestCompat values. | 25 // One of the HitTestCompat values. |
| 42 int ht_location; | 26 int ht_location; |
| 43 // Amount to move the mouse by. | 27 // Amount to move the mouse by. |
| 44 int delta_x; | 28 int delta_x; |
| 45 int delta_y; | 29 int delta_y; |
| 46 gfx::Rect expected_bounds; | 30 gfx::Rect expected_bounds; |
| 47 } data[] = { | 31 } data[] = { |
| 48 // Move. | 32 // Move. |
| 49 {HTCAPTION, 1, 2, gfx::Rect(101, 202, 300, 400)}, | 33 {HTCAPTION, 1, 2, gfx::Rect(101, 202, 300, 400)}, |
| 50 | 34 |
| 51 // Resizing | 35 // Resizing |
| 52 {HTTOPLEFT, 1, 2, gfx::Rect(101, 202, 299, 398)}, | 36 {HTTOPLEFT, 1, 2, gfx::Rect(101, 202, 299, 398)}, |
| 53 {HTLEFT, 1, 2, gfx::Rect(101, 200, 299, 400)}, | 37 {HTLEFT, 1, 2, gfx::Rect(101, 200, 299, 400)}, |
| 54 {HTBOTTOMLEFT, -1, -2, gfx::Rect(99, 200, 301, 398)}, | 38 {HTBOTTOMLEFT, -1, -2, gfx::Rect(99, 200, 301, 398)}, |
| 55 {HTBOTTOM, -1, 4, gfx::Rect(100, 200, 300, 404)}, | 39 {HTBOTTOM, -1, 4, gfx::Rect(100, 200, 300, 404)}, |
| 56 {HTBOTTOMRIGHT, -3, 4, gfx::Rect(100, 200, 297, 404)}, | 40 {HTBOTTOMRIGHT, -3, 4, gfx::Rect(100, 200, 297, 404)}, |
| 57 {HTRIGHT, 6, -4, gfx::Rect(100, 200, 306, 400)}, | 41 {HTRIGHT, 6, -4, gfx::Rect(100, 200, 306, 400)}, |
| 58 {HTTOPRIGHT, 6, 5, gfx::Rect(100, 205, 306, 395)}, | 42 {HTTOPRIGHT, 6, 5, gfx::Rect(100, 205, 306, 395)}, |
| 59 }; | 43 }; |
| 60 | 44 |
| 61 for (size_t i = 0; i < arraysize(data); ++i) { | 45 for (size_t i = 0; i < arraysize(data); ++i) { |
| 62 mus::TestWindow window; | 46 mus::TestWindow window; |
| 63 window.SetBounds(gfx::Rect(100, 200, 300, 400)); | 47 window.SetBounds(gfx::Rect(100, 200, 300, 400)); |
| 64 gfx::Point pointer_location(51, 52); | 48 gfx::Point pointer_location(51, 52); |
| 49 ui::PointerEvent pointer_down_event( |
| 50 ui::ET_POINTER_DOWN, ui::EventPointerType::POINTER_TYPE_TOUCH, |
| 51 pointer_location, pointer_location, ui::EF_NONE, 1, base::TimeDelta()); |
| 65 scoped_ptr<MoveLoop> move_loop = | 52 scoped_ptr<MoveLoop> move_loop = |
| 66 MoveLoop::Create(&window, data[i].ht_location, | 53 MoveLoop::Create(&window, data[i].ht_location, pointer_down_event); |
| 67 *CreatePointerDownEvent(pointer_location)); | |
| 68 ASSERT_TRUE(move_loop.get()) << i; | 54 ASSERT_TRUE(move_loop.get()) << i; |
| 69 pointer_location.Offset(data[i].delta_x, data[i].delta_y); | 55 pointer_location.Offset(data[i].delta_x, data[i].delta_y); |
| 56 ui::PointerEvent pointer_move_event( |
| 57 ui::ET_POINTER_MOVED, ui::EventPointerType::POINTER_TYPE_TOUCH, |
| 58 pointer_location, pointer_location, ui::EF_NONE, 1, base::TimeDelta()); |
| 70 ASSERT_EQ(MoveLoop::MoveResult::CONTINUE, | 59 ASSERT_EQ(MoveLoop::MoveResult::CONTINUE, |
| 71 move_loop->Move(*CreatePointerMove(pointer_location))) | 60 move_loop->Move(pointer_move_event)) |
| 72 << i; | 61 << i; |
| 73 ASSERT_EQ(data[i].expected_bounds, window.bounds()); | 62 ASSERT_EQ(data[i].expected_bounds, window.bounds()); |
| 74 } | 63 } |
| 75 } | 64 } |
| 76 | 65 |
| 77 } // namespace wm | 66 } // namespace wm |
| 78 } // namespace mash | 67 } // namespace mash |
| OLD | NEW |