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

Side by Side Diff: LayoutTests/http/tests/notifications/serviceworkerregistration-document-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, 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 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: Property reflection in the "notificationclick" event.< /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 Persistent Notification object exposes the data property per the
13 // Service Worker accurately reflects the attributes with which the notifi cation 13 // semantics defined by the specification.
14 // was created (for this test --) in the document.
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 var options = { 19 var options = {
21 title: scope, 20 title: scope,
22 dir: 'rtl',
23 lang: 'nl-NL',
24 body: 'Hello, world!',
25 tag: 'tag',
26 // FIXME: Relative URLs for the icon attribute currently get refle cted as
27 // an absolute URL, which should probably be the given relative UR L.
28 icon: 'https://example/icon.png',
29 silent: true,
30 data: [
31 { property: 'foobar',
32 string: '\uDFFF\u0000\uDBFF',
33 scalar: true },
34 12.15
35 ]
36 }; 21 };
37 22
38 testRunner.grantWebNotificationPermission(location.origin, true); 23 testRunner.grantWebNotificationPermission(location.origin, true);
39 getActiveServiceWorkerWithMessagePort(test, script, scope).then(functi on(workerInfo) { 24 getActiveServiceWorkerWithMessagePort(test, script, scope).then(functi on(workerInfo) {
40 // (1) Tell the Service Worker to display a Web Notification.
41 workerInfo.port.postMessage({
42 command: 'show',
43 25
44 title: scope, 26 var assertNotificationDataReflects = function(value) {
45 options: options 27 // (1) Display a Web Notification from the document.
46 }); 28 options.data = value;
29 workerInfo.port.postMessage({
30 command: 'show',
31 title: scope,
32 options: options
33 });
34 }
47 35
48 workerInfo.port.addEventListener('message', function(event) { 36 workerInfo.port.addEventListener('message', function(event) {
49 if (typeof event.data != 'object' || !event.data.command) { 37 if (typeof event.data != 'object' || !event.data.command) {
50 assert_unreached('Invalid message from the Service Worker. '); 38 assert_unreached('Invalid message from the Service Worker. ');
51 return; 39 return;
52 } 40 }
53 41
54 // (2) Listen for confirmation from the Service Worker that th e 42 // (2) Listen for confirmation from the Service Worker that th e
55 // notification's display promise has been resolved. 43 // notification's display promise has been resolved.
56 if (event.data.command == 'show') { 44 if (event.data.command == 'show') {
57 assert_true(event.data.success, 'The notification must hav e been displayed.'); 45 assert_true(event.data.success, 'The notification must hav e been displayed.');
58 testRunner.simulateWebNotificationClick(scope); 46 testRunner.simulateWebNotificationClick(scope);
59 return; 47 return;
60 } 48 }
61 49
62 // (3) Listen for confirmation from the Service Worker that th e 50 // (3) Listen for confirmation from the Service Worker that th e
63 // notification has been clicked on. Make sure that all proper ties 51 // notification has been clicked on. Make sure that data prope rties
64 // set on the Notification object are as expected. 52 // set on the Notification object are as expected.
65 assert_equals(event.data.command, 'click', 'The notification w as expected to be clicked.'); 53 if (typeof options.data === 'object')
54 assert_object_equals(event.data.notification.data, data, ' The data field must be the same.');
55 else
56 assert_equals(event.data.notification.data, options.data, 'The data field must be the same.');
Peter Beverloo 2015/04/21 12:26:36 Does this test pass? The chronology is rather odd
Sanghyun Park 2015/04/21 13:38:34 Oops, I had mistake. I'll re-make this.
57 });
58 assertNotificationDataReflects(true); // Check Boolean type
59 assertNotificationDataReflects(1024); // Check Number type
60 assertNotificationDataReflects(Number.NaN); // Check Number.NaN t ype
61 assertNotificationDataReflects('any data'); // Check String type
66 62
67 Object.keys(options).forEach(function(key) { 63 var cars = new Array('Saab', 'Volvo', 'BMW');
68 if (key == 'data') 64 assertNotificationDataReflects(cars); // Check Array type
69 return; // Check "data" separately to avoid stringify ing it.
70 65
71 assert_equals(event.data.notification[key], options[key], 'The ' + key + ' field must be the same.'); 66 var obj = { first: 'first', second: 'second'};
72 }); 67 assertNotificationDataReflects(obj); // Check Object
73 68
74 assert_object_equals(event.data.notification.data, options.dat a, 'The data field must be the same.'); 69 test.done();
70 }).catch(unreached_rejection(test));
75 71
76 test.done();
77 });
78 }).catch(unreached_rejection(test));
79 72
80 }, 'Clicking on a notification displayed by a Service Worker the notificat ionclick event.'); 73 }, 'Clicking on a notification displayed by a Service Worker the notificat ionclick event.');
81 </script> 74 </script>
82 </body> 75 </body>
83 </html> 76 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698