Index: LayoutTests/http/tests/notifications/serviceworker-notificationclick-event-action-reflection.html |
diff --git a/LayoutTests/http/tests/notifications/serviceworkerregistration-service-worker-click.html b/LayoutTests/http/tests/notifications/serviceworker-notificationclick-event-action-reflection.html |
similarity index 54% |
copy from LayoutTests/http/tests/notifications/serviceworkerregistration-service-worker-click.html |
copy to LayoutTests/http/tests/notifications/serviceworker-notificationclick-event-action-reflection.html |
index 72ad928d2ac2ba076b536cafa66d8a49ffa290ba..590dc519b8e303be86a254eafdb1fae46da5aabe 100644 |
--- a/LayoutTests/http/tests/notifications/serviceworkerregistration-service-worker-click.html |
+++ b/LayoutTests/http/tests/notifications/serviceworker-notificationclick-event-action-reflection.html |
@@ -1,7 +1,7 @@ |
<!doctype html> |
<html> |
<head> |
- <title>Notifications: ServiceWorkerRegistration.showNotification().</title> |
+ <title>Notifications: Action reflection in the "notificationclick" event.</title> |
<script src="../resources/testharness.js"></script> |
<script src="../resources/testharnessreport.js"></script> |
<script src="../serviceworker/resources/test-helpers.js"></script> |
@@ -9,14 +9,26 @@ |
</head> |
<body> |
<script> |
- // Tests that the showNotification() function when used in a Service Worker |
- // resolves a promise, and that the notificationclick event gets fired when |
- // we simulate a click on it. This test requires the test runner. |
+ // Tests that the action property of the "notificationclick" event in the |
+ // Service Worker accurately reflects which action was activated, if any. |
async_test(function(test) { |
- var scope = 'resources/scope/serviceworkerregistration-service-worker-click', |
+ var scope = 'resources/scope/' + location.pathname, |
script = 'resources/instrumentation-service-worker.js'; |
+ var options = { |
+ actions: [] |
+ }; |
+ |
+ var expectedActions = []; |
+ for (var i = 0; i < Notification.maxActions; ++i) { |
+ var action = { action: "action" + i, title: "Action " + i }; |
+ options.actions.push(action); |
+ expectedActions.push(action.action); |
+ } |
+ // Expect empty string when main body of notification is activated. |
+ expectedActions.push(""); |
+ |
testRunner.setPermission('notifications', 'granted', location.origin, location.origin); |
getActiveServiceWorkerWithMessagePort(test, script, scope).then(function(workerInfo) { |
// (1) Tell the Service Worker to display a Web Notification. |
@@ -24,7 +36,7 @@ |
command: 'show', |
title: scope, |
- options: { body: 'Hello, world!' } |
+ options: options |
}); |
workerInfo.port.addEventListener('message', function(event) { |
@@ -37,24 +49,25 @@ |
// notification's display promise has been resolved. |
if (event.data.command == 'show') { |
assert_true(event.data.success, 'The notification must have been displayed.'); |
+ for (var i = 0; i < options.actions.length; ++i) |
+ testRunner.simulateWebNotificationClick(scope, i); |
testRunner.simulateWebNotificationClick(scope); |
return; |
} |
// (3) Listen for confirmation from the Service Worker that the |
- // notification has been clicked on. |
- if (event.data.command == 'click') { |
- assert_equals(event.data.notification.title, scope, 'The right notification must have been clicked.'); |
+ // notification has been clicked on. Make sure that the action |
+ // property set on the NotificationEvent object is as expected. |
+ assert_equals(event.data.command, 'click', 'The notification was expected to be clicked.'); |
- test.done(); |
- return; |
- } |
+ assert_equals(event.data.action, expectedActions.shift()); |
- assert_unreached('Unexpected message from the Service Worker: ' + event.data.command); |
+ if (expectedActions.length === 0) |
+ test.done(); |
}); |
}).catch(unreached_rejection(test)); |
- }, 'Clicking on a notification displayed by a Service Worker the notificationclick event.'); |
+ }, 'NotificationEvent action property should be reflect which action was clicked.'); |
</script> |
</body> |
</html> |