diff --git a/tests/baseline/CMakeLists.txt b/tests/baseline/CMakeLists.txt
index dadfa1ba7d..df5d35863b 100644
--- a/tests/baseline/CMakeLists.txt
+++ b/tests/baseline/CMakeLists.txt
@@ -4,4 +4,5 @@ endif()
if(TARGET Qt::Network AND TARGET Qt::Widgets)
add_subdirectory(widgets)
add_subdirectory(stylesheet)
+ add_subdirectory(text)
endif()
diff --git a/tests/baseline/text/CMakeLists.txt b/tests/baseline/text/CMakeLists.txt
new file mode 100644
index 0000000000..707b3794b5
--- /dev/null
+++ b/tests/baseline/text/CMakeLists.txt
@@ -0,0 +1,16 @@
+list(APPEND test_data "./data")
+
+qt_internal_add_test(tst_baseline_text
+ SOURCES
+ ../shared/baselineprotocol.cpp ../shared/baselineprotocol.h ../shared/lookup3.cpp
+ ../shared/qbaselinetest.cpp ../shared/qbaselinetest.h
+ ../shared/qwidgetbaselinetest.cpp ../shared/qwidgetbaselinetest.h
+ tst_baseline_text.cpp
+ INCLUDE_DIRECTORIES
+ ../shared
+ PUBLIC_LIBRARIES
+ Qt::Gui
+ Qt::Widgets
+ Qt::Network
+ TESTDATA ${test_data}
+)
diff --git a/tests/baseline/text/data/empty.html b/tests/baseline/text/data/empty.html
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/tests/baseline/text/data/list_items_with_code.html b/tests/baseline/text/data/list_items_with_code.html
new file mode 100644
index 0000000000..f2823c8065
--- /dev/null
+++ b/tests/baseline/text/data/list_items_with_code.html
@@ -0,0 +1,8 @@
+
+
Header
+
+ Something (this is code something else)
+ Maybe this is code or not?
+ this is code and it seems to break
+ This has no code
+
diff --git a/tests/baseline/text/tst_baseline_text.cpp b/tests/baseline/text/tst_baseline_text.cpp
new file mode 100644
index 0000000000..363a2ef6cd
--- /dev/null
+++ b/tests/baseline/text/tst_baseline_text.cpp
@@ -0,0 +1,122 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include
+#include
+#include
+
+class tst_Text : public QWidgetBaselineTest
+{
+ Q_OBJECT
+
+public:
+ tst_Text();
+
+ void loadTestFiles();
+
+private slots:
+ void tst_render_data();
+ void tst_render();
+
+private:
+ QDir htmlDir;
+};
+
+tst_Text::tst_Text()
+{
+ QString baseDir = QFINDTESTDATA("data/empty.html");
+ htmlDir = QDir(QFileInfo(baseDir).path());
+}
+
+void tst_Text::loadTestFiles()
+{
+ QTest::addColumn("html");
+
+ QStringList htmlFiles;
+ // first add generic test files
+ for (const auto &qssFile : htmlDir.entryList({QStringLiteral("*.html")}, QDir::Files | QDir::Readable))
+ htmlFiles << htmlDir.absoluteFilePath(qssFile);
+
+ // then test-function specific files
+ const QString testFunction = QString(QTest::currentTestFunction()).remove("tst_").toLower();
+ if (htmlDir.cd(testFunction)) {
+ for (const auto &htmlFile : htmlDir.entryList({QStringLiteral("*.html")}, QDir::Files | QDir::Readable))
+ htmlFiles << htmlDir.absoluteFilePath(htmlFile);
+ htmlDir.cdUp();
+ }
+
+ for (const auto &htmlFile : htmlFiles) {
+ QFileInfo fileInfo(htmlFile);
+ QFile file(htmlFile);
+ file.open(QFile::ReadOnly);
+ QString html = QString::fromUtf8(file.readAll());
+ QBaselineTest::newRow(fileInfo.baseName().toUtf8()) << html;
+ }
+}
+
+void tst_Text::tst_render_data()
+{
+ loadTestFiles();
+}
+
+void tst_Text::tst_render()
+{
+ QFETCH(QString, html);
+
+ QTextDocument textDocument;
+ textDocument.setPageSize(QSizeF(800, 600));
+ textDocument.setHtml(html);
+
+ QImage image(800, 600, QImage::Format_ARGB32);
+ image.fill(Qt::white);
+
+ {
+ QPainter painter(&image);
+
+ QAbstractTextDocumentLayout::PaintContext context;
+ context.palette.setColor(QPalette::Text, Qt::black);
+ textDocument.documentLayout()->draw(&painter, context);
+ }
+
+ QBASELINE_TEST(image);
+}
+
+
+#define main _realmain
+QTEST_MAIN(tst_Text)
+#undef main
+
+int main(int argc, char *argv[])
+{
+ qSetGlobalQHashSeed(0); // Avoid rendering variations caused by QHash randomization
+
+ QBaselineTest::handleCmdLineArgs(&argc, &argv);
+ return _realmain(argc, argv);
+}
+
+#include "tst_baseline_text.moc"