1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
import QtQuick
import QtTest
import QtWebEngine
TestWebEngineView {
id: webEngineView
width: 200
height: 200
property bool deniedGeolocation: false
property bool geoPermissionRequested: false
SignalSpy {
id: featurePermissionSpy
target: webEngineView
signalName: "featurePermissionRequested"
}
onFeaturePermissionRequested: function(securityOrigin, feature) {
if (feature === WebEngineView.Geolocation) {
geoPermissionRequested = true
if (deniedGeolocation) {
webEngineView.grantFeaturePermission(securityOrigin, feature, false)
}
else {
webEngineView.grantFeaturePermission(securityOrigin, feature, true)
}
}
}
TestCase {
name: "WebViewGeopermission"
when: windowShown
function isHandled() {
var handled;
runJavaScript("handled", function(result) {
handled = result;
});
tryVerify(function() { return handled != undefined; }, 5000);
return handled;
}
function getErrorMessage() {
var errorMessage;
runJavaScript("errorMessage", function(result) {
errorMessage = result;
});
tryVerify(function() { return errorMessage != undefined; }, 5000);
return errorMessage;
}
function init() {
deniedGeolocation = false
featurePermissionSpy.clear()
}
function test_geoPermissionRequest() {
compare(featurePermissionSpy.count, 0)
webEngineView.url = Qt.resolvedUrl("geolocation.html")
featurePermissionSpy.wait()
verify(geoPermissionRequested)
compare(featurePermissionSpy.count, 1)
tryVerify(isHandled, 5000)
verify(getErrorMessage() === "")
}
function test_deniedGeolocationByUser() {
deniedGeolocation = true
webEngineView.url = Qt.resolvedUrl("geolocation.html")
featurePermissionSpy.wait()
tryVerify(isHandled, 5000)
compare(getErrorMessage(), "User denied Geolocation")
}
}
}
|