summaryrefslogtreecommitdiffstats
path: root/tests/test_messageview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_messageview.cpp')
-rw-r--r--tests/test_messageview.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/test_messageview.cpp b/tests/test_messageview.cpp
index 0c3353d..4b6bc4c 100644
--- a/tests/test_messageview.cpp
+++ b/tests/test_messageview.cpp
@@ -36,6 +36,8 @@ private slots:
void documentActuallyLoads();
void threadContentReachesThePage();
void dataUrlSubResourceStillBlocked();
+ void zoomIsClampedToARenderableRange();
+ void zoomSurvivesANewDocument();
private:
QWebEngineView *webViewOf(MessageView *view) const
@@ -175,5 +177,58 @@ void TestMessageView::dataUrlSubResourceStillBlocked()
QVERIFY(text.contains(QStringLiteral("visible-text")));
}
+void TestMessageView::zoomIsClampedToARenderableRange()
+{
+ // A factor outside the range leaves the pane unreadable, and the only way
+ // back is a menu entry the user can no longer read. A corrupt state file
+ // reaching setZoomFactor() must not be able to do that.
+ QCOMPARE(MessageView::clampZoom(100.0), MessageView::kMaxZoom);
+ QCOMPARE(MessageView::clampZoom(0.01), MessageView::kMinZoom);
+
+ // A missing or non-numeric state value converts to 0.0, and a hand-edited
+ // one can hold NaN or an infinity. None of those may reach the web view.
+ QCOMPARE(MessageView::clampZoom(0.0), MessageView::kDefaultZoom);
+ QCOMPARE(MessageView::clampZoom(-2.0), MessageView::kDefaultZoom);
+ QCOMPARE(MessageView::clampZoom(qQNaN()), MessageView::kDefaultZoom);
+ QCOMPARE(MessageView::clampZoom(qInf()), MessageView::kDefaultZoom);
+
+ // In-range values pass through untouched.
+ QCOMPARE(MessageView::clampZoom(1.4), 1.4);
+
+ MessageView view;
+ view.setZoomFactor(50.0);
+ QCOMPARE(view.zoomFactor(), MessageView::kMaxZoom);
+}
+
+void TestMessageView::zoomSurvivesANewDocument()
+{
+ // MainWindow persists whatever zoomFactor() reports and never reapplies it
+ // per render, which is only correct if the web view keeps the factor
+ // across setHtml(). Verified rather than assumed.
+ MessageView view;
+ QWebEngineView *web = webViewOf(&view);
+ QVERIFY(web);
+
+ view.setZoomFactor(1.5);
+
+ QSignalSpy loaded(web, &QWebEngineView::loadFinished);
+
+ ParsedMessage message;
+ message.ok = true;
+ message.from = QStringLiteral("Sender <sender@example.org>");
+ message.subject = QStringLiteral("Zoom");
+ message.plainBody = QStringLiteral("body text");
+
+ ThreadRenderItem item;
+ item.message = message;
+ item.cidPrefix = QStringLiteral("m0");
+ item.expanded = true;
+
+ view.showThread({ item });
+ QVERIFY(loaded.wait(15000));
+
+ QCOMPARE(view.zoomFactor(), 1.5);
+}
+
QTEST_MAIN(TestMessageView)
#include "test_messageview.moc"