Debian Codegraph @

tests/unit/mousefilters13/tst_mousefilterstest.cpp

raw
1 /*
2 * Copyright 2014 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17 #include <QtCore/QCoreApplication>
18 #include <QtCore/QEvent>
19 #include <QtQml/QQmlEngine>
20 #include <QtQuick/QQuickItem>
21 #include <QtQuick/QQuickView>
22 #include <QtQuick/private/qquickevents_p_p.h>
23 #include <QtQuick/private/qquickmousearea_p.h>
24 #include <QtTest/QtTest>
25 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
26 #include <LomiriToolkit-Qt6/private/inversemouseareatype_p.h>
27 #else
28 #include <LomiriToolkit/private/inversemouseareatype_p.h>
29 #endif
30 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
31 #include <LomiriToolkit-Qt6/private/quickutils_p.h>
32 #else
33 #include <LomiriToolkit/private/quickutils_p.h>
34 #endif
35 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
36 #include <LomiriToolkit-Qt6/private/ucinversemouse_p.h>
37 #else
38 #include <LomiriToolkit/private/ucinversemouse_p.h>
39 #endif
40 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
41 #include <LomiriToolkit-Qt6/private/ucmouse_p.h>
42 #else
43 #include <LomiriToolkit/private/ucmouse_p.h>
44 #endif
45 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
46 #include <LomiriToolkit-Qt6/private/ucunits_p.h>
47 #else
48 #include <LomiriToolkit/private/ucunits_p.h>
49 #endif
50
51 #include "uctestcase.h"
52 #include "uctestextras.h"
53
54 UT_USE_NAMESPACE
55
56 template<typename T>
57 T *attachedFilter(QQuickItem *item, const QString &objectName)
58 {
59 QQuickItem *testItem = item->objectName() == objectName ? item : item->findChild<QQuickItem*>(objectName);
60 if (testItem) {
61 return qobject_cast<T*>(qmlAttachedPropertiesObject<T>(testItem, false));
62 }
63 return 0;
64 }
65
66 class tst_mouseFilterTest : public QObject
67 {
68 Q_OBJECT
69
70 public:
71 tst_mouseFilterTest() {}
72
73 private:
74 struct FilterParams {
75 QString handler;
76 Qt::MouseButton pressedButton;
77 Qt::MouseButtons pressedButtons;
78 QQuickItem *sender;
79 };
80
81 QString m_modulePath;
82 FilterParams mouseEventParams;
83 FilterParams mouseEvent2Params;
84 FilterParams mouseEvent3Params;
85
86 QQuickView * loadTest(const QString &file)
87 {
88 LomiriTestCase* testCase = new LomiriTestCase(file);
89 return qobject_cast<QQuickView*>(testCase);
90 }
91
92 void mousePressAndHold(QWindow *view, Qt::MouseButton button, Qt::KeyboardModifiers modifiers, const QPoint &point, int delay = UCMouse::DefaultPressAndHoldDelay + 200)
93 {
94 QTest::mousePress(view, button, modifiers, point);
95 QTest::qWait(delay);
96 }
97
98 bool inputPanelPresent()
99 {
100 return !QuickUtils::instance()->inputMethodProvider().isEmpty();
101 }
102
103 QPoint guPoint(qreal guX, qreal guY)
104 {
105 return QPoint(UCUnits::instance()->gu(guX), UCUnits::instance()->gu(guY));
106 }
107
108 void preventDblClick()
109 {
110 QTest::qWait(400);
111 }
112
113 protected Q_SLOTS:
114 void onMouseEvent(QQuickMouseEvent *event, QQuickItem *sender)
115 {
116 mouseEventParams.handler = "EVENT1";
117 mouseEventParams.sender = sender;
118 mouseEventParams.pressedButton = (Qt::MouseButton)event->button();
119 mouseEventParams.pressedButtons = (Qt::MouseButtons)event->buttons();
120 }
121 void onMouseEvent2(QQuickMouseEvent *event, QQuickItem *sender)
122 {
123 mouseEvent2Params.handler = "EVENT2";
124 mouseEvent2Params.sender = sender;
125 mouseEvent2Params.pressedButton = (Qt::MouseButton)event->button();
126 mouseEvent2Params.pressedButtons = (Qt::MouseButtons)event->buttons();
127 }
128 void onMouseEvent3(QQuickMouseEvent *event, QQuickItem *sender)
129 {
130 mouseEvent3Params.handler = "EVENT4";
131 mouseEvent3Params.sender = sender;
132 mouseEvent3Params.pressedButton = (Qt::MouseButton)event->button();
133 mouseEvent3Params.pressedButtons = (Qt::MouseButtons)event->buttons();
134 }
135
136 private Q_SLOTS:
137
138 void initTestCase()
139 {
140 UCTestExtras::registerTouchDevice();
141
142 QString modules(LOMIRI_QML_IMPORT_PATH);
143 QVERIFY(QDir(modules).exists());
144
145 m_modulePath = QDir(modules).absolutePath();
146 }
147
148 void cleanupTestCase()
149 {
150 }
151
152 void testCase_pressedInsideTextInput()
153 {
154 QScopedPointer<QQuickView> view(loadTest("FilterTextInput.qml"));
155 QVERIFY(view);
156 UCMouse *filter = attachedFilter<UCMouse>(view->rootObject(), "FilterOwner");
157 QVERIFY(filter);
158 QSignalSpy pressed(filter, SIGNAL(pressed(QQuickMouseEvent*, QQuickItem*)));
159 QSignalSpy released(filter, SIGNAL(released(QQuickMouseEvent*, QQuickItem*)));
160 QSignalSpy clicked(filter, SIGNAL(clicked(QQuickMouseEvent*, QQuickItem*)));
161 QSignalSpy positionChanged(filter, SIGNAL(positionChanged(QQuickMouseEvent*, QQuickItem*)));
162 QSignalSpy doubleClicked(filter, SIGNAL(doubleClicked(QQuickMouseEvent*, QQuickItem*)));
163 QSignalSpy pressAndHold(filter, SIGNAL(pressAndHold(QQuickMouseEvent*, QQuickItem*)));
164 QSignalSpy entered(filter, SIGNAL(entered(QQuickMouseEvent*, QQuickItem*)));
165 QSignalSpy exited(filter, SIGNAL(exited(QQuickMouseEvent*, QQuickItem*)));
166
167 preventDblClick();
168 QTest::mouseClick(view.data(), Qt::LeftButton, Qt::NoModifier, guPoint(2, 2));
169 QCoreApplication::processEvents();
170 QCOMPARE(view->rootObject()->hasFocus(), true);
171 QCOMPARE(pressed.count(), 1);
172 QCOMPARE(released.count(), 1);
173 QCOMPARE(clicked.count(), 1);
174 QCOMPARE(positionChanged.count(), 0);
175 QCOMPARE(doubleClicked.count(), 0);
176 QCOMPARE(pressAndHold.count(), 0);
177 QCOMPARE(entered.count(), 1);
178 QCOMPARE(exited.count(), 1);
179 }
180
181 void testCase_pressedInsideTextInputHandledAfter()
182 {
183 QScopedPointer<QQuickView> view(loadTest("FilterTextInputAfter.qml"));
184 QVERIFY(view);
185 UCMouse *filter = attachedFilter<UCMouse>(view->rootObject(), "FilterOwner");
186 QVERIFY(filter);
187 QSignalSpy pressed(filter, SIGNAL(pressed(QQuickMouseEvent*, QQuickItem*)));
188 QSignalSpy released(filter, SIGNAL(released(QQuickMouseEvent*, QQuickItem*)));
189 QSignalSpy clicked(filter, SIGNAL(clicked(QQuickMouseEvent*, QQuickItem*)));
190 QSignalSpy positionChanged(filter, SIGNAL(positionChanged(QQuickMouseEvent*, QQuickItem*)));
191 QSignalSpy doubleClicked(filter, SIGNAL(doubleClicked(QQuickMouseEvent*, QQuickItem*)));
192 QSignalSpy pressAndHold(filter, SIGNAL(pressAndHold(QQuickMouseEvent*, QQuickItem*)));
193 QSignalSpy entered(filter, SIGNAL(entered(QQuickMouseEvent*, QQuickItem*)));
194 QSignalSpy exited(filter, SIGNAL(exited(QQuickMouseEvent*, QQuickItem*)));
195
196 preventDblClick();
197 QTest::mouseClick(view.data(), Qt::LeftButton, Qt::NoModifier, guPoint(2, 2));
198 QCoreApplication::processEvents();
199 QCOMPARE(view->rootObject()->hasFocus(), true);
200 QCOMPARE(pressed.count(), 1);
201 QCOMPARE(released.count(), 1);
202 QCOMPARE(clicked.count(), 1);
203 QCOMPARE(positionChanged.count(), 0);
204 QCOMPARE(doubleClicked.count(), 0);
205 QCOMPARE(pressAndHold.count(), 0);
206 QCOMPARE(entered.count(), 1);
207 QCOMPARE(exited.count(), 1);
208 }
209
210 void testCase_pressedOutsideTextInput()
211 {
212 QScopedPointer<QQuickView> view(loadTest("FilterInverseTextInput.qml"));
213 QVERIFY(view);
214 UCInverseMouse *filter = attachedFilter<UCInverseMouse>(view->rootObject(), "FilterOwner");
215 QVERIFY(filter);
216 QSignalSpy pressed(filter, SIGNAL(pressed(QQuickMouseEvent*, QQuickItem*)));
217 QSignalSpy released(filter, SIGNAL(released(QQuickMouseEvent*, QQuickItem*)));
218 QSignalSpy clicked(filter, SIGNAL(clicked(QQuickMouseEvent*, QQuickItem*)));
219 QSignalSpy positionChanged(filter, SIGNAL(positionChanged(QQuickMouseEvent*, QQuickItem*)));
220 QSignalSpy doubleClicked(filter, SIGNAL(doubleClicked(QQuickMouseEvent*, QQuickItem*)));
221 QSignalSpy pressAndHold(filter, SIGNAL(pressAndHold(QQuickMouseEvent*, QQuickItem*)));
222 QSignalSpy entered(filter, SIGNAL(entered(QQuickMouseEvent*, QQuickItem*)));
223 QSignalSpy exited(filter, SIGNAL(exited(QQuickMouseEvent*, QQuickItem*)));
224
225 preventDblClick();
226 QTest::mouseClick(view.data(), Qt::LeftButton, Qt::NoModifier, guPoint(10, 10));
227 QCoreApplication::processEvents();
228 QCOMPARE(view->rootObject()->hasFocus(), false);
229 QCOMPARE(pressed.count(), 1);
230 QCOMPARE(released.count(), 1);
231 QCOMPARE(clicked.count(), 1);
232 QCOMPARE(positionChanged.count(), 0);
233 QCOMPARE(doubleClicked.count(), 0);
234 QCOMPARE(pressAndHold.count(), 0);
235 QCOMPARE(entered.count(), 1);
236 QCOMPARE(exited.count(), 1);
237 }
238
239 void testCase_pressedOutsideTextInputAfter()
240 {
241 LomiriTestCase::ignoreWarning("FilterInverseTextInputAfter.qml", 23, 5, "QML TextInput: Ignoring AfterItem priority for InverseMouse filters.");
242 QScopedPointer<LomiriTestCase> view(new LomiriTestCase("FilterInverseTextInputAfter.qml"));
243 QCOMPARE(view->warnings(), 1);
244 UCInverseMouse *filter = attachedFilter<UCInverseMouse>(view->rootObject(), "FilterOwner");
245 QVERIFY(filter);
246 QSignalSpy pressed(filter, SIGNAL(pressed(QQuickMouseEvent*, QQuickItem*)));
247 QSignalSpy released(filter, SIGNAL(released(QQuickMouseEvent*, QQuickItem*)));
248 QSignalSpy clicked(filter, SIGNAL(clicked(QQuickMouseEvent*, QQuickItem*)));
249 QSignalSpy positionChanged(filter, SIGNAL(positionChanged(QQuickMouseEvent*, QQuickItem*)));
250 QSignalSpy doubleClicked(filter, SIGNAL(doubleClicked(QQuickMouseEvent*, QQuickItem*)));
251 QSignalSpy pressAndHold(filter, SIGNAL(pressAndHold(QQuickMouseEvent*, QQuickItem*)));
252 QSignalSpy entered(filter, SIGNAL(entered(QQuickMouseEvent*, QQuickItem*)));
253 QSignalSpy exited(filter, SIGNAL(exited(QQuickMouseEvent*, QQuickItem*)));
254
255 preventDblClick();
256 QTest::mouseClick(view.data(), Qt::LeftButton, Qt::NoModifier, guPoint(10, 10));
257 QCoreApplication::processEvents();
258 QCOMPARE(view->rootObject()->hasFocus(), false);
259 QCOMPARE(pressed.count(), 1);
260 QCOMPARE(released.count(), 1);
261 QCOMPARE(clicked.count(), 1);
262 QCOMPARE(positionChanged.count(), 0);
263 QCOMPARE(doubleClicked.count(), 0);
264 QCOMPARE(pressAndHold.count(), 0);
265 QCOMPARE(entered.count(), 1);
266 QCOMPARE(exited.count(), 1);
267 }
268
269 void testCase_pressedInsideTextInputTolerance()
270 {
271 QScopedPointer<QQuickView> view(loadTest("FilterTextInputTolerance.qml"));
272 QVERIFY(view);
273 UCMouse *filter = attachedFilter<UCMouse>(view->rootObject(), "FilterOwner");
274 QVERIFY(filter);
275 QSignalSpy pressed(filter, SIGNAL(pressed(QQuickMouseEvent*, QQuickItem*)));
276 QSignalSpy released(filter, SIGNAL(released(QQuickMouseEvent*, QQuickItem*)));
277 QSignalSpy clicked(filter, SIGNAL(clicked(QQuickMouseEvent*, QQuickItem*)));
278 QSignalSpy positionChanged(filter, SIGNAL(positionChanged(QQuickMouseEvent*, QQuickItem*)));
279 QSignalSpy doubleClicked(filter, SIGNAL(doubleClicked(QQuickMouseEvent*, QQuickItem*)));
280 QSignalSpy pressAndHold(filter, SIGNAL(pressAndHold(QQuickMouseEvent*, QQuickItem*)));
281 QSignalSpy entered(filter, SIGNAL(entered(QQuickMouseEvent*, QQuickItem*)));
282 QSignalSpy exited(filter, SIGNAL(exited(QQuickMouseEvent*, QQuickItem*)));
283
284 preventDblClick();
285 QTest::mousePress(view.data(), Qt::LeftButton, Qt::NoModifier, guPoint(2, 2));
286 QTest::mouseMove(view.data(), guPoint(2.2, 2.2));
287 QTest::mouseRelease(view.data(), Qt::LeftButton, Qt::NoModifier, guPoint(2.2, 2.2));
288 QCoreApplication::processEvents();
289 QCOMPARE(view->rootObject()->hasFocus(), true);
290 QCOMPARE(pressed.count(), 1);
291 QCOMPARE(released.count(), 1);
292 QCOMPARE(clicked.count(), 1);
293 QCOMPARE(positionChanged.count(), 1);
294 QCOMPARE(doubleClicked.count(), 0);
295 QCOMPARE(pressAndHold.count(), 0);
296 QCOMPARE(entered.count(), 1);
297 QCOMPARE(exited.count(), 1);
298 }
299
300 void testCase_pressedOutsideTextInputTolerance()
301 {
302 QScopedPointer<QQuickView> view(loadTest("FilterInverseTextInputTolerance.qml"));
303 QVERIFY(view);
304 UCInverseMouse *filter = attachedFilter<UCInverseMouse>(view->rootObject(), "FilterOwner");
305 QVERIFY(filter);
306 QSignalSpy pressed(filter, SIGNAL(pressed(QQuickMouseEvent*, QQuickItem*)));
307 QSignalSpy released(filter, SIGNAL(released(QQuickMouseEvent*, QQuickItem*)));
308 QSignalSpy clicked(filter, SIGNAL(clicked(QQuickMouseEvent*, QQuickItem*)));
309 QSignalSpy positionChanged(filter, SIGNAL(positionChanged(QQuickMouseEvent*, QQuickItem*)));
310 QSignalSpy doubleClicked(filter, SIGNAL(doubleClicked(QQuickMouseEvent*, QQuickItem*)));
311 QSignalSpy pressAndHold(filter, SIGNAL(pressAndHold(QQuickMouseEvent*, QQuickItem*)));
312 QSignalSpy entered(filter, SIGNAL(entered(QQuickMouseEvent*, QQuickItem*)));
313 QSignalSpy exited(filter, SIGNAL(exited(QQuickMouseEvent*, QQuickItem*)));
314
315 preventDblClick();
316 QTest::mousePress(view.data(), Qt::LeftButton, Qt::NoModifier, guPoint(10, 10));
317 QTest::mouseMove(view.data(), guPoint(10.2, 10.2));
318 QTest::mouseRelease(view.data(), Qt::LeftButton, Qt::NoModifier, guPoint(10.2, 10.2));
319 QCoreApplication::processEvents();
320 QCOMPARE(view->rootObject()->hasFocus(), false);
321 QCOMPARE(pressed.count(), 1);
322 QCOMPARE(released.count(), 1);
323 QCOMPARE(clicked.count(), 1);
324 QCOMPARE(positionChanged.count(), 1);
325 QCOMPARE(doubleClicked.count(), 0);
326 QCOMPARE(pressAndHold.count(), 0);
327 QCOMPARE(entered.count(), 1);
328 QCOMPARE(exited.count(), 1);
329 }
330
331 void testCase_pressedInsideTextInputOutOfTolerance()
332 {
333 QScopedPointer<QQuickView> view(loadTest("FilterTextInputTolerance.qml"));
334 QVERIFY(view);
335 UCMouse *filter = attachedFilter<UCMouse>(view->rootObject(), "FilterOwner");
336 QVERIFY(filter);
337 QSignalSpy pressed(filter, SIGNAL(pressed(QQuickMouseEvent*, QQuickItem*)));
338 QSignalSpy released(filter, SIGNAL(released(QQuickMouseEvent*, QQuickItem*)));
339 QSignalSpy clicked(filter, SIGNAL(clicked(QQuickMouseEvent*, QQuickItem*)));
340 QSignalSpy positionChanged(filter, SIGNAL(positionChanged(QQuickMouseEvent*, QQuickItem*)));
341 QSignalSpy doubleClicked(filter, SIGNAL(doubleClicked(QQuickMouseEvent*, QQuickItem*)));
342 QSignalSpy pressAndHold(filter, SIGNAL(pressAndHold(QQuickMouseEvent*, QQuickItem*)));
343 QSignalSpy entered(filter, SIGNAL(entered(QQuickMouseEvent*, QQuickItem*)));
344 QSignalSpy exited(filter, SIGNAL(exited(QQuickMouseEvent*, QQuickItem*)));
345
346 preventDblClick();
347 QTest::mousePress(view.data(), Qt::LeftButton, Qt::NoModifier, guPoint(2, 2));
348 QTest::mouseMove(view.data(), guPoint(2.7, 2.7));
349 QTest::mouseRelease(view.data(), Qt::LeftButton, Qt::NoModifier, guPoint(2.7, 2.7));
350 QCoreApplication::processEvents();
351 QCOMPARE(view->rootObject()->hasFocus(), true);
352 QCOMPARE(pressed.count(), 1);
353 QCOMPARE(released.count(), 1);
354 QCOMPARE(clicked.count(), 0);
355 QCOMPARE(positionChanged.count(), 1);
356 QCOMPARE(doubleClicked.count(), 0);
357 QCOMPARE(pressAndHold.count(), 0);
358 QCOMPARE(entered.count(), 1);
359 QCOMPARE(exited.count(), 1);
360 }
361
362 void testCase_pressedOutsideTextInputOutOfTolerance()
363 {
364 QScopedPointer<QQuickView> view(loadTest("FilterInverseTextInputTolerance.qml"));
365 QVERIFY(view);
366 UCInverseMouse *filter = attachedFilter<UCInverseMouse>(view->rootObject(), "FilterOwner");
367 QVERIFY(filter);
368 QSignalSpy pressed(filter, SIGNAL(pressed(QQuickMouseEvent*, QQuickItem*)));
369 QSignalSpy released(filter, SIGNAL(released(QQuickMouseEvent*, QQuickItem*)));
370 QSignalSpy clicked(filter, SIGNAL(clicked(QQuickMouseEvent*, QQuickItem*)));
371 QSignalSpy positionChanged(filter, SIGNAL(positionChanged(QQuickMouseEvent*, QQuickItem*)));
372 QSignalSpy doubleClicked(filter, SIGNAL(doubleClicked(QQuickMouseEvent*, QQuickItem*)));
373 QSignalSpy pressAndHold(filter, SIGNAL(pressAndHold(QQuickMouseEvent*, QQuickItem*)));
374 QSignalSpy entered(filter, SIGNAL(entered(QQuickMouseEvent*, QQuickItem*)));
375 QSignalSpy exited(filter, SIGNAL(exited(QQuickMouseEvent*, QQuickItem*)));
376
377 preventDblClick();
378 QTest::mousePress(view.data(), Qt::LeftButton, Qt::NoModifier, guPoint(10, 10));
379 QTest::mouseMove(view.data(), guPoint(10.6, 10.6));
380 QTest::mouseRelease(view.data(), Qt::LeftButton, Qt::NoModifier, guPoint(10.6, 10.6));
381 QCoreApplication::processEvents();
382 QCOMPARE(view->rootObject()->hasFocus(), false);
383 QCOMPARE(pressed.count(), 1);
384 QCOMPARE(released.count(), 1);
385 QCOMPARE(clicked.count(), 0);
386 QCOMPARE(positionChanged.count(), 1);
387 QCOMPARE(doubleClicked.count(), 0);
388 QCOMPARE(pressAndHold.count(), 0);
389 QCOMPARE(entered.count(), 1);
390 QCOMPARE(exited.count(), 1);
391 }
392
393 void testCase_pressedOverOSKExcluded()
394 {
395 QScopedPointer<QQuickView> view(loadTest("FilterInverseTextInputOSKExcluded.qml"));
396 QVERIFY(view);
397 UCInverseMouse *filter = attachedFilter<UCInverseMouse>(view->rootObject(), "FilterOwner");
398 QVERIFY(filter);
399
400 QSignalSpy pressed(filter, SIGNAL(pressed(QQuickMouseEvent*, QQuickItem*)));
401 QSignalSpy released(filter, SIGNAL(released(QQuickMouseEvent*, QQuickItem*)));
402 QSignalSpy clicked(filter, SIGNAL(clicked(QQuickMouseEvent*, QQuickItem*)));
403 QSignalSpy positionChanged(filter, SIGNAL(positionChanged(QQuickMouseEvent*, QQuickItem*)));
404 QSignalSpy doubleClicked(filter, SIGNAL(doubleClicked(QQuickMouseEvent*, QQuickItem*)));
405 QSignalSpy pressAndHold(filter, SIGNAL(pressAndHold(QQuickMouseEvent*, QQuickItem*)));
406 QSignalSpy entered(filter, SIGNAL(entered(QQuickMouseEvent*, QQuickItem*)));
407 QSignalSpy exited(filter, SIGNAL(exited(QQuickMouseEvent*, QQuickItem*)));
408
409 // focus TextInput
410 QQuickItem *input = view->rootObject()->findChild<QQuickItem*>("FilterOwner");
411 QVERIFY(input);
412 input->forceActiveFocus();
413 QCOMPARE(input->hasFocus(), true);
414
415 // introduce small delay to suppress double clicks
416 preventDblClick();
417 QTest::mouseClick(view.data(), Qt::LeftButton, Qt::NoModifier, guPoint(10, 10));
418 QCoreApplication::processEvents();
419 preventDblClick();
420 QTest::mouseClick(view.data(), Qt::LeftButton, Qt::NoModifier, guPoint(10, 69));
421 QCoreApplication::processEvents();
422 if (!inputPanelPresent()) {
423 QEXPECT_FAIL(0, "No OSK installed", Abort);
424 }
425 QCOMPARE(pressed.count(), 1);
426 QCOMPARE(released.count(), 1);
427 QCOMPARE(clicked.count(), 1);
428 QCOMPARE(positionChanged.count(), 0);
429 QCOMPARE(doubleClicked.count(), 0);
430 QCOMPARE(pressAndHold.count(), 0);
431 QCOMPARE(entered.count(), 1);
432 QCOMPARE(exited.count(), 1);
433 }
434
435 void testCase_pressAndMovedInsideTextInput()
436 {
437 QScopedPointer<QQuickView> view(loadTest("FilterTextInput.qml"));
438 QVERIFY(view);
439 UCMouse *filter = attachedFilter<UCMouse>(view->rootObject(), "FilterOwner");
440 QVERIFY(filter);
441 QSignalSpy pressed(filter, SIGNAL(pressed(QQuickMouseEvent*, QQuickItem*)));
442 QSignalSpy released(filter, SIGNAL(released(QQuickMouseEvent*, QQuickItem*)));
443 QSignalSpy clicked(filter, SIGNAL(clicked(QQuickMouseEvent*, QQuickItem*)));
444 QSignalSpy positionChanged(filter, SIGNAL(positionChanged(QQuickMouseEvent*, QQuickItem*)));
445 QSignalSpy doubleClicked(filter, SIGNAL(doubleClicked(QQuickMouseEvent*, QQuickItem*)));
446 QSignalSpy pressAndHold(filter, SIGNAL(pressAndHold(QQuickMouseEvent*, QQuickItem*)));
447 QSignalSpy entered(filter, SIGNAL(entered(QQuickMouseEvent*, QQuickItem*)));
448 QSignalSpy exited(filter, SIGNAL(exited(QQuickMouseEvent*, QQuickItem*)));
449
450 // make sure we do not get double click because of the previous tests
451 preventDblClick();
452 QTest::mousePress(view.data(), Qt::LeftButton, Qt::NoModifier, guPoint(2, 2));
453 QTest::mouseMove(view.data(), guPoint(2.7, 2.7));
454 QTest::mouseRelease(view.data(), Qt::LeftButton, Qt::NoModifier, guPoint(2.7, 2.7));
455 QCoreApplication::processEvents();
456 QCOMPARE(view->rootObject()->hasFocus(), true);
457 QCOMPARE(pressed.count(), 1);
458 QCOMPARE(released.count(), 1);
459 QCOMPARE(clicked.count(), 1);
460 QCOMPARE(positionChanged.count(), 1);
461 QCOMPARE(doubleClicked.count(), 0);
462 QCOMPARE(pressAndHold.count(), 0);
463 QCOMPARE(entered.count(), 1);
464 QCOMPARE(exited.count(), 1);
465 }
466
467 void testCase_pressAndMovedOutsideTextInputInTolerance()
468 {
469 QScopedPointer<QQuickView> view(loadTest("FilterInverseTextInputTolerance.qml"));
470 QVERIFY(view);
471 UCInverseMouse *filter = attachedFilter<UCInverseMouse>(view->rootObject(), "FilterOwner");
472 QVERIFY(filter);
473 QSignalSpy pressed(filter, SIGNAL(pressed(QQuickMouseEvent*, QQuickItem*)));
474 QSignalSpy released(filter, SIGNAL(released(QQuickMouseEvent*, QQuickItem*)));
475 QSignalSpy clicked(filter, SIGNAL(clicked(QQuickMouseEvent*, QQuickItem*)));
476 QSignalSpy positionChanged(filter, SIGNAL(positionChanged(QQuickMouseEvent*, QQuickItem*)));
477 QSignalSpy doubleClicked(filter, SIGNAL(doubleClicked(QQuickMouseEvent*, QQuickItem*)));
478 QSignalSpy pressAndHold(filter, SIGNAL(pressAndHold(QQuickMouseEvent*, QQuickItem*)));
479 QSignalSpy entered(filter, SIGNAL(entered(QQuickMouseEvent*, QQuickItem*)));
480 QSignalSpy exited(filter, SIGNAL(exited(QQuickMouseEvent*, QQuickItem*)));
481
482 // make sure we do not get double click because of the previous tests
483 preventDblClick();
484 QTest::mousePress(view.data(), Qt::LeftButton, Qt::NoModifier, guPoint(10, 10));
485 QTest::mouseMove(view.data(), guPoint(10.5, 10.5));
486 QTest::mouseRelease(view.data(), Qt::LeftButton, Qt::NoModifier, guPoint(10.5, 10.5));
487 QCoreApplication::processEvents();
488 QCOMPARE(view->rootObject()->hasFocus(), false);
489 QCOMPARE(pressed.count(), 1);
490 QCOMPARE(released.count(), 1);
491 QCOMPARE(clicked.count(), 1);
492 QCOMPARE(positionChanged.count(), 1);
493 QCOMPARE(doubleClicked.count(), 0);
494 QCOMPARE(pressAndHold.count(), 0);
495 QCOMPARE(entered.count(), 1);
496 QCOMPARE(exited.count(), 1);
497 }
498
499 void testCase_pressAndMovedOutsideTextInputOutTolerance()
500 {
501 QScopedPointer<QQuickView> view(loadTest("FilterInverseTextInputTolerance.qml"));
502 QVERIFY(view);
503 UCInverseMouse *filter = attachedFilter<UCInverseMouse>(view->rootObject(), "FilterOwner");
504 QVERIFY(filter);
505 QSignalSpy pressed(filter, SIGNAL(pressed(QQuickMouseEvent*, QQuickItem*)));
506 QSignalSpy released(filter, SIGNAL(released(QQuickMouseEvent*, QQuickItem*)));
507 QSignalSpy clicked(filter, SIGNAL(clicked(QQuickMouseEvent*, QQuickItem*)));
508 QSignalSpy positionChanged(filter, SIGNAL(positionChanged(QQuickMouseEvent*, QQuickItem*)));
509 QSignalSpy doubleClicked(filter, SIGNAL(doubleClicked(QQuickMouseEvent*, QQuickItem*)));
510 QSignalSpy pressAndHold(filter, SIGNAL(pressAndHold(QQuickMouseEvent*, QQuickItem*)));
511 QSignalSpy entered(filter, SIGNAL(entered(QQuickMouseEvent*, QQuickItem*)));
512 QSignalSpy exited(filter, SIGNAL(exited(QQuickMouseEvent*, QQuickItem*)));
513
514 // make sure we do not get double click because of the previous tests
515 preventDblClick();
516 QTest::mousePress(view.data(), Qt::LeftButton, Qt::NoModifier, guPoint(10, 10));
517 QTest::mouseMove(view.data(), guPoint(15, 15));
518 QTest::mouseRelease(view.data(), Qt::LeftButton, Qt::NoModifier, guPoint(15, 15));
519 QCoreApplication::processEvents();
520 QCOMPARE(view->rootObject()->hasFocus(), false);
521 QCOMPARE(pressed.count(), 1);
522 QCOMPARE(released.count(), 1);
523 QCOMPARE(clicked.count(), 0);
524 QCOMPARE(positionChanged.count(), 1);
525 QCOMPARE(doubleClicked.count(), 0);
526 QCOMPARE(pressAndHold.count(), 0);
527 QCOMPARE(entered.count(), 1);
528 QCOMPARE(exited.count(), 1);
529 }
530
531 void testCase_pressAndHoldDisableClick() {
532 QScopedPointer<QQuickView> view(loadTest("PressAndHoldAcceptedEatsClick.qml"));
533 QVERIFY(view);
534 UCMouse *filter = attachedFilter<UCMouse>(view->rootObject(), "FilterOwner");
535 QVERIFY(filter);
536 QSignalSpy clicked(filter, SIGNAL(clicked(QQuickMouseEvent*, QQuickItem*)));
537 QSignalSpy pressAndHold(filter, SIGNAL(pressAndHold(QQuickMouseEvent*, QQuickItem*)));
538
539 preventDblClick();
540 mousePressAndHold(view.data(), Qt::LeftButton, Qt::NoModifier, guPoint(2, 2));
541 QTest::mouseRelease(view.data(), Qt::LeftButton, Qt::NoModifier, guPoint(2, 2));
542 QCoreApplication::processEvents();
543 QCOMPARE(view->rootObject()->hasFocus(), true);
544 QCOMPARE(pressAndHold.count(), 1);
545 QCOMPARE(clicked.count(), 0);
546 }
547
548 void testCase_pressAndHoldAndClick() {
549 QScopedPointer<QQuickView> view(loadTest("PressAndHoldAndClicked.qml"));
550 QVERIFY(view);
551 UCMouse *filter = attachedFilter<UCMouse>(view->rootObject(), "FilterOwner");
552 QVERIFY(filter);
553 QSignalSpy clicked(filter, SIGNAL(clicked(QQuickMouseEvent*, QQuickItem*)));
554 QSignalSpy pressAndHold(filter, SIGNAL(pressAndHold(QQuickMouseEvent*, QQuickItem*)));
555
556 preventDblClick();
557 mousePressAndHold(view.data(), Qt::LeftButton, Qt::NoModifier, guPoint(2, 2));
558 QTest::mouseRelease(view.data(), Qt::LeftButton, Qt::NoModifier, guPoint(2, 2));
559 QCoreApplication::processEvents();
560 QCOMPARE(view->rootObject()->hasFocus(), true);
561 QCOMPARE(pressAndHold.count(), 1);
562 QCOMPARE(clicked.count(), 1);
563 }
564
565 void testCase_doubleClicked()
566 {
567 QSKIP("FIXME: lp#1542215 Flaky test result");
568 QScopedPointer<QQuickView> view(loadTest("DoubleClicked.qml"));
569 QVERIFY(view);
570 UCMouse *filter = attachedFilter<UCMouse>(view->rootObject(), "FilterOwner");
571 QVERIFY(filter);
572 QQuickItem *input = view->rootObject();
573 QVERIFY(input);
574 QSignalSpy clicked(filter, SIGNAL(clicked(QQuickMouseEvent*, QQuickItem*)));
575 QSignalSpy dblClicked(filter, SIGNAL(doubleClicked(QQuickMouseEvent*, QQuickItem*)));
576
577 preventDblClick();
578 QTest::mouseDClick(view.data(), Qt::LeftButton, Qt::NoModifier, guPoint(2, 2));
579 QCoreApplication::processEvents();
580 QVariant selectedText = input->property("selectedText");
581 QCOMPARE(input->hasFocus(), true);
582 QVERIFY(selectedText.isValid());
583 QVERIFY(!selectedText.toString().isEmpty());
584 // ther emust be one click, the second one should be suppressed
585 // by the doubleClicked() signal being connected at least to signalSpy!
586 QCOMPARE(clicked.count(), 1);
587 QCOMPARE(dblClicked.count(), 1);
588 }
589
590 void testCase_mouseFilterAttachedToNonItem()
591 {
592 LomiriTestCase::ignoreWarning("MouseFilterAttachedToNonItem.qml", 21, 5, "QML QtObject: Warning: Mouse filter can only be attached to Items.");
593 QScopedPointer<LomiriTestCase> testCase(new LomiriTestCase("MouseFilterAttachedToNonItem.qml"));
594 QCOMPARE(testCase->warnings(), 1);
595 }
596
597 void testCase_inverseMouseFilterAttachedToNonItem()
598 {
599 LomiriTestCase::ignoreWarning("InverseMouseFilterAttachedToNonItem.qml", 21, 5, "QML QtObject: Warning: InverseMouse filter can only be attached to Items.");
600 QScopedPointer<LomiriTestCase> testCase(new LomiriTestCase("InverseMouseFilterAttachedToNonItem.qml"));
601 QCOMPARE(testCase->warnings(), 1);
602 }
603
604 void testCase_forwardedEventsToItem()
605 {
606 QScopedPointer<QQuickView> view(loadTest("ForwardedMouseEvents.qml"));
607 QVERIFY(view);
608 UCMouse *filter = attachedFilter<UCMouse>(view->rootObject(), "target");
609 QVERIFY(filter);
610 QQuickItem *input = view->rootObject()->findChild<QQuickItem*>("FilterOwner");
611 QVERIFY(input);
612 QSignalSpy pressed(filter, SIGNAL(pressed(QQuickMouseEvent*, QQuickItem*)));
613 QSignalSpy released(filter, SIGNAL(released(QQuickMouseEvent*, QQuickItem*)));
614 QSignalSpy clicked(filter, SIGNAL(clicked(QQuickMouseEvent*, QQuickItem*)));
615 QSignalSpy positionChanged(filter, SIGNAL(positionChanged(QQuickMouseEvent*, QQuickItem*)));
616 QSignalSpy doubleClicked(filter, SIGNAL(doubleClicked(QQuickMouseEvent*, QQuickItem*)));
617 QSignalSpy pressAndHold(filter, SIGNAL(pressAndHold(QQuickMouseEvent*, QQuickItem*)));
618 QSignalSpy entered(filter, SIGNAL(entered(QQuickMouseEvent*, QQuickItem*)));
619 QSignalSpy exited(filter, SIGNAL(exited(QQuickMouseEvent*, QQuickItem*)));
620
621 preventDblClick();
622 QTest::mouseClick(view.data(), Qt::LeftButton, Qt::NoModifier, guPoint(2, 2));
623 QCoreApplication::processEvents();
624 QCOMPARE(input->hasFocus(), true);
625 QCOMPARE(pressed.count(), 1);
626 QCOMPARE(released.count(), 1);
627 QCOMPARE(clicked.count(), 1);
628 QCOMPARE(positionChanged.count(), 0);
629 QCOMPARE(doubleClicked.count(), 0);
630 QCOMPARE(pressAndHold.count(), 0);
631 QCOMPARE(entered.count(), 1);
632 QCOMPARE(exited.count(), 1);
633 }
634
635 void testCase_forwardedEventsToItemStopped()
636 {
637 QScopedPointer<QQuickView> view(loadTest("ForwardedMouseEventsStopped.qml"));
638 QVERIFY(view);
639 UCMouse *filter = attachedFilter<UCMouse>(view->rootObject(), "target");
640 QVERIFY(filter);
641 QQuickItem *input = view->rootObject()->findChild<QQuickItem*>("FilterOwner");
642 QVERIFY(input);
643 QSignalSpy pressed(filter, SIGNAL(pressed(QQuickMouseEvent*, QQuickItem*)));
644 QSignalSpy released(filter, SIGNAL(released(QQuickMouseEvent*, QQuickItem*)));
645 QSignalSpy clicked(filter, SIGNAL(clicked(QQuickMouseEvent*, QQuickItem*)));
646 QSignalSpy positionChanged(filter, SIGNAL(positionChanged(QQuickMouseEvent*, QQuickItem*)));
647 QSignalSpy doubleClicked(filter, SIGNAL(doubleClicked(QQuickMouseEvent*, QQuickItem*)));
648 QSignalSpy pressAndHold(filter, SIGNAL(pressAndHold(QQuickMouseEvent*, QQuickItem*)));
649 QSignalSpy entered(filter, SIGNAL(entered(QQuickMouseEvent*, QQuickItem*)));
650 QSignalSpy exited(filter, SIGNAL(exited(QQuickMouseEvent*, QQuickItem*)));
651
652 preventDblClick();
653 QTest::mouseClick(view.data(), Qt::LeftButton, Qt::NoModifier, guPoint(2, 2));
654 QCoreApplication::processEvents();
655 QCOMPARE(input->hasFocus(), false);
656 // only the pressed was blocked, the rest of the events land in the proxy
657 QCOMPARE(pressed.count(), 0);
658 QCOMPARE(released.count(), 1);
659 QCOMPARE(clicked.count(), 1);
660 QCOMPARE(positionChanged.count(), 0);
661 QCOMPARE(doubleClicked.count(), 0);
662 QCOMPARE(pressAndHold.count(), 0);
663 QCOMPARE(entered.count(), 1);
664 QCOMPARE(exited.count(), 1);
665 }
666
667 void testCase_forwardedEventsToItemStoppedInForwards()
668 {
669 QScopedPointer<QQuickView> view(loadTest("ForwardedEventsStoppedInForwards.qml"));
670 QVERIFY(view);
671 UCMouse *filter = attachedFilter<UCMouse>(view->rootObject(), "target");
672 QVERIFY(filter);
673 QQuickItem *input = view->rootObject()->findChild<QQuickItem*>("FilterOwner");
674 QVERIFY(input);
675 QSignalSpy pressed(filter, SIGNAL(pressed(QQuickMouseEvent*, QQuickItem*)));
676 QSignalSpy released(filter, SIGNAL(released(QQuickMouseEvent*, QQuickItem*)));
677 QSignalSpy clicked(filter, SIGNAL(clicked(QQuickMouseEvent*, QQuickItem*)));
678 QSignalSpy positionChanged(filter, SIGNAL(positionChanged(QQuickMouseEvent*, QQuickItem*)));
679 QSignalSpy doubleClicked(filter, SIGNAL(doubleClicked(QQuickMouseEvent*, QQuickItem*)));
680 QSignalSpy pressAndHold(filter, SIGNAL(pressAndHold(QQuickMouseEvent*, QQuickItem*)));
681 QSignalSpy entered(filter, SIGNAL(entered(QQuickMouseEvent*, QQuickItem*)));
682 QSignalSpy exited(filter, SIGNAL(exited(QQuickMouseEvent*, QQuickItem*)));
683
684 preventDblClick();
685 QTest::mouseClick(view.data(), Qt::LeftButton, Qt::NoModifier, guPoint(2, 2));
686 QCoreApplication::processEvents();
687 QCOMPARE(input->hasFocus(), false);
688 QCOMPARE(pressed.count(), 1);
689 QCOMPARE(released.count(), 1);
690 QCOMPARE(clicked.count(), 1);
691 QCOMPARE(positionChanged.count(), 0);
692 QCOMPARE(doubleClicked.count(), 0);
693 QCOMPARE(pressAndHold.count(), 0);
694 QCOMPARE(entered.count(), 1);
695 QCOMPARE(exited.count(), 1);
696 }
697
698 void testCase_forwardedEventsToTargetBlocked()
699 {
700 QScopedPointer<QQuickView> view(loadTest("ForwardedEventsToTargetBlocked.qml"));
701 QVERIFY(view);
702 UCMouse *filter = attachedFilter<UCMouse>(view->rootObject(), "target");
703 QVERIFY(filter);
704 QQuickItem *input = view->rootObject()->findChild<QQuickItem*>("FilterOwner");
705 QVERIFY(input);
706 QSignalSpy pressed(filter, SIGNAL(pressed(QQuickMouseEvent*, QQuickItem*)));
707 QSignalSpy released(filter, SIGNAL(released(QQuickMouseEvent*, QQuickItem*)));
708 QSignalSpy clicked(filter, SIGNAL(clicked(QQuickMouseEvent*, QQuickItem*)));
709 QSignalSpy positionChanged(filter, SIGNAL(positionChanged(QQuickMouseEvent*, QQuickItem*)));
710 QSignalSpy doubleClicked(filter, SIGNAL(doubleClicked(QQuickMouseEvent*, QQuickItem*)));
711 QSignalSpy pressAndHold(filter, SIGNAL(pressAndHold(QQuickMouseEvent*, QQuickItem*)));
712 QSignalSpy entered(filter, SIGNAL(entered(QQuickMouseEvent*, QQuickItem*)));
713 QSignalSpy exited(filter, SIGNAL(exited(QQuickMouseEvent*, QQuickItem*)));
714
715 preventDblClick();
716 QTest::mouseClick(view.data(), Qt::LeftButton, Qt::NoModifier, guPoint(2, 2));
717 QCoreApplication::processEvents();
718 QCOMPARE(input->hasFocus(), true);
719 QCOMPARE(pressed.count(), 0);
720 QCOMPARE(released.count(), 1);
721 QCOMPARE(clicked.count(), 1);
722 QCOMPARE(positionChanged.count(), 0);
723 QCOMPARE(doubleClicked.count(), 0);
724 QCOMPARE(pressAndHold.count(), 0);
725 QCOMPARE(entered.count(), 1);
726 QCOMPARE(exited.count(), 1);
727 }
728
729 void testCase_forwardedEventsToMouseArea()
730 {
731 QScopedPointer<QQuickView> view(loadTest("ForwardToMouseArea.qml"));
732 QVERIFY(view);
733 QQuickMouseArea *target = view->rootObject()->findChild<QQuickMouseArea*>("target");
734 QVERIFY(target);
735 QQuickItem *input = view->rootObject()->findChild<QQuickItem*>("FilterOwner");
736 QVERIFY(input);
737 QSignalSpy pressed(target, SIGNAL(pressed(QQuickMouseEvent*)));
738 QSignalSpy released(target, SIGNAL(released(QQuickMouseEvent*)));
739 QSignalSpy clicked(target, SIGNAL(clicked(QQuickMouseEvent*)));
740 QSignalSpy positionChanged(target, SIGNAL(positionChanged(QQuickMouseEvent*)));
741 QSignalSpy doubleClicked(target, SIGNAL(doubleClicked(QQuickMouseEvent*)));
742 QSignalSpy pressAndHold(target, SIGNAL(pressAndHold(QQuickMouseEvent*)));
743 QSignalSpy entered(target, SIGNAL(entered()));
744 QSignalSpy exited(target, SIGNAL(exited()));
745
746 preventDblClick();
747 QTest::mouseClick(view.data(), Qt::LeftButton, Qt::NoModifier, guPoint(2, 2));
748 QCoreApplication::processEvents();
749 QCOMPARE(input->hasFocus(), false);
750 QCOMPARE(pressed.count(), 1);
751 QCOMPARE(released.count(), 1);
752 QCOMPARE(clicked.count(), 1);
753 QCOMPARE(positionChanged.count(), 0);
754 QCOMPARE(doubleClicked.count(), 0);
755 QCOMPARE(pressAndHold.count(), 0);
756 QCOMPARE(entered.count(), 1);
757 QCOMPARE(exited.count(), 1);
758 }
759
760 void testCase_forwardedEventsToTransparentMouseArea()
761 {
762 QSKIP("FIXME: lp#1542215 Flaky test result");
763 QScopedPointer<QQuickView> view(loadTest("ForwardToTransparentMouseArea.qml"));
764 QVERIFY(view);
765 QQuickMouseArea *target = view->rootObject()->findChild<QQuickMouseArea*>("target");
766 QVERIFY(target);
767 QQuickItem *input = view->rootObject()->findChild<QQuickItem*>("FilterOwner");
768 QVERIFY(input);
769 QSignalSpy pressed(target, SIGNAL(pressed(QQuickMouseEvent*)));
770 QSignalSpy released(target, SIGNAL(released(QQuickMouseEvent*)));
771 QSignalSpy clicked(target, SIGNAL(clicked(QQuickMouseEvent*)));
772 QSignalSpy positionChanged(target, SIGNAL(positionChanged(QQuickMouseEvent*)));
773 QSignalSpy doubleClicked(target, SIGNAL(doubleClicked(QQuickMouseEvent*)));
774 QSignalSpy pressAndHold(target, SIGNAL(pressAndHold(QQuickMouseEvent*)));
775 QSignalSpy entered(target, SIGNAL(entered()));
776 QSignalSpy exited(target, SIGNAL(exited()));
777
778 preventDblClick();
779 QTest::mouseClick(input->window(), Qt::LeftButton, Qt::NoModifier, guPoint(10, 7));
780 QCoreApplication::processEvents();
781 QCOMPARE(input->hasFocus(), true);
782 QCOMPARE(pressed.count(), 1);
783 QCOMPARE(released.count(), 1);
784 QCOMPARE(clicked.count(), 1);
785 QCOMPARE(positionChanged.count(), 0);
786 QCOMPARE(doubleClicked.count(), 0);
787 QCOMPARE(pressAndHold.count(), 0);
788 QCOMPARE(entered.count(), 1);
789 QCOMPARE(exited.count(), 1);
790 }
791
792 void testCase_forwardedDblClickToTransparentMouseArea()
793 {
794 QScopedPointer<QQuickView> view(loadTest("ForwardDblClickToTransparentMouseArea.qml"));
795 QVERIFY(view);
796 QQuickMouseArea *target = view->rootObject()->findChild<QQuickMouseArea*>("target");
797 QVERIFY(target);
798 QQuickItem *input = view->rootObject()->findChild<QQuickItem*>("FilterOwner");
799 QVERIFY(input);
800 QSignalSpy doubleClicked(target, SIGNAL(doubleClicked(QQuickMouseEvent*)));
801
802 preventDblClick();
803 QTest::mouseDClick(input->window(), Qt::LeftButton, Qt::NoModifier, guPoint(10, 7));
804 QCoreApplication::processEvents();
805 QCOMPARE(input->hasFocus(), true);
806 QVariant selectedText = input->property("selectedText");
807 QVERIFY(selectedText.isValid());
808 QVERIFY(selectedText.toString().isEmpty());
809 QCOMPARE(doubleClicked.count(), 1);
810 }
811
812 void testCase_forwardedEventsToInverseMouseArea()
813 {
814 QScopedPointer<QQuickView> view(loadTest("ForwardToInverseMouseArea.qml"));
815 QVERIFY(view);
816 QQuickItem *target = view->rootObject()->findChild<QQuickItem*>("target");
817 QVERIFY(target);
818 QQuickItem *input = view->rootObject()->findChild<QQuickItem*>("FilterOwner");
819 QVERIFY(input);
820 QSignalSpy pressed(target, SIGNAL(pressed(QQuickMouseEvent*)));
821 QSignalSpy released(target, SIGNAL(released(QQuickMouseEvent*)));
822 QSignalSpy clicked(target, SIGNAL(clicked(QQuickMouseEvent*)));
823 QSignalSpy positionChanged(target, SIGNAL(positionChanged(QQuickMouseEvent*)));
824 QSignalSpy doubleClicked(target, SIGNAL(doubleClicked(QQuickMouseEvent*)));
825 QSignalSpy pressAndHold(target, SIGNAL(pressAndHold(QQuickMouseEvent*)));
826 QSignalSpy entered(target, SIGNAL(entered()));
827 QSignalSpy exited(target, SIGNAL(exited()));
828
829 preventDblClick();
830 QTest::mouseClick(view.data(), Qt::LeftButton, Qt::NoModifier, guPoint(2, 2));
831 QCoreApplication::processEvents();
832 QCOMPARE(input->hasFocus(), true);
833 QCOMPARE(pressed.count(), 1);
834 QCOMPARE(released.count(), 0);
835 QCOMPARE(clicked.count(), 0);
836 QCOMPARE(positionChanged.count(), 0);
837 QCOMPARE(doubleClicked.count(), 0);
838 QCOMPARE(pressAndHold.count(), 0);
839 QCOMPARE(entered.count(), 1);
840 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
841 QCOMPARE(exited.count(), 1);
842 #else
843 QCOMPARE(exited.count(), 0);
844 #endif
845 }
846
847 void testCase_filterFlickable()
848 {
849 QScopedPointer<QQuickView> view(loadTest("FilterFlickable.qml"));
850 QVERIFY(view);
851 UCMouse *filter = attachedFilter<UCMouse>(view->rootObject(), "FilterOwner");
852 QVERIFY(filter);
853 QQuickItem *flickable = view->rootObject();
854 QVERIFY(flickable);
855 QSignalSpy pressed(filter, SIGNAL(pressed(QQuickMouseEvent*, QQuickItem*)));
856 QSignalSpy released(filter, SIGNAL(released(QQuickMouseEvent*, QQuickItem*)));
857 QSignalSpy clicked(filter, SIGNAL(clicked(QQuickMouseEvent*, QQuickItem*)));
858 QSignalSpy positionChanged(filter, SIGNAL(positionChanged(QQuickMouseEvent*, QQuickItem*)));
859 QSignalSpy doubleClicked(filter, SIGNAL(doubleClicked(QQuickMouseEvent*, QQuickItem*)));
860 QSignalSpy pressAndHold(filter, SIGNAL(pressAndHold(QQuickMouseEvent*, QQuickItem*)));
861 QSignalSpy entered(filter, SIGNAL(entered(QQuickMouseEvent*, QQuickItem*)));
862 QSignalSpy exited(filter, SIGNAL(exited(QQuickMouseEvent*, QQuickItem*)));
863
864 QSignalSpy flickStart(flickable, SIGNAL(movementStarted()));
865
866 preventDblClick();
867 QTest::mousePress(flickable->window(), Qt::LeftButton, Qt::NoModifier, guPoint(5, 5));
868 // Avoid sending MouseMove with no movement.
869 for (int i = 1; i <= 30; i++) {
870 QTest::mouseMove(flickable->window(), guPoint(5 + i, 5 + i));
871 }
872 QCoreApplication::processEvents();
873 QTest::mouseRelease(flickable->window(), Qt::LeftButton, Qt::NoModifier, guPoint(35, 35));
874 QCoreApplication::processEvents();
875
876 QCOMPARE(pressed.count(), 1);
877 QCOMPARE(released.count(), 1);
878 QCOMPARE(clicked.count(), 1);
879 QCOMPARE(positionChanged.count(), 30);
880 QCOMPARE(doubleClicked.count(), 0);
881 QCOMPARE(pressAndHold.count(), 0);
882 QCOMPARE(entered.count(), 1);
883 QCOMPARE(exited.count(), 1);
884 QCOMPARE(flickStart.count(), 1);
885 }
886
887 void testCase_filterFlickableAfter()
888 {
889 QScopedPointer<QQuickView> view(loadTest("FilterFlickableAfter.qml"));
890 QVERIFY(view);
891 UCMouse *filter = attachedFilter<UCMouse>(view->rootObject(), "FilterOwner");
892 QVERIFY(filter);
893 QQuickItem *flickable = view->rootObject()->findChild<QQuickItem*>("FilterOwner");
894 QVERIFY(flickable);
895 QSignalSpy pressed(filter, SIGNAL(pressed(QQuickMouseEvent*, QQuickItem*)));
896 QSignalSpy released(filter, SIGNAL(released(QQuickMouseEvent*, QQuickItem*)));
897 QSignalSpy clicked(filter, SIGNAL(clicked(QQuickMouseEvent*, QQuickItem*)));
898 QSignalSpy positionChanged(filter, SIGNAL(positionChanged(QQuickMouseEvent*, QQuickItem*)));
899 QSignalSpy doubleClicked(filter, SIGNAL(doubleClicked(QQuickMouseEvent*, QQuickItem*)));
900 QSignalSpy pressAndHold(filter, SIGNAL(pressAndHold(QQuickMouseEvent*, QQuickItem*)));
901 QSignalSpy entered(filter, SIGNAL(entered(QQuickMouseEvent*, QQuickItem*)));
902 QSignalSpy exited(filter, SIGNAL(exited(QQuickMouseEvent*, QQuickItem*)));
903
904 QSignalSpy flickStart(flickable, SIGNAL(movementStarted()));
905
906 preventDblClick();
907 QTest::mousePress(flickable->window(), Qt::LeftButton, Qt::NoModifier, guPoint(5, 5));
908 // Avoid sending MouseMove with no movement.
909 for (int i = 1; i <= 30; i++) {
910 QTest::mouseMove(flickable->window(), guPoint(5 + i, 5 + i));
911 }
912 QTest::mouseRelease(flickable->window(), Qt::LeftButton, Qt::NoModifier, guPoint(35, 35));
913 QCoreApplication::processEvents();
914
915 QCOMPARE(pressed.count(), 1);
916 QCOMPARE(released.count(), 1);
917 QCOMPARE(clicked.count(), 1);
918 QCOMPARE(positionChanged.count(), 30);
919 QCOMPARE(doubleClicked.count(), 0);
920 QCOMPARE(pressAndHold.count(), 0);
921 QCOMPARE(entered.count(), 1);
922 QCOMPARE(exited.count(), 1);
923 QCOMPARE(flickStart.count(), 1);
924 }
925
926 void testCase_hover()
927 {
928 QScopedPointer<QQuickView> view(loadTest("FilterFlickableAfter.qml"));
929 QVERIFY(view);
930 UCMouse *filter = attachedFilter<UCMouse>(view->rootObject(), "FilterOwner");
931 QVERIFY(filter);
932 QSignalSpy positionChanged(filter, SIGNAL(positionChanged(QQuickMouseEvent*, QQuickItem*)));
933 QSignalSpy entered(filter, SIGNAL(entered(QQuickMouseEvent*, QQuickItem*)));
934 QSignalSpy exited(filter, SIGNAL(exited(QQuickMouseEvent*, QQuickItem*)));
935 QObject::connect(filter, SIGNAL(entered(QQuickMouseEvent*, QQuickItem*)), this, SLOT(onMouseEvent(QQuickMouseEvent*, QQuickItem*)));
936 QObject::connect(filter, SIGNAL(exited(QQuickMouseEvent*, QQuickItem*)), this, SLOT(onMouseEvent(QQuickMouseEvent*, QQuickItem*)));
937 QObject::connect(filter, SIGNAL(positionChanged(QQuickMouseEvent*, QQuickItem*)), this, SLOT(onMouseEvent2(QQuickMouseEvent*, QQuickItem*)));
938
939 preventDblClick();
940 // Note: press inside the filtered area, so entered() exited() positionChanged() will
941 // all receive the pressed button
942 QTest::mousePress(view.data(), Qt::LeftButton, Qt::NoModifier, guPoint(5, 5));
943 QCoreApplication::processEvents();
944 QCOMPARE(entered.count(), 1);
945 // when entered(), buttons are the same as when pressed
946 QCOMPARE(mouseEventParams.handler, QString("EVENT1"));
947 QCOMPARE(mouseEventParams.pressedButton, Qt::LeftButton);
948
949 QTest::mouseMove(view.data(), guPoint(15, 5));
950 QTest::mouseMove(view.data(), guPoint(25, 5));
951 QCoreApplication::processEvents();
952 QCOMPARE(mouseEvent2Params.handler, QString("EVENT2"));
953 QCOMPARE(mouseEvent2Params.pressedButton, Qt::LeftButton);
954
955 QTest::mouseRelease(view.data(), Qt::LeftButton, Qt::NoModifier, guPoint(35, 5));
956 QCoreApplication::processEvents();
957 QCOMPARE(exited.count(), 1);
958 // when entered(), button is the same when pressed, however buttons
959 // does no longer contains the button pressed
960 QCOMPARE(mouseEventParams.handler, QString("EVENT1"));
961 QCOMPARE(mouseEventParams.pressedButton, Qt::LeftButton);
962
963 // we have 2 moves, but we get 3 position changes, as the release point differs from the last moved point
964 QCOMPARE(positionChanged.count(), 3);
965 }
966
967 void testCase_mouseMove()
968 {
969 QScopedPointer<QQuickView> view(loadTest("HoverEvent.qml"));
970 QVERIFY(view);
971 UCMouse *filter = attachedFilter<UCMouse>(view->rootObject(), "FilterOwner");
972 QVERIFY(filter);
973 QSignalSpy moved(filter, SIGNAL(positionChanged(QQuickMouseEvent*, QQuickItem*)));
974 QSignalSpy entered(filter, SIGNAL(entered(QQuickMouseEvent*, QQuickItem*)));
975 QSignalSpy exited(filter, SIGNAL(exited(QQuickMouseEvent*, QQuickItem*)));
976 QObject::connect(filter, SIGNAL(entered(QQuickMouseEvent*, QQuickItem*)), this, SLOT(onMouseEvent(QQuickMouseEvent*, QQuickItem*)));
977 QObject::connect(filter, SIGNAL(exited(QQuickMouseEvent*, QQuickItem*)), this, SLOT(onMouseEvent(QQuickMouseEvent*, QQuickItem*)));
978 QObject::connect(filter, SIGNAL(positionChanged(QQuickMouseEvent*, QQuickItem*)), this, SLOT(onMouseEvent2(QQuickMouseEvent*, QQuickItem*)));
979
980 preventDblClick();
981 // move mouse while entered() triggers
982 int i, x = view->rootObject()->width() / 2;
983 QTest::mousePress(view.data(), Qt::LeftButton, Qt::NoModifier, QPoint(x, 0));
984 for (i = 0; (i < view->rootObject()->height()) && (entered.count() < 1); i++) {
985 QTest::mouseMove(view.data(), QPoint(x, i));
986 }
987 // Note: as button was pressed outside the filtered area, no button will be reported
988 // by the mouse move.
989 QCOMPARE(mouseEventParams.handler, QString("EVENT1"));
990 QCOMPARE(mouseEventParams.pressedButton, Qt::NoButton);
991 QCOMPARE(mouseEventParams.pressedButtons, Qt::NoButton);
992 // continue to move mouse while exited() triggers
993 while (++i < view->rootObject()->height()) {
994 QTest::mouseMove(view.data(), QPoint(x, i));
995 if (exited.count() >= 1) {
996 break;
997 }
998 QCOMPARE(mouseEvent2Params.handler, QString("EVENT2"));
999 QCOMPARE(mouseEvent2Params.pressedButton, Qt::NoButton);
1000 QCOMPARE(mouseEvent2Params.pressedButtons, Qt::NoButton);
1001 }
1002 // test if we really exited
1003 QCOMPARE(mouseEventParams.handler, QString("EVENT1"));
1004 QCOMPARE(mouseEventParams.pressedButton, Qt::NoButton);
1005 QCOMPARE(mouseEventParams.pressedButtons, Qt::NoButton);
1006
1007 // cleanup
1008 QTest::mouseRelease(view.data(), Qt::LeftButton, Qt::NoModifier, QPoint(x, i));
1009 }
1010
1011 //This is to test that entered/exited events are fired as a consequence of a mouse move.
1012 //When mouse is PRESSED, in fact, you won't get hover events. Mouse moves have to update
1013 //the hovered state (and that will trigger entered()/exited()). This fixes lp:1566378
1014 void testCase_enteredExitedOnMouseMove_lp1566378() {
1015 QScopedPointer<QQuickView> view(loadTest("EnteredExitedOnMouseMove.qml"));
1016 QVERIFY(view);
1017 UCMouse *filter = attachedFilter<UCMouse>(view->rootObject(), "FilterOwner");
1018 QVERIFY(filter);
1019 QSignalSpy pressed(filter, SIGNAL(pressed(QQuickMouseEvent*, QQuickItem*)));
1020 QSignalSpy positionChanged(filter, SIGNAL(positionChanged(QQuickMouseEvent*, QQuickItem*)));
1021 QSignalSpy entered(filter, SIGNAL(entered(QQuickMouseEvent*, QQuickItem*)));
1022 QSignalSpy exited(filter, SIGNAL(exited(QQuickMouseEvent*, QQuickItem*)));
1023
1024 QObject::connect(filter, SIGNAL(pressed(QQuickMouseEvent*, QQuickItem*)), this, SLOT(onMouseEvent(QQuickMouseEvent*, QQuickItem*)));
1025 QObject::connect(filter, SIGNAL(positionChanged(QQuickMouseEvent*, QQuickItem*)), this, SLOT(onMouseEvent2(QQuickMouseEvent*, QQuickItem*)));
1026 QObject::connect(filter, SIGNAL(entered(QQuickMouseEvent*, QQuickItem*)), this, SLOT(onMouseEvent3(QQuickMouseEvent*, QQuickItem*)));
1027 QObject::connect(filter, SIGNAL(exited(QQuickMouseEvent*, QQuickItem*)), this, SLOT(onMouseEvent3(QQuickMouseEvent*, QQuickItem*)));
1028
1029 preventDblClick();
1030
1031 //don't use guPoint(0,0) as it's the same as not passing any point, i.e. it sends mouseMove to the
1032 //center of the view
1033 QTest::mouseMove(view.data(), guPoint(1, 1));
1034 QTest::mouseMove(view.data(), guPoint(15, 15));
1035 QCoreApplication::processEvents();
1036
1037 QCOMPARE(entered.count(), 1);
1038 QCOMPARE(mouseEvent3Params.handler, QString("EVENT4"));
1039 QCOMPARE(mouseEvent3Params.pressedButton, Qt::NoButton);
1040
1041 QTest::mousePress(view.data(), Qt::LeftButton, Qt::NoModifier, guPoint(15, 15));
1042 QCoreApplication::processEvents();
1043 QCOMPARE(mouseEventParams.handler, QString("EVENT1"));
1044 QCOMPARE(mouseEventParams.pressedButton, Qt::LeftButton);
1045
1046 QTest::mouseMove(view.data(), guPoint(25, 15));
1047
1048 //go out of the mousearea on the right
1049 QTest::mouseMove(view.data(), guPoint(45, 15));
1050 QCoreApplication::processEvents();
1051 QCOMPARE(mouseEvent2Params.handler, QString("EVENT2"));
1052 QCOMPARE(mouseEvent2Params.pressedButton, Qt::LeftButton);
1053 QCOMPARE(exited.count(), 1);
1054 QCOMPARE(mouseEvent3Params.handler, QString("EVENT4"));
1055 QCOMPARE(mouseEvent3Params.pressedButton, Qt::LeftButton);
1056
1057 //move back in
1058 QTest::mouseMove(view.data(), guPoint(25, 15));
1059 QCoreApplication::processEvents();
1060 QCOMPARE(mouseEvent2Params.handler, QString("EVENT2"));
1061 QCOMPARE(mouseEvent2Params.pressedButton, Qt::LeftButton);
1062 QCOMPARE(entered.count(), 2);
1063 QCOMPARE(mouseEvent3Params.handler, QString("EVENT4"));
1064 QCOMPARE(mouseEvent3Params.pressedButton, Qt::LeftButton);
1065
1066 //and out again
1067 QTest::mouseMove(view.data(), guPoint(45, 15));
1068 QCoreApplication::processEvents();
1069 QCOMPARE(mouseEvent2Params.handler, QString("EVENT2"));
1070 QCOMPARE(mouseEvent2Params.pressedButton, Qt::LeftButton);
1071 QCOMPARE(exited.count(), 2);
1072 QCOMPARE(mouseEvent3Params.handler, QString("EVENT4"));
1073 QCOMPARE(mouseEvent3Params.pressedButton, Qt::LeftButton);
1074
1075 QTest::mouseRelease(view.data(), Qt::LeftButton, Qt::NoModifier, guPoint(45, 15));
1076 QCoreApplication::processEvents();
1077
1078 QCOMPARE(positionChanged.count(), 4);
1079 }
1080
1081 void testCase_hoverEvents() {
1082 QScopedPointer<QQuickView> view(loadTest("HoverEvent.qml"));
1083 QVERIFY(view);
1084 UCMouse *filter = attachedFilter<UCMouse>(view->rootObject(), "FilterOwner");
1085 QVERIFY(filter);
1086
1087 QSignalSpy entered(filter, SIGNAL(entered(QQuickMouseEvent*, QQuickItem*)));
1088 QSignalSpy moved(filter, SIGNAL(positionChanged(QQuickMouseEvent*, QQuickItem*)));
1089 QSignalSpy exited(filter, SIGNAL(exited(QQuickMouseEvent*, QQuickItem*)));
1090
1091 QObject::connect(filter, SIGNAL(entered(QQuickMouseEvent*, QQuickItem*)), this, SLOT(onMouseEvent(QQuickMouseEvent*, QQuickItem*)));
1092 QObject::connect(filter, SIGNAL(exited(QQuickMouseEvent*, QQuickItem*)), this, SLOT(onMouseEvent(QQuickMouseEvent*, QQuickItem*)));
1093 QObject::connect(filter, SIGNAL(positionChanged(QQuickMouseEvent*, QQuickItem*)), this, SLOT(onMouseEvent2(QQuickMouseEvent*, QQuickItem*)));
1094
1095 // move mouse while entered() triggers
1096 int i, x = view->rootObject()->width() / 2;
1097 for (i = 0; (i < view->rootObject()->height()) && (entered.count() < 1); i++) {
1098 QTest::mouseMove(view.data(), QPoint(x, i));
1099 }
1100 QCOMPARE(mouseEventParams.handler, QString("EVENT1"));
1101 QCOMPARE(mouseEventParams.pressedButton, Qt::NoButton);
1102 QCOMPARE(mouseEventParams.pressedButtons, Qt::NoButton);
1103 // continue to move mouse while exited() triggers
1104 while (++i < view->rootObject()->height()) {
1105 QTest::mouseMove(view.data(), QPoint(x, i));
1106 if (exited.count() >= 1) {
1107 break;
1108 }
1109 QCOMPARE(mouseEvent2Params.handler, QString("EVENT2"));
1110 QCOMPARE(mouseEvent2Params.pressedButton, Qt::NoButton);
1111 QCOMPARE(mouseEvent2Params.pressedButtons, Qt::NoButton);
1112 }
1113 // test if we really exited
1114 QCOMPARE(mouseEventParams.handler, QString("EVENT1"));
1115 QCOMPARE(mouseEventParams.pressedButton, Qt::NoButton);
1116 QCOMPARE(mouseEventParams.pressedButtons, Qt::NoButton);
1117 }
1118
1119 void testCase_forwardComposedEventsToProxy()
1120 {
1121 QScopedPointer<LomiriTestCase> test(new LomiriTestCase("ForwardComposedEvents.qml"));
1122
1123 UCMouse *host = attachedFilter<UCMouse>(test->rootObject(), "host");
1124 QVERIFY(host);
1125 UCMouse *proxy = attachedFilter<UCMouse>(test->rootObject(), "proxy");
1126 QVERIFY(proxy);
1127
1128 QSignalSpy hostHoldSpy(host, SIGNAL(pressAndHold(QQuickMouseEvent*, QQuickItem*)));
1129 QSignalSpy proxyHoldSpy(proxy, SIGNAL(pressAndHold(QQuickMouseEvent*, QQuickItem*)));
1130
1131 // produce long press
1132 // FIXME move this under LomiriTestCase
1133 mousePressAndHold(test.data(), Qt::LeftButton, Qt::NoModifier, guPoint(20, 30));
1134 QCoreApplication::processEvents();
1135 QCOMPARE(hostHoldSpy.count(), 1);
1136 QCOMPARE(proxyHoldSpy.count(), 1);
1137
1138 // click
1139 QTest::mouseRelease(test.data(), Qt::LeftButton, Qt::NoModifier, guPoint(20, 30));
1140 QCoreApplication::processEvents();
1141 }
1142
1143 void testCase_forwardComposedEventsToProxy_whenMoved()
1144 {
1145 QScopedPointer<LomiriTestCase> test(new LomiriTestCase("ForwardComposedEvents.qml"));
1146
1147 UCMouse *host = attachedFilter<UCMouse>(test->rootObject(), "host");
1148 QVERIFY(host);
1149 UCMouse *proxy = attachedFilter<UCMouse>(test->rootObject(), "proxy");
1150 QVERIFY(proxy);
1151
1152 QSignalSpy hostHoldSpy(host, SIGNAL(pressAndHold(QQuickMouseEvent*, QQuickItem*)));
1153 QSignalSpy proxyHoldSpy(proxy, SIGNAL(pressAndHold(QQuickMouseEvent*, QQuickItem*)));
1154
1155 // produce long press, but move mouse while in delay
1156 // FIXME move this under LomiriTestCase
1157 QTest::mousePress(test.data(), Qt::LeftButton, Qt::NoModifier, guPoint(20, 30));
1158 QTest::qWait(UCMouse::DefaultPressAndHoldDelay / 4);
1159 for (int i = 1; i <= 4; i++) {
1160 QTest::mouseMove(test.data(), guPoint(20 + i, 30 + i));
1161 }
1162 QTest::qWait(UCMouse::DefaultPressAndHoldDelay);
1163 QCoreApplication::processEvents();
1164 QCOMPARE(hostHoldSpy.count(), 0);
1165 QCOMPARE(proxyHoldSpy.count(), 0);
1166
1167 // click
1168 QTest::mouseRelease(test.data(), Qt::LeftButton, Qt::NoModifier, guPoint(20, 30));
1169 QCoreApplication::processEvents();
1170 }
1171
1172 void testCase_forwardToChainedItems()
1173 {
1174 QScopedPointer<LomiriTestCase> test(new LomiriTestCase("ForwardEventChained.qml"));
1175
1176 UCMouse *host = attachedFilter<UCMouse>(test->rootObject(), "host");
1177 QVERIFY(host);
1178 UCMouse *proxy1 = attachedFilter<UCMouse>(test->rootObject(), "proxy1");
1179 QVERIFY(proxy1);
1180 UCMouse *proxy2 = attachedFilter<UCMouse>(test->rootObject(), "proxy2");
1181 QVERIFY(proxy2);
1182
1183 QSignalSpy hostPressed(host, SIGNAL(pressed(QQuickMouseEvent*, QQuickItem*)));
1184 QSignalSpy proxy1Pressed(proxy1, SIGNAL(pressed(QQuickMouseEvent*, QQuickItem*)));
1185 QSignalSpy proxy2Pressed(proxy2, SIGNAL(pressed(QQuickMouseEvent*, QQuickItem*)));
1186
1187 QObject::connect(host, SIGNAL(pressed(QQuickMouseEvent*,QQuickItem*)), this, SLOT(onMouseEvent(QQuickMouseEvent*,QQuickItem*)));
1188 QObject::connect(proxy1, SIGNAL(pressed(QQuickMouseEvent*,QQuickItem*)), this, SLOT(onMouseEvent2(QQuickMouseEvent*,QQuickItem*)));
1189 QObject::connect(proxy2, SIGNAL(pressed(QQuickMouseEvent*,QQuickItem*)), this, SLOT(onMouseEvent3(QQuickMouseEvent*,QQuickItem*)));
1190
1191 QTest::mousePress(test.data(), Qt::LeftButton, Qt::NoModifier, guPoint(20, 30));
1192 QCoreApplication::processEvents();
1193 QCOMPARE(hostPressed.count(), 1);
1194 QCOMPARE(proxy1Pressed.count(), 1);
1195 QCOMPARE(proxy2Pressed.count(), 1);
1196
1197 QCOMPARE(mouseEventParams.sender, qobject_cast<QQuickItem*>(host->parent()));
1198 QCOMPARE(mouseEvent2Params.sender, qobject_cast<QQuickItem*>(host->parent()));
1199 QCOMPARE(mouseEvent3Params.sender, qobject_cast<QQuickItem*>(proxy1->parent()));
1200
1201 // click
1202 QTest::mouseRelease(test.data(), Qt::LeftButton, Qt::NoModifier, guPoint(20, 30));
1203 QCoreApplication::processEvents();
1204 }
1205
1206 void testCase_ignoreSynthesizedEvents() {
1207 QScopedPointer<LomiriTestCase> test(new LomiriTestCase("FilterSynthesizedEvents.qml"));
1208 QQuickMouseArea *rootMouseArea = qobject_cast<QQuickMouseArea *>(test->rootObject());
1209 QQuickMouseArea* overlayArea = test->findItem<QQuickMouseArea *>("overlayArea");
1210 UCMouse *overlayFilter = attachedFilter<UCMouse>(test->rootObject(), "overlayArea");
1211
1212 QCOMPARE(rootMouseArea != Q_NULLPTR, true);
1213 QCOMPARE(overlayArea != Q_NULLPTR, true);
1214 QCOMPARE(overlayFilter != Q_NULLPTR, true);
1215
1216 QSignalSpy areaPressed(rootMouseArea, SIGNAL(pressed(QQuickMouseEvent *)));
1217 QSignalSpy overlayAreaPressed(overlayArea, SIGNAL(pressed(QQuickMouseEvent *)));
1218 QSignalSpy overlayFilterPressed(overlayFilter, SIGNAL(pressed(QQuickMouseEvent*, QQuickItem*)));
1219 QCOMPARE(overlayFilter->property("ignoreSynthesizedEvents").toBool(), true);
1220
1221 //we're assuming the priority is set to BeforeItem, the functionality is not priority-dependent anyway,
1222 //just the outcome is.
1223 QCOMPARE(overlayFilter->priority(), UCMouse::BeforeItem);
1224 QCOMPARE(overlayArea->isEnabled(), true);
1225
1226 //send a touch event, which will be converted to a synthesized mouse event, since
1227 //no item in this QML is handling touch events
1228 UCTestExtras::touchPress(0, overlayArea, guPoint(15, 15));
1229 QCoreApplication::processEvents();
1230
1231 QCOMPARE(areaPressed.count(), 0);
1232 QCOMPARE(overlayAreaPressed.count(), 1);
1233 QCOMPARE(overlayFilterPressed.count(), 0);
1234 UCTestExtras::touchRelease(0, overlayArea, guPoint(15, 15));
1235
1236 QCoreApplication::processEvents();
1237
1238 overlayFilter->setProperty("ignoreSynthesizedEvents", false);
1239 QCOMPARE(overlayFilter->property("ignoreSynthesizedEvents").toBool(), false);
1240 UCTestExtras::touchPress(1, overlayArea, guPoint(15, 15));
1241 QCoreApplication::processEvents();
1242
1243 QCOMPARE(areaPressed.count(), 0);
1244 //the filter doesn't accept the pressed event by default
1245 QCOMPARE(overlayAreaPressed.count(), 2);
1246 QCOMPARE(overlayFilterPressed.count(), 1);
1247 UCTestExtras::touchRelease(1, overlayArea, guPoint(15, 15));
1248 QCoreApplication::processEvents();
1249
1250 overlayArea->setEnabled(false);
1251 QCOMPARE(overlayArea->isEnabled(), false);
1252
1253 UCTestExtras::touchPress(2, overlayArea, guPoint(15, 15));
1254 QCoreApplication::processEvents();
1255
1256 //the filter gets the event but its owner is not enabled, so we expect it
1257 //to propagate to the area underneath
1258 QCOMPARE(areaPressed.count(), 1);
1259 QCOMPARE(overlayAreaPressed.count(), 2);
1260 QCOMPARE(overlayFilterPressed.count(), 2);
1261 UCTestExtras::touchRelease(2, overlayArea, guPoint(15, 15));
1262 QCoreApplication::processEvents();
1263 }
1264 };
1265
1266 QTEST_MAIN(tst_mouseFilterTest)
1267
1268 #include "tst_mousefilterstest.moc"