~ubuntu-sdk-team/ubuntu-ui-toolkit/qmlModule

« back to all changes in this revision

Viewing changes to tests/unit_x11/tst_bottomedge/tst_bottomedge.cpp

BorromEdge.preloadContent. Fixes: https://bugs.launchpad.net/bugs/1540454.

Approved by ubuntu-sdk-build-bot, Benjamin Zeller.

Show diffs side-by-side

added added

removed removed

Lines of Context:
114
114
class tst_BottomEdge : public QObject
115
115
{
116
116
    Q_OBJECT
 
117
    QStringList regionObjects;
117
118
private Q_SLOTS:
118
119
 
119
120
    void initTestCase()
121
122
        UCTestExtras::registerTouchDevice();
122
123
    }
123
124
 
 
125
    void init()
 
126
    {
 
127
        regionObjects.clear();
 
128
    }
 
129
 
 
130
private Q_SLOTS:
124
131
    void test_defaults()
125
132
    {
126
133
        QScopedPointer<BottomEdgeTestCase> test(new BottomEdgeTestCase("Defaults.qml"));
137
144
        QCOMPARE(test->regionAt("testItem", 0)->m_from, 0.33);
138
145
        QCOMPARE(test->regionAt("testItem", 0)->m_to, 1.0);
139
146
        QVERIFY(!test->testItem()->activeRegion());
 
147
        QVERIFY(!test->testItem()->preloadContent());
140
148
    }
141
149
 
142
150
    void test_height_moves_when_reparented()
880
888
        bottomEdge->setEnabled(!bottomEdge->isEnabled());
881
889
        QCOMPARE(bottomEdge->isEnabled(), bottomEdge->hint()->isEnabled());
882
890
    }
 
891
 
 
892
    void test_preload_content()
 
893
    {
 
894
        QScopedPointer<BottomEdgeTestCase> test(new BottomEdgeTestCase("PreloadedContent.qml"));
 
895
        UCBottomEdge *bottomEdge = test->testItem();
 
896
 
 
897
        QPoint from(bottomEdge->width() / 2.0f, bottomEdge->height() - 5);
 
898
        QPoint to = from + QPoint(0, -(bottomEdge->parentItem()->height() - 1));
 
899
        QSignalSpy spy(bottomEdge, SIGNAL(activeRegionChanged(UCBottomEdgeRegion*)));
 
900
 
 
901
        connect(bottomEdge, &UCBottomEdge::contentItemChanged, [=]() {
 
902
            regionObjects.append(bottomEdge->contentItem()
 
903
                                    ? bottomEdge->contentItem()->objectName()
 
904
                                    : "NULL");
 
905
        });
 
906
 
 
907
        UCTestExtras::touchPress(0, bottomEdge, from);
 
908
        QPoint movePos(from);
 
909
        while (movePos.y() > to.y()) {
 
910
            QTest::qWait(20);
 
911
            UCTestExtras::touchMove(0, bottomEdge, movePos);
 
912
            movePos += QPoint(0, -10);
 
913
        }
 
914
        QTest::qWait(20);
 
915
        UCTestExtras::touchRelease(0, bottomEdge, movePos);
 
916
        // we should have had 3 active region changes by now
 
917
        // null -> region #0 -> region #1 -> null
 
918
        QCOMPARE(spy.count(), 3);
 
919
        QCOMPARE(regionObjects.size(), 5);
 
920
        int i = 0;
 
921
        QCOMPARE(regionObjects[i++], QString("default"));
 
922
        QCOMPARE(regionObjects[i++], QString("region1"));
 
923
        QCOMPARE(regionObjects[i++], QString("default"));
 
924
        QCOMPARE(regionObjects[i++], QString("region2"));
 
925
        QCOMPARE(regionObjects[i++], QString("default"));
 
926
    }
 
927
 
 
928
    void test_reset_preload_content()
 
929
    {
 
930
        QScopedPointer<BottomEdgeTestCase> test(new BottomEdgeTestCase("PreloadedContent.qml"));
 
931
        UCBottomEdge *bottomEdge = test->testItem();
 
932
 
 
933
        UCBottomEdgePrivate *d = UCBottomEdgePrivate::get(bottomEdge);
 
934
        for (int i = 0; i < d->regions.size(); i++) {
 
935
            QVERIFY(d->regions[i]->regionContent());
 
936
        }
 
937
 
 
938
        // set preloadContent: false
 
939
        bottomEdge->setPreloadContent(false);
 
940
        for (int i = 0; i < d->regions.size(); i++) {
 
941
            QVERIFY(!d->regions[i]->regionContent());
 
942
        }
 
943
    }
 
944
 
 
945
    void test_disabled_content_unloads()
 
946
    {
 
947
        QScopedPointer<BottomEdgeTestCase> test(new BottomEdgeTestCase("PreloadedContent.qml"));
 
948
        UCBottomEdge *bottomEdge = test->testItem();
 
949
 
 
950
        UCBottomEdgePrivate *d = UCBottomEdgePrivate::get(bottomEdge);
 
951
        // disable a region
 
952
        d->regions[0]->setEnabled(false);
 
953
        QVERIFY(!d->regions[0]->regionContent());
 
954
 
 
955
        // enable it
 
956
        d->regions[0]->setEnabled(true);
 
957
        QTRY_VERIFY_WITH_TIMEOUT(d->regions[0]->regionContent() != nullptr, 1000);
 
958
    }
883
959
};
884
960
 
885
961
QTEST_MAIN(tst_BottomEdge)