diff options
author | Kirill Burtsev <kirill.burtsev@qt.io> | 2019-01-31 13:08:21 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-02-06 15:18:18 +0000 |
commit | f4ca67aa7f70f58d39ef8689ddd5910e215ed6cd (patch) | |
tree | ebb9937672b14c725de14fd7da6e3eeac269e861 /tests/auto/shared | |
parent | 7aa06a1614b7ca6508d96ee2e8ef0f4c49038a6f (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/shared')
-rw-r--r-- | tests/auto/shared/data/notification.html | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/tests/auto/shared/data/notification.html b/tests/auto/shared/data/notification.html new file mode 100644 index 000000000..cadcbd942 --- /dev/null +++ b/tests/auto/shared/data/notification.html @@ -0,0 +1,70 @@ +<!doctype html> +<html> +<head> +<title>Desktop Notifications Demo</title> +<script> + function resetPermission() { document.Notification = 'default' } + + function getPermission() { return document.Notification } + + function sendNotification(title, body) { + let notification = new Notification(title, { body: body }) + notification.onclick = function() { console.info('onclick') } + notification.onclose = function() { console.info('onclose') } + notification.onerror = function(error) { console.info('onerror: ' + error) } + notification.onshow = function() { console.info('onshow') } + } + + function makeNotification() { + let title = document.getElementById("title").value + let body = document.getElementById("body").value + console.log('making notification:', title) + sendNotification(title, body) + } + + function requestPermission(callback) { + Notification.requestPermission().then(function (permission) { + document.Notification = permission + if (callback) + callback(permission) + }) + } + + function displayNotification() { + console.info('notifications are ' + document.Notification) + + let state = document.getElementById('state') + + if (document.Notification === 'denied') { + state.innerHTML = 'Notifications disabled' + } else if (document.Notification === 'granted') { + makeNotification() + state.innerHTML = 'notification created' + } else { + state.innerHTML = 'requesting permission...' + requestPermission(function (permission) { + console.info('notifications request: ' + permission) + if (permission === 'granted') { + makeNotification() + state.innerHTML = 'permission granted, notification created' + } else if (permission === 'denied') + state.innerHTML = 'Notifications are disabled' + }) + } + } + + document.addEventListener("DOMContentLoaded", function() { + document.Notification = Notification.permission + }) +</script> +</head> +<body> + <form name="NotificationForm" id="notificationForm"> + Title: <input type="text" id="title" placeholder="Notification title" value='sample title'><br> + Body: <input type="text" id="body" placeholder="Notification body" value='default body'><br> + <input type="button" value="Display Notification" onclick="displayNotification()"><br> + <input type="button" value="Reset Permission" onclick="resetPermission()"> + </form> + <div id='state'></div> +</body> +</html> |