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

Side by Side Diff: LayoutTests/http/tests/notifications/serviceworker-notificationclick-event-data-reflection.html

Issue 1095093002: Add layouttest for notification properties of persistent notification (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 7 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: Property reflection in the "notificationclick" event.< /title> 4 <title>Notifications: data property reflection in the "notificationclick" ev ent.</title>
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 notification available in the "notificationclick" event in the
13 // Service Worker accurately reflects the attributes with which the notifi cation 13 // Service Worker accurately reflects the data attributes of several type
14 // was created (for this test --) in the document. 14 // with which the notification was created (for this test --) in the docum ent.
15 15
16 async_test(function(test) { 16 async_test(function(test) {
17 var scope = 'resources/scope/' + location.pathname, 17 var scope = 'resources/scope/' + location.pathname,
18 script = 'resources/instrumentation-service-worker.js'; 18 script = 'resources/instrumentation-service-worker.js';
19 19
20 var options = { 20 // Set notification's data of several type to a structured clone of op tions's data.
21 title: scope, 21 var notificationDataList = new Array(
22 dir: 'rtl', 22 true, // Check Boolean type
23 lang: 'nl-NL', 23 1024, // Check Number type
24 body: 'Hello, world!', 24 Number.NaN, // Check Number.NaN type
25 tag: 'tag', 25 'any data', // Check String type
26 // FIXME: Relative URLs for the icon attribute currently get refle cted as 26 new Array('Saab', 'Volve', 'BMW'), // Check Array type
27 // an absolute URL, which should probably be the given relative UR L. 27 { first: 'first', second: 'second' } // Check object
28 icon: 'https://example/icon.png', 28 );
29 silent: true,
30 data: [
31 { property: 'foobar',
32 string: '\uDFFF\u0000\uDBFF',
33 scalar: true },
34 12.15
35 ]
36 };
37 29
38 testRunner.setPermission('notifications', 'granted', location.origin, location.origin); 30 testRunner.setPermission('notifications', 'granted', location.origin, location.origin);
39 getActiveServiceWorkerWithMessagePort(test, script, scope).then(functi on(workerInfo) { 31 getActiveServiceWorkerWithMessagePort(test, script, scope).then(functi on(workerInfo) {
40 // (1) Tell the Service Worker to display a Web Notification. 32 // (1) Tell the Service Worker to display a Web Notification.
41 workerInfo.port.postMessage({ 33 var assertNotificationDataReflects = function(pos) {
42 command: 'show', 34 workerInfo.port.postMessage({
35 command: 'show',
43 36
44 title: scope, 37 title: scope,
45 options: options 38 options: {
46 }); 39 title: scope,
40 tag: pos,
41 data: notificationDataList[pos]
42 }
43 });
44 };
47 45
48 workerInfo.port.addEventListener('message', function(event) { 46 workerInfo.port.addEventListener('message', function(event) {
49 if (typeof event.data != 'object' || !event.data.command) { 47 if (typeof event.data != 'object' || !event.data.command) {
50 assert_unreached('Invalid message from the Service Worker. '); 48 assert_unreached('Invalid message from the Service Worker. ');
51 return; 49 return;
52 } 50 }
53 51
54 // (2) Listen for confirmation from the Service Worker that th e 52 // (2) Listen for confirmation from the Service Worker that th e
55 // notification's display promise has been resolved. 53 // notification's display promise has been resolved.
56 if (event.data.command == 'show') { 54 if (event.data.command == 'show') {
57 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.');
58 testRunner.simulateWebNotificationClick(scope); 56 testRunner.simulateWebNotificationClick(scope);
59 return; 57 return;
60 } 58 }
61 59
62 // (3) Listen for confirmation from the Service Worker that th e 60 // (3) Listen for confirmation from the Service Worker that th e
63 // notification has been clicked on. Make sure that all proper ties 61 // notification has been clicked on. Make sure that all proper ties
64 // set on the Notification object are as expected. 62 // set on the Notification object are as expected.
65 assert_equals(event.data.command, 'click', 'The notification w as expected to be clicked.'); 63 assert_equals(event.data.command, 'click', 'The notification w as expected to be clicked.');
66 64
67 Object.keys(options).forEach(function(key) { 65 var pos = event.data.notification.tag;
68 if (key == 'data')
69 return; // Check "data" separately to avoid stringify ing it.
70 66
71 assert_equals(event.data.notification[key], options[key], 'The ' + key + ' field must be the same.'); 67 assert_object_equals(event.data.notification.data, notificatio nDataList[pos], 'The data field must be the same.');
72 });
73 68
74 assert_object_equals(event.data.notification.data, options.dat a, 'The data field must be the same.'); 69 if (pos < notificationDataList.length)
70 assertNotificationDataReflects(++pos);
71 else
72 test.done();
73 });
75 74
76 test.done(); 75 assertNotificationDataReflects(0);
Peter Beverloo 2015/05/14 16:13:36 How long does it take to run this test? I'm a bit
Sanghyun Park 2015/05/15 08:52:34 Results of the tests done, it takes less than one
77 });
78 }).catch(unreached_rejection(test)); 76 }).catch(unreached_rejection(test));
79 77
80 }, 'Clicking on a notification displayed by a Service Worker the notificat ionclick event.'); 78 }, 'Clicking on a notification displayed by a Service Worker the notificat ionclick event.');
81 </script> 79 </script>
82 </body> 80 </body>
83 </html> 81 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698