Index: chrome/renderer/resources/extensions/notifications_custom_bindings.gtestjs |
diff --git a/chrome/renderer/resources/extensions/notifications_custom_bindings.gtestjs b/chrome/renderer/resources/extensions/notifications_custom_bindings.gtestjs |
new file mode 100644 |
index 0000000000000000000000000000000000000000..af1e89f4e1a262a914af7557bd8902884b758c6c |
--- /dev/null |
+++ b/chrome/renderer/resources/extensions/notifications_custom_bindings.gtestjs |
@@ -0,0 +1,104 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+/** |
+ * Test fixture for the notifications custom bindings adapter. |
+ * @constructor |
+ * @extends {testing.Test} |
+ */ |
+function NotificationsCustomBindingsTest() { |
+ testing.Test.call(this); |
+} |
+ |
+NotificationsCustomBindingsTest.prototype = { |
+ __proto__: testing.Test.prototype, |
+ |
+ /** @Override */ |
+ extraLibraries: [ |
+ 'notifications_test_util.js', |
+ 'notifications_custom_bindings.js' |
+ ], |
+}; |
+ |
+TEST_F('NotificationsCustomBindingsTest', 'TestImageDataSetter', function () { |
+ var c = {}; |
+ var k = "key"; |
+ var callback = imageDataSetter(c, k); |
+ callback('val'); |
+ expectTrue(c[k] === 'val'); |
+}); |
+ |
+TEST_F('NotificationsCustomBindingsTest', 'TestGetUrlSpecs', function () { |
+ var imageSizes = { |
+ scaleFactor: 1.0, |
+ icon: { width: 10, height: 10 }, |
+ image: { width: 24, height: 32 }, |
+ buttonIcon: { width: 2, height: 2} |
+ }; |
+ |
+ var notificationDetails = {}; |
+ |
+ var emptySpecs = getUrlSpecs(imageSizes, notificationDetails); |
+ expectTrue(emptySpecs.length === 0); |
+ |
+ notificationDetails.iconUrl = "iconUrl"; |
+ notificationDetails.imageUrl = "imageUrl"; |
+ notificationDetails.buttons = [ |
+ {iconUrl: "buttonOneIconUrl"}, |
+ {iconUrl: "buttonTwoIconUrl"}]; |
+ |
+ var allSpecs = getUrlSpecs(imageSizes, notificationDetails); |
+ expectTrue(allSpecs.length === 4); |
+ |
+ expectFalse(notificationDetails.iconBitmap === "test"); |
+ expectFalse(notificationDetails.imageBitmap === "test"); |
+ expectFalse(notificationDetails.buttons[0].iconBitmap === "test"); |
+ expectFalse(notificationDetails.buttons[1].iconBitmap === "test"); |
+ |
+ for (var i = 0; i < allSpecs.length; i++) { |
+ var expectedKeys = ['path', 'width', 'height', 'callback']; |
+ var spec = allSpecs[i]; |
+ for (var j in expectedKeys) { |
+ expectTrue(spec.hasOwnProperty(expectedKeys[j])); |
+ } |
+ spec.callback(spec.path + "|" + spec.width + "|" + spec.height); |
+ } |
+ |
+ expectTrue(notificationDetails.iconBitmap === "iconUrl|10|10"); |
+ expectTrue(notificationDetails.imageBitmap === "imageUrl|24|32"); |
+ expectTrue( |
+ notificationDetails.buttons[0].iconBitmap === "buttonOneIconUrl|2|2"); |
+ expectTrue( |
+ notificationDetails.buttons[1].iconBitmap === "buttonTwoIconUrl|2|2"); |
+}); |
+ |
+TEST_F('NotificationsCustomBindingsTest', 'TestGetUrlSpecsScaled', function () { |
+ var imageSizes = { |
+ scaleFactor: 2.0, |
+ icon: { width: 10, height: 10 }, |
+ image: { width: 24, height: 32 }, |
+ buttonIcon: { width: 2, height: 2} |
+ }; |
+ var notificationDetails = { |
+ iconUrl: "iconUrl", |
+ imageUrl: "imageUrl", |
+ buttons: [ |
+ {iconUrl: "buttonOneIconUrl"}, |
+ {iconUrl: "buttonTwoIconUrl"} |
+ ] |
+ }; |
+ |
+ var allSpecs = getUrlSpecs(imageSizes, notificationDetails); |
+ for (var i = 0; i < allSpecs.length; i++) { |
+ var spec = allSpecs[i]; |
+ spec.callback(spec.path + "|" + spec.width + "|" + spec.height); |
+ } |
+ |
+ expectEquals(notificationDetails.iconBitmap, "iconUrl|20|20"); |
+ expectEquals(notificationDetails.imageBitmap, "imageUrl|48|64"); |
+ expectEquals(notificationDetails.buttons[0].iconBitmap, |
+ "buttonOneIconUrl|4|4"); |
+ expectEquals(notificationDetails.buttons[1].iconBitmap, |
+ "buttonTwoIconUrl|4|4"); |
+}); |