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

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/notifications/serviceworker-notificationclose-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: Now the test actually works Created 4 years, 10 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 unified diff | Download patch
OLDNEW
1 <!doctype html> 1 <!doctype html>
2 <html> 2 <html>
3 <head> 3 <head>
4 <title>Notifications: data property reflection in the "notificationclick" ev ent.</title> 4 <title>Notifications: Action reflection in the "notificationclose" event.</t itle>
5 <script src="../resources/testharness.js"></script> 5 <script src="../resources/testharness.js"></script>
6 <script src="../resources/testharnessreport.js"></script> 6 <script src="../resources/testharnessreport.js"></script>
7 <script src="../serviceworker/resources/test-helpers.js"></script> 7 <script src="../serviceworker/resources/test-helpers.js"></script>
8 <script src="resources/test-helpers.js"></script> 8 <script src="resources/test-helpers.js"></script>
9 </head> 9 </head>
10 <body> 10 <body>
11 <script> 11 <script>
12 // Tests that the notification available in the "notificationclick" event in the 12 // Tests that the action property of the "notificationclose" event in the
13 // Service Worker accurately reflects the data attributes of several type 13 // Service Worker accurately reflects which action was activated, if any.
14 // with which the notification was created (for this test --) in the docum ent.
15 14
16 async_test(function(test) { 15 async_test(function(test) {
17 var scope = 'resources/scope/' + location.pathname, 16 var scope = 'resources/scope/' + location.pathname,
18 script = 'resources/instrumentation-service-worker.js'; 17 script = 'resources/instrumentation-service-worker.js';
19 18
20 // Set notification's data of several type to a structured clone of op tions's data. 19 // Set notification's data of several type to a structured clone of op tions's data.
21 var notificationDataList = new Array( 20 var notificationDataList = new Array(
22 true, // Check Boolean type 21 true, // Check Boolean type
23 1024, // Check Number type 22 1024, // Check Number type
24 Number.NaN, // Check Number.NaN type 23 Number.NaN, // Check Number.NaN type
(...skipping 22 matching lines...) Expand all
47 workerInfo.port.addEventListener('message', function(event) { 46 workerInfo.port.addEventListener('message', function(event) {
48 if (typeof event.data != 'object' || !event.data.command) { 47 if (typeof event.data != 'object' || !event.data.command) {
49 assert_unreached('Invalid message from the Service Worker. '); 48 assert_unreached('Invalid message from the Service Worker. ');
50 return; 49 return;
51 } 50 }
52 51
53 // (2) Listen for confirmation from the Service Worker that th e 52 // (2) Listen for confirmation from the Service Worker that th e
54 // notification's display promise has been resolved. 53 // notification's display promise has been resolved.
55 if (event.data.command == 'show') { 54 if (event.data.command == 'show') {
56 assert_true(event.data.success, 'The notification must hav e been displayed.'); 55 assert_true(event.data.success, 'The notification must hav e been displayed.');
57 testRunner.simulateWebNotificationClick(scope, -1 /* actio n_index */); 56 testRunner.simulateWebNotificationClose(scope, true /* by_ user */);
Peter Beverloo 2016/02/02 23:50:10 Can we perhaps generalize the data reflection test
Nina 2016/02/03 15:04:23 I refactored the logic into a different file and e
58 return; 57 return;
59 } 58 }
60 59
61 // (3) Listen for confirmation from the Service Worker that th e 60 // (3) Listen for confirmation from the Service Worker that th e
62 // notification has been clicked on. Make sure that all proper ties 61 // notification has been closed. Make sure that all properties
63 // set on the Notification object are as expected. 62 // set on the Notification object are as expected.
64 assert_equals(event.data.command, 'click', 'The notification w as expected to be clicked.'); 63 assert_equals(event.data.command, 'close', 'The notification w as expected to be closed.');
65 64
66 var pos = event.data.notification.tag; 65 var pos = event.data.notification.tag;
67 66
68 if (typeof notificationDataList[pos] === 'object' && notificat ionDataList[pos] !== null) 67 if (typeof notificationDataList[pos] === 'object' && notificat ionDataList[pos] !== null)
69 assert_object_equals(event.data.notification.data, notific ationDataList[pos], 'The data field must be the same.'); 68 assert_object_equals(event.data.notification.data, notific ationDataList[pos], 'The data field must be the same.');
70 else 69 else
71 assert_equals(event.data.notification.data, notificationDa taList[pos], 'The data field must be the same.'); 70 assert_equals(event.data.notification.data, notificationDa taList[pos], 'The data field must be the same.');
72 71
73 if (++pos < notificationDataList.length) 72 if (++pos < notificationDataList.length)
74 assertNotificationDataReflects(pos); 73 assertNotificationDataReflects(pos);
75 else 74 else
76 test.done(); 75 test.done();
77 }); 76 });
78 77
79 assertNotificationDataReflects(0); 78 assertNotificationDataReflects(0);
80 }).catch(unreached_rejection(test)); 79 }).catch(unreached_rejection(test));
81 80
82 }, 'Clicking on a notification displayed by a Service Worker the notificat ionclick event.'); 81 }, 'NotificationEvent data property should be reflected when the notificat ion is closed by the user.');
83 </script> 82 </script>
84 </body> 83 </body>
85 </html> 84 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698