43 Components.utils.import(
"resource://app/jsmodules/sbLibraryUtils.jsm");
45 var
cmdHelper =
Cc[
"@songbirdnest.com/Songbird/PlaylistCommandsHelper;1"]
46 .getService(
Ci.sbIPlaylistCommandsHelper);
48 var
cmdMgr =
Cc[
"@songbirdnest.com/Songbird/PlaylistCommandsManager;1"]
49 .createInstance(
Ci.sbIPlaylistCommandsManager);
52 Constructor(
"@songbirdnest.com/Songbird/PlaylistCommandsBuilder;1",
53 "sbIPlaylistCommandsBuilder");
74 log(
"Testing Playlist Commands Helper:");
102 _log(
"- Testing createCommandObject with appending, inserting, " +
103 "and removing subobjects");
104 var newCommandID =
"test-id-1";
106 var newCommand = cmdHelper.createCommandObjectForAction
112 newCommand.shutdown();
114 _log(
"- Testing createCommandObject with command callbacks and keyboard " +
116 newCommandID =
"test-id-2";
118 newCommand = cmdHelper.createCommandObjectForAction
124 newCommand.shutdown();
126 _log(
"- Testing createCommandObject with submenus");
127 newCommandID =
"test-id-3";
129 newCommand = cmdHelper.createCommandObjectForAction
135 newCommand.shutdown();
166 _log(
"- Testing addCommandObject and removeCommandObject");
169 var locationsArray = [(cmdHelper.TARGET_SERVICEPANE_MENU |
170 cmdHelper.TARGET_TOOLBAR |
171 cmdHelper.TARGET_MEDIAITEM_CONTEXT_MENU),
172 (cmdHelper.TARGET_SERVICEPANE_MENU |
173 cmdHelper.TARGET_TOOLBAR),
174 (cmdHelper.TARGET_SERVICEPANE_MENU |
175 cmdHelper.TARGET_MEDIAITEM_CONTEXT_MENU),
176 (cmdHelper.TARGET_MEDIAITEM_CONTEXT_MENU |
177 cmdHelper.TARGET_TOOLBAR),
178 (cmdHelper.TARGET_MEDIAITEM_CONTEXT_MENU),
179 (cmdHelper.TARGET_TOOLBAR),
180 (cmdHelper.TARGET_SERVICEPANE_MENU)];
183 var databaseGUID =
"test_playlistcommandshelper";
185 testMediaList = testLibrary.createMediaList(
"simple");
192 for (var cmdIndex = 0; cmdIndex < locationsArray.length; cmdIndex++)
195 var newCommandID =
"test-command-" + cmdIndex;
197 var newCommandGUID = cmdHelper.createCommandObjectForAction
199 "test-label-" + cmdIndex,
200 "test-tooltip-" + cmdIndex,
205 var newCommandType = newCommandGUID.duplicate();
207 var addLocs = locationsArray[cmdIndex];
210 for (var
p = 0;
p < 3;
p ++)
212 var addByType =
false;
213 var addByGUID =
false;
231 for (var j = 0; j < locationsArray.length; j++)
235 log(
"\nperforming " + ((addByGUID) ?
"addByGUID " :
"") +
236 ((addByType) ?
"addByType " :
"") +
"with '" + newCommandID +
249 var removeLocs = locationsArray[j];
269 if (addByGUID && guidLocMap[newCommandID] > 0)
271 if (
DEBUG)
_log(
" complete removing " + newCommandID +
273 cmdHelper.removeCommandObjectForGUID(addLocs,
278 guidLocMap[newCommandID] = 0;
281 if (addByType && typeLocMap[newCommandID] > 0)
283 if (
DEBUG)
_log(
" complete removing " + newCommandID +
285 cmdHelper.removeCommandObjectForType(addLocs,
290 typeLocMap[newCommandID] = 0;
296 if (
DEBUG)
_log(
" shutting down " + newCommandID +
" for guid");
297 newCommandGUID.shutdownCommands();
298 if (
DEBUG)
_log(
" shutting down " + newCommandID +
" for type");
299 newCommandType.shutdownCommands();
304 testLibrary.remove(testMediaList);
309 if (guidOrType ==
"type")
313 _log(
" adding " + newCommand.id +
" for type: " +
317 cmdHelper.addCommandObjectForType(locations,
322 typeLocMap[newCommand.id] = locations;
330 _log(
" adding " + newCommand.id +
" for guid: " +
334 cmdHelper.addCommandObjectForGUID(locations,
339 guidLocMap[newCommand.id] = locations;
351 if (guidOrType ==
"type")
355 _log(
" removing " + newCommand.id +
" from type: " +
358 cmdHelper.removeCommandObjectForType(locations,
363 if (typeLocMap[newCommand.id] > 0)
364 typeLocMap[newCommand.id] = (typeLocMap[newCommand.id] & ~locations);
370 _log(
" removing " + newCommand.id +
" from guid: " +
373 cmdHelper.removeCommandObjectForGUID(locations,
377 if (guidLocMap[newCommand.id] > 0)
378 guidLocMap[newCommand.id] = (guidLocMap[newCommand.id] & ~locations);
388 for (var
id in guidLocMap)
391 let checkLocs = guidLocMap[
id];
393 "Command with id '" +
id +
"' is not where it was expected " +
394 "when registered to medialist guid '" + testMediaList.guid +
395 "'.\n" +
"Expected at - " +
flagsToString(checkLocs) +
"\n" +
399 for (var
id in typeLocMap)
402 let checkLocs = typeLocMap[
id];
404 "Command with id '" +
id +
"' is not where it was expected " +
405 "when registered to medialist type '" + testMediaList.type +
422 if (foundLocs != checkLocs)
436 if ((foundLocs & cmdHelper.TARGET_SERVICEPANE_MENU ==
437 checkLocs & cmdHelper.TARGET_SERVICEPANE_MENU) &&
438 ((foundLocs & cmdHelper.TARGET_MEDIAITEM_CONTEXT_MENU) ||
439 (foundLocs & cmdHelper.TARGET_TOOLBAR)))
469 if (guidOrType ==
"type")
472 var spFound = cmdHelper.getCommandObjectForType
473 (cmdHelper.TARGET_SERVICEPANE_MENU,
478 foundLocs = foundLocs | cmdHelper.TARGET_SERVICEPANE_MENU;
481 var cmFound = cmdHelper.getCommandObjectForType
482 (cmdHelper.TARGET_MEDIAITEM_CONTEXT_MENU,
486 foundLocs = foundLocs | cmdHelper.TARGET_MEDIAITEM_CONTEXT_MENU;
489 var tbFound = cmdHelper.getCommandObjectForType
490 (cmdHelper.TARGET_TOOLBAR,
494 foundLocs = foundLocs | cmdHelper.TARGET_TOOLBAR;
498 var spFound = cmdHelper.getCommandObjectForGUID
499 (cmdHelper.TARGET_SERVICEPANE_MENU,
503 foundLocs = foundLocs | cmdHelper.TARGET_SERVICEPANE_MENU;
506 var cmFound = cmdHelper.getCommandObjectForGUID
507 (cmdHelper.TARGET_MEDIAITEM_CONTEXT_MENU,
511 foundLocs = foundLocs | cmdHelper.TARGET_MEDIAITEM_CONTEXT_MENU;
514 var tbFound = cmdHelper.getCommandObjectForGUID
515 (cmdHelper.TARGET_TOOLBAR,
519 foundLocs = foundLocs | cmdHelper.TARGET_TOOLBAR;
535 var testGUID = testMediaList.guid;
538 var rootGUIDItem = cmdMgr.getPlaylistCommandsMediaItem(testGUID,
"");
541 var guidItemChildrenEnum = rootGUIDItem.getChildrenCommandObjects();
542 while(guidItemChildrenEnum.hasMoreElements())
551 var rootGUIDList = cmdMgr.getPlaylistCommandsMediaList(testGUID,
"");
554 var guidListChildrenEnum = rootGUIDList.getChildrenCommandObjects();
555 while(guidListChildrenEnum.hasMoreElements())
564 var testType = testMediaList.type;
567 var rootTypeItem = cmdMgr.getPlaylistCommandsMediaItem(
"", testType);
570 var typeItemChildrenEnum = rootTypeItem.getChildrenCommandObjects();
571 while(typeItemChildrenEnum.hasMoreElements())
580 var rootTypeList = cmdMgr.getPlaylistCommandsMediaList(
"", testType);
583 var typeListChildrenEnum = rootTypeList.getChildrenCommandObjects();
584 while(typeListChildrenEnum.hasMoreElements())
595 playlistCommand = playlistCommand.QueryInterface(
Ci.sbIPlaylistCommands);
596 var
id = playlistCommand.id;
599 if (registrationLoc ==
"medialist")
604 knownLoc = cmdHelper.TARGET_SERVICEPANE_MENU;
612 knownLoc = playlistCommand.targetFlags
615 if (!knownLoc || knownLoc == 0)
621 locMap[
id] = (locMap[
id] ?
627 locMap[
id] = (locMap[
id] ? (locMap[
id] | knownLoc) : knownLoc);
635 str +=
"ServicePane:" +
636 ((
flags & cmdHelper.TARGET_SERVICEPANE_MENU) > 0) +
", ";
639 str +=
"Present in Toolbar and/or Context Menu, but incomplete info";
642 str +=
"Toolbar:" + ((
flags & cmdHelper.TARGET_TOOLBAR) > 0) +
", ";
643 str +=
"Context Menu:" +
644 ((
flags & cmdHelper.TARGET_MEDIAITEM_CONTEXT_MENU) > 0);
function addExistingToLocMap(playlistCommand, locMap, registrationLoc)
const PlaylistCommandsBuilder
function addCommandToLocations(newCommand, testMediaList, locations, guidOrType)
function runTest()
Advanced DataRemote unit tests.
sbDeviceFirmwareAutoCheckForUpdate prototype flags
function testCreateCommandObjectForAction()
function assertTrue(aTest, aMessage)
function makeTriggerCallback(aActionID)
function removeCommandFromLocations(newCommand, testMediaList, locations, guidOrType)
function checkLocationFlags(foundLocs, checkLocs)
function flagsToString(flags)
function testAddAndRemoveCommandObject()
function testSubmenus(aCommand, aMenuID, aTestLength, aNumSubCommands)
function testAppendInsertRemove(aCommand, aMenuID, aTestLength, aNumSubCommands)
function createLibrary(databaseGuid, databaseLocation)
function findCommandLocations(cmdID, guidOrType, testMediaList)
function _log(aMsg, aMenuID)
function assertCommandLocations(testMediaList)
function testCommandCallbacksAndShortcuts(aCommand, aMenuID, aTestLength, aNumSubCommands)
function logExistingCommands(testMediaList)
const DEBUG
Playlist Commands Helper Unit Test File.
const INCOMPLETE_TARGET_FLAGS