summaryrefslogtreecommitdiffstats
path: root/tests/auto/core/qwebengineurlrequestinterceptor/resources
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/core/qwebengineurlrequestinterceptor/resources')
-rw-r--r--tests/auto/core/qwebengineurlrequestinterceptor/resources/content.html3
-rw-r--r--tests/auto/core/qwebengineurlrequestinterceptor/resources/content2.html6
-rw-r--r--tests/auto/core/qwebengineurlrequestinterceptor/resources/content3.html6
-rw-r--r--tests/auto/core/qwebengineurlrequestinterceptor/resources/postBodyFile.txt3
-rw-r--r--tests/auto/core/qwebengineurlrequestinterceptor/resources/sw.html39
-rw-r--r--tests/auto/core/qwebengineurlrequestinterceptor/resources/sw.js15
6 files changed, 64 insertions, 8 deletions
diff --git a/tests/auto/core/qwebengineurlrequestinterceptor/resources/content.html b/tests/auto/core/qwebengineurlrequestinterceptor/resources/content.html
index 360ad65ef..84bf55036 100644
--- a/tests/auto/core/qwebengineurlrequestinterceptor/resources/content.html
+++ b/tests/auto/core/qwebengineurlrequestinterceptor/resources/content.html
@@ -1,5 +1,6 @@
<html>
+<head><link rel="icon" href="data:,"></head>
<body>
-<a>This is test content</a>
+<a>Simple test page without favicon (meaning no separate request from http server)</a>
</body>
</html>
diff --git a/tests/auto/core/qwebengineurlrequestinterceptor/resources/content2.html b/tests/auto/core/qwebengineurlrequestinterceptor/resources/content2.html
new file mode 100644
index 000000000..84bf55036
--- /dev/null
+++ b/tests/auto/core/qwebengineurlrequestinterceptor/resources/content2.html
@@ -0,0 +1,6 @@
+<html>
+<head><link rel="icon" href="data:,"></head>
+<body>
+<a>Simple test page without favicon (meaning no separate request from http server)</a>
+</body>
+</html>
diff --git a/tests/auto/core/qwebengineurlrequestinterceptor/resources/content3.html b/tests/auto/core/qwebengineurlrequestinterceptor/resources/content3.html
new file mode 100644
index 000000000..84bf55036
--- /dev/null
+++ b/tests/auto/core/qwebengineurlrequestinterceptor/resources/content3.html
@@ -0,0 +1,6 @@
+<html>
+<head><link rel="icon" href="data:,"></head>
+<body>
+<a>Simple test page without favicon (meaning no separate request from http server)</a>
+</body>
+</html>
diff --git a/tests/auto/core/qwebengineurlrequestinterceptor/resources/postBodyFile.txt b/tests/auto/core/qwebengineurlrequestinterceptor/resources/postBodyFile.txt
new file mode 100644
index 000000000..7729c4e0a
--- /dev/null
+++ b/tests/auto/core/qwebengineurlrequestinterceptor/resources/postBodyFile.txt
@@ -0,0 +1,3 @@
+{
+"test": "1234"
+}
diff --git a/tests/auto/core/qwebengineurlrequestinterceptor/resources/sw.html b/tests/auto/core/qwebengineurlrequestinterceptor/resources/sw.html
index af44b45a2..fc3d9ded4 100644
--- a/tests/auto/core/qwebengineurlrequestinterceptor/resources/sw.html
+++ b/tests/auto/core/qwebengineurlrequestinterceptor/resources/sw.html
@@ -2,13 +2,40 @@
<html>
<body>
<script>
+ function logState(state) {
+ console.log("Service worker " + state)
+ }
+
+ const registerServiceWorker = async () => {
+ try {
+ var serviceWorker;
+ const registration = await navigator.serviceWorker.register('/sw.js');
+ if (registration.installing) {
+ serviceWorker = registration.installing;
+ } else if (registration.waiting) {
+ serviceWorker = registration.waiting;
+ } else if (registration.active) {
+ serviceWorker = registration.active;
+ }
+ } catch (error) {
+ console.error("Service worker registration error: ${error}");
+ }
+ if (serviceWorker) {
+ logState(serviceWorker.state);
+ serviceWorker.addEventListener('statechange', function(e) {
+ logState(e.target.state);
+ });
+ }
+ };
if ('serviceWorker' in navigator) {
- window.addEventListener('load', function() {
- navigator.serviceWorker.register('/sw.js').then(function(registration) {
- console.log('ServiceWorker registration successful with scope: ', registration.scope);
- }, function(err) {
- console.error('ServiceWorker registration failed: ', err);
- });
+ registerServiceWorker();
+ navigator.serviceWorker.ready.then((registration) => {
+ navigator.serviceWorker.onmessage = (event) => {
+ if (event.data && event.data.type === 'PONG') {
+ console.log("Service worker done");
+ }
+ };
+ registration.active.postMessage({type: 'PING'});
});
}
</script>
diff --git a/tests/auto/core/qwebengineurlrequestinterceptor/resources/sw.js b/tests/auto/core/qwebengineurlrequestinterceptor/resources/sw.js
index 2216e2a07..196a9ad67 100644
--- a/tests/auto/core/qwebengineurlrequestinterceptor/resources/sw.js
+++ b/tests/auto/core/qwebengineurlrequestinterceptor/resources/sw.js
@@ -1,3 +1,16 @@
self.addEventListener('install', function(event) {
- console.log('ServiceWorker installed');
+ event.waitUntil(self.skipWaiting());
+});
+
+self.addEventListener('activate', function(event) {
+ event.waitUntil(self.clients.claim());
+});
+self.addEventListener('message', (event) => {
+ if (event.data && event.data.type === 'PING') {
+ self.clients.matchAll({includeUncontrolled: true, type: 'window'}).then((clients) => {
+ if (clients && clients.length) {
+ clients[0].postMessage({type: 'PONG'});
+ }
+ });
+ }
});