diff options
Diffstat (limited to 'tests/manual/widgets/geolocation')
-rw-r--r-- | tests/manual/widgets/geolocation/CMakeLists.txt | 55 | ||||
-rw-r--r-- | tests/manual/widgets/geolocation/Info.plist | 32 | ||||
-rw-r--r-- | tests/manual/widgets/geolocation/geolocation.html | 32 | ||||
-rw-r--r-- | tests/manual/widgets/geolocation/main.cpp | 51 |
4 files changed, 170 insertions, 0 deletions
diff --git a/tests/manual/widgets/geolocation/CMakeLists.txt b/tests/manual/widgets/geolocation/CMakeLists.txt new file mode 100644 index 000000000..2ca8c2f52 --- /dev/null +++ b/tests/manual/widgets/geolocation/CMakeLists.txt @@ -0,0 +1,55 @@ +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +if (NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(geolocation LANGUAGES CXX) + find_package(Qt6BuildInternals COMPONENTS STANDALONE_TEST) +endif() + +qt_internal_add_manual_test(geolocation + GUI + SOURCES + main.cpp + LIBRARIES + Qt::Core + Qt::Gui + Qt::Test + Qt::WebEngineWidgets + ENABLE_AUTOGEN_TOOLS + moc +) + +set_target_properties(geolocation PROPERTIES + WIN32_EXECUTABLE TRUE + MACOSX_BUNDLE TRUE + MACOSX_BUNDLE_GUI_IDENTIFIER "io.qt.dev.webenginewidgets.geolocation" +) + +set(geolocation_resource_files + "geolocation.html" +) + +qt_add_resources(geolocation "geolocation" + PREFIX + "/" + FILES + ${geolocation_resource_files} +) + + foreach(permission_plugin IN LISTS QT_ALL_PLUGINS_FOUND_BY_FIND_PACKAGE_permissions) + set(permission_plugin "${QT_CMAKE_EXPORT_NAMESPACE}::${permission_plugin}") + qt6_import_plugins(geolocation INCLUDE ${permission_plugin}) + endforeach() + +if (APPLE) + set_target_properties(geolocation PROPERTIES + MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/Info.plist" + ) + + if (NOT CMAKE_GENERATOR STREQUAL "Xcode") + # Need to sign application for location permissions to work + add_custom_command(TARGET geolocation + POST_BUILD COMMAND codesign -s - geolocation.app) + endif() +endif() diff --git a/tests/manual/widgets/geolocation/Info.plist b/tests/manual/widgets/geolocation/Info.plist new file mode 100644 index 000000000..9853e1900 --- /dev/null +++ b/tests/manual/widgets/geolocation/Info.plist @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>CFBundleInfoDictionaryVersion</key> + <string>6.0</string> + <key>CFBundlePackageType</key> + <string>APPL</string> + <key>CFBundleName</key> + <string>${MACOSX_BUNDLE_BUNDLE_NAME}</string> + <key>CFBundleIdentifier</key> + <string>${MACOSX_BUNDLE_GUI_IDENTIFIER}</string> + <key>CFBundleExecutable</key> + <string>${MACOSX_BUNDLE_EXECUTABLE_NAME}</string> + <key>CFBundleVersion</key> + <string>${MACOSX_BUNDLE_BUNDLE_VERSION}</string> + <key>CFBundleShortVersionString</key> + <string>${MACOSX_BUNDLE_SHORT_VERSION_STRING}</string> + <key>LSMinimumSystemVersion</key> + <string>${CMAKE_OSX_DEPLOYMENT_TARGET}</string> + <key>NSHumanReadableCopyright</key> + <string>${MACOSX_BUNDLE_COPYRIGHT}</string> + <key>CFBundleIconFile</key> + <string>${MACOSX_BUNDLE_ICON_FILE}</string> + <key>CFBundleDevelopmentRegion</key> + <string>English</string> + <key>NSSupportsAutomaticGraphicsSwitching</key> + <true/> + <key>NSLocationUsageDescription</key> + <string>Geolocation test would like to give web sites access to your location for demo purposes.</string> +</dict> +</plist> diff --git a/tests/manual/widgets/geolocation/geolocation.html b/tests/manual/widgets/geolocation/geolocation.html new file mode 100644 index 000000000..e8c54bc58 --- /dev/null +++ b/tests/manual/widgets/geolocation/geolocation.html @@ -0,0 +1,32 @@ +<html> +<head> +<title>Geolocation Permission API Test</title> +<script> + +var errorMessage; +var handled = false; + +function successHandler(location) { + var message = document.getElementById("message"); + message.innerHTML = "Latitude: " + location.coords.latitude + + "<br>Longitude: " + location.coords.longitude; + + errorMessage = ""; + handled = true; +} + +function errorHandler(error) { + errorMessage = error.message; + handled = true; +} + +<!-- One shot example --> +navigator.geolocation.getCurrentPosition(successHandler, errorHandler); + +</script> +</head> +<body> +<div id="message">Location unknown</div> +</body> +</html> + diff --git a/tests/manual/widgets/geolocation/main.cpp b/tests/manual/widgets/geolocation/main.cpp new file mode 100644 index 000000000..f33cf5798 --- /dev/null +++ b/tests/manual/widgets/geolocation/main.cpp @@ -0,0 +1,51 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#include <QApplication> +#include <QFormLayout> +#include <QGroupBox> +#include <QHBoxLayout> +#include <QLabel> +#include <QMainWindow> +#include <QMessageBox> +#include <QVBoxLayout> +#include <QWebEnginePage> +#include <QWebEngineView> + +class GeoPermissionWebView : public QWebEngineView { + Q_OBJECT + +public slots: + void handleFeaturePermissionRequested(const QUrl &securityOrigin, + QWebEnginePage::Feature feature) + { + qWarning("Feature Permission"); + QString title = tr("Permission Request"); + QString question = QLatin1String("Allow access to geolocation?"); + if (!question.isEmpty() && QMessageBox::question(window(), title, question) == QMessageBox::Yes) + page()->setFeaturePermission(securityOrigin, feature, + QWebEnginePage::PermissionGrantedByUser); + else + page()->setFeaturePermission(securityOrigin, feature, + QWebEnginePage::PermissionDeniedByUser); + } + +}; + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + QMainWindow w; + GeoPermissionWebView webview; + QWebEnginePage page; + QObject::connect(&page, &QWebEnginePage::featurePermissionRequested, &webview, + &GeoPermissionWebView::handleFeaturePermissionRequested); + webview.setPage(&page); + page.load(QUrl("qrc:/geolocation.html")); + w.setCentralWidget(&webview); + w.show(); + + return a.exec(); +} + +#include "main.moc" |