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

Side by Side Diff: components/exo/touch_unittest.cc

Issue 2396883003: exo: Fix dragging edge cases (Closed)
Patch Set: Fix unit tests Created 4 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 unified diff | Download patch
OLDNEW
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 "ash/aura/wm_window_aura.h" 5 #include "ash/aura/wm_window_aura.h"
6 #include "ash/common/shell_window_ids.h" 6 #include "ash/common/shell_window_ids.h"
7 #include "ash/common/wm/window_positioner.h" 7 #include "ash/common/wm/window_positioner.h"
8 #include "ash/common/wm/window_positioning_utils.h" 8 #include "ash/common/wm/window_positioning_utils.h"
9 #include "ash/common/wm_shell.h" 9 #include "ash/common/wm_shell.h"
10 #include "ash/shell.h" 10 #include "ash/shell.h"
11 #include "components/exo/buffer.h" 11 #include "components/exo/buffer.h"
12 #include "components/exo/display.h"
12 #include "components/exo/shell_surface.h" 13 #include "components/exo/shell_surface.h"
13 #include "components/exo/surface.h" 14 #include "components/exo/surface.h"
14 #include "components/exo/test/exo_test_base.h" 15 #include "components/exo/test/exo_test_base.h"
15 #include "components/exo/test/exo_test_helper.h" 16 #include "components/exo/test/exo_test_helper.h"
16 #include "components/exo/touch.h" 17 #include "components/exo/touch.h"
17 #include "components/exo/touch_delegate.h" 18 #include "components/exo/touch_delegate.h"
18 #include "testing/gmock/include/gmock/gmock.h" 19 #include "testing/gmock/include/gmock/gmock.h"
19 #include "ui/events/base_event_utils.h" 20 #include "ui/events/base_event_utils.h"
20 #include "ui/events/test/event_generator.h" 21 #include "ui/events/test/event_generator.h"
21 #include "ui/views/widget/widget.h" 22 #include "ui/views/widget/widget.h"
(...skipping 13 matching lines...) Expand all
35 MOCK_METHOD4(OnTouchDown, 36 MOCK_METHOD4(OnTouchDown,
36 void(Surface*, base::TimeTicks, int, const gfx::Point&)); 37 void(Surface*, base::TimeTicks, int, const gfx::Point&));
37 MOCK_METHOD2(OnTouchUp, void(base::TimeTicks, int)); 38 MOCK_METHOD2(OnTouchUp, void(base::TimeTicks, int));
38 MOCK_METHOD3(OnTouchMotion, void(base::TimeTicks, int, const gfx::Point&)); 39 MOCK_METHOD3(OnTouchMotion, void(base::TimeTicks, int, const gfx::Point&));
39 MOCK_METHOD0(OnTouchCancel, void()); 40 MOCK_METHOD0(OnTouchCancel, void());
40 }; 41 };
41 42
42 TEST_F(TouchTest, OnTouchDown) { 43 TEST_F(TouchTest, OnTouchDown) {
43 ash::WindowPositioner::DisableAutoPositioning(true); 44 ash::WindowPositioner::DisableAutoPositioning(true);
44 45
46 const Display display;
45 std::unique_ptr<Surface> bottom_surface(new Surface); 47 std::unique_ptr<Surface> bottom_surface(new Surface);
46 std::unique_ptr<ShellSurface> bottom_shell_surface( 48 std::unique_ptr<ShellSurface> bottom_shell_surface(
47 new ShellSurface(bottom_surface.get())); 49 new ShellSurface(display, bottom_surface.get()));
48 gfx::Size bottom_buffer_size(10, 10); 50 gfx::Size bottom_buffer_size(10, 10);
49 std::unique_ptr<Buffer> bottom_buffer( 51 std::unique_ptr<Buffer> bottom_buffer(
50 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(bottom_buffer_size))); 52 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(bottom_buffer_size)));
51 bottom_surface->Attach(bottom_buffer.get()); 53 bottom_surface->Attach(bottom_buffer.get());
52 bottom_surface->Commit(); 54 bottom_surface->Commit();
53 ash::wm::CenterWindow(ash::WmWindowAura::Get( 55 ash::wm::CenterWindow(ash::WmWindowAura::Get(
54 bottom_shell_surface->GetWidget()->GetNativeWindow())); 56 bottom_shell_surface->GetWidget()->GetNativeWindow()));
55 57
56 std::unique_ptr<Surface> top_surface(new Surface); 58 std::unique_ptr<Surface> top_surface(new Surface);
57 std::unique_ptr<ShellSurface> top_shell_surface( 59 std::unique_ptr<ShellSurface> top_shell_surface(
58 new ShellSurface(top_surface.get())); 60 new ShellSurface(display, top_surface.get()));
59 gfx::Size top_buffer_size(8, 8); 61 gfx::Size top_buffer_size(8, 8);
60 std::unique_ptr<Buffer> top_buffer( 62 std::unique_ptr<Buffer> top_buffer(
61 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(top_buffer_size))); 63 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(top_buffer_size)));
62 top_surface->Attach(top_buffer.get()); 64 top_surface->Attach(top_buffer.get());
63 top_surface->Commit(); 65 top_surface->Commit();
64 ash::wm::CenterWindow(ash::WmWindowAura::Get( 66 ash::wm::CenterWindow(ash::WmWindowAura::Get(
65 top_shell_surface->GetWidget()->GetNativeWindow())); 67 top_shell_surface->GetWidget()->GetNativeWindow()));
66 68
67 MockTouchDelegate delegate; 69 MockTouchDelegate delegate;
68 std::unique_ptr<Touch> touch(new Touch(&delegate)); 70 std::unique_ptr<Touch> touch(new Touch(&delegate));
(...skipping 14 matching lines...) Expand all
83 gfx::Point(-1, -1))); 85 gfx::Point(-1, -1)));
84 generator.set_current_location( 86 generator.set_current_location(
85 bottom_surface->window()->GetBoundsInScreen().origin()); 87 bottom_surface->window()->GetBoundsInScreen().origin());
86 generator.PressTouchId(2); 88 generator.PressTouchId(2);
87 89
88 EXPECT_CALL(delegate, OnTouchDestroying(touch.get())); 90 EXPECT_CALL(delegate, OnTouchDestroying(touch.get()));
89 touch.reset(); 91 touch.reset();
90 } 92 }
91 93
92 TEST_F(TouchTest, OnTouchUp) { 94 TEST_F(TouchTest, OnTouchUp) {
95 const Display display;
93 std::unique_ptr<Surface> surface(new Surface); 96 std::unique_ptr<Surface> surface(new Surface);
94 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); 97 std::unique_ptr<ShellSurface> shell_surface(
98 new ShellSurface(display, surface.get()));
95 gfx::Size buffer_size(10, 10); 99 gfx::Size buffer_size(10, 10);
96 std::unique_ptr<Buffer> buffer( 100 std::unique_ptr<Buffer> buffer(
97 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); 101 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
98 surface->Attach(buffer.get()); 102 surface->Attach(buffer.get());
99 surface->Commit(); 103 surface->Commit();
100 104
101 MockTouchDelegate delegate; 105 MockTouchDelegate delegate;
102 std::unique_ptr<Touch> touch(new Touch(&delegate)); 106 std::unique_ptr<Touch> touch(new Touch(&delegate));
103 ui::test::EventGenerator generator(ash::Shell::GetPrimaryRootWindow()); 107 ui::test::EventGenerator generator(ash::Shell::GetPrimaryRootWindow());
104 108
(...skipping 10 matching lines...) Expand all
115 EXPECT_CALL(delegate, OnTouchUp(testing::_, 1)); 119 EXPECT_CALL(delegate, OnTouchUp(testing::_, 1));
116 generator.ReleaseTouchId(1); 120 generator.ReleaseTouchId(1);
117 EXPECT_CALL(delegate, OnTouchUp(testing::_, 2)); 121 EXPECT_CALL(delegate, OnTouchUp(testing::_, 2));
118 generator.ReleaseTouchId(2); 122 generator.ReleaseTouchId(2);
119 123
120 EXPECT_CALL(delegate, OnTouchDestroying(touch.get())); 124 EXPECT_CALL(delegate, OnTouchDestroying(touch.get()));
121 touch.reset(); 125 touch.reset();
122 } 126 }
123 127
124 TEST_F(TouchTest, OnTouchMotion) { 128 TEST_F(TouchTest, OnTouchMotion) {
129 const Display display;
125 std::unique_ptr<Surface> surface(new Surface); 130 std::unique_ptr<Surface> surface(new Surface);
126 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); 131 std::unique_ptr<ShellSurface> shell_surface(
132 new ShellSurface(display, surface.get()));
127 gfx::Size buffer_size(10, 10); 133 gfx::Size buffer_size(10, 10);
128 std::unique_ptr<Buffer> buffer( 134 std::unique_ptr<Buffer> buffer(
129 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); 135 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
130 surface->Attach(buffer.get()); 136 surface->Attach(buffer.get());
131 surface->Commit(); 137 surface->Commit();
132 138
133 MockTouchDelegate delegate; 139 MockTouchDelegate delegate;
134 std::unique_ptr<Touch> touch(new Touch(&delegate)); 140 std::unique_ptr<Touch> touch(new Touch(&delegate));
135 ui::test::EventGenerator generator(ash::Shell::GetPrimaryRootWindow()); 141 ui::test::EventGenerator generator(ash::Shell::GetPrimaryRootWindow());
136 142
(...skipping 17 matching lines...) Expand all
154 EXPECT_CALL(delegate, OnTouchUp(testing::_, testing::_)); 160 EXPECT_CALL(delegate, OnTouchUp(testing::_, testing::_));
155 generator.set_current_location( 161 generator.set_current_location(
156 surface->window()->GetBoundsInScreen().origin()); 162 surface->window()->GetBoundsInScreen().origin());
157 generator.PressMoveAndReleaseTouchBy(100, 100); 163 generator.PressMoveAndReleaseTouchBy(100, 100);
158 164
159 EXPECT_CALL(delegate, OnTouchDestroying(touch.get())); 165 EXPECT_CALL(delegate, OnTouchDestroying(touch.get()));
160 touch.reset(); 166 touch.reset();
161 } 167 }
162 168
163 TEST_F(TouchTest, OnTouchCancel) { 169 TEST_F(TouchTest, OnTouchCancel) {
170 const Display display;
164 std::unique_ptr<Surface> surface(new Surface); 171 std::unique_ptr<Surface> surface(new Surface);
165 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); 172 std::unique_ptr<ShellSurface> shell_surface(
173 new ShellSurface(display, surface.get()));
166 gfx::Size buffer_size(10, 10); 174 gfx::Size buffer_size(10, 10);
167 std::unique_ptr<Buffer> buffer( 175 std::unique_ptr<Buffer> buffer(
168 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); 176 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
169 surface->Attach(buffer.get()); 177 surface->Attach(buffer.get());
170 surface->Commit(); 178 surface->Commit();
171 179
172 MockTouchDelegate delegate; 180 MockTouchDelegate delegate;
173 std::unique_ptr<Touch> touch(new Touch(&delegate)); 181 std::unique_ptr<Touch> touch(new Touch(&delegate));
174 ui::test::EventGenerator generator(ash::Shell::GetPrimaryRootWindow()); 182 ui::test::EventGenerator generator(ash::Shell::GetPrimaryRootWindow());
175 183
(...skipping 11 matching lines...) Expand all
187 EXPECT_CALL(delegate, OnTouchCancel()); 195 EXPECT_CALL(delegate, OnTouchCancel());
188 ui::TouchEvent cancel_event(ui::ET_TOUCH_CANCELLED, gfx::Point(), 1, 196 ui::TouchEvent cancel_event(ui::ET_TOUCH_CANCELLED, gfx::Point(), 1,
189 ui::EventTimeForNow()); 197 ui::EventTimeForNow());
190 generator.Dispatch(&cancel_event); 198 generator.Dispatch(&cancel_event);
191 199
192 EXPECT_CALL(delegate, OnTouchDestroying(touch.get())); 200 EXPECT_CALL(delegate, OnTouchDestroying(touch.get()));
193 touch.reset(); 201 touch.reset();
194 } 202 }
195 203
196 TEST_F(TouchTest, IgnoreTouchEventDuringModal) { 204 TEST_F(TouchTest, IgnoreTouchEventDuringModal) {
205 const Display display;
197 std::unique_ptr<Surface> surface(new Surface); 206 std::unique_ptr<Surface> surface(new Surface);
198 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); 207 std::unique_ptr<ShellSurface> shell_surface(
208 new ShellSurface(display, surface.get()));
199 std::unique_ptr<Buffer> buffer( 209 std::unique_ptr<Buffer> buffer(
200 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(gfx::Size(10, 10)))); 210 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(gfx::Size(10, 10))));
201 surface->Attach(buffer.get()); 211 surface->Attach(buffer.get());
202 surface->Commit(); 212 surface->Commit();
203 gfx::Point location = surface->window()->GetBoundsInScreen().origin(); 213 gfx::Point location = surface->window()->GetBoundsInScreen().origin();
204 214
205 MockTouchDelegate delegate; 215 MockTouchDelegate delegate;
206 std::unique_ptr<Touch> touch(new Touch(&delegate)); 216 std::unique_ptr<Touch> touch(new Touch(&delegate));
207 ui::test::EventGenerator generator(ash::Shell::GetPrimaryRootWindow()); 217 ui::test::EventGenerator generator(ash::Shell::GetPrimaryRootWindow());
208 218
209 // Create surface for modal window. 219 // Create surface for modal window.
210 std::unique_ptr<Surface> surface2(new Surface); 220 std::unique_ptr<Surface> surface2(new Surface);
211 std::unique_ptr<ShellSurface> shell_surface2( 221 std::unique_ptr<ShellSurface> shell_surface2(
212 new ShellSurface(surface2.get(), nullptr, gfx::Rect(0, 0, 5, 5), true, 222 new ShellSurface(display, surface2.get(), nullptr, gfx::Rect(0, 0, 5, 5),
213 ash::kShellWindowId_SystemModalContainer)); 223 true, ash::kShellWindowId_SystemModalContainer));
214 std::unique_ptr<Buffer> buffer2( 224 std::unique_ptr<Buffer> buffer2(
215 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(gfx::Size(5, 5)))); 225 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(gfx::Size(5, 5))));
216 surface2->Attach(buffer2.get()); 226 surface2->Attach(buffer2.get());
217 surface2->Commit(); 227 surface2->Commit();
218 ash::wm::CenterWindow(ash::WmWindowAura::Get(surface2->window())); 228 ash::wm::CenterWindow(ash::WmWindowAura::Get(surface2->window()));
219 gfx::Point location2 = surface2->window()->GetBoundsInScreen().origin(); 229 gfx::Point location2 = surface2->window()->GetBoundsInScreen().origin();
220 230
221 // Make the window modal. 231 // Make the window modal.
222 shell_surface2->SetSystemModal(true); 232 shell_surface2->SetSystemModal(true);
223 EXPECT_TRUE(ash::WmShell::Get()->IsSystemModalWindowOpen()); 233 EXPECT_TRUE(ash::WmShell::Get()->IsSystemModalWindowOpen());
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 } 278 }
269 generator.set_current_location(location); 279 generator.set_current_location(location);
270 generator.PressMoveAndReleaseTouchBy(1, 1); 280 generator.PressMoveAndReleaseTouchBy(1, 1);
271 281
272 EXPECT_CALL(delegate, OnTouchDestroying(touch.get())); 282 EXPECT_CALL(delegate, OnTouchDestroying(touch.get()));
273 touch.reset(); 283 touch.reset();
274 } 284 }
275 285
276 } // namespace 286 } // namespace
277 } // namespace exo 287 } // namespace exo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698