summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2020-04-17 23:23:43 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2022-09-01 06:09:54 +0200
commit2d8c8ac02e8afed8d99996e3d53cacd982badfeb (patch)
tree67373ff0b06e4aadfdb80e8fcc504b132e8ec56c /tests
parent1f7ced8bc0d3c4156648b99b360580b5420acbdc (diff)
Add tst_MultiPageView::navigation() test
The navigation() test is a high-level one to verify that the navigation stack works and that the TableView jumps to the expected locations inside the document when we go to pages, click links and use the forward() and back() methods. It's similar to the internalLink() test, but more programmable. Pick-to: 6.4 Change-Id: I337e2ae283213238288a172d1bab3df07a1395e0 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/pdfquick/multipageview/data/multiPageViewWithFeedback.qml18
-rw-r--r--tests/auto/pdfquick/multipageview/data/qpdfwriter.pdfbin0 -> 33645 bytes
-rw-r--r--tests/auto/pdfquick/multipageview/tst_multipageview.cpp120
3 files changed, 138 insertions, 0 deletions
diff --git a/tests/auto/pdfquick/multipageview/data/multiPageViewWithFeedback.qml b/tests/auto/pdfquick/multipageview/data/multiPageViewWithFeedback.qml
new file mode 100644
index 000000000..93a556c97
--- /dev/null
+++ b/tests/auto/pdfquick/multipageview/data/multiPageViewWithFeedback.qml
@@ -0,0 +1,18 @@
+import QtQuick
+import QtQuick.Pdf
+
+PdfMultiPageView {
+ id: view
+ property point hoverPos: hover.point.position
+ width: 640; height: 480
+ document: PdfDocument { }
+
+ // mouse hover feedback for test development
+ Rectangle {
+ width: 200
+ height: hoverPosLabel.implicitHeight + 12
+ color: "beige"
+ Text { id: hoverPosLabel; x: 6; y: 6; text: view.hoverPos.x + ", " + view.hoverPos.y }
+ }
+ HoverHandler { id: hover }
+}
diff --git a/tests/auto/pdfquick/multipageview/data/qpdfwriter.pdf b/tests/auto/pdfquick/multipageview/data/qpdfwriter.pdf
new file mode 100644
index 000000000..4abc76f6d
--- /dev/null
+++ b/tests/auto/pdfquick/multipageview/data/qpdfwriter.pdf
Binary files differ
diff --git a/tests/auto/pdfquick/multipageview/tst_multipageview.cpp b/tests/auto/pdfquick/multipageview/tst_multipageview.cpp
index fd58c7e24..eb70ebf17 100644
--- a/tests/auto/pdfquick/multipageview/tst_multipageview.cpp
+++ b/tests/auto/pdfquick/multipageview/tst_multipageview.cpp
@@ -21,10 +21,31 @@ class tst_MultiPageView : public QQuickDataTest
private Q_SLOTS:
void internalLink_data();
void internalLink();
+ void navigation_data();
+ void navigation();
void password();
void selectionAndClipboard();
void search();
+public:
+ enum NavigationAction {
+ Back,
+ Forward,
+ GotoPage,
+ GotoLocation,
+ ClickLink
+ };
+ Q_ENUM(NavigationAction)
+
+ struct NavigationCommand {
+ NavigationAction action;
+ int index;
+ QPointF location;
+ qreal zoom;
+ QPointF expectedContentPos;
+ int expectedCurrentPage;
+ };
+
private:
QScopedPointer<QPointingDevice> touchscreen = QScopedPointer<QPointingDevice>(QTest::createTouchDevice());
};
@@ -111,6 +132,105 @@ void tst_MultiPageView::internalLink()
QCOMPARE(pdfView->property("renderScale").toReal(), linkZoom);
}
+void tst_MultiPageView::navigation_data()
+{
+ QTest::addColumn<QList<NavigationCommand>>("actions");
+ const int totalPageSpacing = 832; // 826 points + 6 px (rowSpacing)
+
+ QList<NavigationCommand> actions;
+ actions << NavigationCommand {NavigationAction::GotoPage, 2, {}, 0, {0, 1664}, 2}
+ << NavigationCommand {NavigationAction::GotoPage, 3, {}, 0, {0, 2496}, 3}
+ << NavigationCommand {NavigationAction::Back, 0, {}, 0, {0, 1664}, 2}
+ << NavigationCommand {NavigationAction::Back, 0, {}, 0, {0, 0}, 0};
+ QTest::newRow("goto and back") << actions;
+
+ actions.clear();
+ actions // first link is "More..." going to page 0, location 8, 740
+ << NavigationCommand {NavigationAction::ClickLink, 0, {465, 65}, 0, {0, 740}, 0}
+ << NavigationCommand {NavigationAction::Back, 0, {}, 0, {0, 0}, 0}
+ // link "setPdfVersion()" going to page 3, location 8, 295
+ << NavigationCommand {NavigationAction::ClickLink, 0, {255, 455}, 0, {0, totalPageSpacing * 3 + 295}, 3}
+ << NavigationCommand {NavigationAction::Back, 0, {}, 0, {0, 0}, 0};
+ QTest::newRow("click links and go back, twice") << actions;
+
+ actions.clear();
+ actions // first link is "More..." going to page 0, location 8, 740
+ << NavigationCommand {NavigationAction::ClickLink, 0, {465, 65}, 0, {0, 740}, 0}
+ // link "newPage()" going to page 1, location 8, 290
+ << NavigationCommand {NavigationAction::ClickLink, 0, {480, 40}, 0, {0, totalPageSpacing + 290}, 1} // fails, goes back to page 0
+ << NavigationCommand {NavigationAction::Back, 0, {}, 0, {8, 740}, 0}
+ << NavigationCommand {NavigationAction::Back, 0, {}, 0, {0, 0}, 0};
+ QTest::newRow("click two links in series and then go back") << actions;
+}
+
+void tst_MultiPageView::navigation()
+{
+ QFETCH(QList<NavigationCommand>, actions);
+
+ QQuickView window;
+ window.setColor(Qt::gray);
+ window.setSource(testFileUrl("multiPageViewWithFeedback.qml"));
+ QTRY_COMPARE(window.status(), QQuickView::Ready);
+ QQuickItem *pdfView = window.rootObject();
+ QVERIFY(pdfView);
+ QObject *doc = pdfView->property("document").value<QObject *>();
+ QVERIFY(doc);
+ doc->setProperty("source", testFileUrl("qpdfwriter.pdf"));
+ QQuickItem *table = static_cast<QQuickItem *>(findFirstChild(pdfView, "QQuickTableView"));
+ QVERIFY(table);
+ // Expect that contentY == destination y after a jump, for ease of comparison.
+ // 0.01 is close enough to 0 that we can compare int positions accurately,
+ // but nonzero so that QRectF::isValid() is true in tableView.positionViewAtCell()
+ table->setProperty("jumpLocationMargin", QPointF(0.01, 0.01));
+
+ window.show();
+ window.requestActivate();
+ QVERIFY(QTest::qWaitForWindowExposed(&window));
+
+ QTRY_COMPARE(table->property("contentHeight").toInt(), 3322);
+ QCOMPARE(table->property("contentY").toInt(), 0);
+
+ for (const NavigationCommand &nav : actions) {
+ switch (nav.action) {
+ case NavigationAction::Back:
+ QVERIFY(QMetaObject::invokeMethod(pdfView, "back"));
+ QCOMPARE(pdfView->property("forwardEnabled").toBool(), true);
+ break;
+ case NavigationAction::Forward:
+ QVERIFY(QMetaObject::invokeMethod(pdfView, "forward"));
+ QCOMPARE(pdfView->property("backEnabled").toBool(), true);
+ break;
+ case NavigationAction::GotoPage:
+ QVERIFY(QMetaObject::invokeMethod(pdfView, "goToPage",
+ Q_ARG(QVariant, QVariant(nav.index))));
+ QCOMPARE(pdfView->property("backEnabled").toBool(), true);
+ break;
+ case NavigationAction::GotoLocation:
+ QVERIFY(QMetaObject::invokeMethod(pdfView, "goToLocation",
+ Q_ARG(QVariant, QVariant(nav.index)),
+ Q_ARG(QVariant, QVariant(nav.location)),
+ Q_ARG(QVariant, QVariant(nav.zoom)) ));
+ break;
+ case NavigationAction::ClickLink:
+ // Link delegates don't exist until page rendering is done
+ QTRY_VERIFY(pdfView->property("currentPageRenderingStatus").toInt() == 1); // QQuickImage::Status::Ready
+ QTest::mouseClick(&window, Qt::LeftButton, Qt::NoModifier, nav.location.toPoint());
+ // Wait for the destination page to be rendered
+ QTRY_VERIFY(pdfView->property("currentPageRenderingStatus").toInt() == 1); // QQuickImage::Status::Ready
+ break;
+ }
+ qCDebug(lcTests) << "action" << nav.action << "index" << nav.index
+ << "contentX,Y" << table->property("contentX").toInt() << table->property("contentY").toInt()
+ << "expected" << nav.expectedContentPos;
+ QTRY_COMPARE(table->property("contentY").toInt(), nav.expectedContentPos.y());
+ // some minor side-to-side scrolling happens, in practice
+ QVERIFY(qAbs(table->property("contentX").toInt() - nav.expectedContentPos.x()) < 10);
+ QCOMPARE(pdfView->property("currentPage").toInt(), nav.expectedCurrentPage);
+ }
+
+ QCOMPARE(pdfView->property("backEnabled").toBool(), false);
+}
+
void tst_MultiPageView::password()
{
QQuickView window;