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

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

Issue 1907443007: Use promises in notifications tests and enable controlling the page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Address peter's comments. Created 4 years, 8 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: third_party/WebKit/LayoutTests/http/tests/notifications/serviceworker-notificationclick-event-action-reflection.html
diff --git a/third_party/WebKit/LayoutTests/http/tests/notifications/serviceworker-notificationclick-event-action-reflection.html b/third_party/WebKit/LayoutTests/http/tests/notifications/serviceworker-notificationclick-event-action-reflection.html
index bdef4b925e9bae18b518160a79ce13ab0a94d720..67c439072ce1ac8cd4c00cd54496462c91b32344 100644
--- a/third_party/WebKit/LayoutTests/http/tests/notifications/serviceworker-notificationclick-event-action-reflection.html
+++ b/third_party/WebKit/LayoutTests/http/tests/notifications/serviceworker-notificationclick-event-action-reflection.html
@@ -13,8 +13,9 @@
// Service Worker accurately reflects which action was activated, if any.
async_test(function(test) {
- var scope = 'resources/scope/' + location.pathname,
- script = 'resources/instrumentation-service-worker.js';
+ var scope = 'resources/scope/' + location.pathname;
+ var script = 'instrumentation-service-worker.js';
+ var port;
var options = {
actions: []
@@ -22,40 +23,34 @@
var expectedActions = [];
for (var i = 0; i < Notification.maxActions; ++i) {
- var action = { action: "action" + i, title: "Action " + 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("");
+ expectedActions.push('');
testRunner.setPermission('notifications', 'granted', location.origin, location.origin);
- getActiveServiceWorkerWithMessagePort(test, script, scope).then(function(workerInfo) {
+ getActiveServiceWorkerWithMessagePort(test, script, scope).then(function(info) {
+ port = info.port;
// (1) Tell the Service Worker to display a Web Notification.
- workerInfo.port.postMessage({
+ 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.');
- workerInfo.port.addEventListener('message', function(event) {
- if (typeof event.data != 'object' || !event.data.command) {
- assert_unreached('Invalid message from the Service Worker.');
- return;
- }
+ // (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);
+ testRunner.simulateWebNotificationClick(scope, -1 /* action_index */);
- // (2) Listen for confirmation from the Service Worker that the
- // 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, -1 /* action_index */);
- return;
- }
-
- // (3) Listen for confirmation from the Service Worker that the
+ 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(event.data.command, 'click', 'The notification was expected to be clicked.');

Powered by Google App Engine
This is Rietveld 408576698