aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlpromise
diff options
context:
space:
mode:
authorValery Kotov <kotov.valery@gmail.com>2015-07-16 19:35:55 +0300
committerSimon Hausmann <simon.hausmann@qt.io>2018-10-11 08:27:48 +0000
commitf47c87e75fb94f1b322157fa663ac8b87a4dbd22 (patch)
treeccd08e635759641095544f3a9ce3d41a516f5b84 /tests/auto/qml/qqmlpromise
parent54fdc4de7963437642704c2bcf339979aa4f8734 (diff)
QML Engine: Support for JavaScript Promises
Support for JavaScript Promises. Change-Id: I90ce328b35f3bdf3fd666a8829f22b5d56b6f861 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmlpromise')
-rw-r--r--tests/auto/qml/qqmlpromise/data/promise-all-empty-input.qml58
-rw-r--r--tests/auto/qml/qqmlpromise/data/promise-all-invoke-then-method.qml65
-rw-r--r--tests/auto/qml/qqmlpromise/data/promise-all-noniterable-input.qml59
-rw-r--r--tests/auto/qml/qqmlpromise/data/promise-all-reject-reject-is-last.qml83
-rw-r--r--tests/auto/qml/qqmlpromise/data/promise-all-reject-reject-is-mid.qml83
-rw-r--r--tests/auto/qml/qqmlpromise/data/promise-all-resolve.qml86
-rw-r--r--tests/auto/qml/qqmlpromise/data/promise-async-reject-with-value.qml72
-rw-r--r--tests/auto/qml/qqmlpromise/data/promise-async-resolve-with-value.qml72
-rw-r--r--tests/auto/qml/qqmlpromise/data/promise-executor-function-extensible.qml56
-rw-r--r--tests/auto/qml/qqmlpromise/data/promise-executor-reject.qml64
-rw-r--r--tests/auto/qml/qqmlpromise/data/promise-executor-resolve.qml67
-rw-r--r--tests/auto/qml/qqmlpromise/data/promise-executor-throw-exception.qml59
-rw-r--r--tests/auto/qml/qqmlpromise/data/promise-get-length.qml43
-rw-r--r--tests/auto/qml/qqmlpromise/data/promise-race-empty-input.qml52
-rw-r--r--tests/auto/qml/qqmlpromise/data/promise-race-resolve-1st-in-executor-function.qml62
-rw-r--r--tests/auto/qml/qqmlpromise/data/promise-race-resolve-1st.qml57
-rw-r--r--tests/auto/qml/qqmlpromise/data/promise-race-resolve-2nd.qml75
-rw-r--r--tests/auto/qml/qqmlpromise/data/promise-reject-catch.qml57
-rw-r--r--tests/auto/qml/qqmlpromise/data/promise-reject-with-value.qml55
-rw-r--r--tests/auto/qml/qqmlpromise/data/promise-resolve-function-length.qml55
-rw-r--r--tests/auto/qml/qqmlpromise/data/promise-resolve-is-a-function.qml43
-rw-r--r--tests/auto/qml/qqmlpromise/data/promise-resolve-with-array.qml55
-rw-r--r--tests/auto/qml/qqmlpromise/data/promise-resolve-with-empty.qml54
-rw-r--r--tests/auto/qml/qqmlpromise/data/promise-resolve-with-promise.qml65
-rw-r--r--tests/auto/qml/qqmlpromise/data/promise-resolve-with-value.qml55
-rw-r--r--tests/auto/qml/qqmlpromise/data/then-fulfilled-non-callable.qml93
-rw-r--r--tests/auto/qml/qqmlpromise/data/then-reject-chaining.qml63
-rw-r--r--tests/auto/qml/qqmlpromise/data/then-reject-non-callable.qml72
-rw-r--r--tests/auto/qml/qqmlpromise/data/then-resolve-chaining.qml59
-rw-r--r--tests/auto/qml/qqmlpromise/data/then-resolve-multiple-then.qml65
-rw-r--r--tests/auto/qml/qqmlpromise/qqmlpromise.pro46
-rw-r--r--tests/auto/qml/qqmlpromise/tst_qqmlpromise.cpp276
32 files changed, 2226 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlpromise/data/promise-all-empty-input.qml b/tests/auto/qml/qqmlpromise/data/promise-all-empty-input.qml
new file mode 100644
index 0000000000..43ccf24965
--- /dev/null
+++ b/tests/auto/qml/qqmlpromise/data/promise-all-empty-input.qml
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import QtQuick 2.4
+
+QtObject {
+ property bool wasTestSuccessful: false
+
+ property var promise: Promise.all([]);
+
+ Component.onCompleted: {
+ promise.then(function(value) {
+ if (value.length !== 0) {
+ return;
+ }
+
+ wasTestSuccessful = true
+
+ }, function() {
+ throw new Error("Should never be called")
+ })
+ }
+}
diff --git a/tests/auto/qml/qqmlpromise/data/promise-all-invoke-then-method.qml b/tests/auto/qml/qqmlpromise/data/promise-all-invoke-then-method.qml
new file mode 100644
index 0000000000..ec59c47130
--- /dev/null
+++ b/tests/auto/qml/qqmlpromise/data/promise-all-invoke-then-method.qml
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import QtQuick 2.4
+
+QtObject {
+ property int callCount: 0
+ property bool wasTestSuccessful: false
+
+ property var promise1: new Promise(function() {})
+ property var promise2: new Promise(function() {})
+ property var promise3: new Promise(function() {})
+
+ Component.onCompleted: {
+ promise1.then = null
+ console.log(promise1.then)
+
+ // TODO: This assinment works in JS scope but does not work
+ // in QML scope
+ promise1.then = promise2.then = promise3.then = function(a, b) {
+ console.log("then was called")
+ callCount++;
+ }
+
+ Promise.all([promise1, promise2, promise3])
+
+ console.log("callCount " + callCount)
+ wasTestSuccessful = (callCount === 3)
+ }
+}
diff --git a/tests/auto/qml/qqmlpromise/data/promise-all-noniterable-input.qml b/tests/auto/qml/qqmlpromise/data/promise-all-noniterable-input.qml
new file mode 100644
index 0000000000..a9bdbf2fb7
--- /dev/null
+++ b/tests/auto/qml/qqmlpromise/data/promise-all-noniterable-input.qml
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import QtQuick 2.4
+
+QtObject {
+ property bool wasTestSuccessful: false
+
+ property var nonIterable: 3
+ property var promise: Promise.all(nonIterable);
+
+ Component.onCompleted: {
+ promise.then(function() {
+ throw new Error("Should never be called")
+ }, function(err) {
+ if (!(err instanceof TypeError)) {
+ throw new Error("Should reject with TypeError")
+ return;
+ }
+
+ wasTestSuccessful = true
+ })
+ }
+}
diff --git a/tests/auto/qml/qqmlpromise/data/promise-all-reject-reject-is-last.qml b/tests/auto/qml/qqmlpromise/data/promise-all-reject-reject-is-last.qml
new file mode 100644
index 0000000000..0d3d31d494
--- /dev/null
+++ b/tests/auto/qml/qqmlpromise/data/promise-all-reject-reject-is-last.qml
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import QtQuick 2.4
+
+QtObject {
+ // TODO!
+
+ property int resolveValue: 5
+ property int rejectValue: 10
+ property int resultValue: rejectValue
+ property bool wasTestSuccessful: false
+
+
+ property var delayedEvent: Timer {
+ interval: 0
+ property var handler: null
+ onTriggered: {
+ if (handler) {
+ handler();
+ }
+ }
+ }
+
+ function postEvent(event, value) {
+ delayedEvent.handler = function() { event(value) }
+ delayedEvent.restart();
+ }
+
+ property var promise1: Promise.resolve(resolveValue);
+ property int promise2: resolveValue
+ property var promise3: new Promise(function (resolve, reject) {
+ postEvent(resolve, resolveValue)
+ })
+ property var promise4: Promise.reject(rejectValue)
+
+ Component.onCompleted: {
+ Promise.all([promise1, promise2, promise3, promise4]).then(function() {
+ throw new Error("Should never be called")
+ }, function(value) {
+ if (value !== rejectValue) {
+ return;
+ }
+
+ wasTestSuccessful = true
+ })
+ }
+}
diff --git a/tests/auto/qml/qqmlpromise/data/promise-all-reject-reject-is-mid.qml b/tests/auto/qml/qqmlpromise/data/promise-all-reject-reject-is-mid.qml
new file mode 100644
index 0000000000..67ca95971c
--- /dev/null
+++ b/tests/auto/qml/qqmlpromise/data/promise-all-reject-reject-is-mid.qml
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import QtQuick 2.4
+
+QtObject {
+ // TODO!
+
+ property int resolveValue: 5
+ property int rejectValue: 10
+ property int resultValue: rejectValue
+ property bool wasTestSuccessful: false
+
+
+ property var delayedEvent: Timer {
+ interval: 0
+ property var handler: null
+ onTriggered: {
+ if (handler) {
+ handler();
+ }
+ }
+ }
+
+ function postEvent(event, value) {
+ delayedEvent.handler = function() { event(value) }
+ delayedEvent.restart();
+ }
+
+ property var promise1: Promise.resolve(resolveValue);
+ property int promise2: resolveValue
+ property var promise3: Promise.reject(rejectValue)
+ property var promise4: new Promise(function (resolve, reject) {
+ postEvent(resolve, resolveValue)
+ })
+
+ Component.onCompleted: {
+ Promise.all([promise1, promise2, promise3, promise4]).then(function() {
+ throw new Error("Should never be called")
+ }, function(value) {
+ if (value !== rejectValue) {
+ return;
+ }
+
+ wasTestSuccessful = true
+ })
+ }
+}
diff --git a/tests/auto/qml/qqmlpromise/data/promise-all-resolve.qml b/tests/auto/qml/qqmlpromise/data/promise-all-resolve.qml
new file mode 100644
index 0000000000..1996b7f9c8
--- /dev/null
+++ b/tests/auto/qml/qqmlpromise/data/promise-all-resolve.qml
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import QtQuick 2.4
+
+QtObject {
+ property int resolveValue: 5
+ property var resultValue: [resolveValue, resolveValue, resolveValue]
+ property bool wasTestSuccessful: false
+
+
+ property var delayedEvent: Timer {
+ interval: 0
+ property var handler: null
+ onTriggered: {
+ if (handler) {
+ handler();
+ }
+ }
+ }
+
+ function postEvent(event, value) {
+ delayedEvent.handler = function() { event(value) }
+ delayedEvent.restart();
+ }
+
+ property var promise1: Promise.resolve(resolveValue);
+ property int promise2: resolveValue
+ property var promise3: new Promise(function (resolve, reject) {
+ postEvent(resolve, resolveValue)
+ })
+
+ Component.onCompleted: {
+ Promise.all([promise1, promise2, promise3]).then(function(value) {
+ if (value.length !== resultValue.length) {
+ return;
+ }
+
+ for (var i in value) {
+ if (value[i] !== resultValue[i]) {
+ return;
+ }
+ }
+
+ wasTestSuccessful = true
+
+ }, function() {
+ throw new Error("Should never be called")
+ })
+ }
+}
diff --git a/tests/auto/qml/qqmlpromise/data/promise-async-reject-with-value.qml b/tests/auto/qml/qqmlpromise/data/promise-async-reject-with-value.qml
new file mode 100644
index 0000000000..4c54ad3fc7
--- /dev/null
+++ b/tests/auto/qml/qqmlpromise/data/promise-async-reject-with-value.qml
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import QtQuick 2.4
+
+QtObject {
+ property int rejectValue: 5
+ property bool wasTestSuccessful: false
+
+
+ property var delayedExecutor: Timer {
+ interval: 0
+ property var executor: null
+ onTriggered: {
+ if (executor) {
+ executor();
+ }
+ }
+ }
+
+ property var promise: new Promise(function (resolve, reject) {
+ delayedExecutor.executor = function() {
+ reject(rejectValue)
+ }
+ delayedExecutor.restart();
+ })
+
+ Component.onCompleted: {
+ promise.then(function() {
+ throw new Error("Should never be called")
+ }, function(value) {
+ if (value === rejectValue) {
+ wasTestSuccessful = true
+ }
+ })
+ }
+}
diff --git a/tests/auto/qml/qqmlpromise/data/promise-async-resolve-with-value.qml b/tests/auto/qml/qqmlpromise/data/promise-async-resolve-with-value.qml
new file mode 100644
index 0000000000..a491394a30
--- /dev/null
+++ b/tests/auto/qml/qqmlpromise/data/promise-async-resolve-with-value.qml
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import QtQuick 2.4
+
+QtObject {
+ property int resolveValue: 5
+ property bool wasTestSuccessful: false
+
+
+ property var delayedExecutor: Timer {
+ interval: 0
+ property var executor: null
+ onTriggered: {
+ if (executor) {
+ executor();
+ }
+ }
+ }
+
+ property var promise: new Promise(function (resolve, reject) {
+ delayedExecutor.executor = function() {
+ resolve(resolveValue)
+ }
+ delayedExecutor.restart();
+ })
+
+ Component.onCompleted: {
+ promise.then(function(value) {
+ if (value === resolveValue) {
+ wasTestSuccessful = true
+ }
+ }, function() {
+ throw new Error("Should never be called")
+ })
+ }
+}
diff --git a/tests/auto/qml/qqmlpromise/data/promise-executor-function-extensible.qml b/tests/auto/qml/qqmlpromise/data/promise-executor-function-extensible.qml
new file mode 100644
index 0000000000..e2a264dd3c
--- /dev/null
+++ b/tests/auto/qml/qqmlpromise/data/promise-executor-function-extensible.qml
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import QtQuick 2.0
+
+QtObject {
+ property bool wasTestSuccessful: false
+
+ property var executorFunction: null
+
+ function notPromise(executor) {
+ executorFunction = executor;
+ executor(function() {}, function() {});
+ }
+
+ Component.onCompleted: {
+ Promise.resolve.call(notPromise);
+ wasTestSuccessful = executorFunction !== null &&
+ Object.isExtensible(executorFunction);
+ }
+}
diff --git a/tests/auto/qml/qqmlpromise/data/promise-executor-reject.qml b/tests/auto/qml/qqmlpromise/data/promise-executor-reject.qml
new file mode 100644
index 0000000000..4e609ae4a4
--- /dev/null
+++ b/tests/auto/qml/qqmlpromise/data/promise-executor-reject.qml
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import QtQuick 2.0
+
+QtObject {
+ property string resolution: "reject promise";
+
+ property bool wasExecutorCalled: false
+ property bool wasPromiseRejected: false
+ property bool wasPromiseTypeReturnedByThen: false;
+ property bool wasResolutionForwardedCorrectly: false;
+
+ Component.onCompleted: {
+ var promise = new Promise(function(resolve, reject) {
+ wasExecutorCalled = true;
+ reject(resolution);
+ });
+
+ var res = promise.then(function(result) {
+ wasPromiseRejected = false;
+ }, function(err) {
+ wasPromiseRejected = true;
+ wasResolutionForwardedCorrectly = (err === resolution);
+ });
+
+ wasPromiseTypeReturnedByThen = (typeof res === 'Promise');
+ }
+}
diff --git a/tests/auto/qml/qqmlpromise/data/promise-executor-resolve.qml b/tests/auto/qml/qqmlpromise/data/promise-executor-resolve.qml
new file mode 100644
index 0000000000..659636d6a8
--- /dev/null
+++ b/tests/auto/qml/qqmlpromise/data/promise-executor-resolve.qml
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import QtQuick 2.0
+
+QtObject {
+ property string resolution: "fullfill promise";
+
+ property bool wasExecutorCalled: false
+ property bool wasPromiseResolved: false
+ property bool wasPromiseTypeReturnedByThen: false
+ property bool wasResolutionForwardedCorrectly: false
+ property bool wasNewPromiseObjectCreatedByThen: false
+
+ Component.onCompleted: {
+ var promise = new Promise(function(resolve, reject) {
+ wasExecutorCalled = true;
+ resolve(resolution);
+ });
+
+ var res = promise.then(function(result) {
+ wasPromiseResolved = true;
+ wasResolutionForwardedCorrectly = (result === resolution);
+ }, function(err) {
+ wasPromiseResolved = false;
+ });
+
+ wasPromiseTypeReturnedByThen = (typeof res === 'Promise');
+ console.debug("typeof res: " + (typeof res)) // TODO: remove
+ wasNewPromiseObjectCreatedByThen = (res !== promise);
+ }
+}
diff --git a/tests/auto/qml/qqmlpromise/data/promise-executor-throw-exception.qml b/tests/auto/qml/qqmlpromise/data/promise-executor-throw-exception.qml
new file mode 100644
index 0000000000..9e912635d6
--- /dev/null
+++ b/tests/auto/qml/qqmlpromise/data/promise-executor-throw-exception.qml
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import QtQuick 2.0
+
+QtObject {
+ property bool wasTestSuccessful: false
+
+ property var errorObject: { text: "Exception should not escape executor" }
+
+ property var promise: new Promise(function() {
+ throw errorObject
+ })
+
+ Component.onCompleted: {
+ promise.then(function() {
+ throw new Error("Should never be called")
+ }, function(error) {
+ if (error === errorObject) {
+ wasTestSuccessful = true
+ }
+ })
+ }
+}
diff --git a/tests/auto/qml/qqmlpromise/data/promise-get-length.qml b/tests/auto/qml/qqmlpromise/data/promise-get-length.qml
new file mode 100644
index 0000000000..d42bc61179
--- /dev/null
+++ b/tests/auto/qml/qqmlpromise/data/promise-get-length.qml
@@ -0,0 +1,43 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import QtQuick 2.0
+
+QtObject {
+ property bool wasTestSuccessful: (Promise.length === 1)
+}
diff --git a/tests/auto/qml/qqmlpromise/data/promise-race-empty-input.qml b/tests/auto/qml/qqmlpromise/data/promise-race-empty-input.qml
new file mode 100644
index 0000000000..188b1c2f15
--- /dev/null
+++ b/tests/auto/qml/qqmlpromise/data/promise-race-empty-input.qml
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import QtQuick 2.4
+
+QtObject {
+ property bool wasTestSuccessful: true
+
+ Component.onCompleted: {
+ Promise.race([]).then(function(value) {
+ wasTestSuccessful = false
+ throw new Error("Should never be called")
+ }, function() {
+ throw new Error("Should never be called")
+ })
+ }
+}
diff --git a/tests/auto/qml/qqmlpromise/data/promise-race-resolve-1st-in-executor-function.qml b/tests/auto/qml/qqmlpromise/data/promise-race-resolve-1st-in-executor-function.qml
new file mode 100644
index 0000000000..1d6e47b87e
--- /dev/null
+++ b/tests/auto/qml/qqmlpromise/data/promise-race-resolve-1st-in-executor-function.qml
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import QtQuick 2.4
+
+QtObject {
+ property int resolveValue: 33
+
+ property var promise: new Promise(function (resolve, reject) {
+ resolve(resolveValue)
+ })
+
+ property var resolvedPromiseArray: [promise, Promise.resolve(resolveValue + 5)]
+ property bool wasTestSuccessful: false
+
+ Component.onCompleted: {
+ Promise.race(resolvedPromiseArray).then(function(value) {
+ if (value !== resolveValue) {
+ return;
+ }
+
+ wasTestSuccessful = true
+ }, function() {
+ throw new Error("Should never be called")
+ })
+ }
+}
diff --git a/tests/auto/qml/qqmlpromise/data/promise-race-resolve-1st.qml b/tests/auto/qml/qqmlpromise/data/promise-race-resolve-1st.qml
new file mode 100644
index 0000000000..bd7b3a4026
--- /dev/null
+++ b/tests/auto/qml/qqmlpromise/data/promise-race-resolve-1st.qml
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import QtQuick 2.4
+
+QtObject {
+ property int resolveValue: 33
+ property var resolvedPromiseArray: [Promise.resolve(resolveValue), Promise.resolve(resolveValue + 5)]
+ property bool wasTestSuccessful: false
+
+ Component.onCompleted: {
+ Promise.race(resolvedPromiseArray).then(function(value) {
+ if (value !== resolveValue) {
+ return;
+ }
+
+ wasTestSuccessful = true
+ }, function() {
+ throw new Error("Should never be called")
+ })
+ }
+}
diff --git a/tests/auto/qml/qqmlpromise/data/promise-race-resolve-2nd.qml b/tests/auto/qml/qqmlpromise/data/promise-race-resolve-2nd.qml
new file mode 100644
index 0000000000..e4c1b98acc
--- /dev/null
+++ b/tests/auto/qml/qqmlpromise/data/promise-race-resolve-2nd.qml
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import QtQuick 2.4
+
+QtObject {
+ property int resolveValue: 33
+
+ property var delayedExecutor: Timer {
+ interval: 0
+ property var executor: null
+ onTriggered: {
+ if (executor) {
+ executor();
+ }
+ }
+ }
+
+ property var promise: new Promise(function (resolve, reject) {
+ delayedExecutor.executor = function() {
+ resolve(resolveValue + 5)
+ }
+ delayedExecutor.restart();
+ })
+
+ property var resolvedPromiseArray: [promise, Promise.resolve(resolveValue)]
+ property bool wasTestSuccessful: false
+
+ Component.onCompleted: {
+ Promise.race(resolvedPromiseArray).then(function(value) {
+ if (value !== resolveValue) {
+ return;
+ }
+
+ wasTestSuccessful = true
+ }, function() {
+ throw new Error("Should never be called")
+ })
+ }
+}
diff --git a/tests/auto/qml/qqmlpromise/data/promise-reject-catch.qml b/tests/auto/qml/qqmlpromise/data/promise-reject-catch.qml
new file mode 100644
index 0000000000..a83d2670ba
--- /dev/null
+++ b/tests/auto/qml/qqmlpromise/data/promise-reject-catch.qml
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import QtQuick 2.0
+
+QtObject {
+ property int rejectValue: 5
+ property var promise: Promise.reject(rejectValue)
+ property bool wasTestSuccessful: false
+
+ Component.onCompleted: {
+ promise.then(function() {
+ throw new Error("Should never be called")
+ }).then(function() {
+ throw new Error("Should never be called")
+ }).catch(function(value) {
+ if (value === rejectValue) {
+ wasTestSuccessful = true
+ }
+ })
+ }
+}
diff --git a/tests/auto/qml/qqmlpromise/data/promise-reject-with-value.qml b/tests/auto/qml/qqmlpromise/data/promise-reject-with-value.qml
new file mode 100644
index 0000000000..6b81e83643
--- /dev/null
+++ b/tests/auto/qml/qqmlpromise/data/promise-reject-with-value.qml
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import QtQuick 2.0
+
+QtObject {
+ property int rejectValue: 5
+ property var promise: Promise.reject(rejectValue)
+ property bool wasTestSuccessful: false
+
+ Component.onCompleted: {
+ promise.then(function() {
+ throw new Error("Should never be called")
+ }, function(value) {
+ if (value === rejectValue) {
+ wasTestSuccessful = true
+ }
+ })
+ }
+}
diff --git a/tests/auto/qml/qqmlpromise/data/promise-resolve-function-length.qml b/tests/auto/qml/qqmlpromise/data/promise-resolve-function-length.qml
new file mode 100644
index 0000000000..40d35e5a3b
--- /dev/null
+++ b/tests/auto/qml/qqmlpromise/data/promise-resolve-function-length.qml
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import QtQuick 2.0
+
+QtObject {
+ property var resolveFunction
+ property var promise: new Promise(function(resolve, reject) {
+ resolveFunction = resolve
+ })
+
+ property bool wasTestSuccessful: (typeof resolveFunction === "function" &&
+ typeof resolveFunction.length !== "undefined" &&
+ resolveFunction.length === 1)
+
+ Component.onCompleted: {
+ // TODO: Function length field should be NotWritabel & NotEnumerable & Configurable
+ console.log(Object.getOwnPropertyDescriptor(resolveFunction, "length").configurable)
+ }
+}
diff --git a/tests/auto/qml/qqmlpromise/data/promise-resolve-is-a-function.qml b/tests/auto/qml/qqmlpromise/data/promise-resolve-is-a-function.qml
new file mode 100644
index 0000000000..fbdcc0f8e9
--- /dev/null
+++ b/tests/auto/qml/qqmlpromise/data/promise-resolve-is-a-function.qml
@@ -0,0 +1,43 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import QtQuick 2.0
+
+QtObject {
+ property bool wasTestSuccessful: (typeof Promise.resolve === "function")
+}
diff --git a/tests/auto/qml/qqmlpromise/data/promise-resolve-with-array.qml b/tests/auto/qml/qqmlpromise/data/promise-resolve-with-array.qml
new file mode 100644
index 0000000000..04d2209907
--- /dev/null
+++ b/tests/auto/qml/qqmlpromise/data/promise-resolve-with-array.qml
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import QtQuick 2.0
+
+QtObject {
+ property var resolveValue: [1, 2, 3]
+ property var promise: Promise.resolve(resolveValue)
+ property bool wasTestSuccessful: false
+
+ Component.onCompleted: {
+ promise.then(function(value) {
+ if (value === resolveValue) {
+ wasTestSuccessful = true
+ }
+ }, function() {
+ throw new Error("Should never be called")
+ })
+ }
+}
diff --git a/tests/auto/qml/qqmlpromise/data/promise-resolve-with-empty.qml b/tests/auto/qml/qqmlpromise/data/promise-resolve-with-empty.qml
new file mode 100644
index 0000000000..61c7bf17a6
--- /dev/null
+++ b/tests/auto/qml/qqmlpromise/data/promise-resolve-with-empty.qml
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import QtQuick 2.0
+
+QtObject {
+ property var promise: Promise.resolve()
+ property bool wasTestSuccessful: false
+
+ Component.onCompleted: {
+ promise.then(function(value) {
+ if (typeof value === "undefined") {
+ wasTestSuccessful = true
+ }
+ }, function() {
+ throw new Error("Should never be called")
+ })
+ }
+}
diff --git a/tests/auto/qml/qqmlpromise/data/promise-resolve-with-promise.qml b/tests/auto/qml/qqmlpromise/data/promise-resolve-with-promise.qml
new file mode 100644
index 0000000000..65b39508ad
--- /dev/null
+++ b/tests/auto/qml/qqmlpromise/data/promise-resolve-with-promise.qml
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import QtQuick 2.0
+
+QtObject {
+ property int resolveValue: 5
+ property var originalPromise: Promise.resolve(resolveValue)
+
+ property var castPromise: Promise.resolve(originalPromise)
+ property bool wasTestSuccessful: false
+
+ Component.onCompleted: {
+ if (castPromise !== originalPromise) {
+ console.log("resolve did not return original promise")
+ return;
+ }
+
+ castPromise.then(function(value) {
+ if (value !== resolveValue) {
+ console.log("resolved values are not the same")
+ return;
+ }
+
+ wasTestSuccessful = true
+ }, function() {
+ throw new Error("Should never be called")
+ })
+ }
+}
diff --git a/tests/auto/qml/qqmlpromise/data/promise-resolve-with-value.qml b/tests/auto/qml/qqmlpromise/data/promise-resolve-with-value.qml
new file mode 100644
index 0000000000..a1294cf9a6
--- /dev/null
+++ b/tests/auto/qml/qqmlpromise/data/promise-resolve-with-value.qml
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import QtQuick 2.0
+
+QtObject {
+ property int resolveValue: 5
+ property var promise: Promise.resolve(resolveValue)
+ property bool wasTestSuccessful: false
+
+ Component.onCompleted: {
+ promise.then(function(value) {
+ if (value === resolveValue) {
+ wasTestSuccessful = true
+ }
+ }, function() {
+ throw new Error("Should never be called")
+ })
+ }
+}
diff --git a/tests/auto/qml/qqmlpromise/data/then-fulfilled-non-callable.qml b/tests/auto/qml/qqmlpromise/data/then-fulfilled-non-callable.qml
new file mode 100644
index 0000000000..ee7e3ed7be
--- /dev/null
+++ b/tests/auto/qml/qqmlpromise/data/then-fulfilled-non-callable.qml
@@ -0,0 +1,93 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import QtQuick 2.0
+
+QtObject {
+ property int resolveValue: 5
+
+ property bool promise1WasResolved: false
+ property bool promise2WasResolved: false
+ property bool promise3WasResolved: false
+ property bool promise4WasResolved: true
+
+ property bool wasTestSuccessful: promise1WasResolved && promise2WasResolved &&
+ promise3WasResolved && promise4WasResolved
+
+ // TODO: Should this work as well?
+ // property Promise promise
+ property var promise1: new Promise(function (resolve, reject) {
+ resolve(resolveValue)
+ })
+ property var promise2: new Promise(function (resolve, reject) {
+ resolve(resolveValue)
+ })
+ property var promise3: new Promise(function (resolve, reject) {
+ resolve(resolveValue)
+ })
+ property var promise4: new Promise(function (resolve, reject) {
+ resolve(resolveValue)
+ })
+
+ Component.onCompleted: {
+ promise1.then().then(function (result) {
+ promise1WasResolved = (result === resolveValue);
+ }, function() {
+ throw new Error("Should never be called")
+ })
+ promise2.then(3, 5).then(function (result) {
+ promise2WasResolved = (result === resolveValue);
+ }, function() {
+ throw new Error("Should never be called")
+ })
+ promise3.then(null, function() {
+ throw new Error("Should never be called")
+ }).then(function (result) {
+ promise3WasResolved = (result === resolveValue);
+ }, function() {
+ throw new Error("Should never be called")
+ })
+ /*
+ promise4.then(undefined, undefined).then(function (result) {
+ promise4WasResolved = (result === resolveValue);
+ }, function() {
+ throw new Error("Should never be called")
+ })
+ */
+ }
+}
diff --git a/tests/auto/qml/qqmlpromise/data/then-reject-chaining.qml b/tests/auto/qml/qqmlpromise/data/then-reject-chaining.qml
new file mode 100644
index 0000000000..645ae9b07c
--- /dev/null
+++ b/tests/auto/qml/qqmlpromise/data/then-reject-chaining.qml
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import QtQuick 2.0
+
+QtObject {
+ property int rejectValue: 1
+ property int expectedValue: rejectValue + 2;
+ property bool wasTestSuccessful: false
+
+ Component.onCompleted: {
+ var promise = new Promise(function(resolve, reject) {
+ reject(rejectValue);
+ });
+
+ promise.then(function() {
+ throw new Error("Should never be called")
+ }, function(val) {
+ return val + 2;
+ }).then(function(val) {
+ if (val === expectedValue) {
+ wasTestSuccessful = true
+ }
+ }, function() {
+ throw new Error("Should never be called")
+ });
+ }
+}
diff --git a/tests/auto/qml/qqmlpromise/data/then-reject-non-callable.qml b/tests/auto/qml/qqmlpromise/data/then-reject-non-callable.qml
new file mode 100644
index 0000000000..df708c6218
--- /dev/null
+++ b/tests/auto/qml/qqmlpromise/data/then-reject-non-callable.qml
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import QtQuick 2.0
+
+QtObject {
+ property int rejectValue: 5
+
+ property bool promise1WasRejected: false
+ property bool promise2WasRejected: false
+
+ property bool wasTestSuccessful: promise1WasRejected && promise2WasRejected
+
+ // TODO: Should this work as well?
+ // property Promise promise
+ property var promise1: new Promise(function (resolve, reject) {
+ reject(rejectValue)
+ })
+ property var promise2: new Promise(function (resolve, reject) {
+ reject(rejectValue)
+ })
+
+ Component.onCompleted: {
+ promise1.then().then(function() {
+ promise1WasRejected = false
+ throw new Error("Should never be called")
+ }, function (result) {
+ promise1WasRejected = (result === rejectValue);
+ })
+ promise2.then(3, 5).then(function() {
+ promise2WasRejected = false
+ throw new Error("Should never be called")
+ }, function (result) {
+ promise2WasRejected = (result === rejectValue);
+ })
+ }
+}
diff --git a/tests/auto/qml/qqmlpromise/data/then-resolve-chaining.qml b/tests/auto/qml/qqmlpromise/data/then-resolve-chaining.qml
new file mode 100644
index 0000000000..d65e9c86ac
--- /dev/null
+++ b/tests/auto/qml/qqmlpromise/data/then-resolve-chaining.qml
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import QtQuick 2.0
+
+QtObject {
+ property int resolveValue: 1
+ property int expectedValue: resolveValue + 2;
+ property bool wasTestSuccessful: false
+
+ Component.onCompleted: {
+ var promise = new Promise(function(resolve, reject) {
+ resolve(resolveValue);
+ });
+
+ promise.then(function(val) {
+ return val + 2;
+ }).then(function(val) {
+ if (val === expectedValue) {
+ wasTestSuccessful = true;
+ }
+ });
+ }
+}
diff --git a/tests/auto/qml/qqmlpromise/data/then-resolve-multiple-then.qml b/tests/auto/qml/qqmlpromise/data/then-resolve-multiple-then.qml
new file mode 100644
index 0000000000..48000d5ddc
--- /dev/null
+++ b/tests/auto/qml/qqmlpromise/data/then-resolve-multiple-then.qml
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import QtQuick 2.0
+
+QtObject {
+ property int resolveValue: 5
+
+ property bool was1stCallSucessfull: false
+ property bool was2ndCallSucessfull: false
+
+ property bool wasTestSuccessful: was1stCallSucessfull && was2ndCallSucessfull
+
+ property var promise: new Promise(function (resolve, reject) {
+ resolve(resolveValue)
+ })
+
+ Component.onCompleted: {
+ promise.then(function (result) {
+ was1stCallSucessfull = (result === resolveValue);
+ }, function() {
+ throw new Error("Should never be called")
+ })
+ promise.then(function (result) {
+ was2ndCallSucessfull = (result === resolveValue);
+ }, function() {
+ throw new Error("Should never be called")
+ })
+ }
+}
diff --git a/tests/auto/qml/qqmlpromise/qqmlpromise.pro b/tests/auto/qml/qqmlpromise/qqmlpromise.pro
new file mode 100644
index 0000000000..7cdb02cd61
--- /dev/null
+++ b/tests/auto/qml/qqmlpromise/qqmlpromise.pro
@@ -0,0 +1,46 @@
+CONFIG += testcase
+TARGET = tst_qqmlpromise
+macos:CONFIG -= app_bundle
+
+SOURCES += tst_qqmlpromise.cpp
+
+OTHER_FILES +=
+
+include (../../shared/util.pri)
+
+TESTDATA = data/*
+
+QT += core-private gui-private qml-private testlib
+DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
+
+DISTFILES += \
+ data/then-fulfilled-non-callable.qml \
+ data/then-reject-non-callable.qml \
+ data/then-resolve-multiple-then.qml \
+ data/then-resolve-chaining.qml \
+ data/then-reject-chaining.qml \
+ data/promise-resolve-with-value.qml \
+ data/promise-resolve-with-promise.qml \
+ data/promise-reject-with-value.qml \
+ data/promise-executor-resolve.qml \
+ data/promise-get-length.qml \
+ data/promise-executor-reject.qml \
+ data/promise-reject-catch.qml \
+ data/promise-async-resolve-with-value.qml \
+ data/promise-async-reject-with-value.qml \
+ data/promise-all-resolve.qml \
+ data/promise-all-empty-input.qml \
+ data/promise-resolve-with-array.qml \
+ data/promise-all-reject-reject-is-last.qml \
+ data/promise-all-reject-reject-is-mid.qml \
+ data/promise-race-resolve-1st.qml \
+ data/promise-race-empty-input.qml \
+ data/promise-race-resolve-2nd.qml \
+ data/promise-race-resolve-1st-in-executor-function.qml \
+ data/promise-resolve-is-a-function.qml \
+ data/promise-resolve-function-length.qml \
+ data/promise-all-invoke-then-method.qml \
+ data/promise-resolve-with-empty.qml \
+ data/promise-executor-throw-exception.qml \
+ data/promise-executor-function-extensible.qml \
+ data/promise-all-noniterable-input.qml
diff --git a/tests/auto/qml/qqmlpromise/tst_qqmlpromise.cpp b/tests/auto/qml/qqmlpromise/tst_qqmlpromise.cpp
new file mode 100644
index 0000000000..0f4bb5cdcc
--- /dev/null
+++ b/tests/auto/qml/qqmlpromise/tst_qqmlpromise.cpp
@@ -0,0 +1,276 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <QString>
+#include <QtTest>
+#include <QQmlEngine>
+#include <QQmlComponent>
+#include <QDebug>
+#include <QScopedPointer>
+#include "../../shared/util.h"
+
+class tst_qqmlpromise : public QQmlDataTest
+{
+ Q_OBJECT
+
+public:
+ tst_qqmlpromise() {}
+
+private slots:
+ void promise_all_empty_input();
+ void promise_all_noniterable_input();
+// void promise_all_invoke_then_method();
+ void promise_all_resolve();
+ void promise_all_reject_reject_is_last();
+ void promise_all_reject_reject_is_mid();
+ void promise_get_length();
+ void promise_executor_function_extensible();
+ void promise_executor_reject();
+ void promise_executor_resolve();
+ void promise_executor_throw_exception();
+ void promise_async_resolve_with_value();
+ void promise_async_reject_with_value();
+ void promise_resolve_with_value();
+ void promise_resolve_function_length();
+ void promise_resolve_is_a_function();
+ void promise_resolve_with_array();
+ void promise_resolve_with_empty();
+ void promise_resolve_with_promise();
+ void promise_race_empty_input();
+ void promise_race_resolve_1st_in_executor_function();
+ void promise_race_resolve_1st();
+ void promise_race_resolve_2nd();
+ void promise_reject_with_value();
+ void promise_reject_catch();
+ void then_resolve_chaining();
+ void then_reject_chaining();
+ void then_fulfilled_non_callable();
+ void then_reject_non_callable();
+ void then_resolve_multiple_then();
+
+private:
+ void execute_test(QString testName);
+};
+
+void tst_qqmlpromise::promise_all_empty_input()
+{
+ execute_test("promise-all-empty-input.qml");
+}
+
+void tst_qqmlpromise::promise_all_noniterable_input()
+{
+ execute_test("promise-all-noniterable-input.qml");
+}
+
+// TODO: Fix the test
+//void tst_qqmlpromise::promise_all_invoke_then_method()
+//{
+// execute_test("promise-all-invoke-then-method.qml");
+//}
+
+void tst_qqmlpromise::promise_all_resolve()
+{
+ execute_test("promise-all-resolve.qml");
+}
+
+void tst_qqmlpromise::promise_all_reject_reject_is_last()
+{
+ execute_test("promise-all-reject-reject-is-last.qml");
+}
+
+void tst_qqmlpromise::promise_all_reject_reject_is_mid()
+{
+ execute_test("promise-all-reject-reject-is-mid.qml");
+}
+
+void tst_qqmlpromise::promise_get_length()
+{
+ execute_test("promise-get-length.qml");
+}
+
+void tst_qqmlpromise::promise_executor_resolve()
+{
+ QQmlEngine engine;
+ QQmlComponent component(&engine, testFileUrl("promise-executor-resolve.qml"));
+ QScopedPointer<QObject> object(component.beginCreate(engine.rootContext()));
+ QVERIFY(!object.isNull());
+ component.completeCreate();
+
+ QTRY_COMPARE(object->property("wasExecutorCalled").toBool(), true);
+ QTRY_COMPARE(object->property("wasPromiseResolved").toBool(), true);
+ // TODO: now "object" type is returned. fix
+ // QCOMPARE(object->property("wasPromiseTypeReturnedByThen").toBool(), true);
+ QTRY_COMPARE(object->property("wasResolutionForwardedCorrectly").toBool(), true);
+ QTRY_COMPARE(object->property("wasNewPromiseObjectCreatedByThen").toBool(), true);
+}
+
+void tst_qqmlpromise::promise_executor_throw_exception()
+{
+ execute_test("promise-executor-throw-exception.qml");
+}
+
+void tst_qqmlpromise::promise_async_resolve_with_value()
+{
+ execute_test("promise-async-resolve-with-value.qml");
+}
+
+void tst_qqmlpromise::promise_async_reject_with_value()
+{
+ execute_test("promise-async-reject-with-value.qml");
+}
+
+void tst_qqmlpromise::promise_resolve_with_value()
+{
+ execute_test("promise-resolve-with-value.qml");
+}
+
+void tst_qqmlpromise::promise_resolve_function_length()
+{
+ execute_test("promise-resolve-function-length.qml");
+}
+
+void tst_qqmlpromise::promise_resolve_is_a_function()
+{
+ execute_test("promise-resolve-is-a-function.qml");
+}
+
+void tst_qqmlpromise::promise_resolve_with_array()
+{
+ execute_test("promise-resolve-with-array.qml");
+}
+
+void tst_qqmlpromise::promise_resolve_with_empty()
+{
+ execute_test("promise-resolve-with-empty.qml");
+}
+
+void tst_qqmlpromise::promise_resolve_with_promise()
+{
+ execute_test("promise-resolve-with-promise.qml");
+}
+
+void tst_qqmlpromise::promise_race_empty_input()
+{
+ execute_test("promise-race-empty-input.qml");
+}
+
+void tst_qqmlpromise::promise_race_resolve_1st_in_executor_function()
+{
+ execute_test("promise-race-resolve-1st-in-executor-function.qml");
+}
+
+void tst_qqmlpromise::promise_race_resolve_1st()
+{
+ execute_test("promise-race-resolve-1st.qml");
+}
+
+void tst_qqmlpromise::promise_race_resolve_2nd()
+{
+ execute_test("promise-race-resolve-2nd.qml");
+}
+
+void tst_qqmlpromise::promise_reject_with_value()
+{
+ execute_test("promise-reject-with-value.qml");
+}
+
+void tst_qqmlpromise::promise_reject_catch()
+{
+ execute_test("promise-reject-catch.qml");
+}
+
+void tst_qqmlpromise::promise_executor_function_extensible()
+{
+ execute_test("promise-executor-function-extensible.qml");
+}
+
+void tst_qqmlpromise::promise_executor_reject()
+{
+ QQmlEngine engine;
+ QQmlComponent component(&engine, testFileUrl("promise-executor-reject.qml"));
+ QScopedPointer<QObject> object(component.beginCreate(engine.rootContext()));
+ QVERIFY(!object.isNull());
+ component.completeCreate();
+
+ QTRY_COMPARE(object->property("wasExecutorCalled").toBool(), true);
+ QTRY_COMPARE(object->property("wasPromiseRejected").toBool(), true);
+ // TODO: now "object" type is returned. fix
+ // QCOMPARE(object->property("wasPromiseTypeReturnedByThen").toBool(), true);
+ QTRY_COMPARE(object->property("wasResolutionForwardedCorrectly").toBool(), true);
+}
+
+void tst_qqmlpromise::then_resolve_chaining()
+{
+ execute_test("then-resolve-chaining.qml");
+}
+
+void tst_qqmlpromise::then_reject_chaining()
+{
+ execute_test("then-reject-chaining.qml");
+}
+
+void tst_qqmlpromise::then_fulfilled_non_callable()
+{
+ execute_test("then-fulfilled-non-callable.qml");
+}
+
+void tst_qqmlpromise::then_reject_non_callable()
+{
+ execute_test("then-reject-non-callable.qml");
+}
+
+void tst_qqmlpromise::then_resolve_multiple_then()
+{
+ execute_test("then-resolve-multiple-then.qml");
+}
+
+void tst_qqmlpromise::execute_test(QString testName)
+{
+ QQmlEngine engine;
+ QQmlComponent component(&engine, testFileUrl(testName));
+ QScopedPointer<QObject> object(component.beginCreate(engine.rootContext()));
+ QVERIFY(!object.isNull());
+ component.completeCreate();
+
+ QTRY_COMPARE(object->property("wasTestSuccessful").toBool(), true);
+}
+
+
+QTEST_MAIN(tst_qqmlpromise)
+
+#include "tst_qqmlpromise.moc"