Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Unified Diff: LayoutTests/http/tests/notifications/serviceworkerregistration-service-worker-get.html

Issue 1056573002: Introduce layout tests for SWR.getNotifications() (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: LayoutTests/http/tests/notifications/serviceworkerregistration-service-worker-get.html
diff --git a/LayoutTests/http/tests/notifications/serviceworkerregistration-service-worker-get.html b/LayoutTests/http/tests/notifications/serviceworkerregistration-service-worker-get.html
new file mode 100644
index 0000000000000000000000000000000000000000..5c1e677874abea5071bbe4c1de68f8f733fad334
--- /dev/null
+++ b/LayoutTests/http/tests/notifications/serviceworkerregistration-service-worker-get.html
@@ -0,0 +1,71 @@
+<!doctype html>
+<html>
+ <head>
+ <title>Notifications: ServiceWorkerRegistration.getNotifications() within a Service Worker.</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'
+ });
+ }).then(function() {
+ return info.registration.showNotification('Hello again, world!', {
+ body: 'Second notification'
+ });
+ }).then(function() {
+ // (2) Request the Service Worker to give us all notifications.
+ info.port.postMessage({
+ command: 'get'
+ });
+
+ info.port.addEventListener('message', function(event) {
johnme 2015/04/09 10:29:50 Ditto
Peter Beverloo 2015/04/17 13:03:17 Acknowledged.
+ 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, 2);
+
+ // We don't want to make any promises about the order of the
+ // returned notifications in |notifications|.
+ var firstIndex = notifications[0].title == 'Hello, world!' ? 0 : 1;
+ var secondIndex = firstIndex ? 0 : 1;
+
+ assert_equals(notifications[firstIndex].title, 'Hello, world!');
+ assert_equals(notifications[firstIndex].body, 'First notification');
+
+ assert_equals(notifications[secondIndex].title, 'Hello again, world!');
+ assert_equals(notifications[secondIndex].body, 'Second notification');
+
+ test.done();
johnme 2015/04/09 10:29:50 Perhaps you could also test that registration.getN
Peter Beverloo 2015/04/17 13:03:17 We have tests covering the correctness of both pro
+ });
+ }).catch(unreached_rejection(test));
+
+ }, 'ServiceWorkerRegistration.getNotifications() returns the opened notifications within a Service Worker.');
+ </script>
+ </body>
+</html>

Powered by Google App Engine
This is Rietveld 408576698