diff options
Diffstat (limited to '')
-rw-r--r-- | dom/serviceworkers/test/notification/register.html | 11 | ||||
-rw-r--r-- | dom/serviceworkers/test/notification_constructor_error.js | 1 | ||||
-rw-r--r-- | dom/serviceworkers/test/notification_get_sw.js | 0 | ||||
-rw-r--r-- | dom/serviceworkers/test/notification_openWindow_worker.js | 25 | ||||
-rw-r--r-- | dom/serviceworkers/test/notificationclick-otherwindow.html | 30 | ||||
-rw-r--r-- | dom/serviceworkers/test/notificationclick.html | 27 | ||||
-rw-r--r-- | dom/serviceworkers/test/notificationclick.js | 23 | ||||
-rw-r--r-- | dom/serviceworkers/test/notificationclick_focus.html | 28 | ||||
-rw-r--r-- | dom/serviceworkers/test/notificationclick_focus.js | 49 | ||||
-rw-r--r-- | dom/serviceworkers/test/notificationclose.html | 37 | ||||
-rw-r--r-- | dom/serviceworkers/test/notificationclose.js | 31 |
11 files changed, 262 insertions, 0 deletions
diff --git a/dom/serviceworkers/test/notification/register.html b/dom/serviceworkers/test/notification/register.html new file mode 100644 index 0000000000..b7df73bede --- /dev/null +++ b/dom/serviceworkers/test/notification/register.html @@ -0,0 +1,11 @@ +<!DOCTYPE html> +<script> + function done() { + parent.callback(); + } + + navigator.serviceWorker.ready.then(done); + navigator.serviceWorker.register("../notification_get_sw.js", {scope: "."}).catch(function(e) { + dump("Registration failure " + e.message + "\n"); + }); +</script> diff --git a/dom/serviceworkers/test/notification_constructor_error.js b/dom/serviceworkers/test/notification_constructor_error.js new file mode 100644 index 0000000000..644dba480e --- /dev/null +++ b/dom/serviceworkers/test/notification_constructor_error.js @@ -0,0 +1 @@ +new Notification("Hi there"); diff --git a/dom/serviceworkers/test/notification_get_sw.js b/dom/serviceworkers/test/notification_get_sw.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/dom/serviceworkers/test/notification_get_sw.js diff --git a/dom/serviceworkers/test/notification_openWindow_worker.js b/dom/serviceworkers/test/notification_openWindow_worker.js new file mode 100644 index 0000000000..890f70f795 --- /dev/null +++ b/dom/serviceworkers/test/notification_openWindow_worker.js @@ -0,0 +1,25 @@ +const gRoot = "http://mochi.test:8888/tests/dom/serviceworkers/test/"; +const gTestURL = gRoot + "test_notification_openWindow.html"; +const gClientURL = gRoot + "file_notification_openWindow.html"; + +onmessage = function (event) { + if (event.data !== "DONE") { + dump(`ERROR: received unexpected message: ${JSON.stringify(event.data)}\n`); + } + + event.waitUntil( + clients.matchAll({ includeUncontrolled: true }).then(cl => { + for (let client of cl) { + // The |gClientURL| window closes itself after posting the DONE message, + // so we don't need to send it anything here. + if (client.url === gTestURL) { + client.postMessage("DONE"); + } + } + }) + ); +}; + +onnotificationclick = function (event) { + clients.openWindow(gClientURL); +}; diff --git a/dom/serviceworkers/test/notificationclick-otherwindow.html b/dom/serviceworkers/test/notificationclick-otherwindow.html new file mode 100644 index 0000000000..f64e82aabd --- /dev/null +++ b/dom/serviceworkers/test/notificationclick-otherwindow.html @@ -0,0 +1,30 @@ +<!-- + Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ +--> +<!DOCTYPE HTML> +<html> +<head> + <title>Bug 1114554 - controlled page</title> +<script class="testbody" type="text/javascript"> + var testWindow = parent; + if (opener) { + testWindow = opener; + } + + navigator.serviceWorker.ready.then(function(swr) { + var ifr = document.createElement("iframe"); + document.documentElement.appendChild(ifr); + ifr.contentWindow.ServiceWorkerRegistration.prototype.showNotification + .call(swr, "Hi there. The ServiceWorker should receive a click event for this.", { data: { complex: ["jsval", 5] }}); + }); + + navigator.serviceWorker.onmessage = function(msg) { + testWindow.callback(msg.data.result); + }; +</script> + +</head> +<body> +</body> +</html> diff --git a/dom/serviceworkers/test/notificationclick.html b/dom/serviceworkers/test/notificationclick.html new file mode 100644 index 0000000000..448764a1cb --- /dev/null +++ b/dom/serviceworkers/test/notificationclick.html @@ -0,0 +1,27 @@ +<!-- + Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ +--> +<!DOCTYPE HTML> +<html> +<head> + <title>Bug 1114554 - controlled page</title> +<script class="testbody" type="text/javascript"> + var testWindow = parent; + if (opener) { + testWindow = opener; + } + + navigator.serviceWorker.ready.then(function(swr) { + swr.showNotification("Hi there. The ServiceWorker should receive a click event for this.", { data: { complex: ["jsval", 5] }}); + }); + + navigator.serviceWorker.onmessage = function(msg) { + testWindow.callback(msg.data.result); + }; +</script> + +</head> +<body> +</body> +</html> diff --git a/dom/serviceworkers/test/notificationclick.js b/dom/serviceworkers/test/notificationclick.js new file mode 100644 index 0000000000..ae776095c7 --- /dev/null +++ b/dom/serviceworkers/test/notificationclick.js @@ -0,0 +1,23 @@ +// Any copyright is dedicated to the Public Domain. +// http://creativecommons.org/publicdomain/zero/1.0/ +// +onnotificationclick = function (e) { + self.clients.matchAll().then(function (clients) { + if (clients.length === 0) { + dump( + "********************* CLIENTS LIST EMPTY! Test will timeout! ***********************\n" + ); + return; + } + + clients.forEach(function (client) { + client.postMessage({ + result: + e.notification.data && + e.notification.data.complex && + e.notification.data.complex[0] == "jsval" && + e.notification.data.complex[1] == 5, + }); + }); + }); +}; diff --git a/dom/serviceworkers/test/notificationclick_focus.html b/dom/serviceworkers/test/notificationclick_focus.html new file mode 100644 index 0000000000..0152d397f3 --- /dev/null +++ b/dom/serviceworkers/test/notificationclick_focus.html @@ -0,0 +1,28 @@ +<!-- + Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ +--> +<!DOCTYPE HTML> +<html> +<head> + <title>Bug 1144660 - controlled page</title> +<script class="testbody" type="text/javascript"> + var testWindow = parent; + if (opener) { + testWindow = opener; + } + + navigator.serviceWorker.ready.then(function(swr) { + swr.showNotification("Hi there. The ServiceWorker should receive a click event for this."); + }); + + navigator.serviceWorker.onmessage = function(msg) { + dump("GOT Message " + JSON.stringify(msg.data) + "\n"); + testWindow.callback(msg.data.ok); + }; +</script> + +</head> +<body> +</body> +</html> diff --git a/dom/serviceworkers/test/notificationclick_focus.js b/dom/serviceworkers/test/notificationclick_focus.js new file mode 100644 index 0000000000..1f0924560a --- /dev/null +++ b/dom/serviceworkers/test/notificationclick_focus.js @@ -0,0 +1,49 @@ +// Any copyright is dedicated to the Public Domain. +// http://creativecommons.org/publicdomain/zero/1.0/ +// + +function promisifyTimerFocus(client, delay) { + return new Promise(function (resolve, reject) { + setTimeout(function () { + client.focus().then(resolve, reject); + }, delay); + }); +} + +onnotificationclick = function (e) { + e.waitUntil( + self.clients.matchAll().then(function (clients) { + if (clients.length === 0) { + dump( + "********************* CLIENTS LIST EMPTY! Test will timeout! ***********************\n" + ); + return Promise.resolve(); + } + + var immediatePromise = clients[0].focus(); + var withinTimeout = promisifyTimerFocus(clients[0], 100); + + var afterTimeout = promisifyTimerFocus(clients[0], 2000).then( + function () { + throw "Should have failed!"; + }, + function () { + return Promise.resolve(); + } + ); + + return Promise.all([immediatePromise, withinTimeout, afterTimeout]) + .then(function () { + clients.forEach(function (client) { + client.postMessage({ ok: true }); + }); + }) + .catch(function (ex) { + dump("Error " + ex + "\n"); + clients.forEach(function (client) { + client.postMessage({ ok: false }); + }); + }); + }) + ); +}; diff --git a/dom/serviceworkers/test/notificationclose.html b/dom/serviceworkers/test/notificationclose.html new file mode 100644 index 0000000000..f18801122e --- /dev/null +++ b/dom/serviceworkers/test/notificationclose.html @@ -0,0 +1,37 @@ +<!-- + Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ +--> +<!DOCTYPE HTML> +<html> +<head> + <title>Bug 1265841 - controlled page</title> +<script class="testbody" type="text/javascript"> + var testWindow = parent; + if (opener) { + testWindow = opener; + } + + navigator.serviceWorker.ready.then(function(swr) { + return swr.showNotification( + "Hi there. The ServiceWorker should receive a close event for this.", + { data: { complex: ["jsval", 5] }}).then(function() { + return swr; + }); + }).then(function(swr) { + return swr.getNotifications(); + }).then(function(notifications) { + notifications.forEach(function(notification) { + notification.close(); + }); + }); + + navigator.serviceWorker.onmessage = function(msg) { + testWindow.callback(msg.data); + }; +</script> + +</head> +<body> +</body> +</html> diff --git a/dom/serviceworkers/test/notificationclose.js b/dom/serviceworkers/test/notificationclose.js new file mode 100644 index 0000000000..17c135a308 --- /dev/null +++ b/dom/serviceworkers/test/notificationclose.js @@ -0,0 +1,31 @@ +// Any copyright is dedicated to the Public Domain. +// http://creativecommons.org/publicdomain/zero/1.0/ +// +onnotificationclose = function (e) { + e.waitUntil( + (async function () { + let windowOpened = true; + await clients.openWindow("hello.html").catch(err => { + windowOpened = false; + }); + + self.clients.matchAll().then(function (clients) { + if (clients.length === 0) { + dump("*** CLIENTS LIST EMPTY! Test will timeout! ***\n"); + return; + } + + clients.forEach(function (client) { + client.postMessage({ + result: + e.notification.data && + e.notification.data.complex && + e.notification.data.complex[0] == "jsval" && + e.notification.data.complex[1] == 5, + windowOpened, + }); + }); + }); + })() + ); +}; |