31 Components.utils.import(
"resource://gre/modules/XPCOMUtils.jsm");
44 "chrome://bluemonday/content/xul/miniplayer.xul" ];
52 var
feathersManager = Components.classes[
'@songbirdnest.com/songbird/feathersmanager;1']
53 .getService(Components.interfaces.sbIFeathersManager);
56 Components.utils.import(
"resource://app/jsmodules/RDFHelper.jsm");
68 "@songbirdnest.com/Songbird/DataRemote;1",
69 Components.interfaces.sbIDataRemote,
"init");
85 originalDataRemoteValues.push(layoutDataRemote.stringValue);
86 originalDataRemoteValues.push(skinDataRemote.stringValue);
87 originalDataRemoteValues.push(previousLayoutDataRemote.stringValue);
88 originalDataRemoteValues.push(previousSkinDataRemote.stringValue);
97 layoutDataRemote.stringValue = originalDataRemoteValues.shift();
98 skinDataRemote.stringValue = originalDataRemoteValues.shift();
99 previousLayoutDataRemote.stringValue = originalDataRemoteValues.shift();
100 previousSkinDataRemote.stringValue = originalDataRemoteValues.shift();
112 var o =
new Object();
113 o.wrappedJSObject = o;
114 o.QueryInterface = XPCOMUtils.generateQI([
Ci.sbISkinDescription,
115 Ci.sbILayoutDescription]);
124 var feathersChangeListener = {
129 onFeathersUpdate:
function() {
130 this.updateCounter++;
137 onFeathersSelectRequest:
function(layoutDesc, skinDesc) {
138 assertEqual(layoutDesc.wrappedJSObject,
this.expectLayout);
139 assertEqual(skinDesc.wrappedJSObject,
this.expectSkin);
141 onFeathersSelectComplete:
function(layoutDesc, skinDesc) {
142 assertEqual(layoutDesc.wrappedJSObject,
this.expectLayout);
143 assertEqual(skinDesc.wrappedJSObject,
this.expectSkin);
144 this.expectLayout =
null;
145 this.expectSkin =
null;
150 if (!iid.equals(Components.interfaces.sbIFeathersChangeListener))
151 throw Components.results.NS_ERROR_NO_INTERFACE;
160 function wrapEnumerator(enumerator, iface)
162 while (enumerator.hasMoreElements()) {
163 yield enumerator.getNext().QueryInterface(iface);
172 function assertEnumeratorEqualsArray(enumerator, list) {
173 list = list.concat([]);
174 for (var item in enumerator) {
175 assertTrue(list.indexOf(item.wrappedJSObject) > -1);
176 list.splice(list.indexOf(item.wrappedJSObject), 1);
188 function assertEnumeratorMatchesFieldArray(enumerator, field, list) {
189 list = list.concat([]);
190 for (var item in enumerator) {
192 item[field] +
" not found in list: '" + list +
"'\n");
193 list.splice(list.indexOf(item[field]), 1);
204 function testAddonMetadataReader()
208 "rdf:addon-metadata",
209 "urn:songbird:addon:root",
215 var deprecatedLayouts = [];
216 for (var
i = 0;
i < addons.length;
i++) {
217 var addon = addons[
i];
219 log(
"FeatherAddon found: " + addon.id);
220 var skins = addon.skin;
221 for (var j = 0; j < skins.length; j++){
222 log(
" > Feather: " + skins[j].
name +
" (" + skins[j].internalName +
")");
223 if (addon.id ==
"gonzo@songbirdnest.com"){
224 log(
" ignored, it is the Gonzo feather");
228 gBundledSkins.push(skins[j].internalName.toString());
230 var layouts = addon.layout;
231 for (var j = 0; j < layouts.length; j++){
232 log(
" > Layout: " + layouts[j].
name +
" (" + layouts[j].
url +
")");
237 if (addon.id ==
"gonzo@songbirdnest.com") {
238 deprecatedLayouts.push(layouts[j].
url.toString());
240 gBundledLayouts.push(layouts[j].
url.toString());
247 gBundledLayouts = gBundledLayouts.concat(deprecatedLayouts);
252 assertEqual(feathersManager.skinCount, skinNames.length);
253 var enumerator = wrapEnumerator(feathersManager.getSkinDescriptions(),
254 Components.interfaces.sbISkinDescription);
255 assertEnumeratorMatchesFieldArray(enumerator,
"internalName", skinNames);
260 assertEqual(feathersManager.layoutCount, layoutURLs.length);
261 enumerator = wrapEnumerator(feathersManager.getLayoutDescriptions(),
262 Components.interfaces.sbILayoutDescription);
263 assertEnumeratorMatchesFieldArray(enumerator,
"url", layoutURLs);
266 enumerator = wrapEnumerator(feathersManager.getSkinsForLayout(layoutURLs[0]),
267 Components.interfaces.sbISkinDescription);
268 assertEnumeratorMatchesFieldArray(enumerator,
"internalName", [gBundledSkins[0]]);
269 enumerator = wrapEnumerator(feathersManager.getSkinsForLayout(layoutURLs[1]),
270 Components.interfaces.sbISkinDescription);
271 assertEnumeratorMatchesFieldArray(enumerator,
"internalName", [gBundledSkins[0]]);
275 var sysInfo = Components.classes[
"@mozilla.org/system-info;1"]
276 .getService(Components.interfaces.nsIPropertyBag2);
277 if (sysInfo.getProperty(
"name") ==
"Darwin")
278 assertEqual( feathersManager.isChromeEnabled(layoutURLs[0], skinNames[0]),
true);
280 assertEqual( feathersManager.isChromeEnabled(layoutURLs[0], skinNames[1]),
false);
283 assertEqual( feathersManager.isOnTop(layoutURLs[0], skinNames[0]),
false);
284 assertEqual( feathersManager.isOnTop(layoutURLs[1], skinNames[0]),
false);
288 for each (thing
in gRequiredSkinInternalNames)
289 assertTrue( feathersManager.getSkinDescription(thing) );
290 for each (thing
in gRequiredLayoutURLs)
291 assertTrue( feathersManager.getLayoutDescription(thing) );
298 function testDefaultRevert() {
300 previousLayoutDataRemote.stringValue =
"somethingrandom";
301 layoutDataRemote.stringValue =
"somethingelse";
304 feathersManager.switchFeathers(feathersManager.previousLayoutURL,
305 feathersManager.previousSkinName);
309 assertEqual(skinDataRemote.stringValue, gDefaultSkinName);
310 assertEqual(layoutDataRemote.stringValue, gDefaultMainLayoutURL);
313 feathersManager.switchFeathers(feathersManager.previousLayoutURL,
314 feathersManager.previousSkinName);
318 assertEqual(skinDataRemote.stringValue, gDefaultSkinName);
319 assertEqual(layoutDataRemote.stringValue, gDefaultSecondaryLayoutURL);
326 function submitFeathers()
330 skin.name =
"Blue Skin";
331 skin.internalName =
"blue/1.0";
333 feathersManager.registerSkin(skin);
336 skin.name =
"Red Skin";
337 skin.internalName =
"red/1.0";
339 feathersManager.registerSkin(skin);
342 skin.name =
"Orange Skin";
343 skin.internalName =
"orange/1.0";
345 feathersManager.registerSkin(skin);
349 layout.name =
"Big Layout";
350 layout.url =
"chrome://biglayout/content/mainwin.xul";
351 layouts.push(layout);
352 feathersManager.registerLayout(layout);
355 layout.name =
"Mini Layout";
356 layout.url =
"chrome://minilayout/content/mini.xul";
357 layouts.push(layout);
358 feathersManager.registerLayout(layout);
362 feathersManager.assertCompatibility(layouts[1].
url, skins[0].internalName,
false,
true);
363 feathersManager.assertCompatibility(layouts[1].url, skins[1].internalName,
false,
false);
364 feathersManager.assertCompatibility(layouts[0].url, skins[2].internalName,
true,
false);
371 function teardown() {
372 skins.forEach(
function(skin) {
373 feathersManager.unregisterSkin(skin);
376 layouts.forEach(
function(layout) {
377 feathersManager.unregisterLayout(layout);
382 feathersManager.unassertCompatibility(layouts[1].url, skins[0].internalName);
383 feathersManager.unassertCompatibility(layouts[1].url, skins[1].internalName);
387 feathersManager.removeListener(feathersChangeListener);
389 feathersManager.unassertCompatibility(layouts[0].url, skins[2].internalName);
404 var AppPrefs =
Cc[
"@mozilla.org/fuel/application;1"]
405 .getService(
Ci.fuelIApplication).prefs;
407 gDefaultSecondaryLayoutURL =
411 layoutDataRemote.stringValue =
"";
412 skinDataRemote.stringValue =
"";
413 previousLayoutDataRemote.stringValue =
"";
414 previousSkinDataRemote.stringValue =
"";
417 feathersManager.addListener(feathersChangeListener);
423 testAddonMetadataReader();
429 enumerator = wrapEnumerator(feathersManager.getSkinDescriptions(),
430 Components.interfaces.sbISkinDescription);
431 for (var item in enumerator) feathersManager.unregisterSkin(item);
432 enumerator = wrapEnumerator(feathersManager.getLayoutDescriptions(),
433 Components.interfaces.sbILayoutDescription);
434 for (var item in enumerator) feathersManager.unregisterLayout(item);
441 feathersChangeListener.updateCounter = 0;
447 assertEqual(feathersChangeListener.updateCounter, 8);
453 assertEqual(feathersManager.skinCount, skins.length);
454 var enumerator = wrapEnumerator(feathersManager.getSkinDescriptions(),
455 Components.interfaces.sbISkinDescription);
456 assertEnumeratorEqualsArray(enumerator, skins);
459 assertEqual(feathersManager.layoutCount, layouts.length);
460 enumerator = wrapEnumerator(feathersManager.getLayoutDescriptions(),
461 Components.interfaces.sbILayoutDescription);
462 assertEnumeratorEqualsArray(enumerator, layouts);
465 var desc = feathersManager.getSkinDescription(skins[1].internalName).wrappedJSObject;
467 desc = feathersManager.getLayoutDescription(layouts[1].url).wrappedJSObject;
472 enumerator = wrapEnumerator(feathersManager.getSkinsForLayout(layouts[0].url),
473 Components.interfaces.sbISkinDescription);
474 assertEnumeratorEqualsArray(enumerator, [skins[2]]);
475 enumerator = wrapEnumerator(feathersManager.getSkinsForLayout(layouts[1].url),
476 Components.interfaces.sbISkinDescription);
477 assertEnumeratorEqualsArray(enumerator, [skins[0], skins[1]]);
478 enumerator = wrapEnumerator(feathersManager.getLayoutsForSkin(skins[0].internalName),
479 Components.interfaces.sbILayoutDescription);
480 assertEnumeratorEqualsArray(enumerator, [layouts[1]]);
484 assertEqual( feathersManager.isChromeEnabled(layouts[1].url, skins[0].internalName),
false);
485 assertEqual( feathersManager.isChromeEnabled(layouts[1].url, skins[1].internalName),
false);
486 assertEqual( feathersManager.isChromeEnabled(layouts[0].url, skins[2].internalName),
true);
490 assertEqual( feathersManager.isOnTop(layouts[1].url, skins[0].internalName),
false);
491 assertEqual( feathersManager.isOnTop(layouts[1].url, skins[1].internalName),
false);
492 assertEqual( feathersManager.isOnTop(layouts[0].url, skins[2].internalName),
false);
499 layoutDataRemote.stringValue = layouts[0].url;
500 skinDataRemote.stringValue = skins[2].internalName;
506 feathersManager.switchFeathers(layouts[0].url, skins[1].internalName);
514 feathersChangeListener.expectSkin = skins[0];
515 feathersChangeListener.expectLayout = layouts[1];
516 feathersManager.switchFeathers(layouts[1].url, skins[0].internalName);
526 feathersChangeListener.expectSkin = skins[2];
527 feathersChangeListener.expectLayout = layouts[0];
528 feathersManager.switchFeathers(feathersManager.previousLayoutURL,
529 feathersManager.previousSkinName);
543 feathersChangeListener.updateCounter = 0;
550 assertEqual(feathersChangeListener.updateCounter, 7);
551 feathersChangeListener.updateCounter = 0;
556 enumerator = feathersManager.getSkinDescriptions();
560 enumerator = feathersManager.getLayoutDescriptions();
565 enumerator = feathersManager.getSkinsForLayout(layouts[0].url);
567 enumerator = feathersManager.getSkinsForLayout(layouts[1].url);
572 return Components.results.NS_OK;
function newFeathersDescription()
const PREF_DEFAULT_MAIN_LAYOUT
function restoreDataRemotes()
const PREF_DEFAULT_SECONDARY_LAYOUT
var originalDataRemoteValues
sbOSDControlService prototype QueryInterface
function assertTrue(aTest, aMessage)
function assertEqual(aExpected, aActual, aMessage)
function RDFHelper(aRdf, aDatasource, aResource, aNamespaces)
var gDefaultSecondaryLayoutURL
function saveDataRemotes()
var previousLayoutDataRemote
var gDefaultMainLayoutURL
var gRequiredSkinInternalNames
_getSelectedPageStyle s i
const PREF_DEFAULT_SKIN_INTERNALNAME
var previousSkinDataRemote