blob: 86c4c024d1389d93dca600140094cc2416bc7a0d [file] [log] [blame]
<!doctype html>
<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>
<script src="resources/test-helpers.js"></script>
// 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/' + location.pathname;
var script = 'instrumentation-service-worker.js';
var port;
var options = {
actions: []
var expectedActions = [];
for (var i = 0; i < Notification.maxActions; ++i) {
var action = { action: 'action' + i, title: 'Action ' + i };
// Expect empty string when main body of notification is activated.
testRunner.setPermission('notifications', 'granted', location.origin, location.origin);
getActiveServiceWorkerWithMessagePort(test, script, scope).then(function(info) {
port = info.port;
// (1) Tell the Service Worker to display a Web Notification.
return sendCommand(port, {
command: 'show',
title: scope,
options: options
}).then(function(data) {
// (2) Confirm that the service worker displayed the notification successfully.
assert_true(data.success, 'The notification must have been displayed.');
// (3) Simulate a click on each button and on the notification body.
for (var i = 0; i < options.actions.length; ++i)
testRunner.simulateWebNotificationClick(scope, i);
port.addEventListener('message', function(event) {
// (4) Listen for confirmation from the Service Worker that the
// notification has been clicked on. Make sure that the action
// property set on the NotificationEvent object is as expected.
assert_equals(, 'click', 'The notification was expected to be clicked.');
assert_equals(, expectedActions.shift());
if (expectedActions.length === 0)
}, 'NotificationEvent action property should be reflect which action was clicked.');