| 1 | /* |
| 2 | * Copyright 2015 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 <QtGlobal> |
| 18 | |
| 19 | #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) |
| 20 | #include <LomiriGestures-Qt6/private/ucswipearea_p_p.h> |
| 21 | #else |
| 22 | #include <LomiriGestures/private/ucswipearea_p_p.h> |
| 23 | #endif |
| 24 | #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) |
| 25 | #include <LomiriToolkit-Qt6/private/ucaction_p.h> |
| 26 | #else |
| 27 | #include <LomiriToolkit/private/ucaction_p.h> |
| 28 | #endif |
| 29 | #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) |
| 30 | #include <LomiriToolkit-Qt6/private/ucbottomedge_p.h> |
| 31 | #else |
| 32 | #include <LomiriToolkit/private/ucbottomedge_p.h> |
| 33 | #endif |
| 34 | #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) |
| 35 | #include <LomiriToolkit-Qt6/private/ucbottomedge_p_p.h> |
| 36 | #else |
| 37 | #include <LomiriToolkit/private/ucbottomedge_p_p.h> |
| 38 | #endif |
| 39 | #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) |
| 40 | #include <LomiriToolkit-Qt6/private/ucbottomedgehint_p.h> |
| 41 | #else |
| 42 | #include <LomiriToolkit/private/ucbottomedgehint_p.h> |
| 43 | #endif |
| 44 | #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) |
| 45 | #include <LomiriToolkit-Qt6/private/ucbottomedgeregion_p.h> |
| 46 | #else |
| 47 | #include <LomiriToolkit/private/ucbottomedgeregion_p.h> |
| 48 | #endif |
| 49 | #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) |
| 50 | #include <LomiriToolkit-Qt6/private/ucbottomedgeregion_p_p.h> |
| 51 | #else |
| 52 | #include <LomiriToolkit/private/ucbottomedgeregion_p_p.h> |
| 53 | #endif |
| 54 | #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) |
| 55 | #include <LomiriToolkit-Qt6/private/ucheader_p.h> |
| 56 | #else |
| 57 | #include <LomiriToolkit/private/ucheader_p.h> |
| 58 | #endif |
| 59 | #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) |
| 60 | #include <LomiriToolkit-Qt6/private/ucunits_p.h> |
| 61 | #else |
| 62 | #include <LomiriToolkit/private/ucunits_p.h> |
| 63 | #endif |
| 64 | #define private public |
| 65 | #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) |
| 66 | #include <LomiriToolkit-Qt6/private/quickutils_p.h> |
| 67 | #else |
| 68 | #include <LomiriToolkit/private/quickutils_p.h> |
| 69 | #endif |
| 70 | #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) |
| 71 | #include <LomiriToolkit-Qt6/private/ucbottomedgestyle_p.h> |
| 72 | #else |
| 73 | #include <LomiriToolkit/private/ucbottomedgestyle_p.h> |
| 74 | #endif |
| 75 | #undef private |
| 76 | #include <QtQml/QQmlListReference> |
| 77 | #include <QtQml/QtQml> |
| 78 | #include <QtTest/QtTest> |
| 79 | |
| 80 | #include "uctestcase.h" |
| 81 | #include "uctestextras.h" |
| 82 | |
| 83 | UT_USE_NAMESPACE |
| 84 | |
| 85 | Q_DECLARE_METATYPE(Qt::Key) |
| 86 | |
| 87 | #define QVERIFY_RETURN(statement, returnValue) \ |
| 88 | do {\ |
| 89 | if (!QTest::qVerify((statement), #statement, "", __FILE__, __LINE__))\ |
| 90 | return returnValue;\ |
| 91 | } while (0) |
| 92 | |
| 93 | class BottomEdgeTestCase : public LomiriTestCase |
| 94 | { |
| 95 | Q_OBJECT |
| 96 | public: |
| 97 | BottomEdgeTestCase(const QString& file, ResizeMode resize = SizeViewToRootObject, bool assertOnFailure = true, QWindow* parent = 0) |
| 98 | : LomiriTestCase(file, resize, assertOnFailure, parent) |
| 99 | { |
| 100 | // make sure we disable the mouse |
| 101 | QuickUtils::instance()->m_mouseAttached = false; |
| 102 | |
| 103 | // patch all BottomEdges' SwipeArea gesture recognition timer |
| 104 | QList<UCBottomEdge*> list = findChildren<UCBottomEdge*>(); |
| 105 | for (int i = 0; i < list.size(); ++i) { |
| 106 | UCBottomEdge *bottomEdge = list[i]; |
| 107 | UCSwipeArea *swipeArea = bottomEdge->hint()->swipeArea(); |
| 108 | swipeArea->setImmediateRecognition(true); |
| 109 | } |
| 110 | } |
| 111 | ~BottomEdgeTestCase() |
| 112 | { |
| 113 | // add a small timeout after each run to have a proper cleanup |
| 114 | QTest::qWait(400); |
| 115 | } |
| 116 | |
| 117 | UCBottomEdge *testItem(const QString &objectName = "testItem") |
| 118 | { |
| 119 | return findItem<UCBottomEdge*>(objectName); |
| 120 | } |
| 121 | |
| 122 | typedef QList<UCBottomEdgeRegion*> RegionList; |
| 123 | RegionList *regions(const QString &testItem) |
| 124 | { |
| 125 | QQmlListProperty<UCBottomEdgeRegion> qmlRegions(this->testItem(testItem)->regions()); |
| 126 | return reinterpret_cast<RegionList*>(qmlRegions.data); |
| 127 | } |
| 128 | |
| 129 | UCBottomEdgeRegion *regionAt(const QString &testItem, int index) |
| 130 | { |
| 131 | QVERIFY_RETURN(regions(testItem), nullptr); |
| 132 | QVERIFY_RETURN(regions(testItem)->size() > index, nullptr); |
| 133 | return regions(testItem)->at(index); |
| 134 | } |
| 135 | |
| 136 | bool hasContentAutoCollapse(const QString &testItem = "testItem") |
| 137 | { |
| 138 | UCBottomEdge *bottomEdge = this->testItem(testItem); |
| 139 | QQuickItem *contentItem = bottomEdge->contentItem(); |
| 140 | if (!contentItem) { |
| 141 | return false; |
| 142 | } |
| 143 | // we do not have the PageHeader in cpp, therefore we need the same workaround we have in the code |
| 144 | UCHeader *header = contentItem->findChild<UCHeader*>(); |
| 145 | if (!QuickUtils::inherits(header, "PageHeader")) { |
| 146 | return false; |
| 147 | } |
| 148 | |
| 149 | #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) |
| 150 | QQmlListReference navigationActions(header, /* property */ "navigationActions"); |
| 151 | #else |
| 152 | QQmlListReference navigationActions(header, /* property */ "navigationActions", qmlEngine(header)); |
| 153 | #endif |
| 154 | if (navigationActions.count() <= 0) { |
| 155 | return false; |
| 156 | } |
| 157 | return (qobject_cast<UCCollapseAction*>(navigationActions.at(0)) != Q_NULLPTR); |
| 158 | } |
| 159 | |
| 160 | void guToPoints(QList<QPoint> &guMoves) |
| 161 | { |
| 162 | for (int i = 0; i < guMoves.size(); i++) { |
| 163 | guMoves[i] = QPointF(UCUnits::instance()->gu(guMoves[i].x()), UCUnits::instance()->gu(guMoves[i].y())).toPoint(); |
| 164 | } |
| 165 | } |
| 166 | }; |
| 167 | |
| 168 | |
| 169 | class tst_BottomEdge : public QObject |
| 170 | { |
| 171 | Q_OBJECT |
| 172 | QStringList regionObjects; |
| 173 | private Q_SLOTS: |
| 174 | |
| 175 | void initTestCase() |
| 176 | { |
| 177 | UCTestExtras::registerTouchDevice(); |
| 178 | } |
| 179 | |
| 180 | void init() |
| 181 | { |
| 182 | regionObjects.clear(); |
| 183 | } |
| 184 | |
| 185 | private Q_SLOTS: |
| 186 | void test_defaults() |
| 187 | { |
| 188 | QScopedPointer<BottomEdgeTestCase> test(new BottomEdgeTestCase("Defaults.qml")); |
| 189 | QCOMPARE(test->testItem()->height(), test->rootObject()->height()); |
| 190 | QCOMPARE(test->testItem()->dragProgress(), 0.0); |
| 191 | QCOMPARE(test->testItem()->dragDirection(), UCBottomEdge::Undefined); |
| 192 | QCOMPARE(test->testItem()->status(), UCBottomEdge::Hidden); |
| 193 | QCOMPARE(test->testItem()->contentUrl(), QUrl()); |
| 194 | QVERIFY(!test->testItem()->contentComponent()); |
| 195 | QVERIFY(!test->testItem()->contentItem()); |
| 196 | QVERIFY(test->regions("testItem")); |
| 197 | QCOMPARE(test->regions("testItem")->size(), 1); |
| 198 | QCOMPARE(test->regionAt("testItem", 0)->objectName(), QString("default_BottomEdgeRegion")); |
| 199 | QCOMPARE(UCBottomEdgeRegionPrivate::get(test->regionAt("testItem", 0))->from, 0.0); |
| 200 | QCOMPARE(UCBottomEdgeRegionPrivate::get(test->regionAt("testItem", 0))->to, 1.0); |
| 201 | QVERIFY(!test->testItem()->activeRegion()); |
| 202 | QVERIFY(!test->testItem()->preloadContent()); |
| 203 | } |
| 204 | |
| 205 | void test_height_moves_when_reparented() |
| 206 | { |
| 207 | QScopedPointer<BottomEdgeTestCase> test(new BottomEdgeTestCase("DifferentSizes.qml")); |
| 208 | QQuickItem *newParent = test->rootObject(); |
| 209 | QQuickItem *oldParent = test->findItem<QQuickItem*>("oldParent"); |
| 210 | UCBottomEdge *testItem = test->testItem(); |
| 211 | |
| 212 | QSignalSpy spy(testItem, SIGNAL(implicitHeightChanged())); |
| 213 | testItem->setParentItem(newParent); |
| 214 | LomiriTestCase::waitForSignal(&spy); |
| 215 | |
| 216 | // change the implicit height so we are sure we don't get the height change triggered |
| 217 | testItem->setImplicitHeight(0); |
| 218 | spy.clear(); |
| 219 | oldParent->setHeight(20); |
| 220 | QEXPECT_FAIL(0, "no implicitHeight change is expected", Continue); |
| 221 | QVERIFY(spy.wait(400)); |
| 222 | } |
| 223 | |
| 224 | void test_panel_is_last_item_of_parent() |
| 225 | { |
| 226 | QScopedPointer<BottomEdgeTestCase> test(new BottomEdgeTestCase("LastItem.qml")); |
| 227 | QQuickItem *bottomEdgeParent = test->testItem()->parentItem(); |
| 228 | UCBottomEdgePrivate *privateTestItem = UCBottomEdgePrivate::get(test->testItem()); |
| 229 | QCOMPARE(bottomEdgeParent->childItems().last(), privateTestItem->styleItem); |
| 230 | |
| 231 | QQuickItem *dynamicItem = test->findItem<QQuickItem*>("dynamicItem"); |
| 232 | dynamicItem->setParentItem(bottomEdgeParent); |
| 233 | // still the last one |
| 234 | QCOMPARE(bottomEdgeParent->childItems().last(), privateTestItem->styleItem); |
| 235 | } |
| 236 | |
| 237 | void test_commit_when_clicked() |
| 238 | { |
| 239 | QScopedPointer<BottomEdgeTestCase> test(new BottomEdgeTestCase("BottomEdgeInItem.qml")); |
| 240 | test->testItem()->hint()->setStatus(UCBottomEdgeHint::Locked); |
| 241 | UCBottomEdgeHint *hint = test->testItem()->hint(); |
| 242 | QTest::mouseClick(test->testItem()->hint()->window(), Qt::LeftButton, Qt::NoModifier, LomiriTestCase::centerOf(hint, true).toPoint()); |
| 243 | QTRY_COMPARE_WITH_TIMEOUT(test->testItem()->status(), UCBottomEdge::Committed, 1000); |
| 244 | } |
| 245 | |
| 246 | void test_commit_when_touch_clicked() |
| 247 | { |
| 248 | QSKIP("Failing on Qt 5.9"); |
| 249 | |
| 250 | QScopedPointer<BottomEdgeTestCase> test(new BottomEdgeTestCase("BottomEdgeInItem.qml")); |
| 251 | UCBottomEdgeHint *hint = test->testItem()->hint(); |
| 252 | // swipe a bit to reveal |
| 253 | |
| 254 | UCTestExtras::touchDrag(0, hint, QPoint(hint->width() / 2, hint->height()), QPoint(0, -hint->height())); |
| 255 | QTRY_COMPARE_WITH_TIMEOUT(hint->status(), UCBottomEdgeHint::Active, 1000); |
| 256 | |
| 257 | UCTestExtras::touchClick(0, hint, LomiriTestCase::centerOf(hint).toPoint()); |
| 258 | QTRY_COMPARE_WITH_TIMEOUT(test->testItem()->status(), UCBottomEdge::Committed, 1000); |
| 259 | } |
| 260 | |
| 261 | void test_overridden_triggers_bug1524234() |
| 262 | { |
| 263 | QScopedPointer<BottomEdgeTestCase> test(new BottomEdgeTestCase("OverriddenHintTrigger.qml")); |
| 264 | test->testItem()->hint()->setStatus(UCBottomEdgeHint::Locked); |
| 265 | UCBottomEdgeHint *hint = test->testItem()->hint(); |
| 266 | UCAction *action = hint->action(); |
| 267 | QSignalSpy actionSpy(action, SIGNAL(triggered(QVariant))); |
| 268 | QSignalSpy hintSpy(hint, SIGNAL(triggered(QVariant))); |
| 269 | |
| 270 | QTest::mouseClick(test->testItem()->hint()->window(), Qt::LeftButton, Qt::NoModifier, LomiriTestCase::centerOf(hint, true).toPoint()); |
| 271 | QTRY_COMPARE_WITH_TIMEOUT(test->testItem()->status(), UCBottomEdge::Committed, 1000); |
| 272 | |
| 273 | QCOMPARE(actionSpy.count(), 0); |
| 274 | QCOMPARE(hintSpy.count(), 1); |
| 275 | } |
| 276 | |
| 277 | void test_revealed_when_hint_threshold_passed_data() |
| 278 | { |
| 279 | QTest::addColumn<bool>("withMouse"); |
| 280 | QTest::addColumn<bool>("lockHint"); |
| 281 | QTest::addColumn<bool>("xfail"); |
| 282 | |
| 283 | QTest::newRow("drag with mouse, unlocked hint") << true << false << true; |
| 284 | QTest::newRow("drag with mouse, locked hint") << true << true << false; |
| 285 | QTest::newRow("drag with touch, unlocked hint") << false << false << false; |
| 286 | QTest::newRow("drag with touch, locked hint") << false << true << false; |
| 287 | } |
| 288 | void test_revealed_when_hint_threshold_passed() |
| 289 | { |
| 290 | QFETCH(bool, withMouse); |
| 291 | QFETCH(bool, lockHint); |
| 292 | QFETCH(bool, xfail); |
| 293 | |
| 294 | QScopedPointer<BottomEdgeTestCase> test(new BottomEdgeTestCase("BottomEdgeInItem.qml")); |
| 295 | UCBottomEdge *bottomEdge = test->testItem(); |
| 296 | UCBottomEdgeStyle *style = UCBottomEdgePrivate::get(bottomEdge)->bottomPanel; |
| 297 | QSignalSpy spy(bottomEdge, &UCBottomEdge::statusChanged); |
| 298 | |
| 299 | // swipe till we reveal it |
| 300 | QPoint from(bottomEdge->width() / 2.0f, bottomEdge->height() - 1); |
| 301 | QPoint delta(0, -(2 * style->m_revealThreshold)); |
| 302 | if (lockHint) { |
| 303 | bottomEdge->hint()->setStatus(UCBottomEdgeHint::Locked); |
| 304 | } |
| 305 | if (withMouse) { |
| 306 | UCTestExtras::mouseDrag(bottomEdge, from, delta, Qt::LeftButton); |
| 307 | } else { |
| 308 | UCTestExtras::touchDrag(0, bottomEdge, from, delta, 8); |
| 309 | } |
| 310 | if (xfail) { |
| 311 | QEXPECT_FAIL(0, "failure expected", Continue); |
| 312 | } |
| 313 | QVERIFY(spy.wait(500)); |
| 314 | if (xfail) { |
| 315 | QCOMPARE(spy.count(), 0); |
| 316 | } else { |
| 317 | // there must be two state changes here, one Hidden->Revealed, and one Revealed->Hidden |
| 318 | QCOMPARE(spy.count(), 2); |
| 319 | QList<QVariant> state1 = spy.at(0); |
| 320 | QCOMPARE(state1[0].value<UCBottomEdge::Status>(), UCBottomEdge::Revealed); |
| 321 | QList<QVariant> state2 = spy.at(1); |
| 322 | QCOMPARE(state2[0].value<UCBottomEdge::Status>(), UCBottomEdge::Hidden); |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | void test_commit_when_onethird_passed_data() |
| 327 | { |
| 328 | QTest::addColumn<bool>("withMouse"); |
| 329 | |
| 330 | QTest::newRow("with mouse") << true; |
| 331 | QTest::newRow("with touch") << false; |
| 332 | } |
| 333 | void test_commit_when_onethird_passed() |
| 334 | { |
| 335 | QFETCH(bool, withMouse); |
| 336 | |
| 337 | QScopedPointer<BottomEdgeTestCase> test(new BottomEdgeTestCase("BottomEdgeInItem.qml")); |
| 338 | UCBottomEdge *bottomEdge = test->testItem(); |
| 339 | |
| 340 | QPoint from(bottomEdge->width() / 2.0f, bottomEdge->height() - 1); |
| 341 | // add some extra space for the touch |
| 342 | QPoint delta(0, -(bottomEdge->height() / 3 + UCUnits::instance()->gu(6))); |
| 343 | |
| 344 | if (withMouse) { |
| 345 | bottomEdge->hint()->setStatus(UCBottomEdgeHint::Locked); |
| 346 | } |
| 347 | // we need to do the swipe in more steps |
| 348 | if (withMouse) { |
| 349 | UCTestExtras::mouseDrag(bottomEdge, from, delta, Qt::LeftButton, Qt::NoModifier, 20); |
| 350 | } else { |
| 351 | UCTestExtras::touchDrag(0, bottomEdge, from, delta, 20); |
| 352 | } |
| 353 | QTRY_COMPARE_WITH_TIMEOUT(bottomEdge->status(), UCBottomEdge::Committed, 1000); |
| 354 | } |
| 355 | |
| 356 | void test_collapse_before_onethird_data() |
| 357 | { |
| 358 | QTest::addColumn<bool>("withMouse"); |
| 359 | |
| 360 | QTest::newRow("with mouse") << true; |
| 361 | QTest::newRow("with touch") << false; |
| 362 | } |
| 363 | void test_collapse_before_onethird() |
| 364 | { |
| 365 | QFETCH(bool, withMouse); |
| 366 | |
| 367 | QScopedPointer<BottomEdgeTestCase> test(new BottomEdgeTestCase("BottomEdgeInItem.qml")); |
| 368 | UCBottomEdge *bottomEdge = test->testItem(); |
| 369 | |
| 370 | QPoint from(bottomEdge->width() / 2.0f, bottomEdge->height() - 1); |
| 371 | QPoint delta(0, -(bottomEdge->height() / 4)); |
| 372 | |
| 373 | if (withMouse) { |
| 374 | bottomEdge->hint()->setStatus(UCBottomEdgeHint::Locked); |
| 375 | } |
| 376 | // we need to do the swipe in more steps |
| 377 | if (withMouse) { |
| 378 | UCTestExtras::mouseDrag(bottomEdge, from, delta, Qt::LeftButton, Qt::NoModifier, 20); |
| 379 | } else { |
| 380 | UCTestExtras::touchDrag(0, bottomEdge, from, delta, 20); |
| 381 | } |
| 382 | QTRY_COMPARE_WITH_TIMEOUT(bottomEdge->status(), UCBottomEdge::Hidden, 1000); |
| 383 | } |
| 384 | |
| 385 | void test_collapse_when_dragged_downwards_data() |
| 386 | { |
| 387 | // when onethird not passed |
| 388 | // when onethird was passed |
| 389 | QTest::addColumn<bool>("withMouse"); |
| 390 | QTest::addColumn< QList<QPoint> >("moves"); |
| 391 | |
| 392 | QList<QPoint> shortPath, longPath; |
| 393 | // upwards |
| 394 | for (int i = 0; i < 10; i++) { |
| 395 | shortPath << QPoint(0, -3); |
| 396 | longPath << QPoint(0, -7); |
| 397 | } |
| 398 | // downwards |
| 399 | for (int i = 0; i < 5; i++) { |
| 400 | shortPath << QPoint(0, 2); |
| 401 | longPath << QPoint(0, 2); |
| 402 | } |
| 403 | |
| 404 | QTest::newRow("with mouse, onethird not passed") |
| 405 | << true << shortPath; |
| 406 | QTest::newRow("with touch, onethird not passed") |
| 407 | << false << shortPath; |
| 408 | QTest::newRow("with mouse, onethird passed") |
| 409 | << true << longPath; |
| 410 | QTest::newRow("with touch, onethird passed") |
| 411 | << false << longPath; |
| 412 | } |
| 413 | void test_collapse_when_dragged_downwards() |
| 414 | { |
| 415 | QFETCH(bool, withMouse); |
| 416 | QFETCH(QList<QPoint>, moves); |
| 417 | |
| 418 | QScopedPointer<BottomEdgeTestCase> test(new BottomEdgeTestCase("BottomEdgeInItem.qml")); |
| 419 | UCBottomEdge *bottomEdge = test->testItem(); |
| 420 | test->guToPoints(moves); |
| 421 | |
| 422 | QPoint from(bottomEdge->width() / 2.0f, bottomEdge->height() - 1); |
| 423 | moves.prepend(from); |
| 424 | |
| 425 | if (withMouse) { |
| 426 | bottomEdge->hint()->setStatus(UCBottomEdgeHint::Locked); |
| 427 | } |
| 428 | if (withMouse) { |
| 429 | UCTestExtras::mouseDragWithPoints(bottomEdge, moves, Qt::LeftButton); |
| 430 | } else { |
| 431 | UCTestExtras::touchDragWithPoints(0, bottomEdge, moves); |
| 432 | } |
| 433 | QTRY_COMPARE_WITH_TIMEOUT(bottomEdge->status(), UCBottomEdge::Hidden, 1000); |
| 434 | } |
| 435 | |
| 436 | void test_height_less_than_parent() |
| 437 | { |
| 438 | QScopedPointer<BottomEdgeTestCase> test(new BottomEdgeTestCase("ShorterBottomEdge.qml")); |
| 439 | UCBottomEdge *bottomEdge = test->testItem(); |
| 440 | UCBottomEdgeStyle *style = UCBottomEdgePrivate::get(bottomEdge)->bottomPanel; |
| 441 | bottomEdge->commit(); |
| 442 | QTRY_COMPARE_WITH_TIMEOUT(bottomEdge->status(), UCBottomEdge::Committed, 1000); |
| 443 | QCOMPARE(style->m_panel->y(), bottomEdge->y()); |
| 444 | } |
| 445 | |
| 446 | void test_do_not_overshoot_data() |
| 447 | { |
| 448 | QTest::addColumn<bool>("withMouse"); |
| 449 | |
| 450 | QTest::newRow("with touch") << false; |
| 451 | QTest::newRow("with mouse") << true; |
| 452 | } |
| 453 | void test_do_not_overshoot() |
| 454 | { |
| 455 | QFETCH(bool, withMouse); |
| 456 | |
| 457 | QScopedPointer<BottomEdgeTestCase> test(new BottomEdgeTestCase("ShorterBottomEdge.qml")); |
| 458 | UCBottomEdge *bottomEdge = test->testItem(); |
| 459 | UCBottomEdgeStyle *style = UCBottomEdgePrivate::get(bottomEdge)->bottomPanel; |
| 460 | |
| 461 | QPoint from(bottomEdge->width() / 2.0f, bottomEdge->height() - 1); |
| 462 | QPoint to = from + QPoint(0, -(bottomEdge->parentItem()->height() - 1)); |
| 463 | |
| 464 | if (withMouse) { |
| 465 | bottomEdge->hint()->setStatus(UCBottomEdgeHint::Locked); |
| 466 | from = bottomEdge->mapToScene(from).toPoint(); |
| 467 | to = bottomEdge->mapToScene(to).toPoint(); |
| 468 | QTest::mousePress(bottomEdge->window(), Qt::LeftButton, Qt::NoModifier, from, 20); |
| 469 | QPoint movePos(from); |
| 470 | while (movePos.y() > to.y()) { |
| 471 | QTest::mouseMove(bottomEdge->window(), movePos, 20); |
| 472 | movePos += QPoint(0, -10); |
| 473 | QVERIFY(style->m_panel->y() >= bottomEdge->y()); |
| 474 | } |
| 475 | QTest::mouseRelease(bottomEdge->window(), Qt::LeftButton, Qt::NoModifier, movePos, 20); |
| 476 | } else { |
| 477 | UCTestExtras::touchPress(0, bottomEdge, from); |
| 478 | QPoint movePos(from); |
| 479 | while (movePos.y() > to.y()) { |
| 480 | QTest::qWait(20); |
| 481 | UCTestExtras::touchMove(0, bottomEdge, movePos); |
| 482 | movePos += QPoint(0, -10); |
| 483 | QVERIFY(style->m_panel->y() >= bottomEdge->y()); |
| 484 | } |
| 485 | QTest::qWait(20); |
| 486 | UCTestExtras::touchRelease(0, bottomEdge, movePos); |
| 487 | } |
| 488 | } |
| 489 | |
| 490 | void test_commitStarted_commitCompleted_emitted() |
| 491 | { |
| 492 | QScopedPointer<BottomEdgeTestCase> test(new BottomEdgeTestCase("BottomEdgeInItem.qml")); |
| 493 | UCBottomEdge *bottomEdge = test->testItem(); |
| 494 | |
| 495 | QSignalSpy commitStartedSpy(bottomEdge, SIGNAL(commitStarted())); |
| 496 | QSignalSpy commitCompletedSpy(bottomEdge, SIGNAL(commitCompleted())); |
| 497 | bottomEdge->commit(); |
| 498 | QTRY_COMPARE_WITH_TIMEOUT(commitStartedSpy.count(), 1, 1000); |
| 499 | QTRY_COMPARE_WITH_TIMEOUT(commitCompletedSpy.count(), 1, 1000); |
| 500 | } |
| 501 | |
| 502 | void test_collapseStarted_collapseCompleted_emitted() |
| 503 | { |
| 504 | QScopedPointer<BottomEdgeTestCase> test(new BottomEdgeTestCase("BottomEdgeInItem.qml")); |
| 505 | UCBottomEdge *bottomEdge = test->testItem(); |
| 506 | bottomEdge->commit(); |
| 507 | QTRY_COMPARE_WITH_TIMEOUT(bottomEdge->status(), UCBottomEdge::Committed, 1000); |
| 508 | // wait few milliseconds before we initiate collapse |
| 509 | QTest::qWait(200); |
| 510 | |
| 511 | QSignalSpy collapseStartedSpy(bottomEdge, SIGNAL(collapseStarted())); |
| 512 | QSignalSpy collapseCompletedSpy(bottomEdge, SIGNAL(collapseCompleted())); |
| 513 | bottomEdge->collapse(); |
| 514 | QTRY_COMPARE_WITH_TIMEOUT(collapseStartedSpy.count(), 1, 1000); |
| 515 | QTRY_COMPARE_WITH_TIMEOUT(collapseCompletedSpy.count(), 1, 1000); |
| 516 | } |
| 517 | |
| 518 | void test_collapse_during_commit() |
| 519 | { |
| 520 | QScopedPointer<BottomEdgeTestCase> test(new BottomEdgeTestCase("BottomEdgeInItem.qml")); |
| 521 | UCBottomEdge *bottomEdge = test->testItem(); |
| 522 | |
| 523 | QSignalSpy commitStartedSpy(bottomEdge, SIGNAL(commitStarted())); |
| 524 | QSignalSpy commitCompletedSpy(bottomEdge, SIGNAL(commitCompleted())); |
| 525 | QSignalSpy collapseStartedSpy(bottomEdge, SIGNAL(collapseStarted())); |
| 526 | QSignalSpy collapseCompletedSpy(bottomEdge, SIGNAL(collapseCompleted())); |
| 527 | |
| 528 | connect(bottomEdge, SIGNAL(commitStarted()), bottomEdge, SLOT(collapse()), Qt::QueuedConnection); |
| 529 | |
| 530 | bottomEdge->commit(); |
| 531 | |
| 532 | QTRY_COMPARE_WITH_TIMEOUT(commitStartedSpy.count(), 1, 1000); |
| 533 | QTRY_COMPARE_WITH_TIMEOUT(commitCompletedSpy.count(), 0, 1000); |
| 534 | QTRY_COMPARE_WITH_TIMEOUT(collapseStartedSpy.count(), 1, 1000); |
| 535 | QTRY_COMPARE_WITH_TIMEOUT(collapseCompletedSpy.count(), 1, 1000); |
| 536 | } |
| 537 | |
| 538 | void test_commit_during_collapse() |
| 539 | { |
| 540 | QScopedPointer<BottomEdgeTestCase> test(new BottomEdgeTestCase("BottomEdgeInItem.qml")); |
| 541 | UCBottomEdge *bottomEdge = test->testItem(); |
| 542 | bottomEdge->commit(); |
| 543 | |
| 544 | QSignalSpy commitStartedSpy(bottomEdge, SIGNAL(commitStarted())); |
| 545 | QSignalSpy commitCompletedSpy(bottomEdge, SIGNAL(commitCompleted())); |
| 546 | QSignalSpy collapseStartedSpy(bottomEdge, SIGNAL(collapseStarted())); |
| 547 | QSignalSpy collapseCompletedSpy(bottomEdge, SIGNAL(collapseCompleted())); |
| 548 | |
| 549 | connect(bottomEdge, SIGNAL(collapseStarted()), bottomEdge, SLOT(commit()), Qt::QueuedConnection); |
| 550 | |
| 551 | bottomEdge->collapse(); |
| 552 | QTRY_COMPARE_WITH_TIMEOUT(collapseStartedSpy.count(), 1, 1000); |
| 553 | QTRY_COMPARE_WITH_TIMEOUT(collapseCompletedSpy.count(), 0, 1000); |
| 554 | QTRY_COMPARE_WITH_TIMEOUT(commitStartedSpy.count(), 1, 1000); |
| 555 | QTRY_COMPARE_WITH_TIMEOUT(commitCompletedSpy.count(), 1, 1000); |
| 556 | } |
| 557 | |
| 558 | // region tests |
| 559 | |
| 560 | void test_region_operations_data() |
| 561 | { |
| 562 | QTest::addColumn<QString>("document"); |
| 563 | QTest::addColumn<QString>("warning"); |
| 564 | QTest::addColumn<qreal>("xFrom"); |
| 565 | QTest::addColumn<qreal>("xTo"); |
| 566 | QTest::addColumn<QString>("xName"); |
| 567 | |
| 568 | QTest::newRow("add through regions property") |
| 569 | << "AddCustomRegionUsingRegionsProperty.qml" |
| 570 | << QString() |
| 571 | << 0.0 << 1.0 << QString("customRegion"); |
| 572 | QTest::newRow("add through data property") |
| 573 | << "AddCustomRegionUsingDataProperty.qml" |
| 574 | << QString() |
| 575 | << 0.0 << 1.0 << QString("customRegion"); |
| 576 | QTest::newRow("add through Component.onCompleted") |
| 577 | << "AddCustomRegionOnCompleted.qml" |
| 578 | << QString() |
| 579 | << 0.0 << 1.0 << QString("customRegion"); |
| 580 | QTest::newRow("add owned by other BottomEdge") |
| 581 | << "AddCustomRegionOwnedByOtherBottomEdge.qml" |
| 582 | << "QML BottomEdge: Cannot reuse region owned by other BottomEdge components" |
| 583 | // we should have the default region still |
| 584 | << 0.0 << 1.0 << "default_BottomEdgeRegion"; |
| 585 | QTest::newRow("clear") |
| 586 | << "ClearCustomRegions.qml" |
| 587 | << QString() |
| 588 | // we should have the default region back |
| 589 | << 0.0 << 1.0 << "default_BottomEdgeRegion"; |
| 590 | } |
| 591 | |
| 592 | void test_region_operations() |
| 593 | { |
| 594 | QFETCH(QString, document); |
| 595 | QFETCH(QString, warning); |
| 596 | QFETCH(qreal, xFrom); |
| 597 | QFETCH(qreal, xTo); |
| 598 | QFETCH(QString, xName); |
| 599 | |
| 600 | if (!warning.isEmpty()) { |
| 601 | LomiriTestCase::ignoreWarning(document, 26, 5, warning, 1); |
| 602 | } |
| 603 | QScopedPointer<BottomEdgeTestCase> test(new BottomEdgeTestCase(document)); |
| 604 | UCBottomEdge *bottomEdge = test->testItem(); |
| 605 | UCBottomEdgePrivate *privateBottomEdge = UCBottomEdgePrivate::get(bottomEdge); |
| 606 | |
| 607 | // the regions has the custom one |
| 608 | QCOMPARE(privateBottomEdge->regions.size(), 1); |
| 609 | UCBottomEdgeRegion *region = privateBottomEdge->regions[0]; |
| 610 | QVERIFY(region); |
| 611 | QCOMPARE(UCBottomEdgeRegionPrivate::get(region)->from, xFrom); |
| 612 | QCOMPARE(UCBottomEdgeRegionPrivate::get(region)->to, xTo); |
| 613 | QCOMPARE(region->objectName(), xName); |
| 614 | } |
| 615 | |
| 616 | void test_active_region_changes() |
| 617 | { |
| 618 | QScopedPointer<BottomEdgeTestCase> test(new BottomEdgeTestCase("LeanActiveRegionChange.qml")); |
| 619 | UCBottomEdge *bottomEdge = test->testItem(); |
| 620 | |
| 621 | QPoint from(bottomEdge->width() / 2.0f, bottomEdge->height() - 5); |
| 622 | QPoint to = from + QPoint(0, -(bottomEdge->parentItem()->height() - 1)); |
| 623 | QSignalSpy spy(bottomEdge, &UCBottomEdge::activeRegionChanged); |
| 624 | |
| 625 | UCTestExtras::touchPress(0, bottomEdge, from); |
| 626 | QPoint movePos(from); |
| 627 | while (movePos.y() > to.y()) { |
| 628 | QTest::qWait(20); |
| 629 | UCTestExtras::touchMove(0, bottomEdge, movePos); |
| 630 | movePos += QPoint(0, -10); |
| 631 | } |
| 632 | QTest::qWait(20); |
| 633 | UCTestExtras::touchRelease(0, bottomEdge, movePos); |
| 634 | // we should have had 4 active region changes by now |
| 635 | // null -> defaultRegion -> region #0 -> region #1 -> defaultRegion |
| 636 | QCOMPARE(spy.count(), 4); |
| 637 | } |
| 638 | |
| 639 | void test_region_signals_emitted_data() |
| 640 | { |
| 641 | QTest::addColumn<bool>("withMouse"); |
| 642 | |
| 643 | QTest::newRow("with mouse") << true; |
| 644 | QTest::newRow("with touch") << false; |
| 645 | } |
| 646 | void test_region_signals_emitted() |
| 647 | { |
| 648 | QFETCH(bool, withMouse); |
| 649 | |
| 650 | QScopedPointer<BottomEdgeTestCase> test(new BottomEdgeTestCase("BottomEdgeInItem.qml")); |
| 651 | UCBottomEdge *bottomEdge = test->testItem(); |
| 652 | UCBottomEdgePrivate *privateBottomEdge = UCBottomEdgePrivate::get(bottomEdge); |
| 653 | UCBottomEdgeRegion *region = privateBottomEdge->regions[0]; |
| 654 | |
| 655 | // change the region so we can get the signals while dragged |
| 656 | UCBottomEdgeRegionPrivate::get(region)->from = 0.1; |
| 657 | UCBottomEdgeRegionPrivate::get(region)->to = 0.2; |
| 658 | |
| 659 | QPoint from(bottomEdge->width() / 2.0f, bottomEdge->height() - 5); |
| 660 | QPoint delta(0, -(bottomEdge->height() / 3 + UCUnits::instance()->gu(6))); |
| 661 | QSignalSpy entered(region, SIGNAL(entered())); |
| 662 | QSignalSpy exited(region, SIGNAL(exited())); |
| 663 | |
| 664 | if (withMouse) { |
| 665 | bottomEdge->hint()->setStatus(UCBottomEdgeHint::Locked); |
| 666 | } |
| 667 | if (withMouse) { |
| 668 | UCTestExtras::mouseDrag(bottomEdge, from, delta, Qt::LeftButton, Qt::NoModifier); |
| 669 | } else { |
| 670 | UCTestExtras::touchDrag(0, bottomEdge, from, delta); |
| 671 | } |
| 672 | QTRY_COMPARE_WITH_TIMEOUT(entered.count(), 1, 500); |
| 673 | // exit should not be emitted as the region is not left when committed |
| 674 | QTRY_COMPARE_WITH_TIMEOUT(exited.count(), 0, 500); |
| 675 | } |
| 676 | |
| 677 | void test_region_dragEnded_emitted_data() |
| 678 | { |
| 679 | QTest::addColumn<bool>("withMouse"); |
| 680 | |
| 681 | QTest::newRow("with mouse") << true; |
| 682 | QTest::newRow("with touch") << false; |
| 683 | } |
| 684 | void test_region_dragEnded_emitted() |
| 685 | { |
| 686 | QFETCH(bool, withMouse); |
| 687 | |
| 688 | QScopedPointer<BottomEdgeTestCase> test(new BottomEdgeTestCase("BottomEdgeInItem.qml")); |
| 689 | UCBottomEdge *bottomEdge = test->testItem(); |
| 690 | UCBottomEdgePrivate *privateBottomEdge = UCBottomEdgePrivate::get(bottomEdge); |
| 691 | UCBottomEdgeRegion *region = privateBottomEdge->regions[0]; |
| 692 | |
| 693 | QSignalSpy dragEnded(region, SIGNAL(dragEnded())); |
| 694 | QPoint from(bottomEdge->width() / 2.0f, bottomEdge->height() - 5); |
| 695 | QPoint delta(0, -(bottomEdge->height() / 2.0f)); |
| 696 | if (withMouse) { |
| 697 | bottomEdge->hint()->setStatus(UCBottomEdgeHint::Locked); |
| 698 | UCTestExtras::mouseDrag(bottomEdge, from, delta, Qt::LeftButton, Qt::NoModifier); |
| 699 | } else { |
| 700 | UCTestExtras::touchDrag(0, bottomEdge, from, delta); |
| 701 | } |
| 702 | LomiriTestCase::waitForSignal(&dragEnded); |
| 703 | } |
| 704 | |
| 705 | void test_alternative_content_for_default_commit_region() |
| 706 | { |
| 707 | QScopedPointer<BottomEdgeTestCase> test(new BottomEdgeTestCase("AlternateDefaultRegionContent.qml")); |
| 708 | UCBottomEdge *bottomEdge = test->testItem(); |
| 709 | |
| 710 | QPoint from(bottomEdge->width() / 2.0f, bottomEdge->height() - 5); |
| 711 | QPoint delta(0, -(bottomEdge->height() / 2)); |
| 712 | |
| 713 | UCTestExtras::touchDrag(0, bottomEdge, from, delta, 20); |
| 714 | QTRY_COMPARE_WITH_TIMEOUT(bottomEdge->status(), UCBottomEdge::Committed, 1000); |
| 715 | QCOMPARE(bottomEdge->contentItem()->objectName(), QString("regionContent")); |
| 716 | } |
| 717 | |
| 718 | void test_end_drag_in_region_commits_to_the_region_data() |
| 719 | { |
| 720 | QTest::addColumn<bool>("withMouse"); |
| 721 | |
| 722 | QTest::newRow("with mouse") << true; |
| 723 | QTest::newRow("with touch") << false; |
| 724 | } |
| 725 | void test_end_drag_in_region_commits_to_the_region() |
| 726 | { |
| 727 | QFETCH(bool, withMouse); |
| 728 | |
| 729 | QScopedPointer<BottomEdgeTestCase> test(new BottomEdgeTestCase("AlternateDefaultRegionContent.qml")); |
| 730 | UCBottomEdge *bottomEdge = test->testItem(); |
| 731 | UCBottomEdgePrivate *privateBottomEdge = UCBottomEdgePrivate::get(bottomEdge); |
| 732 | UCBottomEdgeRegion *region = privateBottomEdge->regions[0]; |
| 733 | UCBottomEdgeStyle *style = UCBottomEdgePrivate::get(bottomEdge)->bottomPanel; |
| 734 | |
| 735 | // alter default region for testing |
| 736 | UCBottomEdgeRegionPrivate::get(region)->to = 0.6; |
| 737 | |
| 738 | QPoint from(bottomEdge->width() / 2.0f, bottomEdge->height() - 5); |
| 739 | QPoint delta(0, -(bottomEdge->height() / 2)); |
| 740 | |
| 741 | if (withMouse) { |
| 742 | bottomEdge->hint()->setStatus(UCBottomEdgeHint::Locked); |
| 743 | UCTestExtras::mouseDrag(bottomEdge, from, delta, Qt::LeftButton, Qt::NoModifier); |
| 744 | } else { |
| 745 | UCTestExtras::touchDrag(0, bottomEdge, from, delta, 20); |
| 746 | } |
| 747 | |
| 748 | QTRY_COMPARE_WITH_TIMEOUT(bottomEdge->status(), UCBottomEdge::Committed, 1000); |
| 749 | QCOMPARE(bottomEdge->activeRegion(), region); |
| 750 | // the top of the committed content should not be the top of the bottom edge |
| 751 | QVERIFY(style->m_panel->y() > bottomEdge->y()); |
| 752 | } |
| 753 | |
| 754 | void test_drag_ends_in_uncovered_region_collapses_data() |
| 755 | { |
| 756 | QTest::addColumn<bool>("withMouse"); |
| 757 | |
| 758 | QTest::newRow("with mouse") << true; |
| 759 | QTest::newRow("with touch") << false; |
| 760 | } |
| 761 | void test_drag_ends_in_uncovered_region_collapses() |
| 762 | { |
| 763 | QFETCH(bool, withMouse); |
| 764 | |
| 765 | QScopedPointer<BottomEdgeTestCase> test(new BottomEdgeTestCase("UncoveredByRegion.qml")); |
| 766 | UCBottomEdge *bottomEdge = test->testItem(); |
| 767 | UCBottomEdgePrivate *privateBottomEdge = UCBottomEdgePrivate::get(bottomEdge); |
| 768 | UCBottomEdgeRegion *region = privateBottomEdge->regions[0]; |
| 769 | |
| 770 | QPoint from(bottomEdge->width() / 2.0f, bottomEdge->height() - 1); |
| 771 | QPoint to = from + QPoint(0, -(bottomEdge->parentItem()->height() - UCUnits::instance()->gu(10))); |
| 772 | // let us know when we are out of the region |
| 773 | QSignalSpy exitRegion(region, SIGNAL(exited())); |
| 774 | |
| 775 | if (withMouse) { |
| 776 | bottomEdge->hint()->setStatus(UCBottomEdgeHint::Locked); |
| 777 | from = bottomEdge->mapToScene(from).toPoint(); |
| 778 | to = bottomEdge->mapToScene(to).toPoint(); |
| 779 | QTest::mousePress(bottomEdge->window(), Qt::LeftButton, Qt::NoModifier, from, 20); |
| 780 | QPoint movePos(from); |
| 781 | while (movePos.y() > to.y()) { |
| 782 | QTest::mouseMove(bottomEdge->window(), movePos, 20); |
| 783 | movePos += QPoint(0, -20); |
| 784 | } |
| 785 | movePos -= QPoint(0, -20); |
| 786 | QTest::mouseRelease(bottomEdge->window(), Qt::LeftButton, Qt::NoModifier, movePos, 20); |
| 787 | } else { |
| 788 | UCTestExtras::touchPress(0, bottomEdge, from); |
| 789 | QPoint movePos(from); |
| 790 | while (movePos.y() > to.y()) { |
| 791 | QTest::qWait(20); |
| 792 | UCTestExtras::touchMove(0, bottomEdge, movePos); |
| 793 | movePos += QPoint(0, -20); |
| 794 | } |
| 795 | movePos -= QPoint(0, -20); |
| 796 | QTest::qWait(20); |
| 797 | UCTestExtras::touchRelease(0, bottomEdge, movePos); |
| 798 | } |
| 799 | |
| 800 | // we should be collapsing! |
| 801 | QTRY_COMPARE_WITH_TIMEOUT(bottomEdge->status(), UCBottomEdge::Committed, 1000); |
| 802 | } |
| 803 | |
| 804 | void test_commit_region_content_data() |
| 805 | { |
| 806 | QTest::addColumn<bool>("withMouse"); |
| 807 | |
| 808 | QTest::newRow("with mouse") << true; |
| 809 | QTest::newRow("with touch") << false; |
| 810 | } |
| 811 | void test_commit_region_content() |
| 812 | { |
| 813 | QFETCH(bool, withMouse); |
| 814 | |
| 815 | QScopedPointer<BottomEdgeTestCase> test(new BottomEdgeTestCase("AlternateRegionContent.qml")); |
| 816 | UCBottomEdge *bottomEdge = test->testItem(); |
| 817 | UCBottomEdgePrivate *privateBottomEdge = UCBottomEdgePrivate::get(bottomEdge); |
| 818 | UCBottomEdgeRegion *region = privateBottomEdge->regions[0]; |
| 819 | |
| 820 | // alter region for testing |
| 821 | UCBottomEdgeRegionPrivate::get(region)->from = 0.1; |
| 822 | UCBottomEdgeRegionPrivate::get(region)->to = 0.8; |
| 823 | // and connect commit to dragEnded |
| 824 | connect(region, &UCBottomEdgeRegion::dragEnded, bottomEdge, &UCBottomEdge::commit); |
| 825 | |
| 826 | QPoint from(bottomEdge->width() / 2.0f, bottomEdge->height() - 5); |
| 827 | QPoint to = from + QPoint(0, -(bottomEdge->parentItem()->height() - 1)); |
| 828 | |
| 829 | if (withMouse) { |
| 830 | bottomEdge->hint()->setStatus(UCBottomEdgeHint::Locked); |
| 831 | from = bottomEdge->mapToScene(from).toPoint(); |
| 832 | to = bottomEdge->mapToScene(to).toPoint(); |
| 833 | QTest::mousePress(bottomEdge->window(), Qt::LeftButton, Qt::NoModifier, from, 20); |
| 834 | QPoint movePos(from); |
| 835 | while (movePos.y() > to.y() && (bottomEdge->activeRegion() != region)) { |
| 836 | QTest::mouseMove(bottomEdge->window(), movePos, 20); |
| 837 | movePos += QPoint(0, -10); |
| 838 | } |
| 839 | QTest::mouseRelease(bottomEdge->window(), Qt::LeftButton, Qt::NoModifier, movePos, 20); |
| 840 | } else { |
| 841 | UCTestExtras::touchPress(0, bottomEdge, from); |
| 842 | QPoint movePos(from); |
| 843 | while (movePos.y() > to.y() && (bottomEdge->activeRegion() != region)) { |
| 844 | QTest::qWait(20); |
| 845 | UCTestExtras::touchMove(0, bottomEdge, movePos); |
| 846 | movePos += QPoint(0, -10); |
| 847 | } |
| 848 | QTest::qWait(20); |
| 849 | UCTestExtras::touchRelease(0, bottomEdge, movePos); |
| 850 | } |
| 851 | QTRY_COMPARE_WITH_TIMEOUT(bottomEdge->status(), UCBottomEdge::Committed, 1000); |
| 852 | QCOMPARE(bottomEdge->contentItem()->objectName(), QString("regionContent")); |
| 853 | } |
| 854 | |
| 855 | void test_overlapping_regions() |
| 856 | { |
| 857 | QString document("OverlappingRegions.qml"); |
| 858 | LomiriTestCase::ignoreWarning(document, 34, 9, "QML BottomEdgeRegion: Region intersects the one from index 0 having from: 0.2 and to: 0.5", 1); |
| 859 | LomiriTestCase::ignoreWarning(document, 37, 9, "QML BottomEdgeRegion: Region intersects the one from index 0 having from: 0.2 and to: 0.5", 1); |
| 860 | LomiriTestCase::ignoreWarning(document, 37, 9, "QML BottomEdgeRegion: Region at index 1 contains this region. This region will never activate.", 1); |
| 861 | LomiriTestCase::ignoreWarning(document, 41, 9, "QML BottomEdgeRegion: Region at index 1 contains this region. This region will never activate.", 1); |
| 862 | QScopedPointer<BottomEdgeTestCase> test(new BottomEdgeTestCase(document)); |
| 863 | } |
| 864 | |
| 865 | void test_region_does_not_activate_when_from_greater_than_to_data() |
| 866 | { |
| 867 | QTest::addColumn<bool>("withMouse"); |
| 868 | |
| 869 | QTest::newRow("with mouse") << true; |
| 870 | QTest::newRow("with touch") << false; |
| 871 | } |
| 872 | void test_region_does_not_activate_when_from_greater_than_to() |
| 873 | { |
| 874 | QFETCH(bool, withMouse); |
| 875 | |
| 876 | QScopedPointer<BottomEdgeTestCase> test(new BottomEdgeTestCase("AlternateRegionContent.qml")); |
| 877 | UCBottomEdge *bottomEdge = test->testItem(); |
| 878 | UCBottomEdgePrivate *privateBottomEdge = UCBottomEdgePrivate::get(bottomEdge); |
| 879 | UCBottomEdgeRegion *region = privateBottomEdge->regions[0]; |
| 880 | |
| 881 | // adjust region data for the test |
| 882 | UCBottomEdgeRegionPrivate::get(region)->from = 0.4; |
| 883 | UCBottomEdgeRegionPrivate::get(region)->to = 0.2; |
| 884 | QPoint from(bottomEdge->width() / 2.0f, bottomEdge->height() - 5); |
| 885 | QPoint delta(0, -(bottomEdge->height() / 2.0f)); |
| 886 | QSignalSpy activeRegion(bottomEdge, &UCBottomEdge::activeRegionChanged); |
| 887 | if (withMouse) { |
| 888 | bottomEdge->hint()->setStatus(UCBottomEdgeHint::Locked); |
| 889 | UCTestExtras::mouseDrag(bottomEdge, from, delta, Qt::LeftButton, Qt::NoModifier, 10); |
| 890 | } else { |
| 891 | UCTestExtras::touchDrag(0, bottomEdge, from, delta, 10); |
| 892 | } |
| 893 | QEXPECT_FAIL(0, "region should not activate", Continue); |
| 894 | QVERIFY(activeRegion.wait(400)); |
| 895 | } |
| 896 | |
| 897 | void test_autocollapse_navigation_action_on_commit_completed_data() |
| 898 | { |
| 899 | QTest::addColumn<QString>("document"); |
| 900 | |
| 901 | QTest::newRow("content has PageHeader") << "AutoCollapseInPageHeader.qml"; |
| 902 | QTest::newRow("content is Page with PageHeader") << "AutoCollapseInPageWithPageHeader.qml"; |
| 903 | } |
| 904 | void test_autocollapse_navigation_action_on_commit_completed() |
| 905 | { |
| 906 | QFETCH(QString, document); |
| 907 | |
| 908 | QScopedPointer<BottomEdgeTestCase> test(new BottomEdgeTestCase(document)); |
| 909 | UCBottomEdge *bottomEdge = test->testItem(); |
| 910 | |
| 911 | BottomEdgeTestCase *testCase = test.data(); |
| 912 | connect(bottomEdge, &UCBottomEdge::contentItemChanged, [=]() { |
| 913 | QVERIFY(!testCase->hasContentAutoCollapse()); |
| 914 | }); |
| 915 | connect(bottomEdge, &UCBottomEdge::commitCompleted, [=]() { |
| 916 | QVERIFY(testCase->hasContentAutoCollapse()); |
| 917 | }); |
| 918 | // drag slowly |
| 919 | QPoint from(bottomEdge->width() / 2.0f, bottomEdge->height() - 5); |
| 920 | QPoint delta(0, -bottomEdge->height()); |
| 921 | UCTestExtras::touchDrag(0, bottomEdge, from, delta, 20); |
| 922 | } |
| 923 | |
| 924 | void test_bottomedge_hint_enabled() { |
| 925 | QScopedPointer<BottomEdgeTestCase> view(new BottomEdgeTestCase("Defaults.qml")); |
| 926 | UCBottomEdge *bottomEdge = view->testItem(); |
| 927 | QCOMPARE(bottomEdge->isEnabled(), bottomEdge->hint()->isEnabled()); |
| 928 | bottomEdge->setEnabled(!bottomEdge->isEnabled()); |
| 929 | QCOMPARE(bottomEdge->isEnabled(), bottomEdge->hint()->isEnabled()); |
| 930 | } |
| 931 | |
| 932 | void test_collapse_by_keyboard_data() |
| 933 | { |
| 934 | QTest::addColumn<Qt::Key>("key"); |
| 935 | |
| 936 | QTest::newRow("space") << Qt::Key_Space; |
| 937 | QTest::newRow("enter") << Qt::Key_Enter; |
| 938 | QTest::newRow("return") << Qt::Key_Return; |
| 939 | } |
| 940 | void test_collapse_by_keyboard() { |
| 941 | QFETCH(Qt::Key, key); |
| 942 | |
| 943 | QScopedPointer<BottomEdgeTestCase> view(new BottomEdgeTestCase("Defaults.qml")); |
| 944 | view->rootObject()->forceActiveFocus(); |
| 945 | QTRY_COMPARE_WITH_TIMEOUT(view->rootObject()->property("activeFocus").toBool(), true, 1000); |
| 946 | UCBottomEdge *bottomEdge = view->testItem(); |
| 947 | QTest::keyClick(bottomEdge->hint()->window(), Qt::Key_Tab); |
| 948 | QTRY_COMPARE_WITH_TIMEOUT(bottomEdge->hint()->property("activeFocus").toBool(), true, 1000); |
| 949 | QTRY_COMPARE_WITH_TIMEOUT(bottomEdge->hint()->property("keyNavigationFocus").toBool(), true, 1000); |
| 950 | QTest::keyClick(bottomEdge->hint()->window(), key); |
| 951 | QSignalSpy commitCompletedSpy(bottomEdge, SIGNAL(commitCompleted())); |
| 952 | QTRY_COMPARE_WITH_TIMEOUT(commitCompletedSpy.count(), 1, 1000); |
| 953 | QTest::keyClick(bottomEdge->hint()->window(), Qt::Key_Escape); |
| 954 | QSignalSpy collapseCompletedSpy(bottomEdge, SIGNAL(collapseCompleted())); |
| 955 | QTRY_COMPARE_WITH_TIMEOUT(collapseCompletedSpy.count(), 1, 1000); |
| 956 | } |
| 957 | |
| 958 | void test_preload_content() |
| 959 | { |
| 960 | QScopedPointer<BottomEdgeTestCase> test(new BottomEdgeTestCase("PreloadedContent.qml")); |
| 961 | UCBottomEdge *bottomEdge = test->testItem(); |
| 962 | |
| 963 | QPoint from(bottomEdge->width() / 2.0f, bottomEdge->height() - 5); |
| 964 | QPoint to = from + QPoint(0, -(bottomEdge->parentItem()->height() - 1)); |
| 965 | QSignalSpy spy(bottomEdge, &UCBottomEdge::activeRegionChanged); |
| 966 | |
| 967 | connect(bottomEdge, &UCBottomEdge::contentItemChanged, [=]() { |
| 968 | regionObjects.append(bottomEdge->contentItem() |
| 969 | ? bottomEdge->contentItem()->objectName() |
| 970 | : "NULL"); |
| 971 | }); |
| 972 | |
| 973 | UCTestExtras::touchPress(0, bottomEdge, from); |
| 974 | QPoint movePos(from); |
| 975 | while (movePos.y() > to.y()) { |
| 976 | QTest::qWait(20); |
| 977 | UCTestExtras::touchMove(0, bottomEdge, movePos); |
| 978 | movePos += QPoint(0, -10); |
| 979 | } |
| 980 | QTest::qWait(20); |
| 981 | UCTestExtras::touchRelease(0, bottomEdge, movePos); |
| 982 | // we should have had 4 active region changes by now |
| 983 | // null -> defaultRegion -> region #0 -> region #1 -> null |
| 984 | QCOMPARE(spy.count(), 4); |
| 985 | QCOMPARE(regionObjects.size(), 6); |
| 986 | // the first two regions content is the same |
| 987 | int i = 0; |
| 988 | QCOMPARE(regionObjects[i++], QString("default")); |
| 989 | QCOMPARE(regionObjects[i++], QString("default")); |
| 990 | QCOMPARE(regionObjects[i++], QString("region1")); |
| 991 | QCOMPARE(regionObjects[i++], QString("default")); |
| 992 | QCOMPARE(regionObjects[i++], QString("region2")); |
| 993 | QCOMPARE(regionObjects[i++], QString("default")); |
| 994 | } |
| 995 | |
| 996 | void test_preload_content_url() |
| 997 | { |
| 998 | QScopedPointer<BottomEdgeTestCase> test(new BottomEdgeTestCase("PreloadContentUrl.qml")); |
| 999 | UCBottomEdge *bottomEdge = test->testItem(); |
| 1000 | |
| 1001 | // commit so the contentItem is set |
| 1002 | bottomEdge->commit(); |
| 1003 | QTRY_VERIFY(bottomEdge->contentItem()); |
| 1004 | } |
| 1005 | |
| 1006 | void test_reset_preload_content() |
| 1007 | { |
| 1008 | QScopedPointer<BottomEdgeTestCase> test(new BottomEdgeTestCase("PreloadedContent.qml")); |
| 1009 | UCBottomEdge *bottomEdge = test->testItem(); |
| 1010 | |
| 1011 | UCBottomEdgePrivate *d = UCBottomEdgePrivate::get(bottomEdge); |
| 1012 | for (int i = 0; i < d->regions.size(); i++) { |
| 1013 | QTRY_VERIFY(UCBottomEdgeRegionPrivate::get(d->regions[i])->contentItem); |
| 1014 | } |
| 1015 | |
| 1016 | // set preloadContent: false |
| 1017 | bottomEdge->setPreloadContent(false); |
| 1018 | for (int i = 0; i < d->regions.size(); i++) { |
| 1019 | QVERIFY(!UCBottomEdgeRegionPrivate::get(d->regions[i])->contentItem); |
| 1020 | } |
| 1021 | } |
| 1022 | |
| 1023 | void test_disabled_content_unloads() |
| 1024 | { |
| 1025 | QScopedPointer<BottomEdgeTestCase> test(new BottomEdgeTestCase("PreloadedContent.qml")); |
| 1026 | UCBottomEdge *bottomEdge = test->testItem(); |
| 1027 | |
| 1028 | UCBottomEdgePrivate *d = UCBottomEdgePrivate::get(bottomEdge); |
| 1029 | // disable a region |
| 1030 | d->regions[0]->setEnabled(false); |
| 1031 | QVERIFY(!UCBottomEdgeRegionPrivate::get(d->regions[0])->contentItem); |
| 1032 | |
| 1033 | // enable it |
| 1034 | d->regions[0]->setEnabled(true); |
| 1035 | QTRY_VERIFY_WITH_TIMEOUT(UCBottomEdgeRegionPrivate::get(d->regions[0])->contentItem != nullptr, 1000); |
| 1036 | } |
| 1037 | |
| 1038 | void test_action_triggered_commits() |
| 1039 | { |
| 1040 | QScopedPointer<BottomEdgeTestCase> test(new BottomEdgeTestCase("BottomEdgeWithAction.qml")); |
| 1041 | UCBottomEdge *bottomEdge = test->testItem(); |
| 1042 | UCAction *action = bottomEdge->hint()->action(); |
| 1043 | QVERIFY(action); |
| 1044 | |
| 1045 | // trigger action |
| 1046 | action->trigger(); |
| 1047 | QTRY_COMPARE_WITH_TIMEOUT(bottomEdge->status(), UCBottomEdge::Committed, 2000); |
| 1048 | QVERIFY(bottomEdge->contentItem()); |
| 1049 | } |
| 1050 | }; |
| 1051 | |
| 1052 | QTEST_MAIN(tst_BottomEdge) |
| 1053 | |
| 1054 | #include "tst_bottomedge.moc" |