summaryrefslogtreecommitdiffstats
path: root/tests/auto/pdfquick/multipageview
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/pdfquick/multipageview')
-rw-r--r--tests/auto/pdfquick/multipageview/BLACKLIST10
-rw-r--r--tests/auto/pdfquick/multipageview/CMakeLists.txt4
-rw-r--r--tests/auto/pdfquick/multipageview/data/jumpOnDocumentReady.qml18
-rw-r--r--tests/auto/pdfquick/multipageview/tst_multipageview.cpp141
4 files changed, 142 insertions, 31 deletions
diff --git a/tests/auto/pdfquick/multipageview/BLACKLIST b/tests/auto/pdfquick/multipageview/BLACKLIST
index b608bef1c..9012902f6 100644
--- a/tests/auto/pdfquick/multipageview/BLACKLIST
+++ b/tests/auto/pdfquick/multipageview/BLACKLIST
@@ -1,3 +1,7 @@
-# QTBUG-106072
-[password]
-windows
+# QTBUG-111306
+[navigation:click links and go back, twice]
+android
+
+# QTBUG-111306
+[navigation:click two links in series and then go back]
+android
diff --git a/tests/auto/pdfquick/multipageview/CMakeLists.txt b/tests/auto/pdfquick/multipageview/CMakeLists.txt
index 283bebc79..50f7d7d8f 100644
--- a/tests/auto/pdfquick/multipageview/CMakeLists.txt
+++ b/tests/auto/pdfquick/multipageview/CMakeLists.txt
@@ -20,11 +20,11 @@ qt_internal_add_test(tst_multipageview
qt_internal_extend_target(tst_multipageview CONDITION ANDROID OR IOS
DEFINES
- QT_QMLTEST_DATADIR=\\\":/data\\\"
+ QT_QMLTEST_DATADIR=":/data"
)
qt_internal_extend_target(tst_multipageview CONDITION NOT ANDROID AND NOT IOS
DEFINES
- QT_QMLTEST_DATADIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}/data\\\"
+ QT_QMLTEST_DATADIR="${CMAKE_CURRENT_SOURCE_DIR}/data"
)
diff --git a/tests/auto/pdfquick/multipageview/data/jumpOnDocumentReady.qml b/tests/auto/pdfquick/multipageview/data/jumpOnDocumentReady.qml
new file mode 100644
index 000000000..ce74f5ed8
--- /dev/null
+++ b/tests/auto/pdfquick/multipageview/data/jumpOnDocumentReady.qml
@@ -0,0 +1,18 @@
+import QtQuick
+import QtQuick.Pdf
+
+PdfMultiPageView {
+ id: view
+ width: 480
+ height: 480
+
+ document: PdfDocument {
+ id: document
+ onStatusChanged: {
+ if(status === PdfDocument.Ready)
+ view.goToPage(2)
+ }
+ }
+
+ Component.onCompleted: document.source = "bookmarksAndLinks.pdf"
+}
diff --git a/tests/auto/pdfquick/multipageview/tst_multipageview.cpp b/tests/auto/pdfquick/multipageview/tst_multipageview.cpp
index eb70ebf17..71c09077c 100644
--- a/tests/auto/pdfquick/multipageview/tst_multipageview.cpp
+++ b/tests/auto/pdfquick/multipageview/tst_multipageview.cpp
@@ -1,17 +1,20 @@
// Copyright (C) 2022 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QSignalSpy>
#include <QTest>
#include <QtCore/QLoggingCategory>
#include <QtGui/QClipboard>
#include <QtGui/QPointingDevice>
+#include <QtGui/QStyleHints>
#include <QtQuick/QQuickView>
#include <QtPdfQuick/private/qquickpdflinkmodel_p.h>
#include <QtPdfQuick/private/qquickpdfsearchmodel_p.h>
#include <QtPdfQuick/private/qquickpdfpageimage_p.h>
#include "../shared/util.h"
+using namespace Qt::StringLiterals;
+
Q_LOGGING_CATEGORY(lcTests, "qt.pdf.tests")
class tst_MultiPageView : public QQuickDataTest
@@ -26,6 +29,8 @@ private Q_SLOTS:
void password();
void selectionAndClipboard();
void search();
+ void pinchDragPinch();
+ void jumpOnDocumentReady();
public:
enum NavigationAction {
@@ -57,7 +62,7 @@ void tst_MultiPageView::internalLink_data()
QTest::addColumn<qreal>("expectedZoom");
QTest::addColumn<QPoint>("expectedScroll");
- QTest::newRow("first link") << 0 << 1 << qreal(1) << QPoint(134, 1276);
+ QTest::newRow("first link") << 0 << 1 << qreal(1) << QPoint(134, 1286);
// TODO fails because it zooms out, and the view leaves gaps between pages currently
// QTest::newRow("second link") << 1 << 2 << qreal(0.5) << QPoint(0, 717);
}
@@ -73,7 +78,7 @@ void tst_MultiPageView::internalLink()
QVERIFY(showView(window, testFileUrl("multiPageView.qml")));
QQuickItem *pdfView = window.rootObject();
QVERIFY(pdfView);
- pdfView->setProperty("source", "bookmarksAndLinks.pdf");
+ pdfView->setProperty("source", testFileUrl("bookmarksAndLinks.pdf"));
QTRY_COMPARE(pdfView->property("currentPageRenderingStatus").toInt(), QQuickPdfPageImage::Ready);
QQuickItem *table = static_cast<QQuickItem *>(findFirstChild(pdfView, "QQuickTableView"));
@@ -257,27 +262,27 @@ void tst_MultiPageView::password()
// actual QPdfDocument::pageCountChanged(int), for comparison with the illusory QQuickPdfDocument::pageCountChanged
QVERIFY(extPageCountChangedSpy.isValid());
- QVERIFY(pdfView->setProperty("source", u"pdf-sample.protected.pdf"_qs));
+ QVERIFY(pdfView->setProperty("source", testFileUrl(u"pdf-sample.protected.pdf"_s)));
- QTRY_COMPARE(passwordRequiredSpy.count(), 1);
+ QTRY_COMPARE(passwordRequiredSpy.size(), 1);
qCDebug(lcTests) << "error while awaiting password" << doc->error()
- << "passwordRequired count" << passwordRequiredSpy.count()
- << "statusChanged count" << statusChangedSpy.count();
+ << "passwordRequired count" << passwordRequiredSpy.size()
+ << "statusChanged count" << statusChangedSpy.size();
QCOMPARE(doc->property("status").toInt(), int(QPdfDocument::Status::Error));
- QCOMPARE(pageCountChangedSpy.count(), 0);
- QCOMPARE(extPageCountChangedSpy.count(), 0);
- QCOMPARE(statusChangedSpy.count(), 2); // Loading and then Error
+ QCOMPARE(pageCountChangedSpy.size(), 0);
+ QCOMPARE(extPageCountChangedSpy.size(), 0);
+ QCOMPARE(statusChangedSpy.size(), 2); // Loading and then Error
statusChangedSpy.clear();
- QVERIFY(doc->setProperty("password", u"Qt"_qs));
- QCOMPARE(passwordChangedSpy.count(), 1);
+ QVERIFY(doc->setProperty("password", u"Qt"_s));
+ QCOMPARE(passwordChangedSpy.size(), 1);
QTRY_COMPARE(doc->property("status").toInt(), int(QPdfDocument::Status::Ready));
qCDebug(lcTests) << "after setPassword" << doc->error()
- << "passwordChanged count" << passwordChangedSpy.count()
- << "statusChanged count" << statusChangedSpy.count()
- << "pageCountChanged count" << pageCountChangedSpy.count();
- QCOMPARE(statusChangedSpy.count(), 2); // Loading and then Ready
- QCOMPARE(pageCountChangedSpy.count(), 1);
- QCOMPARE(extPageCountChangedSpy.count(), pageCountChangedSpy.count());
+ << "passwordChanged count" << passwordChangedSpy.size()
+ << "statusChanged count" << statusChangedSpy.size()
+ << "pageCountChanged count" << pageCountChangedSpy.size();
+ QCOMPARE(statusChangedSpy.size(), 2); // Loading and then Ready
+ QCOMPARE(pageCountChangedSpy.size(), 1);
+ QCOMPARE(extPageCountChangedSpy.size(), pageCountChangedSpy.size());
}
void tst_MultiPageView::selectionAndClipboard()
@@ -288,13 +293,13 @@ void tst_MultiPageView::selectionAndClipboard()
QVERIFY(pdfView);
QQuickPdfDocument *doc = pdfView->property("document").value<QQuickPdfDocument*>();
QVERIFY(doc);
- QVERIFY(doc->setProperty("password", u"Qt"_qs));
- QVERIFY(pdfView->setProperty("source", u"pdf-sample.protected.pdf"_qs));
+ QVERIFY(doc->setProperty("password", u"Qt"_s));
+ QVERIFY(pdfView->setProperty("source", testFileUrl((u"pdf-sample.protected.pdf"_s))));
QTRY_COMPARE(pdfView->property("currentPageRenderingStatus").toInt(), QQuickPdfPageImage::Ready);
QVERIFY(QMetaObject::invokeMethod(pdfView, "selectAll"));
QString sel = pdfView->property("selectedText").toString();
- QCOMPARE(sel.length(), 1073);
+ QCOMPARE(sel.size(), 1073);
#if QT_CONFIG(clipboard)
QClipboard *clip = qApp->clipboard();
@@ -316,8 +321,8 @@ void tst_MultiPageView::search()
QTRY_COMPARE(pdfView->width(), 200);
QQuickPdfDocument *doc = pdfView->property("document").value<QQuickPdfDocument*>();
QVERIFY(doc);
- QVERIFY(doc->setProperty("password", u"Qt"_qs));
- QVERIFY(pdfView->setProperty("source", u"pdf-sample.protected.pdf"_qs));
+ QVERIFY(doc->setProperty("password", u"Qt"_s));
+ QVERIFY(pdfView->setProperty("source", testFileUrl(u"pdf-sample.protected.pdf"_s)));
QTRY_COMPARE(pdfView->property("currentPageRenderingStatus").toInt(), QQuickPdfPageImage::Ready);
QPdfSearchModel *searchModel = pdfView->property("searchModel").value<QPdfSearchModel*>();
QVERIFY(searchModel);
@@ -328,17 +333,17 @@ void tst_MultiPageView::search()
QObject *multiline = findFirstChild(firstPage, "QQuickPathMultiline");
QVERIFY(multiline);
- pdfView->setProperty("searchString", u"PDF"_qs);
+ pdfView->setProperty("searchString", u"PDF"_s);
QTRY_COMPARE(searchModel->rowCount(QModelIndex()), 7); // occurrences of the word "PDF" in this file
const int count = searchModel->rowCount(QModelIndex());
QList<QList<QPointF>> resultOutlines = multiline->property("paths").value<QList<QList<QPointF>>>();
- QCOMPARE(resultOutlines.count(), 7);
+ QCOMPARE(resultOutlines.size(), 7);
QPoint contentPos = tableViewContentPos(table);
int movements = 0;
for (int i = 0; i < count; ++i) {
// only one page, so IndexOnPage data is the same as overall index
QCOMPARE(i, searchModel->data(searchModel->index(i), int(QPdfSearchModel::Role::IndexOnPage)).toInt());
- QCOMPARE(resultOutlines.at(i).count(), 5); // 5-point polygon is a rectangle (including drawing back to the start, to close it)
+ QCOMPARE(resultOutlines.at(i).size(), 5); // 5-point polygon is a rectangle (including drawing back to the start, to close it)
QCOMPARE(resultOutlines.at(i).first(), searchModel->data(searchModel->index(i), int(QPdfSearchModel::Role::Location)).toPointF());
QVERIFY(QMetaObject::invokeMethod(pdfView, "searchForward"));
@@ -353,5 +358,89 @@ void tst_MultiPageView::search()
QVERIFY(movements > 4);
}
+void tst_MultiPageView::pinchDragPinch()
+{
+ qputenv("QML_NO_TOUCH_COMPRESSION", "1");
+ QQuickView window;
+ QVERIFY(showView(window, testFileUrl("multiPageView.qml")));
+ QQuickItem *pdfView = window.rootObject();
+ QVERIFY(pdfView);
+ pdfView->setProperty("source", testFileUrl("bookmarksAndLinks.pdf"));
+ QTRY_COMPARE(pdfView->property("currentPageRenderingStatus").toInt(), QQuickPdfPageImage::Ready);
+ QQuickItem *table = static_cast<QQuickItem *>(findFirstChild(pdfView, "QQuickTableView"));
+ QVERIFY(table);
+ QQuickItem *firstPage = tableViewItemAtCell(table, 0, 0);
+ QVERIFY(firstPage);
+ QQuickItem *paper = firstPage->childAt(10, 10);
+ QVERIFY(paper);
+ QQuickPdfPageImage *image = firstPage->findChild<QQuickPdfPageImage *>();
+ QVERIFY(image);
+
+ auto pinch = [&window, paper, this]() {
+ const int threshold = QGuiApplication::styleHints()->startDragDistance();
+ const int movement = 100;
+ QCOMPARE_GT(movement, threshold);
+ const qreal initialScale = paper->scale();
+ QPoint p0(100, 200);
+ QPoint p1(200, 200);
+ QTest::QTouchEventSequence seq = QTest::touchEvent(&window, touchscreen.get());
+ seq.press(0, p0, &window).commit();
+ seq.stationary(0).press(1, p1, &window).commit();
+ p1.setX(p1.x() + movement);
+ QSignalSpy frameSwappedSpy(&window, &QQuickWindow::frameSwapped);
+ seq.stationary(0).move(1, p1, &window).commit();
+ // after a frame is rendered, the PinchHandler ought to be active
+ // (but verifying it would require private API)
+ QTRY_VERIFY(frameSwappedSpy.size() > 0);
+ QTRY_COMPARE(paper->scale(), initialScale);
+
+ for (int i = 1; i <= 2; ++i) {
+ p1.setX(p1.x() + movement);
+ seq.stationary(0).move(1, p1, &window).commit();
+ QTRY_COMPARE(paper->scale(), initialScale + i * 0.5);
+ }
+ seq.release(0, p0, &window).release(1, p1, &window).commit();
+ };
+
+ auto drag = [&window, table, this]() {
+ const int movement = 100;
+ QPoint p0(200, 200);
+ QTest::QTouchEventSequence seq = QTest::touchEvent(&window, touchscreen.get());
+ seq.press(0, p0, &window).commit();
+ p0.setY(p0.y() + movement);
+ seq.move(0, p0, &window).commit();
+ p0.setY(p0.y() + movement);
+ seq.move(0, p0, &window).commit();
+ seq.release(0, p0, &window).commit();
+ QTRY_COMPARE(table->property("moving"), false);
+ };
+
+ pinch();
+ qCDebug(lcTests) << "new scale" << pdfView->property("renderScale").toReal();
+ QTRY_COMPARE(pdfView->property("renderScale").toReal(), 2);
+
+ drag();
+ QCOMPARE(pdfView->property("renderScale").toReal(), 2);
+
+ pinch();
+ qCDebug(lcTests) << "new scale" << pdfView->property("renderScale").toReal();
+ QTRY_COMPARE(pdfView->property("renderScale").toReal(), 4);
+
+ // wait for rendering to be done before we exit: if we delete the document
+ // prematurely, QPdfIOHandler might access a dangling pointer
+ QTRY_COMPARE(image->status(), QQuickPdfPageImage::Ready);
+}
+
+void tst_MultiPageView::jumpOnDocumentReady() // QTBUG-119416
+{
+ QQuickView window;
+ QVERIFY(showView(window, testFileUrl("jumpOnDocumentReady.qml")));
+ QQuickItem *pdfView = window.rootObject();
+ QVERIFY(pdfView);
+
+ // QML calls view.goToPage(2): verify that it eventually happens
+ QTRY_COMPARE(pdfView->property("currentPage").toInt(), 2);
+}
+
QTEST_MAIN(tst_MultiPageView)
#include "tst_multipageview.moc"