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

Unified Diff: LayoutTests/http/tests/notifications/serviceworker-notificationclick-event-action-reflection.html

Issue 1264403002: Test that NotificationEvent.action is set correctly (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@click_actions1
Patch Set: Rebase Created 5 years, 4 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/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>

Powered by Google App Engine
This is Rietveld 408576698