7 #include "flutter/fml/macros.h"
8 #include "flutter/shell/platform/windows/testing/mock_window_binding_handler_delegate.h"
9 #include "gtest/gtest.h"
24 HRESULT(REFIID,
void**));
27 ActivateConfiguration,
28 HRESULT(DIRECTMANIPULATION_CONFIGURATION));
31 HRESULT(DIRECTMANIPULATION_CONFIGURATION));
34 HRESULT(IDirectManipulationContent*));
38 IDirectManipulationViewportEventHandler*,
44 HRESULT(REFIID,
void**));
47 HRESULT(DIRECTMANIPULATION_STATUS*));
50 HRESULT(REFIID,
void**, UINT32*));
60 HRESULT(DIRECTMANIPULATION_CONFIGURATION));
63 HRESULT(IDirectManipulationContent*));
69 HRESULT(DIRECTMANIPULATION_MOTION_TYPES));
73 HRESULT(DIRECTMANIPULATION_INPUT_MODE));
76 HRESULT(DIRECTMANIPULATION_GESTURE_CONFIGURATION));
79 HRESULT(IUnknown*, UINT32));
82 HRESULT(DIRECTMANIPULATION_INPUT_MODE));
85 HRESULT(DIRECTMANIPULATION_VIEWPORT_OPTIONS));
88 HRESULT(
const RECT*));
91 HRESULT(
const float*, DWORD));
95 HRESULT(
const float*, DWORD));
99 HRESULT(
const float,
const float,
const float,
const float, BOOL));
113 HRESULT(REFIID,
void**));
117 HRESULT(
float*, DWORD));
120 HRESULT(
float*, DWORD));
123 HRESULT(REFIID,
void**, UINT32*));
126 HRESULT(REFIID,
void**));
129 HRESULT(
const RECT*));
132 HRESULT(IUnknown*, UINT32));
134 SyncContentTransform,
135 HRESULT(
const float*, DWORD));
141 TEST(DirectManipulationTest, TestGesture) {
143 MockWindowBindingHandlerDelegate delegate;
145 const float scale = 1.5;
146 const float pan_x = 32.0;
147 const float pan_y = 16.0;
148 const int DISPLAY_WIDTH = 800;
149 const int DISPLAY_HEIGHT = 600;
150 auto owner = std::make_unique<DirectManipulationOwner>(
nullptr);
151 owner->SetBindingHandlerDelegate(&delegate);
153 fml::MakeRefCounted<DirectManipulationEventHandler>(owner.get());
154 int32_t device_id = (int32_t)
reinterpret_cast<int64_t
>(handler.get());
155 EXPECT_CALL(viewport, GetPrimaryContent(_, _))
156 .WillOnce(::testing::Invoke([&
content](REFIID in,
void** out) {
160 .RetiresOnSaturation();
161 EXPECT_CALL(
content, GetContentTransform(_, 6))
162 .WillOnce(::testing::Invoke([scale](
float* transform, DWORD size) {
168 .RetiresOnSaturation();
169 EXPECT_CALL(delegate, OnPointerPanZoomStart(device_id));
170 handler->OnViewportStatusChanged((IDirectManipulationViewport*)&viewport,
171 DIRECTMANIPULATION_RUNNING,
172 DIRECTMANIPULATION_READY);
173 EXPECT_CALL(
content, GetContentTransform(_, 6))
174 .WillOnce(::testing::Invoke(
175 [scale, pan_x, pan_y](
float* transform, DWORD size) {
176 transform[0] = scale;
177 transform[4] = pan_x;
178 transform[5] = pan_y;
181 EXPECT_CALL(delegate,
182 OnPointerPanZoomUpdate(device_id, pan_x, pan_y, scale, 0));
183 handler->OnContentUpdated((IDirectManipulationViewport*)&viewport,
184 (IDirectManipulationContent*)&
content);
185 EXPECT_CALL(delegate, OnPointerPanZoomEnd(device_id));
186 EXPECT_CALL(viewport, GetViewportRect(_))
187 .WillOnce(::testing::Invoke([DISPLAY_WIDTH, DISPLAY_HEIGHT](RECT* rect) {
190 rect->right = DISPLAY_WIDTH;
191 rect->bottom = DISPLAY_HEIGHT;
194 EXPECT_CALL(viewport, ZoomToRect(0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT,
false))
195 .WillOnce(::testing::Return(S_OK));
196 handler->OnViewportStatusChanged((IDirectManipulationViewport*)&viewport,
197 DIRECTMANIPULATION_INERTIA,
198 DIRECTMANIPULATION_RUNNING);
199 handler->OnViewportStatusChanged((IDirectManipulationViewport*)&viewport,
200 DIRECTMANIPULATION_READY,
201 DIRECTMANIPULATION_INERTIA);
205 TEST(DirectManipulationTest, TestRounding) {
207 MockWindowBindingHandlerDelegate delegate;
209 const float scale = 1.5;
210 const int DISPLAY_WIDTH = 800;
211 const int DISPLAY_HEIGHT = 600;
212 auto owner = std::make_unique<DirectManipulationOwner>(
nullptr);
213 owner->SetBindingHandlerDelegate(&delegate);
215 fml::MakeRefCounted<DirectManipulationEventHandler>(owner.get());
216 int32_t device_id = (int32_t)
reinterpret_cast<int64_t
>(handler.get());
217 EXPECT_CALL(viewport, GetPrimaryContent(_, _))
218 .WillOnce(::testing::Invoke([&
content](REFIID in,
void** out) {
222 .RetiresOnSaturation();
223 EXPECT_CALL(
content, GetContentTransform(_, 6))
224 .WillOnce(::testing::Invoke([scale](
float* transform, DWORD size) {
230 .RetiresOnSaturation();
231 EXPECT_CALL(delegate, OnPointerPanZoomStart(device_id));
232 handler->OnViewportStatusChanged((IDirectManipulationViewport*)&viewport,
233 DIRECTMANIPULATION_RUNNING,
234 DIRECTMANIPULATION_READY);
235 EXPECT_CALL(
content, GetContentTransform(_, 6))
236 .WillOnce(::testing::Invoke([scale](
float* transform, DWORD size) {
237 transform[0] = 1.5000001f;
242 .RetiresOnSaturation();
243 EXPECT_CALL(delegate,
244 OnPointerPanZoomUpdate(device_id, 4.0, 0, 1.5000001f, 0))
246 EXPECT_CALL(delegate, OnPointerPanZoomUpdate(device_id, 4.0, 0, 1.5f, 0))
248 .RetiresOnSaturation();
249 EXPECT_CALL(
content, GetContentTransform(_, 6))
250 .WillOnce(::testing::Invoke([scale](
float* transform, DWORD size) {
251 transform[0] = 1.50000065f;
256 .RetiresOnSaturation();
257 EXPECT_CALL(delegate,
258 OnPointerPanZoomUpdate(device_id, 2.0, 0, 1.50000065f, 0))
260 EXPECT_CALL(delegate,
261 OnPointerPanZoomUpdate(device_id, 2.0, 0, 1.50000047f, 0))
263 .RetiresOnSaturation();
264 EXPECT_CALL(delegate, OnPointerPanZoomEnd(device_id));
265 EXPECT_CALL(viewport, GetViewportRect(_))
266 .WillOnce(::testing::Invoke([DISPLAY_WIDTH, DISPLAY_HEIGHT](RECT* rect) {
269 rect->right = DISPLAY_WIDTH;
270 rect->bottom = DISPLAY_HEIGHT;
273 EXPECT_CALL(viewport, ZoomToRect(0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT,
false))
274 .WillOnce(::testing::Return(S_OK));
275 handler->OnContentUpdated((IDirectManipulationViewport*)&viewport,
276 (IDirectManipulationContent*)&
content);
277 handler->OnContentUpdated((IDirectManipulationViewport*)&viewport,
278 (IDirectManipulationContent*)&
content);
279 handler->OnViewportStatusChanged((IDirectManipulationViewport*)&viewport,
280 DIRECTMANIPULATION_INERTIA,
281 DIRECTMANIPULATION_RUNNING);
282 handler->OnViewportStatusChanged((IDirectManipulationViewport*)&viewport,
283 DIRECTMANIPULATION_READY,
284 DIRECTMANIPULATION_INERTIA);
287 TEST(DirectManipulationTest, TestInertiaCancelSentForUserCancel) {
289 MockWindowBindingHandlerDelegate delegate;
291 const int DISPLAY_WIDTH = 800;
292 const int DISPLAY_HEIGHT = 600;
293 auto owner = std::make_unique<DirectManipulationOwner>(
nullptr);
294 owner->SetBindingHandlerDelegate(&delegate);
296 fml::MakeRefCounted<DirectManipulationEventHandler>(owner.get());
297 int32_t device_id = (int32_t)
reinterpret_cast<int64_t
>(handler.get());
299 EXPECT_CALL(viewport, GetViewportRect(_))
300 .WillOnce(::testing::Invoke([DISPLAY_WIDTH, DISPLAY_HEIGHT](RECT* rect) {
303 rect->right = DISPLAY_WIDTH;
304 rect->bottom = DISPLAY_HEIGHT;
307 EXPECT_CALL(viewport, ZoomToRect(0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT,
false))
308 .WillOnce(::testing::Return(S_OK));
309 EXPECT_CALL(delegate, OnPointerPanZoomEnd(device_id));
310 handler->OnViewportStatusChanged((IDirectManipulationViewport*)&viewport,
311 DIRECTMANIPULATION_INERTIA,
312 DIRECTMANIPULATION_RUNNING);
314 EXPECT_CALL(
content, GetContentTransform(_, 6))
315 .WillOnce(::testing::Invoke([](
float* transform, DWORD size) {
321 handler->OnContentUpdated((IDirectManipulationViewport*)&viewport,
322 (IDirectManipulationContent*)&
content);
323 EXPECT_CALL(
content, GetContentTransform(_, 6))
324 .WillOnce(::testing::Invoke([](
float* transform, DWORD size) {
330 handler->OnContentUpdated((IDirectManipulationViewport*)&viewport,
331 (IDirectManipulationContent*)&
content);
334 EXPECT_CALL(delegate, OnScrollInertiaCancel(device_id));
335 handler->OnViewportStatusChanged((IDirectManipulationViewport*)&viewport,
336 DIRECTMANIPULATION_READY,
337 DIRECTMANIPULATION_INERTIA);
340 TEST(DirectManipulationTest, TestInertiaCamcelNotSentAtInertiaEnd) {
342 MockWindowBindingHandlerDelegate delegate;
344 const int DISPLAY_WIDTH = 800;
345 const int DISPLAY_HEIGHT = 600;
346 auto owner = std::make_unique<DirectManipulationOwner>(
nullptr);
347 owner->SetBindingHandlerDelegate(&delegate);
349 fml::MakeRefCounted<DirectManipulationEventHandler>(owner.get());
350 int32_t device_id = (int32_t)
reinterpret_cast<int64_t
>(handler.get());
352 EXPECT_CALL(viewport, GetViewportRect(_))
353 .WillOnce(::testing::Invoke([DISPLAY_WIDTH, DISPLAY_HEIGHT](RECT* rect) {
356 rect->right = DISPLAY_WIDTH;
357 rect->bottom = DISPLAY_HEIGHT;
360 EXPECT_CALL(viewport, ZoomToRect(0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT,
false))
361 .WillOnce(::testing::Return(S_OK));
362 EXPECT_CALL(delegate, OnPointerPanZoomEnd(device_id));
363 handler->OnViewportStatusChanged((IDirectManipulationViewport*)&viewport,
364 DIRECTMANIPULATION_INERTIA,
365 DIRECTMANIPULATION_RUNNING);
367 EXPECT_CALL(
content, GetContentTransform(_, 6))
368 .WillOnce(::testing::Invoke([](
float* transform, DWORD size) {
374 handler->OnContentUpdated((IDirectManipulationViewport*)&viewport,
375 (IDirectManipulationContent*)&
content);
376 EXPECT_CALL(
content, GetContentTransform(_, 6))
377 .WillOnce(::testing::Invoke([](
float* transform, DWORD size) {
383 handler->OnContentUpdated((IDirectManipulationViewport*)&viewport,
384 (IDirectManipulationContent*)&
content);
386 EXPECT_CALL(delegate, OnScrollInertiaCancel(device_id)).Times(0);
387 handler->OnViewportStatusChanged((IDirectManipulationViewport*)&viewport,
388 DIRECTMANIPULATION_READY,
389 DIRECTMANIPULATION_INERTIA);
394 TEST(DirectManipulationTest, TestGestureWithInitialData) {
396 MockWindowBindingHandlerDelegate delegate;
398 const float scale = 1.5;
399 const float pan_x = 32.0;
400 const float pan_y = 16.0;
401 const int DISPLAY_WIDTH = 800;
402 const int DISPLAY_HEIGHT = 600;
403 auto owner = std::make_unique<DirectManipulationOwner>(
nullptr);
404 owner->SetBindingHandlerDelegate(&delegate);
406 fml::MakeRefCounted<DirectManipulationEventHandler>(owner.get());
407 int32_t device_id = (int32_t)
reinterpret_cast<int64_t
>(handler.get());
408 EXPECT_CALL(viewport, GetPrimaryContent(_, _))
409 .WillOnce(::testing::Invoke([&
content](REFIID in,
void** out) {
413 .RetiresOnSaturation();
414 EXPECT_CALL(
content, GetContentTransform(_, 6))
415 .WillOnce(::testing::Invoke([scale](
float* transform, DWORD size) {
417 transform[4] = 234.0;
418 transform[5] = 345.0;
421 .RetiresOnSaturation();
422 EXPECT_CALL(delegate, OnPointerPanZoomStart(device_id));
423 handler->OnViewportStatusChanged((IDirectManipulationViewport*)&viewport,
424 DIRECTMANIPULATION_RUNNING,
425 DIRECTMANIPULATION_READY);
426 EXPECT_CALL(
content, GetContentTransform(_, 6))
427 .WillOnce(::testing::Invoke(
428 [scale, pan_x, pan_y](
float* transform, DWORD size) {
429 transform[0] = 2.0f * scale;
430 transform[4] = 234.0 + pan_x;
431 transform[5] = 345.0 + pan_y;
434 EXPECT_CALL(delegate,
435 OnPointerPanZoomUpdate(device_id, pan_x, pan_y, scale, 0));
436 handler->OnContentUpdated((IDirectManipulationViewport*)&viewport,
437 (IDirectManipulationContent*)&
content);
438 EXPECT_CALL(delegate, OnPointerPanZoomEnd(device_id));
439 EXPECT_CALL(viewport, GetViewportRect(_))
440 .WillOnce(::testing::Invoke([DISPLAY_WIDTH, DISPLAY_HEIGHT](RECT* rect) {
443 rect->right = DISPLAY_WIDTH;
444 rect->bottom = DISPLAY_HEIGHT;
447 EXPECT_CALL(viewport, ZoomToRect(0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT,
false))
448 .WillOnce(::testing::Return(S_OK));
449 handler->OnViewportStatusChanged((IDirectManipulationViewport*)&viewport,
450 DIRECTMANIPULATION_INERTIA,
451 DIRECTMANIPULATION_RUNNING);
452 handler->OnViewportStatusChanged((IDirectManipulationViewport*)&viewport,
453 DIRECTMANIPULATION_READY,
454 DIRECTMANIPULATION_INERTIA);