| Index: LayoutTests/http/tests/notifications/serviceworkerregistration-service-worker-get-filter.html
|
| diff --git a/LayoutTests/http/tests/notifications/serviceworkerregistration-service-worker-get-filter.html b/LayoutTests/http/tests/notifications/serviceworkerregistration-service-worker-get-filter.html
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..0eed0b4aad9d3c2481094e06af786c4e05d39f7b
|
| --- /dev/null
|
| +++ b/LayoutTests/http/tests/notifications/serviceworkerregistration-service-worker-get-filter.html
|
| @@ -0,0 +1,68 @@
|
| +<!doctype html>
|
| +<html>
|
| + <head>
|
| + <title>Notifications: ServiceWorkerRegistration.getNotifications() within a Service Worker with a filter.</title>
|
| + <script src="../resources/testharness.js"></script>
|
| + <script src="../resources/testharnessreport.js"></script>
|
| + <script src="../serviceworker/resources/test-helpers.js"></script>
|
| + <script src="resources/test-helpers.js"></script>
|
| + </head>
|
| + <body>
|
| + <script>
|
| + // Tests that the getNotifications() function when used in a Service Worker
|
| + // return an array of the notifications which were previously displayed using
|
| + // the same Service Worker registration id.
|
| + async_test(function(test) {
|
| + var scope = 'resources/scope/' + location.pathname,
|
| + script = 'resources/instrumentation-service-worker.js';
|
| +
|
| + testRunner.grantWebNotificationPermission(location.origin, true);
|
| +
|
| + var info = null;
|
| + getActiveServiceWorkerWithMessagePort(test, script, scope).then(function(workerInfo) {
|
| + info = workerInfo;
|
| +
|
| + // (1) Display two notifications in the Document.
|
| + return info.registration.showNotification('Hello, world!', {
|
| + body: 'First notification',
|
| + tag: 'banana',
|
| + });
|
| + }).then(function() {
|
| + return info.registration.showNotification('Hello again, world!', {
|
| + body: 'Second notification',
|
| + tag: 'strawberry',
|
| + });
|
| + }).then(function() {
|
| + // (2) Request the Service Worker to give us all notifications.
|
| + info.port.postMessage({
|
| + command: 'get',
|
| + filter: {
|
| + tag: 'strawberry',
|
| + }
|
| + });
|
| +
|
| + info.port.addEventListener('message', function(event) {
|
| + if (typeof event.data != 'object' || !event.data.command) {
|
| + assert_unreached('Invalid message from the Service Worker.');
|
| + return;
|
| + }
|
| +
|
| + // (3) Confirm that the Service Worker was able to read both of them.
|
| + assert_equals(event.data.command, 'get');
|
| + assert_true(event.data.success);
|
| +
|
| + var notifications = event.data.notifications;
|
| +
|
| + assert_equals(notifications.length, 1);
|
| +
|
| + assert_equals(notifications[0].title, 'Hello again, world!');
|
| + assert_equals(notifications[0].body, 'Second notification');
|
| +
|
| + test.done();
|
| + });
|
| + }).catch(unreached_rejection(test));
|
| +
|
| + }, 'ServiceWorkerRegistration.getNotifications() returns the opened notifications within a Service Worker with a filter.');
|
| + </script>
|
| + </body>
|
| +</html>
|
|
|