From 0b7e479235aec74f051af4d5ef95e74753b59c6d Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Fri, 22 Feb 2019 18:13:34 +0100 Subject: Create import directory from intercepted URL, not orignial one If the qmldir URL got intercepted, we should use the intercepted URL to get to the contents to be loaded. Fixes: QTBUG-73843 Change-Id: I51715575e767ed429a8237517f47196677409fe0 Reviewed-by: Simon Hausmann --- tests/auto/qml/qqmlimport/data/interceptQmldir.qml | 7 ++++++ .../auto/qml/qqmlimport/data/intercepted/View.qml | 5 ++++ tests/auto/qml/qqmlimport/data/intercepted/qmldir | 2 ++ tests/auto/qml/qqmlimport/tst_qqmlimport.cpp | 28 ++++++++++++++++++++++ 4 files changed, 42 insertions(+) create mode 100644 tests/auto/qml/qqmlimport/data/interceptQmldir.qml create mode 100644 tests/auto/qml/qqmlimport/data/intercepted/View.qml create mode 100644 tests/auto/qml/qqmlimport/data/intercepted/qmldir (limited to 'tests/auto/qml') diff --git a/tests/auto/qml/qqmlimport/data/interceptQmldir.qml b/tests/auto/qml/qqmlimport/data/interceptQmldir.qml new file mode 100644 index 0000000000..bf485b2282 --- /dev/null +++ b/tests/auto/qml/qqmlimport/data/interceptQmldir.qml @@ -0,0 +1,7 @@ +import QtQml 2.2 + +import "$(INTERCEPT)" as Intercepted + +QtObject { + property QtObject view: Intercepted.View {} +} diff --git a/tests/auto/qml/qqmlimport/data/intercepted/View.qml b/tests/auto/qml/qqmlimport/data/intercepted/View.qml new file mode 100644 index 0000000000..92aa3af95a --- /dev/null +++ b/tests/auto/qml/qqmlimport/data/intercepted/View.qml @@ -0,0 +1,5 @@ +import QtQml 2.2 + +QtObject { + property int foo: 12 +} diff --git a/tests/auto/qml/qqmlimport/data/intercepted/qmldir b/tests/auto/qml/qqmlimport/data/intercepted/qmldir new file mode 100644 index 0000000000..ab31de73d8 --- /dev/null +++ b/tests/auto/qml/qqmlimport/data/intercepted/qmldir @@ -0,0 +1,2 @@ +module SomeModule +View 1.0 View.qml diff --git a/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp b/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp index 70aaa9678e..a3cb68fdcb 100644 --- a/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp +++ b/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -43,6 +44,7 @@ private slots: void uiFormatLoading(); void completeQmldirPaths_data(); void completeQmldirPaths(); + void interceptQmldir(); void cleanup(); }; @@ -185,6 +187,32 @@ void tst_QQmlImport::completeQmldirPaths() QCOMPARE(QQmlImports::completeQmldirPaths(uri, basePaths, majorVersion, minorVersion), expectedPaths); } +class QmldirUrlInterceptor : public QQmlAbstractUrlInterceptor { +public: + QUrl intercept(const QUrl &url, DataType type) override + { + if (type != UrlString && !url.isEmpty() && url.isValid()) { + QString str = url.toString(QUrl::None); + return str.replace(QStringLiteral("$(INTERCEPT)"), QStringLiteral("intercepted")); + } + return url; + } +}; + +void tst_QQmlImport::interceptQmldir() +{ + QQmlEngine engine; + QmldirUrlInterceptor interceptor; + engine.setUrlInterceptor(&interceptor); + + QQmlComponent component(&engine); + component.loadUrl(testFileUrl("interceptQmldir.qml")); + QVERIFY(component.isReady()); + QScopedPointer obj(component.create()); + QVERIFY(!obj.isNull()); +} + + QTEST_MAIN(tst_QQmlImport) #include "tst_qqmlimport.moc" -- cgit v1.2.3