From d6c5c3b529ca49452ecd74a7e139f189c7fb0efc Mon Sep 17 00:00:00 2001 From: Kevin Krammer Date: Mon, 12 Oct 2015 16:24:59 +0200 Subject: Pass Qt.include() URLs through the URL interceptor if present JavaScript files loaded by the Qt.include() function did not get passed through the QQmlEngine's URL interceptor, while those loaded by import statements did. Now both include variants have the resolved URL passed through the interceptor, e.g. an installed QQmlFileSelector Task-number: QTBUG-50483 Change-Id: Ife75e6b644687f3fb04048a311e570cdcbab8c6d Reviewed-by: Simon Hausmann --- .../qml/qqmlengine/data/interception/includes/Intercepted.qml | 5 +++++ .../qml/qqmlengine/data/interception/includes/intercepted.js | 3 +++ .../data/interception/includes/intercepted/included.js | 3 +++ .../data/interception/includes/intercepted/intercepted.js | 3 +++ .../interception/includes/intercepted/intercepted/included.js | 3 +++ .../qqmlengine/data/interception/includes/urlInterceptor.qml | 11 +++++++++++ tests/auto/qml/qqmlengine/tst_qqmlengine.cpp | 9 +++++++++ 7 files changed, 37 insertions(+) create mode 100644 tests/auto/qml/qqmlengine/data/interception/includes/Intercepted.qml create mode 100644 tests/auto/qml/qqmlengine/data/interception/includes/intercepted.js create mode 100644 tests/auto/qml/qqmlengine/data/interception/includes/intercepted/included.js create mode 100644 tests/auto/qml/qqmlengine/data/interception/includes/intercepted/intercepted.js create mode 100644 tests/auto/qml/qqmlengine/data/interception/includes/intercepted/intercepted/included.js create mode 100644 tests/auto/qml/qqmlengine/data/interception/includes/urlInterceptor.qml (limited to 'tests/auto/qml') diff --git a/tests/auto/qml/qqmlengine/data/interception/includes/Intercepted.qml b/tests/auto/qml/qqmlengine/data/interception/includes/Intercepted.qml new file mode 100644 index 0000000000..449207e0e3 --- /dev/null +++ b/tests/auto/qml/qqmlengine/data/interception/includes/Intercepted.qml @@ -0,0 +1,5 @@ +import QtQml 2.0 + +QtObject { + property string myStr: "base file" +} diff --git a/tests/auto/qml/qqmlengine/data/interception/includes/intercepted.js b/tests/auto/qml/qqmlengine/data/interception/includes/intercepted.js new file mode 100644 index 0000000000..fef9f3cd44 --- /dev/null +++ b/tests/auto/qml/qqmlengine/data/interception/includes/intercepted.js @@ -0,0 +1,3 @@ +Qt.include("intercepted/included.js") + +var myStr = myString() diff --git a/tests/auto/qml/qqmlengine/data/interception/includes/intercepted/included.js b/tests/auto/qml/qqmlengine/data/interception/includes/intercepted/included.js new file mode 100644 index 0000000000..b6e141dfaa --- /dev/null +++ b/tests/auto/qml/qqmlengine/data/interception/includes/intercepted/included.js @@ -0,0 +1,3 @@ +function myString() { + return "base include file"; +} diff --git a/tests/auto/qml/qqmlengine/data/interception/includes/intercepted/intercepted.js b/tests/auto/qml/qqmlengine/data/interception/includes/intercepted/intercepted.js new file mode 100644 index 0000000000..fef9f3cd44 --- /dev/null +++ b/tests/auto/qml/qqmlengine/data/interception/includes/intercepted/intercepted.js @@ -0,0 +1,3 @@ +Qt.include("intercepted/included.js") + +var myStr = myString() diff --git a/tests/auto/qml/qqmlengine/data/interception/includes/intercepted/intercepted/included.js b/tests/auto/qml/qqmlengine/data/interception/includes/intercepted/intercepted/included.js new file mode 100644 index 0000000000..c0215ebbe5 --- /dev/null +++ b/tests/auto/qml/qqmlengine/data/interception/includes/intercepted/intercepted/included.js @@ -0,0 +1,3 @@ +function myString() { + return "intercepted include file"; +} diff --git a/tests/auto/qml/qqmlengine/data/interception/includes/urlInterceptor.qml b/tests/auto/qml/qqmlengine/data/interception/includes/urlInterceptor.qml new file mode 100644 index 0000000000..be86195bd8 --- /dev/null +++ b/tests/auto/qml/qqmlengine/data/interception/includes/urlInterceptor.qml @@ -0,0 +1,11 @@ +import QtQml 2.0 +import "intercepted.js" as Script + +QtObject { + property url filePath: "doesNotExist.file" + property url resolvedUrl: Qt.resolvedUrl("doesNotExist.file"); + property url absoluteUrl: Qt.resolvedUrl("file:///doesNotExist.file"); + property string childString: child.myStr + property string scriptString: Script.myStr + property Intercepted child: Intercepted {} +} diff --git a/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp b/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp index 486a0b4e87..eb432f3cfa 100644 --- a/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp +++ b/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp @@ -746,6 +746,15 @@ void tst_qqmlengine::urlInterceptor_data() << QStringLiteral("base file") << testFileUrl("interception/strings/intercepted/doesNotExist.file").toString() << QStringLiteral("file:///intercepted/doesNotExist.file"); + + QTest::newRow("InterceptIncludes") + << testFileUrl("interception/includes/urlInterceptor.qml") + << (QList() << QQmlAbstractUrlInterceptor::JavaScriptFile) + << testFileUrl("interception/includes/doesNotExist.file").toString() + << QStringLiteral("base file") + << QStringLiteral("intercepted include file") + << testFileUrl("interception/includes/doesNotExist.file").toString() + << QStringLiteral("file:///doesNotExist.file"); } void tst_qqmlengine::urlInterceptor() -- cgit v1.2.3