test_imagelabellink.js
Go to the documentation of this file.
1 /*
2  *=BEGIN SONGBIRD GPL
3  *
4  * This file is part of the Songbird web player.
5  *
6  * Copyright(c) 2005-2010 POTI, Inc.
7  * http://www.songbirdnest.com
8  *
9  * This file may be licensed under the terms of of the
10  * GNU General Public License Version 2 (the ``GPL'').
11  *
12  * Software distributed under the License is distributed
13  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
14  * express or implied. See the GPL for the specific language
15  * governing rights and limitations.
16  *
17  * You should have received a copy of the GPL along with this
18  * program. If not, go to http://www.gnu.org/licenses/gpl.html
19  * or write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  *=END SONGBIRD GPL
23  */
24 
25 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
26 
27 function runTest() {
28 
29  const prop = "http://songbirdnest.com/data/1.0#imageLabelLink";
30 
31  var builder =
32  Cc["@songbirdnest.com/Songbird/Properties/Builder/ImageLabelLink;1"]
33  .createInstance(Ci.sbIImageLabelLinkPropertyBuilder)
34  .QueryInterface(Ci.sbIClickablePropertyBuilder);
35 
36  builder.propertyID = prop;
37  builder.displayName = "Display";
38 
39  const K_DATA = {
40  "dummy": { label: "Dummy",
41  image: "http://0/dummy.png" },
42  "two": { label: "\u01d5\u0144\u0131\u00e7\u00f8\u0111\u0115",
43  image: "http://0/two.png" },
44  "": { label: "Default",
45  image: "http://0/default.png" }
46  };
47  for (let key in K_DATA) {
48  builder.addImage(key ? key : null, K_DATA[key].image);
49  builder.addLabel(key ? key : null, K_DATA[key].label);
50  }
51 
52  var pi;
53 
54  function onclick(aPropertyInfo, aItem, aEvent, aContext) {
55  // Validate results.
56  assertEqual(aPropertyInfo, pi);
57  assertEqual(aItem.wrappedJSObject, item);
58  assertEqual(aEvent.wrappedJSObject, event);
59  assertEqual(aContext.wrappedJSObject, context);
60 
61  // Remove object references.
62  pi = null;
63 
64  // Test is done.
65  testFinished();
66  }
67  builder.addClickHandler(onclick);
68 
69  pi = builder.get();
70  assertTrue(pi instanceof Ci.sbITreeViewPropertyInfo,
71  "image label link property info should be a sbITreeViewPropertyInfo!");
72  assertTrue(pi instanceof Ci.sbIClickablePropertyInfo,
73  "image label link property info should be a sbIClickablePropertyInfo!");
74 
75  assertEqual(pi.type, "image");
76  assertEqual(pi.id, prop);
77  assertEqual(pi.displayName, "Display");
78 
79  for (let key in K_DATA) {
80  assertEqual(pi.format(key), K_DATA[key].label,
81  "Expecting to display [" + K_DATA[key].label +
82  "] for property value [" + key + "]");
83  assertEqual(pi.getImageSrc(key), K_DATA[key].image,
84  "Expecting to get image [" + K_DATA[key].image +
85  "] for property value [" + key + "]");
86  }
87  assertEqual(pi.format("missing"), K_DATA[""].label,
88  "Expecting to use default label [" + K_DATA[""].label +
89  "] for missing key [missing]");
90  assertEqual(pi.getImageSrc("missing"), K_DATA[""].image,
91  "Expecting to use default image [" + K_DATA[""].image +
92  "] for missing key [missing]");
93 
94  var item = #1= {
95  QueryInterface: XPCOMUtils.generateQI([Ci.sbIMediaItem]),
96  wrappedJSObject: #1#
97  };
98  var event = #2= { wrappedJSObject: #2# };
99  var context = #3= { wrappedJSObject: #3# };
100  pi.onClick(item, event, context);
101  testPending();
102 }
const Cc
function testFinished()
var event
sbOSDControlService prototype QueryInterface
function assertTrue(aTest, aMessage)
function assertEqual(aExpected, aActual, aMessage)
this _contentSandbox label
Definition: FeedWriter.js:814
return null
Definition: FeedWriter.js:1143
const Ci
function testPending()