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

Unified Diff: third_party/WebKit/LayoutTests/http/tests/notifications/resources/test-helpers.js

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/resources/test-helpers.js
diff --git a/third_party/WebKit/LayoutTests/http/tests/notifications/resources/test-helpers.js b/third_party/WebKit/LayoutTests/http/tests/notifications/resources/test-helpers.js
index fca5463c72841efe40fc2ad556868a9b1995d9ac..608f37f42f7520efd4bea4809ae6123f24d49634 100644
--- a/third_party/WebKit/LayoutTests/http/tests/notifications/resources/test-helpers.js
+++ b/third_party/WebKit/LayoutTests/http/tests/notifications/resources/test-helpers.js
@@ -66,3 +66,38 @@ function getActiveServiceWorkerWithMessagePort(test, script, scope)
});
});
}
+
+// Sends a message with |data| over |port|. Returns a promise that either rejects when a bad
+// response message is received, or otherwise resolves with the response data.
+function sendCommand(port, data)
+{
+ return new Promise((resolve, reject) => {
+ port.postMessage(data);
+ port.addEventListener('message', function listener(event) {
+ port.removeEventListener('message', listener);
+ if (typeof event.data != 'object' || !event.data.command) {
+ reject(new Error('Invalid message from the Service Worker.'));
+ } else {
+ resolve(event.data);
+ }
+ });
+ });
+}
+
+// Simulates a click on the notification whose title equals |title|. The |actionIndex| specifies
+// which action button to activate, where -1 means the notification itself is clicked, not an action
+// button.
+function simulateNotificationClick(title, actionIndex, port)
+{
+ return new Promise((resolve, reject) => {
+ testRunner.simulateWebNotificationClick(title, actionIndex);
+ port.addEventListener('message', function listener(event) {
+ port.removeEventListener('message', listener);
+ if (typeof event.data != 'object' || event.data.command != 'click') {
+ reject(new Error('Invalid message from the Service Worker.'));
+ } else {
+ resolve(event.data);
+ }
+ });
+ });
+}

Powered by Google App Engine
This is Rietveld 408576698