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

Side by Side Diff: mash/wm/move_loop_unittest.cc

Issue 1459653002: Gets mustash frames looking like that of ash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update test Created 5 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « mash/wm/move_loop.cc ('k') | mash/wm/non_client_frame_controller.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "mash/wm/move_loop.h"
6
7 #include "components/mus/public/cpp/tests/test_window.h"
8 #include "mojo/converters/input_events/input_events_type_converters.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/events/event.h"
11 #include "ui/gfx/geometry/point.h"
12 #include "ui/gfx/geometry/rect.h"
13
14 using MoveLoopTest = testing::Test;
15
16 namespace {
17
18 // Sets the client area for |window|. Padding is provided on the top so that
19 // there is a movable region. All other edges are sized to
20 // |MoveLoop::kResizeSize|.
21 void SetClientArea(mus::Window* window) {
22 if (window->bounds().IsEmpty())
23 window->SetBounds(gfx::Rect(100, 200, 300, 400));
24
25 window->SetClientArea(
26 gfx::Insets(MoveLoop::kResizeSize + 10, MoveLoop::kResizeSize,
27 MoveLoop::kResizeSize, MoveLoop::kResizeSize));
28 }
29
30 mus::mojom::EventPtr CreatePointerDownEvent(const gfx::Point& location) {
31 const ui::TouchEvent event(ui::ET_TOUCH_PRESSED, location, 1,
32 base::TimeDelta());
33 return mus::mojom::Event::From(static_cast<const ui::Event&>(event));
34 }
35
36 mus::mojom::EventPtr CreatePointerMove(const gfx::Point& location) {
37 const ui::TouchEvent event(ui::ET_TOUCH_MOVED, location, 1,
38 base::TimeDelta());
39 return mus::mojom::Event::From(static_cast<const ui::Event&>(event));
40 }
41
42 enum class HorizontalLocation {
43 LEFT,
44 MIDDLE,
45 RIGHT,
46 };
47
48 enum class VerticalLocation {
49 TOP_MOVE,
50 TOP_RESIZE,
51 MIDDLE,
52 BOTTOM,
53 };
54
55 int HorizontalLocationToPoint(const mus::Window* window,
56 HorizontalLocation loc) {
57 if (loc == HorizontalLocation::LEFT)
58 return 0;
59 return loc == HorizontalLocation::MIDDLE ? window->bounds().width() / 2
60 : window->bounds().width() - 1;
61 }
62
63 int VerticalLocationToPoint(const mus::Window* window, VerticalLocation loc) {
64 switch (loc) {
65 case VerticalLocation::TOP_MOVE:
66 return MoveLoop::kResizeSize + 1;
67 case VerticalLocation::TOP_RESIZE:
68 return 0;
69 case VerticalLocation::MIDDLE:
70 return window->bounds().height() / 2;
71 case VerticalLocation::BOTTOM:
72 return window->bounds().height() - 1;
73 }
74 return 0;
75 }
76
77 gfx::Point LocationToPoint(const mus::Window* window,
78 HorizontalLocation h_loc,
79 VerticalLocation v_loc) {
80 return gfx::Point(HorizontalLocationToPoint(window, h_loc),
81 VerticalLocationToPoint(window, v_loc));
82 }
83
84 } // namespace
85
86 TEST_F(MoveLoopTest, Move) {
87 struct TestData {
88 HorizontalLocation initial_h_loc;
89 VerticalLocation initial_v_loc;
90 // Number of values in delta_* that are valid. For example, if this is 1
91 // then only one move is generated with thye point |delta_x[0]|,
92 // |delta_y[0]|.
93 int delta_count;
94 int delta_x[3];
95 int delta_y[3];
96 gfx::Rect expected_bounds;
97 } data[] = {
98 // Move.
99 {HorizontalLocation::MIDDLE,
100 VerticalLocation::TOP_MOVE,
101 1,
102 {1, 0, 0},
103 {2, 0, 0},
104 gfx::Rect(101, 202, 300, 400)},
105
106 // Resize from top, left.
107 {HorizontalLocation::LEFT,
108 VerticalLocation::TOP_RESIZE,
109 1,
110 {1, 0, 0},
111 {2, 0, 0},
112 gfx::Rect(101, 202, 299, 398)},
113
114 // Resize from left.
115 {HorizontalLocation::LEFT,
116 VerticalLocation::MIDDLE,
117 1,
118 {1, 0, 0},
119 {2, 0, 0},
120 gfx::Rect(101, 200, 299, 400)},
121
122 // Resize from bottom, left.
123 {HorizontalLocation::LEFT,
124 VerticalLocation::BOTTOM,
125 1,
126 {-1, 0, 0},
127 {-2, 0, 0},
128 gfx::Rect(99, 200, 301, 398)},
129
130 // Resize from bottom.
131 {HorizontalLocation::MIDDLE,
132 VerticalLocation::BOTTOM,
133 1,
134 {-1, 0, 0},
135 {4, 0, 0},
136 gfx::Rect(100, 200, 300, 404)},
137
138 // Resize from bottom, right.
139 {HorizontalLocation::RIGHT,
140 VerticalLocation::BOTTOM,
141 1,
142 {-3, 0, 0},
143 {4, 0, 0},
144 gfx::Rect(100, 200, 297, 404)},
145
146 // Resize from right.
147 {HorizontalLocation::RIGHT,
148 VerticalLocation::MIDDLE,
149 1,
150 {6, 0, 0},
151 {-4, 0, 0},
152 gfx::Rect(100, 200, 306, 400)},
153
154 // Resize from top, right.
155 {HorizontalLocation::RIGHT,
156 VerticalLocation::TOP_RESIZE,
157 1,
158 {6, 0, 0},
159 {5, 0, 0},
160 gfx::Rect(100, 205, 306, 395)},
161 };
162
163 for (size_t i = 0; i < arraysize(data); ++i) {
164 mus::TestWindow window;
165 SetClientArea(&window);
166 gfx::Point pointer_location(
167 LocationToPoint(&window, data[i].initial_h_loc, data[i].initial_v_loc));
168 scoped_ptr<MoveLoop> move_loop =
169 MoveLoop::Create(&window, *CreatePointerDownEvent(pointer_location));
170 ASSERT_TRUE(move_loop.get()) << i;
171 for (int j = 0; j < data[i].delta_count; ++j) {
172 pointer_location.Offset(data[i].delta_x[j], data[i].delta_y[j]);
173 ASSERT_EQ(MoveLoop::MoveResult::CONTINUE,
174 move_loop->Move(*CreatePointerMove(pointer_location)))
175 << i << " " << j;
176 }
177 ASSERT_EQ(data[i].expected_bounds, window.bounds());
178 }
179 }
OLDNEW
« no previous file with comments | « mash/wm/move_loop.cc ('k') | mash/wm/non_client_frame_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698