aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2016-05-19 13:04:54 +0200
committerLiang Qi <liang.qi@qt.io>2016-05-19 20:41:34 +0200
commit63ec33e79cf86c4312c58bea12a2aab400890c70 (patch)
tree5c9b5cd51276ea0a3ca42567666a09e70efa11cc /tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp
parentb9e4a4df577959579b2322fb6077bde82d9ffce3 (diff)
parentafc84775efdc6e13e2e210bb94e115b378d90134 (diff)
Merge remote-tracking branch 'origin/5.6' into 5.7
Conflicts: src/plugins/qmltooling/qmldbg_profiler/qqmlprofilerservice.cpp src/qml/jsruntime/qv4engine.cpp src/qml/jsruntime/qv4engine_p.h Change-Id: I89ffccd699bee675732758d039e22224b275d60d
Diffstat (limited to 'tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp')
-rw-r--r--tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp
index c1e51410c8..83bf783cf4 100644
--- a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp
+++ b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp
@@ -35,6 +35,7 @@
#include <QtQuick>
#include <QtQuick/private/qquickrectangle_p.h>
#include <QtQuick/private/qquickmousearea_p.h>
+#include <private/qv8engine_p.h>
#include <qcolor.h>
#include "../../shared/util.h"
#include "testhttpserver.h"
@@ -111,6 +112,7 @@ private slots:
void onDestructionCount();
void recursion();
void recursionContinuation();
+ void callingContextForInitialProperties();
private:
QQmlEngine engine;
@@ -518,6 +520,63 @@ void tst_qqmlcomponent::recursionContinuation()
QVERIFY(object->property("success").toBool());
}
+class CallingContextCheckingClass : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(int value READ value WRITE setValue)
+public:
+ CallingContextCheckingClass()
+ : m_value(0)
+ {}
+
+ int value() const { return m_value; }
+ void setValue(int v) {
+ scopeObject.clear();
+ callingContextData.setContextData(0);
+
+ m_value = v;
+ QJSEngine *jsEngine = qjsEngine(this);
+ if (!jsEngine)
+ return;
+ QV4::ExecutionEngine *v4 = QV8Engine::getV4(jsEngine);
+ if (!v4)
+ return;
+ QV4::Scope scope(v4);
+ QV4::Scoped<QV4::QmlContext> qmlContext(scope, v4->qmlContext());
+ if (!qmlContext)
+ return;
+ callingContextData = qmlContext->qmlContext();
+ scopeObject = qmlContext->qmlScope();
+ }
+
+ int m_value;
+ QQmlGuardedContextData callingContextData;
+ QPointer<QObject> scopeObject;
+};
+
+void tst_qqmlcomponent::callingContextForInitialProperties()
+{
+ qmlRegisterType<CallingContextCheckingClass>("qqmlcomponenttest", 1, 0, "CallingContextCheckingClass");
+
+ QQmlComponent testFactory(&engine, testFileUrl("callingQmlContextComponent.qml"));
+
+ QQmlComponent component(&engine, testFileUrl("callingQmlContext.qml"));
+ QScopedPointer<QObject> root(component.beginCreate(engine.rootContext()));
+ QVERIFY(!root.isNull());
+ root->setProperty("factory", QVariant::fromValue(&testFactory));
+ component.completeCreate();
+ QTRY_VERIFY(qvariant_cast<QObject *>(root->property("incubatedObject")));
+ QObject *o = qvariant_cast<QObject *>(root->property("incubatedObject"));
+ CallingContextCheckingClass *checker = qobject_cast<CallingContextCheckingClass*>(o);
+ QVERIFY(checker);
+
+ QVERIFY(!checker->callingContextData.isNull());
+ QVERIFY(checker->callingContextData->urlString().endsWith(QStringLiteral("callingQmlContext.qml")));
+
+ QVERIFY(!checker->scopeObject.isNull());
+ QVERIFY(checker->scopeObject->metaObject()->indexOfProperty("incubatedObject") != -1);
+}
+
QTEST_MAIN(tst_qqmlcomponent)
#include "tst_qqmlcomponent.moc"