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

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

Issue 1656823002: Add layout tests for ServiceWorker's notificationclose event. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactored data reflection tests + nits Created 4 years, 11 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-data-reflection.html
diff --git a/third_party/WebKit/LayoutTests/http/tests/notifications/serviceworker-notificationclick-event-data-reflection.html b/third_party/WebKit/LayoutTests/http/tests/notifications/serviceworker-notificationclick-event-data-reflection.html
index 693f0ac6eeabfe5133ff46f6e17889ef50b845c6..570fb24aabf7b5dc873e059516bb38366287c7c2 100644
--- a/third_party/WebKit/LayoutTests/http/tests/notifications/serviceworker-notificationclick-event-data-reflection.html
+++ b/third_party/WebKit/LayoutTests/http/tests/notifications/serviceworker-notificationclick-event-data-reflection.html
@@ -2,9 +2,11 @@
<html>
<head>
<title>Notifications: data property reflection in the "notificationclick" event.</title>
+ <script src="../resources/permissions-helper.js"></script>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="../serviceworker/resources/test-helpers.js"></script>
+ <script src="resources/notification-data-reflection-test.js"></script>
<script src="resources/test-helpers.js"></script>
</head>
<body>
@@ -14,71 +16,12 @@
// with which the notification was created (for this test --) in the document.
async_test(function(test) {
- var scope = 'resources/scope/' + location.pathname,
- script = 'resources/instrumentation-service-worker.js';
-
- // Set notification's data of several type to a structured clone of options's data.
- var notificationDataList = new Array(
- true, // Check Boolean type
- 1024, // Check Number type
- Number.NaN, // Check Number.NaN type
- 'any data', // Check String type
- null, // Check null
- new Array('Saab', 'Volvo', 'BMW'), // Check Array type
- { first: 'first', second: 'second' } // Check object
- );
-
- 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.
- var assertNotificationDataReflects = function(pos) {
- workerInfo.port.postMessage({
- command: 'show',
-
- title: scope,
- options: {
- title: scope,
- tag: pos,
- data: notificationDataList[pos]
- }
- });
- };
-
- workerInfo.port.addEventListener('message', function(event) {
- if (typeof event.data != 'object' || !event.data.command) {
- assert_unreached('Invalid message from the Service Worker.');
- return;
- }
-
- // (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.');
- testRunner.simulateWebNotificationClick(scope, -1 /* action_index */);
- return;
- }
-
- // (3) Listen for confirmation from the Service Worker that the
- // notification has been clicked on. Make sure that all properties
- // set on the Notification object are as expected.
- assert_equals(event.data.command, 'click', 'The notification was expected to be clicked.');
-
- var pos = event.data.notification.tag;
-
- if (typeof notificationDataList[pos] === 'object' && notificationDataList[pos] !== null)
- assert_object_equals(event.data.notification.data, notificationDataList[pos], 'The data field must be the same.');
- else
- assert_equals(event.data.notification.data, notificationDataList[pos], 'The data field must be the same.');
-
- if (++pos < notificationDataList.length)
- assertNotificationDataReflects(pos);
- else
- test.done();
- });
-
- assertNotificationDataReflects(0);
- }).catch(unreached_rejection(test));
-
+ runNotificationDataReflectionTest(test, {
+ run: function (scope) {
+ testRunner.simulateWebNotificationClick(scope, -1 /* action_index */);
+ },
+ name: 'click'
+ });
}, 'Clicking on a notification displayed by a Service Worker the notificationclick event.');
</script>
</body>

Powered by Google App Engine
This is Rietveld 408576698