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;
42 log(
"Testing DisplayPanes Service:");
44 paneMgr =
Cc[
"@songbirdnest.com/Songbird/DisplayPane/Manager;1"]
45 .getService(
Ci.sbIDisplayPaneManager);
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; },
65 paneMgr.addListener(listener);
67 log(
"Testing registration via install.rdf");
70 testContent(
"chrome://songbird-test-display-pane/content/testDisplayPane.html",
71 "chrome://songbird-test-display-pane/content/testDisplayPane.html",
73 "http://www.songbirdnest.com/favicon.ico", 180, 50,
"test-content-group");
77 log(
"Testing component in display-pane-provider category");
79 "provider_component_contentUrl",
80 "provider_component_contentTitle",
81 "provider_component_contentIcon",
82 220, 340,
"provider_component_suggestedContentGroups");
86 var installedList = paneMgr.contentList;
88 while (installedList.hasMoreElements()) {
90 installedList.getNext().QueryInterface(
Ci.sbIDisplayPaneContentInfo);
91 paneList[contentInfo.contentUrl] = contentInfo;
95 for (contentInfo in paneList) {
96 paneMgr.unregisterContent(contentInfo);
99 installedList = paneMgr.contentList;
100 assertBool(!installedList.hasMoreElements(),
"installedList should be empty");
102 log(
"Testing pane registration");
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");
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");
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");
122 paneMgr.updateContentInfo(
"url3",
"title4",
"icon4");
123 testInfo(cbparam,
"url3",
"title4",
"icon4", 50, 60,
"group3");
125 log(
"Testing pane unregistration");
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");
134 paneMgr.unregisterContent(
"url1");
135 testInfo(cbparam,
"url1",
"title1",
"icon1", 10, 20,
"group1");
136 testContent(
"url3",
"url3",
"title4",
"icon4", 50, 60,
"group3");
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");
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");
158 log(
"Testing host registration");
162 paneMgr.registerInstantiator(h1);
163 assertEquals(cbparam.contentGroup,
"group1",
"contentGroup");
167 paneMgr.registerInstantiator(h2);
168 assertEquals(cbparam.contentGroup,
"group2",
"contentGroup");
172 paneMgr.registerInstantiator(h3);
173 assertEquals(cbparam.contentGroup,
"group3",
"contentGroup");
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");
182 log(
"Testing host unregistration");
185 paneMgr.unregisterInstantiator(h1);
186 assertEquals(cbparam.contentGroup,
"group1",
"contentGroup");
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");
195 paneMgr.unregisterInstantiator(h3);
196 assertEquals(cbparam.contentGroup,
"group3",
"contentGroup");
198 hosts = paneMgr.instantiatorsList;
199 assertBool(hosts.hasMoreElements(),
"instantiatorsList should not be empty");
200 assertEquals(hosts.getNext().contentGroup,
"group2",
"contentGroup");
203 paneMgr.unregisterInstantiator(h2);
204 assertEquals(cbparam.contentGroup,
"group2",
"contentGroup");
206 hosts = paneMgr.instantiatorsList;
207 assertBool(!hosts.hasMoreElements(),
"instantiatorsList should be empty");
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);
218 paneMgr.showPane(
"url2");
219 testInfo(loaded,
"url2",
"title2",
"icon2", 30, 40,
"group2");
221 assertEquals(h2, paneMgr.getInstantiatorForWindow(h2.contentWindow),
"instantiator");
222 paneMgr.unregisterContent(
"url2");
223 paneMgr.unregisterInstantiator(h1);
224 paneMgr.unregisterInstantiator(h2);
225 paneMgr.unregisterInstantiator(h3);
227 log(
"Tests completed, cleaning up");
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,
242 paneMgr.removeListener(listener);
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);
250 function testInfo(info, matchurl, matchtitle, matchicon, matchwidth, matchheight, matchgroup) {
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");
261 fail(msgprefix +
" should be " + s2 +
", not " + s1 +
"!");
279 get contentGroup() {
return groupid; },
280 get contentUrl() {
return ""; },
281 get contentTitle() {
return ""; },
282 get contentIcon() {
return ""; },
284 set collapsed(
val) {},
285 loadContent:
function(aPane) { loaded = aPane; group = groupid; },
286 hide:
function() { },
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;
function testInfo(info, matchurl, matchtitle, matchicon, matchwidth, matchheight, matchgroup)
function testDisplayPanesService()
sbOSDControlService prototype QueryInterface
function testContent(url, matchurl, matchtitle, matchicon, matchwidth, matchheight, matchgroup)
function assertValue(value, expected, msg)
function makeInstantiator(groupid)
this _dialogInput val(dateText)
function runTest()
Advanced DataRemote unit tests.
function assertBool(boolval, msg)
function assertEquals(s1, s2, msgprefix)