aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2013-06-24 11:26:22 +0200
committerSimon Hausmann <simon.hausmann@digia.com>2013-06-24 11:48:46 +0200
commit1a9759855639b9e2b3cdc0687d3381dcbf6c9815 (patch)
treeb2da51f6eddddb83c2d97cdcfac24d38d2e67a4e /tests/auto/qml/qqmlengine/tst_qqmlengine.cpp
parent8217ec1b888f3ff93f004801b018c5f85362c484 (diff)
parente1fc2793aef53b84a3f1e19b6d6bdf1141340074 (diff)
Merge branch 'dev' of ssh://codereview.qt-project.org/qt/qtdeclarative into wip/v4
Conflicts: src/imports/qtquick2/plugins.qmltypes src/qml/debugger/qv8debugservice.cpp src/qml/qml/qml.pri src/qml/qml/qqmlcompiler.cpp src/qml/qml/qqmlcomponent.cpp src/qml/qml/qqmlcontext.cpp src/qml/qml/qqmldata_p.h src/qml/qml/qqmlengine_p.h src/qml/qml/qqmljavascriptexpression.cpp src/qml/qml/qqmlxmlhttprequest.cpp src/qml/qml/v4/qv4bindings.cpp src/qml/qml/v4/qv4irbuilder.cpp src/qml/qml/v4/qv4jsonobject_p.h src/qml/qml/v8/qqmlbuiltinfunctions.cpp src/qml/qml/v8/qv8bindings.cpp src/qml/qml/v8/qv8contextwrapper.cpp src/qml/qml/v8/qv8listwrapper.cpp src/qml/qml/v8/qv8qobjectwrapper.cpp src/qml/qml/v8/qv8qobjectwrapper_p.h src/qml/qml/v8/qv8sequencewrapper_p_p.h src/qml/qml/v8/qv8typewrapper.cpp src/qml/qml/v8/qv8valuetypewrapper.cpp src/qml/types/qqmldelegatemodel.cpp src/quick/items/context2d/qquickcanvasitem.cpp src/quick/items/context2d/qquickcontext2d.cpp sync.profile tests/auto/qml/qjsengine/tst_qjsengine.cpp tests/benchmarks/qml/animation/animation.pro tools/qmlprofiler/qmlprofiler.pro Change-Id: I18a76b8a81d87523247fa03a44ca334b1a2360c9
Diffstat (limited to 'tests/auto/qml/qqmlengine/tst_qqmlengine.cpp')
-rw-r--r--tests/auto/qml/qqmlengine/tst_qqmlengine.cpp96
1 files changed, 96 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp b/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp
index 9177ff58f7..d604118b58 100644
--- a/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp
+++ b/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp
@@ -54,6 +54,7 @@
#include <QQmlExpression>
#include <QQmlIncubationController>
#include <private/qqmlengine_p.h>
+#include <private/qqmlabstracturlinterceptor_p.h>
class tst_qqmlengine : public QQmlDataTest
{
@@ -79,6 +80,8 @@ private slots:
void multipleEngines();
void qtqmlModule_data();
void qtqmlModule();
+ void urlInterceptor_data();
+ void urlInterceptor();
public slots:
QObject *createAQObjectForOwnershipTest ()
@@ -674,6 +677,99 @@ void tst_qqmlengine::qtqmlModule()
}
}
+class CustomSelector : public QQmlAbstractUrlInterceptor
+{
+public:
+ virtual QUrl intercept(const QUrl &url, QQmlAbstractUrlInterceptor::DataType d)
+ {
+ if (url.scheme() != QStringLiteral("file"))
+ return url;
+ if (!m_interceptionPoints.contains(d))
+ return url;
+
+ QString alteredPath = url.path();
+ int a = alteredPath.lastIndexOf('/');
+ if (a < 0)
+ a = 0;
+ alteredPath.insert(a, QStringLiteral("/intercepted"));
+
+ QUrl ret = url;
+ ret.setPath(alteredPath);
+ return ret;
+ }
+ QList<QQmlAbstractUrlInterceptor::DataType> m_interceptionPoints;
+};
+
+Q_DECLARE_METATYPE(QList<QQmlAbstractUrlInterceptor::DataType>);
+void tst_qqmlengine::urlInterceptor_data()
+{
+ QTest::addColumn<QUrl>("testFile");
+ QTest::addColumn<QList<QQmlAbstractUrlInterceptor::DataType> >("interceptionPoint");
+ QTest::addColumn<QString>("expectedFilePath");
+ QTest::addColumn<QString>("expectedChildString");
+ QTest::addColumn<QString>("expectedScriptString");
+ QTest::addColumn<QString>("expectedResolvedUrl");
+ QTest::addColumn<QString>("expectedAbsoluteUrl");
+
+ QTest::newRow("InterceptTypes")
+ << testFileUrl("interception/types/urlInterceptor.qml")
+ << (QList<QQmlAbstractUrlInterceptor::DataType>() << QQmlAbstractUrlInterceptor::QmlFile << QQmlAbstractUrlInterceptor::JavaScriptFile << QQmlAbstractUrlInterceptor::UrlString)
+ << testFileUrl("interception/types/intercepted/doesNotExist.file").toString()
+ << QStringLiteral("intercepted")
+ << QStringLiteral("intercepted")
+ << testFileUrl("interception/types/intercepted/doesNotExist.file").toString()
+ << QStringLiteral("file:///intercepted/doesNotExist.file");
+
+ QTest::newRow("InterceptQmlDir")
+ << testFileUrl("interception/qmldir/urlInterceptor.qml")
+ << (QList<QQmlAbstractUrlInterceptor::DataType>() << QQmlAbstractUrlInterceptor::QmldirFile << QQmlAbstractUrlInterceptor::UrlString)
+ << testFileUrl("interception/qmldir/intercepted/doesNotExist.file").toString()
+ << QStringLiteral("intercepted")
+ << QStringLiteral("base file")
+ << testFileUrl("interception/qmldir/intercepted/doesNotExist.file").toString()
+ << QStringLiteral("file:///intercepted/doesNotExist.file");
+
+ QTest::newRow("InterceptStrings")
+ << testFileUrl("interception/strings/urlInterceptor.qml")
+ << (QList<QQmlAbstractUrlInterceptor::DataType>() << QQmlAbstractUrlInterceptor::UrlString)
+ << testFileUrl("interception/strings/intercepted/doesNotExist.file").toString()
+ << QStringLiteral("base file")
+ << QStringLiteral("base file")
+ << testFileUrl("interception/strings/intercepted/doesNotExist.file").toString()
+ << QStringLiteral("file:///intercepted/doesNotExist.file");
+}
+
+void tst_qqmlengine::urlInterceptor()
+{
+
+ QFETCH(QUrl, testFile);
+ QFETCH(QList<QQmlAbstractUrlInterceptor::DataType>, interceptionPoint);
+ QFETCH(QString, expectedFilePath);
+ QFETCH(QString, expectedChildString);
+ QFETCH(QString, expectedScriptString);
+ QFETCH(QString, expectedResolvedUrl);
+ QFETCH(QString, expectedAbsoluteUrl);
+
+ QQmlEngine e;
+ CustomSelector cs;
+ cs.m_interceptionPoints = interceptionPoint;
+ e.setUrlInterceptor(&cs);
+ QQmlComponent c(&e, testFile); //Note that this can get intercepted too
+ QObject *o = c.create();
+ if (!o)
+ qDebug() << c.errorString();
+ QVERIFY(o);
+ //Test a URL as a property initialization
+ QCOMPARE(o->property("filePath").toString(), expectedFilePath);
+ //Test a URL as a Type location
+ QCOMPARE(o->property("childString").toString(), expectedChildString);
+ //Test a URL as a Script location
+ QCOMPARE(o->property("scriptString").toString(), expectedScriptString);
+ //Test a URL as a resolveUrl() call
+ QCOMPARE(o->property("resolvedUrl").toString(), expectedResolvedUrl);
+ QCOMPARE(o->property("absoluteUrl").toString(), expectedAbsoluteUrl);
+}
+
QTEST_MAIN(tst_qqmlengine)
#include "tst_qqmlengine.moc"