OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 /** | |
6 * Test fixture for the notifications custom bindings adapter. | |
7 * @constructor | |
8 * @extends {testing.Test} | |
9 */ | |
10 function NotificationsCustomBindingsTest() { | |
11 testing.Test.call(this); | |
12 } | |
13 | |
14 NotificationsCustomBindingsTest.prototype = { | |
15 __proto__: testing.Test.prototype, | |
16 | |
17 /** @Override */ | |
18 extraLibraries: [ | |
19 'notifications_test_util.js', | |
20 'notifications_custom_bindings.js' | |
21 ], | |
22 }; | |
23 | |
24 TEST_F('NotificationsCustomBindingsTest', 'TestImageDataSetter', function () { | |
25 var c = {}; | |
26 var k = "key"; | |
27 var callback = imageDataSetter(c, k); | |
28 callback('val'); | |
29 expectTrue(c[k] === 'val'); | |
30 }); | |
31 | |
32 TEST_F('NotificationsCustomBindingsTest', 'TestGetUrlSpecs', function () { | |
33 var imageSizes = { | |
34 scaleFactor: 1.0, | |
35 icon: { width: 10, height: 10 }, | |
36 image: { width: 24, height: 32 }, | |
37 buttonIcon: { width: 2, height: 2} | |
38 }; | |
39 | |
40 var notificationDetails = {}; | |
41 | |
42 var emptySpecs = getUrlSpecs(imageSizes, notificationDetails); | |
43 expectTrue(emptySpecs.length === 0); | |
44 | |
45 notificationDetails.iconUrl = "iconUrl"; | |
46 notificationDetails.imageUrl = "imageUrl"; | |
47 notificationDetails.buttons = [ | |
48 {iconUrl: "buttonOneIconUrl"}, | |
49 {iconUrl: "buttonTwoIconUrl"}]; | |
50 | |
51 var allSpecs = getUrlSpecs(imageSizes, notificationDetails); | |
52 expectTrue(allSpecs.length === 4); | |
53 | |
54 expectFalse(notificationDetails.iconBitmap === "test"); | |
55 expectFalse(notificationDetails.imageBitmap === "test"); | |
56 expectFalse(notificationDetails.buttons[0].iconBitmap === "test"); | |
57 expectFalse(notificationDetails.buttons[1].iconBitmap === "test"); | |
58 | |
59 for (var i = 0; i < allSpecs.length; i++) { | |
60 var expectedKeys = ['path', 'width', 'height', 'callback']; | |
61 var spec = allSpecs[i]; | |
62 for (var j in expectedKeys) { | |
63 expectTrue(spec.hasOwnProperty(expectedKeys[j])); | |
64 } | |
65 spec.callback(spec.path + "|" + spec.width + "|" + spec.height); | |
66 } | |
67 | |
68 expectTrue(notificationDetails.iconBitmap === "iconUrl|10|10"); | |
69 expectTrue(notificationDetails.imageBitmap === "imageUrl|24|32"); | |
70 expectTrue( | |
71 notificationDetails.buttons[0].iconBitmap === "buttonOneIconUrl|2|2"); | |
72 expectTrue( | |
73 notificationDetails.buttons[1].iconBitmap === "buttonTwoIconUrl|2|2"); | |
74 }); | |
75 | |
76 TEST_F('NotificationsCustomBindingsTest', 'TestGetUrlSpecsScaled', function () { | |
77 var imageSizes = { | |
78 scaleFactor: 2.0, | |
79 icon: { width: 10, height: 10 }, | |
80 image: { width: 24, height: 32 }, | |
81 buttonIcon: { width: 2, height: 2} | |
82 }; | |
83 var notificationDetails = { | |
84 iconUrl: "iconUrl", | |
85 imageUrl: "imageUrl", | |
86 buttons: [ | |
87 {iconUrl: "buttonOneIconUrl"}, | |
88 {iconUrl: "buttonTwoIconUrl"} | |
89 ] | |
90 }; | |
91 | |
92 var allSpecs = getUrlSpecs(imageSizes, notificationDetails); | |
93 for (var i = 0; i < allSpecs.length; i++) { | |
94 var spec = allSpecs[i]; | |
95 spec.callback(spec.path + "|" + spec.width + "|" + spec.height); | |
96 } | |
97 | |
98 expectEquals(notificationDetails.iconBitmap, "iconUrl|20|20"); | |
99 expectEquals(notificationDetails.imageBitmap, "imageUrl|48|64"); | |
100 expectEquals(notificationDetails.buttons[0].iconBitmap, | |
101 "buttonOneIconUrl|4|4"); | |
102 expectEquals(notificationDetails.buttons[1].iconBitmap, | |
103 "buttonTwoIconUrl|4|4"); | |
104 }); | |
OLD | NEW |