summaryrefslogtreecommitdiffstats
path: root/tests/auto/quick
diff options
context:
space:
mode:
authorAdam Kallai <kadam@inf.u-szeged.hu>2015-08-05 09:04:30 -0700
committerAdam Kallai <kadam@inf.u-szeged.hu>2015-09-01 14:18:55 +0000
commitbbf750845908d1663fabf94a7babcfa07ec24c69 (patch)
tree4c2079c520c1838788d79a38d020d0b151432b22 /tests/auto/quick
parent60d67ffcadccdbc074d3d40e93357801e417b444 (diff)
Add tst_geopermission QML test case
Change-Id: Icfb74f3ef8b0745d3fc0a7335f8344960a74fa0b Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
Diffstat (limited to 'tests/auto/quick')
-rw-r--r--tests/auto/quick/qmltests/data/geolocation.html26
-rw-r--r--tests/auto/quick/qmltests/data/tst_geopermission.qml105
-rw-r--r--tests/auto/quick/qmltests/qmltests.pro2
3 files changed, 133 insertions, 0 deletions
diff --git a/tests/auto/quick/qmltests/data/geolocation.html b/tests/auto/quick/qmltests/data/geolocation.html
new file mode 100644
index 000000000..c095a6b9e
--- /dev/null
+++ b/tests/auto/quick/qmltests/data/geolocation.html
@@ -0,0 +1,26 @@
+<html>
+<head>
+<title>Geolocation Permission API Test</title>
+<script>
+
+function successHandler(location) {
+ var message = document.getElementById("message");
+ message.innerHTML = "Latitude: " + location.coords.latitude +
+ "<br>Longitude: " + location.coords.longitude;
+
+}
+
+function errorHandler(error) {
+ console.error(error.message);
+}
+
+<!-- One shot example -->
+navigator.geolocation.getCurrentPosition(successHandler, errorHandler);
+
+</script>
+</head>
+<body>
+<div id="message">Location unknown</div>
+</body>
+</html>
+
diff --git a/tests/auto/quick/qmltests/data/tst_geopermission.qml b/tests/auto/quick/qmltests/data/tst_geopermission.qml
new file mode 100644
index 000000000..acb561825
--- /dev/null
+++ b/tests/auto/quick/qmltests/data/tst_geopermission.qml
@@ -0,0 +1,105 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtWebEngine 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** As a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.2
+import QtTest 1.0
+import QtWebEngine 1.1
+
+TestWebEngineView {
+ id: webEngineView
+ width: 200
+ height: 200
+
+ property bool deniedGeolocation: false
+ property bool geoPermissionRequested: false
+ property string consoleErrorMessage: ""
+
+ SignalSpy {
+ id: featurePermissionSpy
+ target: webEngineView
+ signalName: "featurePermissionRequested"
+ }
+
+ onFeaturePermissionRequested: {
+ if (feature === WebEngineView.Geolocation) {
+ geoPermissionRequested = true
+ if (deniedGeolocation) {
+ webEngineView.grantFeaturePermission(securityOrigin, feature, false)
+ }
+ else {
+ webEngineView.grantFeaturePermission(securityOrigin, feature, true)
+ }
+ }
+ }
+
+ onJavaScriptConsoleMessage: {
+ if (level === WebEngineView.ErrorMessageLevel)
+ consoleErrorMessage = message
+ }
+
+ TestCase {
+ name: "WebViewGeopermission"
+ when: windowShown
+
+ function init() {
+ deniedGeolocation = false
+ consoleErrorMessage = ""
+ featurePermissionSpy.clear()
+ }
+
+ function test_geoPermissionRequest() {
+ compare(featurePermissionSpy.count, 0)
+ webEngineView.url = Qt.resolvedUrl("geolocation.html")
+ featurePermissionSpy.wait()
+ verify(geoPermissionRequested)
+ compare(featurePermissionSpy.count, 1)
+ if (consoleErrorMessage) // Print the error message if it fails to get user's location
+ fail(consoleErrorMessage)
+ }
+
+ function test_deniedGeolocationByUser() {
+ deniedGeolocation = true
+ webEngineView.url = Qt.resolvedUrl("geolocation.html")
+ featurePermissionSpy.wait()
+ compare(consoleErrorMessage, "User denied Geolocation")
+ }
+ }
+}
diff --git a/tests/auto/quick/qmltests/qmltests.pro b/tests/auto/quick/qmltests/qmltests.pro
index 68e9dc002..9f6f55275 100644
--- a/tests/auto/quick/qmltests/qmltests.pro
+++ b/tests/auto/quick/qmltests/qmltests.pro
@@ -15,6 +15,7 @@ OTHER_FILES += \
$$PWD/data/favicon.html \
$$PWD/data/favicon.png \
$$PWD/data/favicon2.html \
+ $$PWD/data/geolocation.html \
$$PWD/data/javascript.html \
$$PWD/data/link.html \
$$PWD/data/prompt.html \
@@ -28,6 +29,7 @@ OTHER_FILES += \
$$PWD/data/tst_desktopBehaviorLoadHtml.qml \
$$PWD/data/tst_download.qml \
$$PWD/data/tst_favIconLoad.qml \
+ $$PWD/data/tst_geopermission.qml \
$$PWD/data/tst_javaScriptDialogs.qml \
$$PWD/data/tst_linkHovered.qml \
$$PWD/data/tst_loadFail.qml \