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

Side by Side Diff: chrome/renderer/resources/extensions/notifications_custom_bindings.gtestjs

Issue 354733002: Notifications API support for images with multiple scale factors. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updates custom bindings tests. Created 6 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * Test fixture for the notifications custom bindings adapter. 6 * Test fixture for the notifications custom bindings adapter.
7 * @constructor 7 * @constructor
8 * @extends {testing.Test} 8 * @extends {testing.Test}
9 */ 9 */
10 function NotificationsCustomBindingsTest() { 10 function NotificationsCustomBindingsTest() {
11 testing.Test.call(this); 11 testing.Test.call(this);
12 } 12 }
13 13
14 NotificationsCustomBindingsTest.prototype = { 14 NotificationsCustomBindingsTest.prototype = {
15 __proto__: testing.Test.prototype, 15 __proto__: testing.Test.prototype,
16 16
17 /** @Override */ 17 /** @Override */
18 extraLibraries: [ 18 extraLibraries: [
19 'notifications_test_util.js', 19 'notifications_test_util.js',
20 'notifications_custom_bindings.js' 20 'notifications_custom_bindings.js'
21 ], 21 ],
22 }; 22 };
23 23
24 TEST_F('NotificationsCustomBindingsTest', 'TestImageDataSetter', function () { 24 TEST_F('NotificationsCustomBindingsTest', 'TestImageDataSetter', function () {
25 var c = {}; 25 var c = {};
26 var k = "key"; 26 var k = "key";
27 var callback = imageDataSetter(c, k); 27 var callback = imageDataSetter(c, k);
28 callback('val'); 28 callback('val');
29 expectTrue(c[k] === 'val'); 29 expectTrue(c.src === 'val');
30 }); 30 });
31 31
32 TEST_F('NotificationsCustomBindingsTest', 'TestGetUrlSpecs', function () { 32 TEST_F('NotificationsCustomBindingsTest', 'TestGetUrlSpecs', function () {
33 var imageSizes = { 33 var imageSizes = {
34 scaleFactor: 1.0, 34 scaleFactor: 1.0,
35 icon: { width: 10, height: 10 }, 35 icon: { width: 10, height: 10 },
36 image: { width: 24, height: 32 }, 36 image: { width: 24, height: 32 },
37 buttonIcon: { width: 2, height: 2} 37 buttonIcon: { width: 2, height: 2}
38 }; 38 };
39 39
40 var notificationDetails = {}; 40 var notificationDetails = {};
41 41
42 var emptySpecs = getUrlSpecs(imageSizes, notificationDetails);
43 expectTrue(emptySpecs.length === 0);
44
45 notificationDetails.iconUrl = "iconUrl"; 42 notificationDetails.iconUrl = "iconUrl";
46 notificationDetails.imageUrl = "imageUrl"; 43 notificationDetails.imageUrl = "imageUrl";
47 notificationDetails.buttons = [ 44 notificationDetails.buttons = [
48 {iconUrl: "buttonOneIconUrl"}, 45 {iconUrl: "buttonOneIconUrl"},
49 {iconUrl: "buttonTwoIconUrl"}]; 46 {iconUrl: "buttonTwoIconUrl"}];
50 47
48 notificationDetails =
49 translateBitmapUrls("", notificationDetails, undefined)[1];
51 var allSpecs = getUrlSpecs(imageSizes, notificationDetails); 50 var allSpecs = getUrlSpecs(imageSizes, notificationDetails);
52 expectTrue(allSpecs.length === 4); 51 expectTrue(allSpecs.length === 4);
53 52
54 expectFalse(notificationDetails.iconBitmap === "test"); 53 expectFalse(notificationDetails.iconBitmap === "test");
55 expectFalse(notificationDetails.imageBitmap === "test"); 54 expectFalse(notificationDetails.imageBitmap === "test");
56 expectFalse(notificationDetails.buttons[0].iconBitmap === "test"); 55 expectFalse(notificationDetails.buttons[0].iconBitmap === "test");
57 expectFalse(notificationDetails.buttons[1].iconBitmap === "test"); 56 expectFalse(notificationDetails.buttons[1].iconBitmap === "test");
58 57
59 for (var i = 0; i < allSpecs.length; i++) { 58 for (var i = 0; i < allSpecs.length; i++) {
60 var expectedKeys = ['path', 'width', 'height', 'callback']; 59 var expectedKeys = ['path', 'width', 'height', 'callback'];
61 var spec = allSpecs[i]; 60 var spec = allSpecs[i];
62 for (var j in expectedKeys) { 61 for (var j in expectedKeys) {
63 expectTrue(spec.hasOwnProperty(expectedKeys[j])); 62 expectTrue(spec.hasOwnProperty(expectedKeys[j]));
64 } 63 }
65 spec.callback(spec.path + "|" + spec.width + "|" + spec.height); 64 spec.callback(spec.path + "|" + spec.width + "|" + spec.height);
66 } 65 }
67 66
68 expectTrue(notificationDetails.iconBitmap === "iconUrl|10|10"); 67 expectTrue(notificationDetails.iconReps[0].src === "iconUrl|10|10");
69 expectTrue(notificationDetails.imageBitmap === "imageUrl|24|32"); 68 expectTrue(notificationDetails.imageReps[0].src === "imageUrl|24|32");
70 expectTrue( 69 expectTrue(
71 notificationDetails.buttons[0].iconBitmap === "buttonOneIconUrl|2|2"); 70 notificationDetails.buttons[0].iconReps[0].src ===
71 "buttonOneIconUrl|2|2");
72 expectTrue( 72 expectTrue(
73 notificationDetails.buttons[1].iconBitmap === "buttonTwoIconUrl|2|2"); 73 notificationDetails.buttons[1].iconReps[0].src ===
74 "buttonTwoIconUrl|2|2");
74 }); 75 });
75 76
76 TEST_F('NotificationsCustomBindingsTest', 'TestGetUrlSpecsScaled', function () { 77 TEST_F('NotificationsCustomBindingsTest', 'TestGetUrlSpecsScaled', function () {
77 var imageSizes = { 78 var imageSizes = {
78 scaleFactor: 2.0, 79 scaleFactor: 2.0,
79 icon: { width: 10, height: 10 }, 80 icon: { width: 10, height: 10 },
80 image: { width: 24, height: 32 }, 81 image: { width: 24, height: 32 },
81 buttonIcon: { width: 2, height: 2} 82 buttonIcon: { width: 2, height: 2}
82 }; 83 };
83 var notificationDetails = { 84 var notificationDetails = {
84 iconUrl: "iconUrl", 85 iconUrl: "iconUrl",
85 imageUrl: "imageUrl", 86 imageUrl: "imageUrl",
86 buttons: [ 87 buttons: [
87 {iconUrl: "buttonOneIconUrl"}, 88 {iconUrl: "buttonOneIconUrl"},
88 {iconUrl: "buttonTwoIconUrl"} 89 {iconUrl: "buttonTwoIconUrl"}
89 ] 90 ]
90 }; 91 };
92 notificationDetails =
93 translateBitmapUrls("", notificationDetails, undefined)[1];
91 94
92 var allSpecs = getUrlSpecs(imageSizes, notificationDetails); 95 var allSpecs = getUrlSpecs(imageSizes, notificationDetails);
93 for (var i = 0; i < allSpecs.length; i++) { 96 for (var i = 0; i < allSpecs.length; i++) {
94 var spec = allSpecs[i]; 97 var spec = allSpecs[i];
95 spec.callback(spec.path + "|" + spec.width + "|" + spec.height); 98 spec.callback(spec.path + "|" + spec.width + "|" + spec.height);
96 } 99 }
97 100
98 expectEquals(notificationDetails.iconBitmap, "iconUrl|20|20"); 101 expectEquals(notificationDetails.iconReps[0].src, "iconUrl|20|20");
99 expectEquals(notificationDetails.imageBitmap, "imageUrl|48|64"); 102 expectEquals(notificationDetails.imageReps[0].src, "imageUrl|48|64");
100 expectEquals(notificationDetails.buttons[0].iconBitmap, 103 expectEquals(notificationDetails.buttons[0].iconReps[0].src,
101 "buttonOneIconUrl|4|4"); 104 "buttonOneIconUrl|4|4");
102 expectEquals(notificationDetails.buttons[1].iconBitmap, 105 expectEquals(notificationDetails.buttons[1].iconReps[0].src,
103 "buttonTwoIconUrl|4|4"); 106 "buttonTwoIconUrl|4|4");
104 }); 107 });
OLDNEW
« no previous file with comments | « chrome/common/extensions/api/notifications.idl ('k') | chrome/renderer/resources/extensions/notifications_custom_bindings.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698