summaryrefslogtreecommitdiffstats
path: root/tests/auto/quick
diff options
context:
space:
mode:
authorKirill Burtsev <kirill.burtsev@qt.io>2019-01-31 13:08:21 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2019-02-06 15:18:18 +0000
commitf4ca67aa7f70f58d39ef8689ddd5910e215ed6cd (patch)
treeebb9937672b14c725de14fd7da6e3eeac269e861 /tests/auto/quick
parent7aa06a1614b7ca6508d96ee2e8ef0f4c49038a6f (diff)
Web Notifications API
Implements API for end-user notifications. Co-authored by Allan Sandfeld Jensen [ChangeLog][Profile] Support for Web Notifications API for end-user notifications through QWebEngineNotification Task-number: QTBUG-50995 Fixes: QTBUG-51191 Change-Id: Icebaaa05275a713e801f1f8ecdaaec725fa264c8 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'tests/auto/quick')
-rw-r--r--tests/auto/quick/publicapi/tst_publicapi.cpp18
-rw-r--r--tests/auto/quick/qmltests/data/tst_notification.qml116
-rw-r--r--tests/auto/quick/qmltests/qmltests.pro1
3 files changed, 135 insertions, 0 deletions
diff --git a/tests/auto/quick/publicapi/tst_publicapi.cpp b/tests/auto/quick/publicapi/tst_publicapi.cpp
index 4cbadfdaa..b50a7d782 100644
--- a/tests/auto/quick/publicapi/tst_publicapi.cpp
+++ b/tests/auto/quick/publicapi/tst_publicapi.cpp
@@ -35,6 +35,7 @@
#include <QtTest/QtTest>
#include <QtWebEngine/QQuickWebEngineProfile>
#include <QtWebEngine/QQuickWebEngineScript>
+#include <QtWebEngineCore/QWebEngineNotification>
#include <QtWebEngineCore/QWebEngineQuotaRequest>
#include <QtWebEngineCore/QWebEngineRegisterProtocolHandlerRequest>
#include <private/qquickwebengineview_p.h>
@@ -82,6 +83,7 @@ static const QList<const QMetaObject *> typesToCheck = QList<const QMetaObject *
<< &QQuickWebEngineContextMenuRequest::staticMetaObject
<< &QWebEngineQuotaRequest::staticMetaObject
<< &QWebEngineRegisterProtocolHandlerRequest::staticMetaObject
+ << &QWebEngineNotification::staticMetaObject
;
static QList<const char *> knownEnumNames = QList<const char *>();
@@ -286,6 +288,7 @@ static const QStringList expectedAPI = QStringList()
<< "QQuickWebEngineProfile.clearHttpCache() --> void"
<< "QQuickWebEngineProfile.downloadFinished(QQuickWebEngineDownloadItem*) --> void"
<< "QQuickWebEngineProfile.downloadRequested(QQuickWebEngineDownloadItem*) --> void"
+ << "QQuickWebEngineProfile.userNotification(QWebEngineNotification*) --> void"
<< "QQuickWebEngineProfile.httpAcceptLanguage --> QString"
<< "QQuickWebEngineProfile.httpAcceptLanguageChanged() --> void"
<< "QQuickWebEngineProfile.httpCacheMaximumSize --> int"
@@ -564,6 +567,7 @@ static const QStringList expectedAPI = QStringList()
<< "QQuickWebEngineView.NewViewInTab --> NewViewDestination"
<< "QQuickWebEngineView.NewViewInWindow --> NewViewDestination"
<< "QQuickWebEngineView.NoErrorDomain --> ErrorDomain"
+ << "QQuickWebEngineView.Notifications --> Feature"
<< "QQuickWebEngineView.NoWebAction --> WebAction"
<< "QQuickWebEngineView.NormalTerminationStatus --> RenderProcessTerminationStatus"
<< "QQuickWebEngineView.Note --> PrintedPageSizeId"
@@ -703,6 +707,20 @@ static const QStringList expectedAPI = QStringList()
<< "QWebEngineRegisterProtocolHandlerRequest.origin --> QUrl"
<< "QWebEngineRegisterProtocolHandlerRequest.reject() --> void"
<< "QWebEngineRegisterProtocolHandlerRequest.scheme --> QString"
+ << "QWebEngineNotification.origin --> QUrl"
+ << "QWebEngineNotification.icon --> QIcon"
+ << "QWebEngineNotification.title --> QString"
+ << "QWebEngineNotification.message --> QString"
+ << "QWebEngineNotification.tag --> QString"
+ << "QWebEngineNotification.language --> QString"
+ << "QWebEngineNotification.direction --> Direction"
+ << "QWebEngineNotification.LeftToRight --> Direction"
+ << "QWebEngineNotification.RightToLeft --> Direction"
+ << "QWebEngineNotification.DirectionAuto --> Direction"
+ << "QWebEngineNotification.show() --> void"
+ << "QWebEngineNotification.click() --> void"
+ << "QWebEngineNotification.close() --> void"
+ << "QWebEngineNotification.closed() --> void"
;
static bool isCheckedEnum(const QByteArray &typeName)
diff --git a/tests/auto/quick/qmltests/data/tst_notification.qml b/tests/auto/quick/qmltests/data/tst_notification.qml
new file mode 100644
index 000000000..609a04f61
--- /dev/null
+++ b/tests/auto/quick/qmltests/data/tst_notification.qml
@@ -0,0 +1,116 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtWebEngine module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** 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 General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** 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-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.2
+import QtTest 1.0
+import QtWebEngine 1.9
+
+TestWebEngineView {
+ id: view
+ width: 320
+ height: 320
+
+ property bool permissionRequested: false
+ property bool grantPermission: false
+
+ signal consoleMessage(string message)
+
+ SignalSpy {
+ id: spyRequest
+ target: view
+ signalName: 'featurePermissionRequested'
+ }
+
+ onFeaturePermissionRequested: {
+ if (feature === WebEngineView.Notifications) {
+ permissionRequested = true
+ view.grantFeaturePermission(securityOrigin, feature, grantPermission)
+ }
+ }
+
+ TestCase {
+ name: 'WebEngineNotification'
+ when: windowShown
+
+ function resolverUrl(html) {
+ return Qt.resolvedUrl('../../../shared/data/' + html)
+ }
+
+ function init() {
+ permissionRequested = false
+ spyRequest.clear()
+ }
+
+ function test_request_data() {
+ return [
+ { tag: 'grant', grant: true, permission: 'granted' },
+ { tag: 'deny', grant: false, permission: 'denied' },
+ ]
+ }
+
+ function test_request(data) {
+ grantPermission = data.grant
+
+ view.url = resolverUrl('notification.html')
+ verify(view.waitForLoadSucceeded())
+
+ view.runJavaScript('resetPermission()')
+ let result = {}
+
+ view.runJavaScript('getPermission()', function (permission) { result.permission = permission })
+ tryCompare(result, 'permission', 'default')
+
+ view.runJavaScript('requestPermission()')
+ spyRequest.wait()
+ verify(permissionRequested)
+ compare(spyRequest.count, 1)
+
+ view.runJavaScript('getPermission()', function (permission) { result.permission = permission })
+ tryCompare(result, 'permission', data.permission)
+ }
+
+ function test_notification() {
+ grantPermission = true
+
+ view.url = resolverUrl('notification.html')
+ view.waitForLoadSucceeded()
+
+ view.runJavaScript('requestPermission()')
+ spyRequest.wait()
+ verify(permissionRequested)
+
+ let title = 'Title', message = 'Message', notification = null
+ view.profile.userNotification.connect(function (n) { notification = n })
+
+ view.runJavaScript('sendNotification("' + title + '", "' + message + '")')
+ tryVerify(function () { return notification !== null })
+ compare(notification.title, title)
+ compare(notification.message, message)
+ }
+ }
+}
diff --git a/tests/auto/quick/qmltests/qmltests.pro b/tests/auto/quick/qmltests/qmltests.pro
index ad479cd31..00e884e11 100644
--- a/tests/auto/quick/qmltests/qmltests.pro
+++ b/tests/auto/quick/qmltests/qmltests.pro
@@ -67,6 +67,7 @@ OTHER_FILES += \
$$PWD/data/tst_navigationHistory.qml \
$$PWD/data/tst_navigationRequested.qml \
$$PWD/data/tst_newViewRequest.qml \
+ $$PWD/data/tst_notification.qml \
$$PWD/data/tst_profile.qml \
$$PWD/data/tst_properties.qml \
$$PWD/data/tst_runJavaScript.qml \