diff options
author | Alan Alpert <aalpert@blackberry.com> | 2013-07-18 06:02:37 -0700 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-11-11 12:18:15 +0100 |
commit | 054e50babc340f1d8b6c037fca143f90dbd0c1f2 (patch) | |
tree | d15e6d1a746d28138bdf479024a51c94cb5fa8a2 /tests/auto/qml/qqmlengine | |
parent | 98c47db70a72a8afbd86afd355dadb1ce9113361 (diff) |
Intercept qmldir files with the url interceptor
There's another code path which loads qmldir files directly, and it did
not use the interceptor when available.
Note that this, like other interceptors, does not affect baseUrl and so
any other qmldir file still must have paths relative from the initial URL.
Change-Id: I620943c36d488d22fbaf1793514075d31ab76e3e
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'tests/auto/qml/qqmlengine')
6 files changed, 31 insertions, 1 deletions
diff --git a/tests/auto/qml/qqmlengine/data/interception/imports/Test.2/qmldir b/tests/auto/qml/qqmlengine/data/interception/imports/Test.2/qmldir new file mode 100644 index 0000000000..971812c162 --- /dev/null +++ b/tests/auto/qml/qqmlengine/data/interception/imports/Test.2/qmldir @@ -0,0 +1 @@ +This qmldir file is intentionally invalid, as the URL interception should prevent it being accessed. diff --git a/tests/auto/qml/qqmlengine/data/interception/module/intercepted/Intercepted.qml b/tests/auto/qml/qqmlengine/data/interception/module/intercepted/Intercepted.qml new file mode 100644 index 0000000000..5416ef5dcc --- /dev/null +++ b/tests/auto/qml/qqmlengine/data/interception/module/intercepted/Intercepted.qml @@ -0,0 +1,9 @@ +import QtQml 2.0 + +QtObject { + property url filePath: "doesNotExist.file" + property url resolvedUrl: Qt.resolvedUrl("doesNotExist.file"); + property url absoluteUrl: Qt.resolvedUrl("file:///doesNotExist.file"); + property string childString: "intercepted" + property string scriptString: "intercepted" +} diff --git a/tests/auto/qml/qqmlengine/data/interception/module/intercepted/comment b/tests/auto/qml/qqmlengine/data/interception/module/intercepted/comment new file mode 100644 index 0000000000..b10233e48d --- /dev/null +++ b/tests/auto/qml/qqmlengine/data/interception/module/intercepted/comment @@ -0,0 +1 @@ +Note that the paths are relative the the qmldir file in the actual module path, not the intercepted qmldir file diff --git a/tests/auto/qml/qqmlengine/data/interception/module/intercepted/qmldir b/tests/auto/qml/qqmlengine/data/interception/module/intercepted/qmldir new file mode 100644 index 0000000000..c5457b232a --- /dev/null +++ b/tests/auto/qml/qqmlengine/data/interception/module/intercepted/qmldir @@ -0,0 +1 @@ +TestObject 2.0 ../../module/intercepted/Intercepted.qml diff --git a/tests/auto/qml/qqmlengine/data/interception/module/urlInterceptor.qml b/tests/auto/qml/qqmlengine/data/interception/module/urlInterceptor.qml new file mode 100644 index 0000000000..b79a783582 --- /dev/null +++ b/tests/auto/qml/qqmlengine/data/interception/module/urlInterceptor.qml @@ -0,0 +1,3 @@ +import Test 2.0 //This import will be intercepted to make this file valid + +TestObject {} diff --git a/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp b/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp index 42e17d5624..004514d39c 100644 --- a/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp +++ b/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp @@ -680,6 +680,7 @@ void tst_qqmlengine::qtqmlModule() class CustomSelector : public QQmlAbstractUrlInterceptor { public: + CustomSelector(const QUrl &base):m_base(base){} virtual QUrl intercept(const QUrl &url, QQmlAbstractUrlInterceptor::DataType d) { if (url.scheme() != QStringLiteral("file")) @@ -687,6 +688,9 @@ public: if (!m_interceptionPoints.contains(d)) return url; + if (url.path().endsWith("Test.2/qmldir"))//Special case + return QUrl::fromLocalFile(m_base.path() + "interception/module/intercepted/qmldir"); + QString alteredPath = url.path(); int a = alteredPath.lastIndexOf('/'); if (a < 0) @@ -698,6 +702,7 @@ public: return ret; } QList<QQmlAbstractUrlInterceptor::DataType> m_interceptionPoints; + QUrl m_base; }; Q_DECLARE_METATYPE(QList<QQmlAbstractUrlInterceptor::DataType>); @@ -729,6 +734,15 @@ void tst_qqmlengine::urlInterceptor_data() << testFileUrl("interception/qmldir/intercepted/doesNotExist.file").toString() << QStringLiteral("file:///intercepted/doesNotExist.file"); + QTest::newRow("InterceptModule")//just a Test{}, needs to intercept the module import for it to work + << testFileUrl("interception/module/urlInterceptor.qml") + << (QList<QQmlAbstractUrlInterceptor::DataType>() << QQmlAbstractUrlInterceptor::QmldirFile ) + << testFileUrl("interception/module/intercepted/doesNotExist.file").toString() + << QStringLiteral("intercepted") + << QStringLiteral("intercepted") + << testFileUrl("interception/module/intercepted/doesNotExist.file").toString() + << QStringLiteral("file:///doesNotExist.file"); + QTest::newRow("InterceptStrings") << testFileUrl("interception/strings/urlInterceptor.qml") << (QList<QQmlAbstractUrlInterceptor::DataType>() << QQmlAbstractUrlInterceptor::UrlString) @@ -751,7 +765,8 @@ void tst_qqmlengine::urlInterceptor() QFETCH(QString, expectedAbsoluteUrl); QQmlEngine e; - CustomSelector cs; + e.setImportPathList(QStringList() << testFileUrl("interception/imports").toLocalFile()); + CustomSelector cs(testFileUrl("")); cs.m_interceptionPoints = interceptionPoint; e.setUrlInterceptor(&cs); QQmlComponent c(&e, testFile); //Note that this can get intercepted too |