diff options
author | Simon Hausmann <simon.hausmann@digia.com> | 2014-07-26 09:14:44 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@digia.com> | 2014-07-26 13:21:16 +0200 |
commit | 75d8ebb3e6925f500ddeefe2ab491be2ae83264c (patch) | |
tree | 6874c91386434f4a1934a9555a3f1d5daf69434c /tests | |
parent | fcb40ff6d71f4561401e6b2bd4d7fc706fff8eee (diff) | |
parent | ba8416b80f42c81387170620472194e7a76429b8 (diff) |
Merge remote-tracking branch 'origin/5.3' into dev
Conflicts:
src/qml/compiler/qv4ssa.cpp
src/qml/jsruntime/qv4arrayobject.cpp
src/qml/jsruntime/qv4engine.cpp
Change-Id: Ie3ef6202b6a3a8521971e1be10c40c6a2db6989c
Diffstat (limited to 'tests')
7 files changed, 341 insertions, 8 deletions
diff --git a/tests/auto/qml/qqmlecmascript/data/sequenceConversion.array.qml b/tests/auto/qml/qqmlecmascript/data/sequenceConversion.array.qml index 8847055a70..5103168fd3 100644 --- a/tests/auto/qml/qqmlecmascript/data/sequenceConversion.array.qml +++ b/tests/auto/qml/qqmlecmascript/data/sequenceConversion.array.qml @@ -165,6 +165,43 @@ Item { } } } + + // unshift + msco.stringListProperty = [ "one", "two" ] + var unshiftedVal = msco.stringListProperty.unshift("zero") + expected = [ "zero", "one", "two" ] + if (msco.stringListProperty.toString() != expected.toString()) success = false; + expected = 3 + if (msco.stringListProperty.length != expected) success = false + msco.stringListProperty = [ ] + msco.stringListProperty.unshift("zero", "one") + expected = [ "zero", "one" ] + if (msco.stringListProperty.toString() != expected.toString()) success = false; + expected = 2 + if (msco.stringListProperty.length != expected) success = false + + // shift + msco.stringListProperty = [ "one", "two", "three" ] + var shiftVal = msco.stringListProperty.shift() + expected = [ "two", "three" ] + if (msco.stringListProperty.toString() != expected.toString()) success = false; + expected = "one" + if (shiftVal != expected) success = false + shiftVal = msco.stringListProperty.shift() + expected = [ "three" ] + if (msco.stringListProperty.toString() != expected.toString()) success = false; + expected = "two" + if (shiftVal != expected) success = false + shiftVal = msco.stringListProperty.shift() + expected = 0 + if (msco.stringListProperty.length != expected) success = false; + expected = "three" + if (shiftVal != expected) success = false + shiftVal = msco.stringListProperty.shift() + expected = 0 + if (msco.stringListProperty.length != expected) success = false; + expected = undefined + if (shiftVal != expected) success = false } property variant variantList: [ 1, 2, 3, 4, 5 ]; diff --git a/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp b/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp index 863fb69b84..a350074b42 100644 --- a/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp +++ b/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp @@ -3613,12 +3613,13 @@ void tst_QQuickGridView::resetModel_headerFooter() model.reset(); - header = findItem<QQuickItem>(contentItem, "header"); - QVERIFY(header); + // A reset should not force a new header or footer to be created. + QQuickItem *newHeader = findItem<QQuickItem>(contentItem, "header"); + QVERIFY(newHeader == header); QCOMPARE(header->y(), -header->height()); - footer = findItem<QQuickItem>(contentItem, "footer"); - QVERIFY(footer); + QQuickItem *newFooter = findItem<QQuickItem>(contentItem, "footer"); + QVERIFY(newFooter == footer); QCOMPARE(footer->y(), 60.*2); delete window; diff --git a/tests/auto/quick/qquicklistview/data/simplelistview.qml b/tests/auto/quick/qquicklistview/data/simplelistview.qml new file mode 100644 index 0000000000..56a96150c5 --- /dev/null +++ b/tests/auto/quick/qquicklistview/data/simplelistview.qml @@ -0,0 +1,11 @@ +import QtQuick 2.0 + +ListView { + width: 400 + height: 400 + model: 100 + delegate: Rectangle { + height: 40; width: 400 + color: index % 2 ? "lightsteelblue" : "lightgray" + } +} diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp index b909d14301..c8ab62cbbc 100644 --- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp +++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp @@ -231,6 +231,9 @@ private slots: void roundingErrors(); void roundingErrors_data(); + void QTBUG_38209(); + void programmaticFlickAtBounds(); + private: template <class T> void items(const QUrl &source); template <class T> void changed(const QUrl &source); @@ -4081,12 +4084,13 @@ void tst_QQuickListView::resetModel_headerFooter() model.reset(); - header = findItem<QQuickItem>(contentItem, "header"); - QVERIFY(header); + // A reset should not force a new header or footer to be created. + QQuickItem *newHeader = findItem<QQuickItem>(contentItem, "header"); + QVERIFY(newHeader == header); QCOMPARE(header->y(), -header->height()); - footer = findItem<QQuickItem>(contentItem, "footer"); - QVERIFY(footer); + QQuickItem *newFooter = findItem<QQuickItem>(contentItem, "footer"); + QVERIFY(newFooter == footer); QCOMPARE(footer->y(), 30.*4); delete window; @@ -7362,6 +7366,58 @@ void tst_QQuickListView::roundingErrors_data() QTest::newRow("pixelAligned=false") << false; } +void tst_QQuickListView::QTBUG_38209() +{ + QScopedPointer<QQuickView> window(createView()); + window->setSource(testFileUrl("simplelistview.qml")); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window.data())); + + QQuickListView *listview = qobject_cast<QQuickListView *>(window->rootObject()); + QVERIFY(listview); + + // simulate mouse flick + flick(window.data(), QPoint(200, 200), QPoint(200, 50), 100); + QTRY_VERIFY(listview->isMoving() == false); + qreal contentY = listview->contentY(); + + // flick down + listview->flick(0, 1000); + + // ensure we move more than just a couple pixels + QTRY_VERIFY(contentY - listview->contentY() > qreal(100.0)); +} + +void tst_QQuickListView::programmaticFlickAtBounds() +{ + QScopedPointer<QQuickView> window(createView()); + window->setSource(testFileUrl("simplelistview.qml")); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window.data())); + + QQuickListView *listview = qobject_cast<QQuickListView *>(window->rootObject()); + QVERIFY(listview); + QSignalSpy spy(listview, SIGNAL(contentYChanged())); + + // flick down + listview->flick(0, 1000); + + // verify that there is movement beyond bounds + QVERIFY(spy.wait(100)); + + // reset, and test with StopAtBounds + listview->cancelFlick(); + listview->returnToBounds(); + QTRY_COMPARE(listview->contentY(), qreal(0.0)); + listview->setBoundsBehavior(QQuickFlickable::StopAtBounds); + + // flick down + listview->flick(0, 1000); + + // verify that there is no movement beyond bounds + QVERIFY(!spy.wait(100)); +} + QTEST_MAIN(tst_QQuickListView) #include "tst_qquicklistview.moc" diff --git a/tests/auto/quick/qquickpathview/data/changePathDuringRefill.qml b/tests/auto/quick/qquickpathview/data/changePathDuringRefill.qml new file mode 100644 index 0000000000..f02ab35faf --- /dev/null +++ b/tests/auto/quick/qquickpathview/data/changePathDuringRefill.qml @@ -0,0 +1,45 @@ +import QtQuick 2.3 + +PathView { + id: view + objectName: "pathView" + width: 100 + height: delegateHeight * pathItemCount + model: ["A", "B", "C"] + pathItemCount: 3 + anchors.centerIn: parent + + property int delegateHeight: 0 + + activeFocusOnTab: true + Keys.onDownPressed: view.incrementCurrentIndex() + Keys.onUpPressed: view.decrementCurrentIndex() + preferredHighlightBegin: 0.5 + preferredHighlightEnd: 0.5 + + delegate: Rectangle { + objectName: "delegate" + modelData + width: view.width + height: textItem.height + border.color: "red" + + onHeightChanged: { + if (index == 0) + view.delegateHeight = textItem.height + } + + Text { + id: textItem + text: modelData + } + } + + path: Path { + startX: view.width / 2 + startY: 0 + PathLine { + x: view.width / 2 + y: view.pathItemCount * view.delegateHeight + } + } +} diff --git a/tests/auto/quick/qquickpathview/data/incorrectSteal.qml b/tests/auto/quick/qquickpathview/data/incorrectSteal.qml new file mode 100644 index 0000000000..bcd6923b73 --- /dev/null +++ b/tests/auto/quick/qquickpathview/data/incorrectSteal.qml @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Flickable { + objectName: "flickable" + width: 400; height: 400 + + contentHeight: height + contentWidth: width * 3 + contentX: 400 + + Row { + Rectangle { width: 400; height: 400; color: "green" } + Rectangle { + width: 400; height: 400; color: "blue" + clip: true + + PathView { + id: pathView + objectName: "pathView" + width: parent.width + height: 200 + anchors.verticalCenter: parent.verticalCenter + + dragMargin: 400 + pathItemCount: 6 + + model: 10 + path: Path { + startX: -pathView.width / 2 + startY: pathView.height / 2 + PathLine { x: pathView.width + pathView.width / 2; y: pathView.height / 2 } + } + + delegate: Rectangle { + width: 100; height: 200 + color: "purple" + MouseArea { + anchors.fill: parent + } + } + } + } + Rectangle { width: 400; height: 400; color: "yellow" } + } +} diff --git a/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp b/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp index 579cb954aa..1960775ad3 100644 --- a/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp +++ b/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp @@ -47,6 +47,7 @@ #include <QtQml/qqmlexpression.h> #include <QtQml/qqmlincubator.h> #include <QtQuick/private/qquickpathview_p.h> +#include <QtQuick/private/qquickflickable_p.h> #include <QtQuick/private/qquickpath_p.h> #include <QtQuick/private/qquicktext_p.h> #include <QtQuick/private/qquickrectangle_p.h> @@ -142,6 +143,8 @@ private slots: void indexAt_itemAt(); void indexAt_itemAt_data(); void cacheItemCount(); + void incorrectSteal(); + void changePathDuringRefill(); }; class TestObject : public QObject @@ -2120,7 +2123,102 @@ void tst_QQuickPathView::cacheItemCount() bool b = true; controller.incubateWhile(&b); } +} + +static void testCurrentIndexChange(QQuickPathView *pathView, const QStringList &objectNamesInOrder) +{ + for (int visualIndex = 0; visualIndex < objectNamesInOrder.size() - 1; ++visualIndex) { + QQuickRectangle *delegate = findItem<QQuickRectangle>(pathView, objectNamesInOrder.at(visualIndex)); + QVERIFY(delegate); + + QQuickRectangle *nextDelegate = findItem<QQuickRectangle>(pathView, objectNamesInOrder.at(visualIndex + 1)); + QVERIFY(nextDelegate); + + QVERIFY(delegate->y() < nextDelegate->y()); + } +} + +void tst_QQuickPathView::changePathDuringRefill() +{ + QScopedPointer<QQuickView> window(createView()); + + window->setSource(testFileUrl("changePathDuringRefill.qml")); + window->show(); + QVERIFY(QTest::qWaitForWindowActive(window.data())); + QCOMPARE(window.data(), qGuiApp->focusWindow()); + + QQuickPathView *pathView = qobject_cast<QQuickPathView*>(window->rootObject()); + QVERIFY(pathView != 0); + + testCurrentIndexChange(pathView, QStringList() << "delegateC" << "delegateA" << "delegateB"); + + pathView->incrementCurrentIndex(); + /* + Decrementing moves delegateA down, resulting in an offset of 1, + so incrementing will move it up, resulting in an offset of 2: + + delegateC delegateA + delegateA => delegateB + delegateB delegateC + */ + QTRY_COMPARE(pathView->offset(), 2.0); + testCurrentIndexChange(pathView, QStringList() << "delegateA" << "delegateB" << "delegateC"); +} + +void tst_QQuickPathView::incorrectSteal() +{ + QScopedPointer<QQuickView> window(createView()); + QQuickViewTestUtil::moveMouseAway(window.data()); + window->setSource(testFileUrl("incorrectSteal.qml")); + window->show(); + window->requestActivate(); + QVERIFY(QTest::qWaitForWindowActive(window.data())); + QCOMPARE(window.data(), qGuiApp->focusWindow()); + + QQuickPathView *pathview = findItem<QQuickPathView>(window->rootObject(), "pathView"); + QVERIFY(pathview != 0); + + QQuickFlickable *flickable = qobject_cast<QQuickFlickable*>(window->rootObject()); + QVERIFY(flickable != 0); + + QSignalSpy movingSpy(pathview, SIGNAL(movingChanged())); + QSignalSpy moveStartedSpy(pathview, SIGNAL(movementStarted())); + QSignalSpy moveEndedSpy(pathview, SIGNAL(movementEnded())); + + QSignalSpy fflickingSpy(flickable, SIGNAL(flickingChanged())); + QSignalSpy fflickStartedSpy(flickable, SIGNAL(flickStarted())); + QSignalSpy fflickEndedSpy(flickable, SIGNAL(flickEnded())); + + int waitInterval = 5; + QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(23,218)); + + QTest::mouseMove(window.data(), QPoint(25,218), waitInterval); + QTest::mouseMove(window.data(), QPoint(26,218), waitInterval); + QTest::mouseMove(window.data(), QPoint(28,219), waitInterval); + QTest::mouseMove(window.data(), QPoint(31,219), waitInterval); + QTest::mouseMove(window.data(), QPoint(39,219), waitInterval); + + // first move beyond threshold does not trigger drag + QVERIFY(!pathview->isMoving()); + QVERIFY(!pathview->isDragging()); + QCOMPARE(movingSpy.count(), 0); + QCOMPARE(moveStartedSpy.count(), 0); + QCOMPARE(moveEndedSpy.count(), 0); + QCOMPARE(fflickingSpy.count(), 0); + QCOMPARE(fflickStartedSpy.count(), 0); + QCOMPARE(fflickEndedSpy.count(), 0); + + // no further moves after the initial move beyond threshold + QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(53,219)); + QTRY_COMPARE(movingSpy.count(), 2); + QTRY_COMPARE(moveEndedSpy.count(), 1); + QCOMPARE(moveStartedSpy.count(), 1); + // Flickable should not handle this + QEXPECT_FAIL("", "QTBUG-37859", Abort); + QCOMPARE(fflickingSpy.count(), 0); + QCOMPARE(fflickStartedSpy.count(), 0); + QCOMPARE(fflickEndedSpy.count(), 0); } QTEST_MAIN(tst_QQuickPathView) |