diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2019-07-03 14:35:10 +0200 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2019-07-03 15:18:01 +0200 |
commit | 2149842f7b147e78fbc167c0bc657a9333fde7c2 (patch) | |
tree | 4453a99d2a20960abc9f59265831ef9682cecc1e /tests | |
parent | 0f2178a7e3cba4992f8b6e32927534daa5c6ee7e (diff) |
Intercept image source url
Fixes: QTBUG-55027
Task-number: QTBUG-76879
Change-Id: Id0c7b33cf22827ebc984c4ee848ef4f63c359b20
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/quick/qquickimage/tst_qquickimage.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickimage/tst_qquickimage.cpp b/tests/auto/quick/qquickimage/tst_qquickimage.cpp index d1f46a3912..c722f2fc2c 100644 --- a/tests/auto/quick/qquickimage/tst_qquickimage.cpp +++ b/tests/auto/quick/qquickimage/tst_qquickimage.cpp @@ -45,6 +45,7 @@ #include <QQuickWindow> #include <QQuickView> #include <QQuickImageProvider> +#include <QQmlAbstractUrlInterceptor> #include "../../shared/util.h" #include "../../shared/testhttpserver.h" @@ -95,6 +96,7 @@ private slots: void highDpiFillModesAndSizes_data(); void highDpiFillModesAndSizes(); void hugeImages(); + void urlInterceptor(); private: QQmlEngine engine; @@ -1100,6 +1102,36 @@ void tst_qquickimage::hugeImages() QCOMPARE(contents.pixel(199, 99), qRgba(0, 0, 255, 255)); } + +class MyInterceptor : public QQmlAbstractUrlInterceptor +{ +public: + MyInterceptor(QUrl url) : QQmlAbstractUrlInterceptor(), m_url(url) {} + QUrl intercept(const QUrl &url, QQmlAbstractUrlInterceptor::DataType type) + { + if (url.scheme() == "interceptthis") + return m_url; + return url; + } + + QUrl m_url; +}; + +void tst_qquickimage::urlInterceptor() +{ + QQmlEngine engine; + MyInterceptor interceptor {testFileUrl("colors.png")}; + engine.setUrlInterceptor(&interceptor); + + QQmlComponent c(&engine); + + c.setData("import QtQuick 2.12; Image { objectName: \"item\"; source: width == 0 ? \"interceptthis:doesNotExist\" : \"interceptthis:doesNotExist\"}", QUrl{}); + QScopedPointer<QQuickImage> object { qobject_cast<QQuickImage*>(c.create())}; + QVERIFY(object); + QTRY_COMPARE(object->status(), QQuickImage::Ready); + QTRY_COMPARE(object->progress(), 1.0); +} + QTEST_MAIN(tst_qquickimage) #include "tst_qquickimage.moc" |