summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qdeclarativeworkerscript
diff options
context:
space:
mode:
authorBea Lam <bea.lam@nokia.com>2011-02-10 05:31:17 (GMT)
committerBea Lam <bea.lam@nokia.com>2011-02-11 01:00:21 (GMT)
commit974db3ce58307069fcafdee2c5636ff72b061134 (patch)
tree9c09b23dcf4a6ee90ec27990085332d0af1256c1 /tests/auto/declarative/qdeclarativeworkerscript
parentabd0103ef31b1aad5bfa0e75ee0270d9342c92e7 (diff)
downloadQt-974db3ce58307069fcafdee2c5636ff72b061134.zip
Qt-974db3ce58307069fcafdee2c5636ff72b061134.tar.gz
Qt-974db3ce58307069fcafdee2c5636ff72b061134.tar.bz2
Report any exceptions occurring in WorkerScript javascript code
Task-number: QTBUG-17183 Change-Id: I709cca0bdce247ca9250c4f334654e2ff57b0b32 Reviewed-by: Aaron Kennedy
Diffstat (limited to 'tests/auto/declarative/qdeclarativeworkerscript')
-rw-r--r--tests/auto/declarative/qdeclarativeworkerscript/data/script_error_onCall.js6
-rw-r--r--tests/auto/declarative/qdeclarativeworkerscript/data/script_error_onLoad.js5
-rw-r--r--tests/auto/declarative/qdeclarativeworkerscript/data/worker_error_onCall.qml6
-rw-r--r--tests/auto/declarative/qdeclarativeworkerscript/data/worker_error_onLoad.qml7
-rw-r--r--tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp52
5 files changed, 76 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativeworkerscript/data/script_error_onCall.js b/tests/auto/declarative/qdeclarativeworkerscript/data/script_error_onCall.js
new file mode 100644
index 0000000..f589b0e
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeworkerscript/data/script_error_onCall.js
@@ -0,0 +1,6 @@
+WorkerScript.onMessage = function(msg) {
+ var a = 123
+ var b = 345
+ var f = getData()
+}
+
diff --git a/tests/auto/declarative/qdeclarativeworkerscript/data/script_error_onLoad.js b/tests/auto/declarative/qdeclarativeworkerscript/data/script_error_onLoad.js
new file mode 100644
index 0000000..1d6eab2
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeworkerscript/data/script_error_onLoad.js
@@ -0,0 +1,5 @@
+WorkerScript.onMessage = function(msg) {
+ var a = 123
+ aoij awef aljfaow eij
+}
+
diff --git a/tests/auto/declarative/qdeclarativeworkerscript/data/worker_error_onCall.qml b/tests/auto/declarative/qdeclarativeworkerscript/data/worker_error_onCall.qml
new file mode 100644
index 0000000..90c4617
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeworkerscript/data/worker_error_onCall.qml
@@ -0,0 +1,6 @@
+import QtQuick 1.0
+
+BaseWorker {
+ source: "script_error_onCall.js"
+}
+
diff --git a/tests/auto/declarative/qdeclarativeworkerscript/data/worker_error_onLoad.qml b/tests/auto/declarative/qdeclarativeworkerscript/data/worker_error_onLoad.qml
new file mode 100644
index 0000000..0b9d21d
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeworkerscript/data/worker_error_onLoad.qml
@@ -0,0 +1,7 @@
+import QtQuick 1.0
+
+BaseWorker {
+ source: "script_error_onLoad.js"
+}
+
+
diff --git a/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp b/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp
index aaedd82..4b922fb 100644
--- a/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp
+++ b/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp
@@ -41,6 +41,8 @@
#include <qtest.h>
#include <QtCore/qdebug.h>
#include <QtCore/qtimer.h>
+#include <QtCore/qdir.h>
+#include <QtCore/qfileinfo.h>
#include <QtScript/qscriptengine.h>
#include <QtDeclarative/qdeclarativecomponent.h>
@@ -58,6 +60,13 @@ Q_DECLARE_METATYPE(QScriptValue)
#define SRCDIR "."
#endif
+inline QUrl TEST_FILE(const QString &filename)
+{
+ QFileInfo fileInfo(__FILE__);
+ return QUrl::fromLocalFile(fileInfo.absoluteDir().filePath(filename));
+}
+
+
class tst_QDeclarativeWorkerScript : public QObject
{
Q_OBJECT
@@ -70,6 +79,8 @@ private slots:
void messaging_sendQObjectList();
void messaging_sendJsObject();
void script_with_pragma();
+ void scriptError_onLoad();
+ void scriptError_onCall();
private:
void waitForEchoMessage(QDeclarativeWorkerScript *worker) {
@@ -215,6 +226,47 @@ void tst_QDeclarativeWorkerScript::script_with_pragma()
delete worker;
}
+static QString qdeclarativeworkerscript_lastWarning;
+static void qdeclarativeworkerscript_warningsHandler(QtMsgType type, const char *msg)
+{
+ if (type == QtWarningMsg)
+ qdeclarativeworkerscript_lastWarning = QString::fromUtf8(msg);
+}
+
+void tst_QDeclarativeWorkerScript::scriptError_onLoad()
+{
+ QDeclarativeComponent component(&m_engine, SRCDIR "/data/worker_error_onLoad.qml");
+
+ QtMsgHandler previousMsgHandler = qInstallMsgHandler(qdeclarativeworkerscript_warningsHandler);
+ QDeclarativeWorkerScript *worker = qobject_cast<QDeclarativeWorkerScript*>(component.create());
+ QVERIFY(worker != 0);
+
+ QTRY_COMPARE(qdeclarativeworkerscript_lastWarning,
+ TEST_FILE("data/script_error_onLoad.js").toString() + QLatin1String(":3: SyntaxError: Parse error"));
+
+ qInstallMsgHandler(previousMsgHandler);
+ qApp->processEvents();
+ delete worker;
+}
+
+void tst_QDeclarativeWorkerScript::scriptError_onCall()
+{
+ QDeclarativeComponent component(&m_engine, SRCDIR "/data/worker_error_onCall.qml");
+ QDeclarativeWorkerScript *worker = qobject_cast<QDeclarativeWorkerScript*>(component.create());
+ QVERIFY(worker != 0);
+
+ QtMsgHandler previousMsgHandler = qInstallMsgHandler(qdeclarativeworkerscript_warningsHandler);
+ QVariant value;
+ QVERIFY(QMetaObject::invokeMethod(worker, "testSend", Q_ARG(QVariant, value)));
+
+ QTRY_COMPARE(qdeclarativeworkerscript_lastWarning,
+ TEST_FILE("data/script_error_onCall.js").toString() + QLatin1String(":4: ReferenceError: Can't find variable: getData"));
+
+ qInstallMsgHandler(previousMsgHandler);
+ qApp->processEvents();
+ delete worker;
+}
+
QTEST_MAIN(tst_QDeclarativeWorkerScript)