test_displaypanes.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 
29 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
30 if (typeof(Cc) == "undefined")
31  this.Cc = Components.classes;
32 if (typeof(Ci) == "undefined")
33  this.Ci = Components.interfaces;
34 
35 
36 var loaded = null;
37 var group = null;
38 var paneMgr = null;
39 
40 function runTest () {
41 
42  log("Testing DisplayPanes Service:");
43 
44  paneMgr = Cc["@songbirdnest.com/Songbird/DisplayPane/Manager;1"]
45  .getService(Ci.sbIDisplayPaneManager);
46 
48 
49  log("OK");
50 }
51 
53 
54  var cbparam;
55  var listener = {
56  onRegisterContent: function(aPane) { cbparam = aPane; },
57  onUnregisterContent: function(aPane) { cbparam = aPane; },
58  onPaneInfoChanged: function(aPane) { cbparam = aPane; },
59  onRegisterInstantiator: function(aInstantiator) { cbparam = aInstantiator; },
60  onUnregisterInstantiator: function(aInstantiator) { cbparam = aInstantiator; },
61 
62  QueryInterface: XPCOMUtils.generateQI([Ci.sbIDisplayPaneListener])
63  }
64 
65  paneMgr.addListener(listener);
66 
67  log("Testing registration via install.rdf");
68 
69  // This content should have been supplied by the test-extension/install.rdf
70  testContent("chrome://songbird-test-display-pane/content/testDisplayPane.html",
71  "chrome://songbird-test-display-pane/content/testDisplayPane.html",
72  "Display Pane Test",
73  "http://www.songbirdnest.com/favicon.ico", 180, 50, "test-content-group");
74 
75  // This content should have been registered by the component in
76  // ../src/sbTestDisplayPaneProvider.js
77  log("Testing component in display-pane-provider category");
78  testContent("provider_component_contentUrl",
79  "provider_component_contentUrl",
80  "provider_component_contentTitle",
81  "provider_component_contentIcon",
82  220, 340, "provider_component_suggestedContentGroups");
83 
84  // Be sure to remove any registered panes so we can start with a fresh list,
85  // then register them again when we are done so we don't affect other tests.
86  var installedList = paneMgr.contentList;
87  var paneList = []; // Keep a list of registered panes for after the test.
88  while (installedList.hasMoreElements()) {
89  var contentInfo =
90  installedList.getNext().QueryInterface(Ci.sbIDisplayPaneContentInfo);
91  paneList[contentInfo.contentUrl] = contentInfo;
92  }
93 
94  // Unregister existing display panes
95  for (contentInfo in paneList) {
96  paneMgr.unregisterContent(contentInfo);
97  }
98 
99  installedList = paneMgr.contentList;
100  assertBool(!installedList.hasMoreElements(), "installedList should be empty");
101 
102  log("Testing pane registration");
103 
104  cbparam = null;
105  paneMgr.registerContent("url1", "title1", "icon1", 10, 20, "group1", false);
106  testInfo(cbparam, "url1", "title1", "icon1", 10, 20, "group1");
107  testContent("url1", "url1", "title1", "icon1", 10, 20, "group1");
108 
109  cbparam = null;
110  paneMgr.registerContent("url2", "title2", "icon2", 30, 40, "group2", false);
111  testInfo(cbparam, "url2", "title2", "icon2", 30, 40, "group2");
112  testContent("url2", "url2", "title2", "icon2", 30, 40, "group2");
113 
114  cbparam = null;
115  paneMgr.registerContent("url3", "title3", "icon3", 50, 60, "group3", false);
116  testInfo(cbparam, "url3", "title3", "icon3", 50, 60, "group3");
117  testContent("url3", "url3", "title3", "icon3", 50, 60, "group3");
118  testContent("url1", "url1", "title1", "icon1", 10, 20, "group1");
119  testContent("url2", "url2", "title2", "icon2", 30, 40, "group2");
120 
121  cbparam = null;
122  paneMgr.updateContentInfo("url3", "title4", "icon4");
123  testInfo(cbparam, "url3", "title4", "icon4", 50, 60, "group3");
124 
125  log("Testing pane unregistration");
126 
127  cbparam = null;
128  paneMgr.unregisterContent("url2");
129  testInfo(cbparam, "url2", "title2", "icon2", 30, 40, "group2");
130  testContent("url1", "url1", "title1", "icon1", 10, 20, "group1");
131  testContent("url3", "url3", "title4", "icon4", 50, 60, "group3");
132 
133  cbparam = null;
134  paneMgr.unregisterContent("url1");
135  testInfo(cbparam, "url1", "title1", "icon1", 10, 20, "group1");
136  testContent("url3", "url3", "title4", "icon4", 50, 60, "group3");
137 
138  cbparam = null;
139  paneMgr.unregisterContent("url3");
140  testInfo(cbparam, "url3", "title4", "icon4", 50, 60, "group3");
141  var contentlist = paneMgr.contentList;
142  assertBool(!contentlist.hasMoreElements(), "contentList should be empty");
143  contentlist = null;
144 
145  paneMgr.registerContent("url1", "title1", "icon1", 10, 20, "group1", false);
146  testContent("url1", "url1", "title1", "icon1", 10, 20, "group1");
147  paneMgr.registerContent("url3", "title3", "icon3", 50, 60, "group3", false);
148  testContent("url3", "url3", "title3", "icon3", 50, 60, "group3");
149  paneMgr.registerContent("url2", "title2", "icon2", 30, 40, "group2", false);
150  testContent("url2", "url2", "title2", "icon2", 30, 40, "group2");
151  paneMgr.unregisterContent("url3");
152  paneMgr.unregisterContent("url1");
153  paneMgr.unregisterContent("url2");
154  contentlist = paneMgr.contentList;
155  assertBool(!contentlist.hasMoreElements(), "contentList should be empty");
156  contentlist = null;
157 
158  log("Testing host registration");
159 
160  cbparam = null;
161  var h1 = makeInstantiator("group1");
162  paneMgr.registerInstantiator(h1);
163  assertEquals(cbparam.contentGroup, "group1", "contentGroup");
164 
165  cbparam = null;
166  var h2 = makeInstantiator("group2");
167  paneMgr.registerInstantiator(h2);
168  assertEquals(cbparam.contentGroup, "group2", "contentGroup");
169 
170  cbparam = null;
171  var h3 = makeInstantiator("group3");
172  paneMgr.registerInstantiator(h3);
173  assertEquals(cbparam.contentGroup, "group3", "contentGroup");
174 
175  var hosts = paneMgr.instantiatorsList;
176  assertBool(hosts.hasMoreElements(), "instantiatorsList should not be empty");
177  assertEquals(hosts.getNext().contentGroup, "group1", "contentGroup");
178  assertEquals(hosts.getNext().contentGroup, "group2", "contentGroup");
179  assertEquals(hosts.getNext().contentGroup, "group3", "contentGroup");
180  hosts = null;
181 
182  log("Testing host unregistration");
183 
184  cbparam = null;
185  paneMgr.unregisterInstantiator(h1);
186  assertEquals(cbparam.contentGroup, "group1", "contentGroup");
187 
188  hosts = paneMgr.instantiatorsList;
189  assertBool(hosts.hasMoreElements(), "instantiatorsList should not be empty");
190  assertEquals(hosts.getNext().contentGroup, "group2", "contentGroup");
191  assertEquals(hosts.getNext().contentGroup, "group3", "contentGroup");
192 
193  hosts = null;
194  cbparam = null;
195  paneMgr.unregisterInstantiator(h3);
196  assertEquals(cbparam.contentGroup, "group3", "contentGroup");
197 
198  hosts = paneMgr.instantiatorsList;
199  assertBool(hosts.hasMoreElements(), "instantiatorsList should not be empty");
200  assertEquals(hosts.getNext().contentGroup, "group2", "contentGroup");
201  hosts = null;
202  cbparam = null;
203  paneMgr.unregisterInstantiator(h2);
204  assertEquals(cbparam.contentGroup, "group2", "contentGroup");
205 
206  hosts = paneMgr.instantiatorsList;
207  assertBool(!hosts.hasMoreElements(), "instantiatorsList should be empty");
208  hosts = null;
209 
210 
211  log("Testing spawning");
212  paneMgr.registerInstantiator(h1);
213  paneMgr.registerInstantiator(h2);
214  paneMgr.registerInstantiator(h3);
215  paneMgr.registerContent("url2", "title2", "icon2", 30, 40, "group2", false);
216  loaded = null;
217  group = null;
218  paneMgr.showPane("url2");
219  testInfo(loaded, "url2", "title2", "icon2", 30, 40, "group2");
220  assertEquals(group, "group2", "group");
221  assertEquals(h2, paneMgr.getInstantiatorForWindow(h2.contentWindow), "instantiator");
222  paneMgr.unregisterContent("url2");
223  paneMgr.unregisterInstantiator(h1);
224  paneMgr.unregisterInstantiator(h2);
225  paneMgr.unregisterInstantiator(h3);
226 
227  log("Tests completed, cleaning up");
228 
229  // Register the original display panes
230  for (contentInfo in paneList) {
231  if (!paneMgr.getPaneInfo(contentInfo)) {
232  paneMgr.registerContent(paneList[contentInfo].contentUrl,
233  paneList[contentInfo].contentTitle,
234  paneList[contentInfo].contentIcon,
235  paneList[contentInfo].defaultWidth,
236  paneList[contentInfo].defaultHeight,
237  paneList[contentInfo].suggestedContentGroups,
238  false);
239  }
240  }
241 
242  paneMgr.removeListener(listener);
243 }
244 
245 function testContent(url, matchurl, matchtitle, matchicon, matchwidth, matchheight, matchgroup) {
246  var info = paneMgr.getPaneInfo(url);
247  testInfo(info, matchurl, matchtitle, matchicon, matchwidth, matchheight, matchgroup);
248 }
249 
250 function testInfo(info, matchurl, matchtitle, matchicon, matchwidth, matchheight, matchgroup) {
251  assertEquals(info.contentUrl, matchurl, "contentUrl");
252  assertEquals(info.contentTitle, matchtitle, "contentTitle");
253  assertEquals(info.contentIcon, matchicon, "contentIcon");
254  assertEquals(info.defaultWidth, matchwidth, "defaultWidth");
255  assertEquals(info.defaultHeight, matchheight, "defaultHeight");
256  assertEquals(info.suggestedContentGroups, matchgroup, "suggestedContentGroups");
257 }
258 
259 function assertEquals(s1, s2, msgprefix) {
260  if (s1 != s2) {
261  fail(msgprefix + " should be " + s2 + ", not " + s1 + "!");
262  }
263 }
264 
265 function assertBool(boolval, msg) {
266  if (!boolval) {
267  fail(msg);
268  }
269 }
270 
272  if (value != expected) {
273  fail(msg);
274  }
275 }
276 
277 function makeInstantiator(groupid) {
278  var instantiator = {
279  get contentGroup() { return groupid; },
280  get contentUrl() { return ""; },
281  get contentTitle() { return ""; },
282  get contentIcon() { return ""; },
283  get collapsed() {},
284  set collapsed(val) {},
285  loadContent: function(aPane) { loaded = aPane; group = groupid; },
286  hide: function() { },
287  contentWindow: {
288  QueryInterface: XPCOMUtils.generateQI([Ci.nsIDOMWindow])
289  },
290  QueryInterface: XPCOMUtils.generateQI([Ci.sbIDisplayPaneInstantiator])
291  }
292 
293  // use a supports-interface-pointer to make sure we get the XPConnect wrapped objects
294  var sip = Cc["@mozilla.org/supports-interface-pointer;1"]
295  .createInstance(Ci.nsISupportsInterfacePointer);
296  sip.dataIID = Ci.sbIDisplayPaneInstantiator;
297  sip.data = instantiator;
298  instantiator = sip.data;
299  sip.data = null; // prevent leaks
300  return instantiator;
301 }
302 
const Cc
function testInfo(info, matchurl, matchtitle, matchicon, matchwidth, matchheight, matchgroup)
function fail(aMessage)
function testDisplayPanesService()
function log(s)
sbOSDControlService prototype QueryInterface
function testContent(url, matchurl, matchtitle, matchicon, matchwidth, matchheight, matchgroup)
function assertValue(value, expected, msg)
var loaded
function makeInstantiator(groupid)
this _dialogInput val(dateText)
var paneMgr
return null
Definition: FeedWriter.js:1143
function runTest()
Advanced DataRemote unit tests.
var expected
function url(spec)
countRef value
Definition: FeedWriter.js:1423
const Ci
function msg
function assertBool(boolval, msg)
var group
function assertEquals(s1, s2, msgprefix)