From 8f19bab7b6963a05c48938eb4660bc0457f659f7 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Wed, 21 Dec 2022 14:30:36 +0100 Subject: [PATCH] QTextImageHandler: Add test coverage for resources and URLs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If an image source in HTML is specified via local file name or resource path (i.e. without qrc prefix), then the correct image is loaded. With file:/ or qrc:/ schema however, the image is either not loaded at all, or the 2x image is not loaded. The qt_findAtNxFile helper in qicon.cpp gets a URL path, but expects a file path (that can be tested with QFile::exists). Task-number: QTBUG-109212 Change-Id: Ibcf687c69b3e53a10f21d718d28c8177a02d6be6 Reviewed-by: Tor Arne Vestbø (cherry picked from commit c9cf4037cafe22aa20cfea6efe1c6a4c7211d21f) Reviewed-by: Qt Cherry-pick Bot --- tests/auto/gui/text/qtextimagehandler/CMakeLists.txt | 7 +++++++ .../text/qtextimagehandler/tst_qtextimagehandler.cpp | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/tests/auto/gui/text/qtextimagehandler/CMakeLists.txt b/tests/auto/gui/text/qtextimagehandler/CMakeLists.txt index c9d20fe9563..45feab12f11 100644 --- a/tests/auto/gui/text/qtextimagehandler/CMakeLists.txt +++ b/tests/auto/gui/text/qtextimagehandler/CMakeLists.txt @@ -14,3 +14,10 @@ qt_internal_add_test(tst_qtextimagehandler TESTDATA ${test_data} ) + +qt_internal_add_resource(tst_qtextimagehandler "qtextimagehandler" + PREFIX + "/" + FILES + ${test_data} +) diff --git a/tests/auto/gui/text/qtextimagehandler/tst_qtextimagehandler.cpp b/tests/auto/gui/text/qtextimagehandler/tst_qtextimagehandler.cpp index ed01db4e2d9..ca35cf0c75c 100644 --- a/tests/auto/gui/text/qtextimagehandler/tst_qtextimagehandler.cpp +++ b/tests/auto/gui/text/qtextimagehandler/tst_qtextimagehandler.cpp @@ -42,6 +42,9 @@ void tst_QTextImageHandler::loadAtNImages_data() QTest::addColumn("imageFile"); QTest::addRow("file") << QFINDTESTDATA("data/image.png"); + QTest::addRow("file_url") << QString("file:/") + QFINDTESTDATA("data/image.png"); + QTest::addRow("resource") << ":/data/image.png"; + QTest::addRow("qrc_url") << "qrc:/data/image.png"; } void tst_QTextImageHandler::loadAtNImages() @@ -68,6 +71,13 @@ void tst_QTextImageHandler::loadAtNImages() p.end(); QVERIFY(!img.isNull()); const auto expectedColor = dpr == 1 ? Qt::red : Qt::green; +#ifdef Q_OS_ANDROID // On Android, file:/ fails completely + QEXPECT_FAIL("file_url", "file:/ schema not handled - QTBUG-109212", Continue); +#else + if (dpr != 1) + QEXPECT_FAIL("file_url", "Nx images not resolved for file:/ schema - QTBUG-109212", Continue); +#endif + QEXPECT_FAIL("qrc_url", "qrc:/ schema not handled - QTBUG-109212", Continue); QCOMPARE(img.pixelColor(0, 0), expectedColor); } }