From 978550b6c75b204fad433437d153794ae98eea9f Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Tue, 7 Feb 2012 17:52:52 +1000 Subject: Resolve StyledText img tags relative to baseUrl. Change-Id: I954195d52330c65e851b7c0fcdb6c8dabf29335d Reviewed-by: Yann Bodson --- tests/auto/qtquick2/qquicktext/tst_qquicktext.cpp | 83 +++++++++++++++++++++++ 1 file changed, 83 insertions(+) (limited to 'tests/auto/qtquick2/qquicktext/tst_qquicktext.cpp') diff --git a/tests/auto/qtquick2/qquicktext/tst_qquicktext.cpp b/tests/auto/qtquick2/qquicktext/tst_qquicktext.cpp index 96449c00cc..8e3a1f4864 100644 --- a/tests/auto/qtquick2/qquicktext/tst_qquicktext.cpp +++ b/tests/auto/qtquick2/qquicktext/tst_qquicktext.cpp @@ -108,6 +108,8 @@ private slots: void lineLaidOut(); + void imgTagsBaseUrl_data(); + void imgTagsBaseUrl(); void imgTagsAlign_data(); void imgTagsAlign(); void imgTagsMultipleImages(); @@ -1549,6 +1551,87 @@ void tst_qquicktext::lineLaidOut() delete canvas; } +void tst_qquicktext::imgTagsBaseUrl_data() +{ + QTest::addColumn("src"); + QTest::addColumn("baseUrl"); + QTest::addColumn("contextUrl"); + QTest::addColumn("imgHeight"); + + QTest::newRow("absolute local") + << testFileUrl("images/heart200.png") + << QUrl() + << QUrl() + << 181.; + QTest::newRow("relative local context 1") + << QUrl("images/heart200.png") + << QUrl() + << testFileUrl("/app.qml") + << 181.; + QTest::newRow("relative local context 2") + << QUrl("heart200.png") + << QUrl() + << testFileUrl("images/app.qml") + << 181.; + QTest::newRow("relative local base 1") + << QUrl("images/heart200.png") + << testFileUrl("") + << testFileUrl("nonexistant/app.qml") + << 181.; + QTest::newRow("relative local base 2") + << QUrl("heart200.png") + << testFileUrl("images/") + << testFileUrl("nonexistant/app.qml") + << 181.; + QTest::newRow("base relative to local context") + << QUrl("heart200.png") + << testFileUrl("images/") + << testFileUrl("/app.qml") + << 181.; + + QTest::newRow("absolute remote") + << QUrl("http://127.0.0.1:14453/images/heart200.png") + << QUrl() + << QUrl() + << 181.; + QTest::newRow("relative remote base 1") + << QUrl("images/heart200.png") + << QUrl("http://127.0.0.1:14453/") + << testFileUrl("nonexistant/app.qml") + << 181.; + QTest::newRow("relative remote base 2") + << QUrl("heart200.png") + << QUrl("http://127.0.0.1:14453/images/") + << testFileUrl("nonexistant/app.qml") + << 181.; +} + +void tst_qquicktext::imgTagsBaseUrl() +{ + QFETCH(QUrl, src); + QFETCH(QUrl, baseUrl); + QFETCH(QUrl, contextUrl); + QFETCH(qreal, imgHeight); + + TestHTTPServer server(14453); + server.serveDirectory(testFile("")); + + QByteArray baseUrlFragment; + if (!baseUrl.isEmpty()) + baseUrlFragment = "; baseUrl: \"" + baseUrl.toEncoded() + "\""; + QByteArray componentStr = "import QtQuick 2.0\nText { text: \"This is a test \"" + baseUrlFragment + " }"; + + QDeclarativeComponent component(&engine); + component.setData(componentStr, contextUrl); + QScopedPointer object(component.create()); + QQuickText *textObject = qobject_cast(object.data()); + QVERIFY(textObject); + + QCoreApplication::processEvents(); + + QTRY_COMPARE(textObject->height(), imgHeight); +} + void tst_qquicktext::imgTagsAlign_data() { QTest::addColumn("src"); -- cgit v1.2.3