33 return this.
Application =
Cc[
"@mozilla.org/fuel/application;1"]
34 .getService(
Ci.fuelIApplication);
38 Components.utils.import(
'resource://gre/modules/XPCOMUtils.jsm');
43 var
SB_NS =
"http://songbirdnest.com/data/1.0#";
44 var SB_MEDIAFILEMANAGER =
"@songbirdnest.com/Songbird/media-manager/file;1";
46 var SB_MM_PROP_FOLDER =
"media-folder";
47 var SB_MM_PROP_FMTFILE =
"file-format";
48 var SB_MM_PROP_FMTDIR =
"dir-format";
52 var gResultInformation = [
53 { originalFileName:
"TestFile1.mp3",
54 expectedFileName:
"1 - Sample.mp3",
55 expectedFolder:
"Managed/Songbird/Unit Test Classics",
56 expectedAction:
Ci.sbIMediaFileManager.MANAGE_COPY |
57 Ci.sbIMediaFileManager.MANAGE_RENAME },
58 { originalFileName:
"TestFile2.mp3",
59 expectedFileName:
"2 - Sample.mp3",
60 expectedFolder:
"Managed/Songbird/Unit Test Classics",
61 expectedAction:
Ci.sbIMediaFileManager.MANAGE_COPY |
62 Ci.sbIMediaFileManager.MANAGE_RENAME },
63 { originalFileName:
"TestFile3.mp3",
64 expectedFileName:
"3 - Sample.mp3",
65 expectedFolder:
"Managed/Songbird/Unit Test Classics",
66 expectedAction:
Ci.sbIMediaFileManager.MANAGE_COPY |
67 Ci.sbIMediaFileManager.MANAGE_RENAME },
69 { originalFileName:
"TestFile4.mp3",
70 expectedFileName:
"1 - TestFile4.mp3",
71 expectedFolder:
"Managed/Unknown Artist/Unknown Album",
72 expectedAction:
Ci.sbIMediaFileManager.MANAGE_COPY |
73 Ci.sbIMediaFileManager.MANAGE_RENAME },
75 { originalFileName:
"TestFile5.mp3",
76 expectedFileName:
"1 - Sample.mp3",
77 expectedFolder:
"Managed/Songbird/Unknown Album",
78 expectedAction:
Ci.sbIMediaFileManager.MANAGE_COPY |
79 Ci.sbIMediaFileManager.MANAGE_RENAME },
81 { originalFileName:
"TestFile6.mp3",
82 expectedFileName:
"1 - Sample.mp3",
83 expectedFolder:
"Managed/Unknown Artist/Unit Test Classics",
84 expectedAction:
Ci.sbIMediaFileManager.MANAGE_COPY |
85 Ci.sbIMediaFileManager.MANAGE_RENAME },
87 { originalFileName:
"TestFile7.mp3",
88 expectedFileName:
"01 - Sample7.mp3",
89 expectedFolder:
"Managed/Songbird/Unit Test Classics",
90 expectedAction:
Ci.sbIMediaFileManager.MANAGE_COPY |
91 Ci.sbIMediaFileManager.MANAGE_RENAME },
93 { originalFileName:
"TestFile8.mp3",
94 expectedFileName:
"11 - Sample8.mp3",
95 expectedFolder:
"Managed/Songbird/Unit Test Classics",
96 expectedAction:
Ci.sbIMediaFileManager.MANAGE_MOVE |
97 Ci.sbIMediaFileManager.MANAGE_RENAME }
112 function getMediaManagerProperties () {
119 managedFolder.append(
"Managed");
121 managedFolder.create(
Ci.nsIFile.DIRECTORY_TYPE, 0777);
123 var properties =
Cc[
"@mozilla.org/hash-property-bag;1"]
124 .createInstance(
Ci.nsIWritablePropertyBag2);;
126 properties.setPropertyAsInterface(SB_MM_PROP_FOLDER, managedFolder);
127 properties.setPropertyAsAString(SB_MM_PROP_FMTFILE,
128 SB_NS +
"trackNumber," +
130 SB_NS +
"trackName");
131 properties.setPropertyAsAString(SB_MM_PROP_FMTDIR,
132 SB_NS +
"artistName," +
134 SB_NS +
"albumName");
143 function addItemsToLibrary(aLibrary) {
144 var toAdd =
Cc[
"@songbirdnest.com/moz/xpcom/threadsafe-array;1"]
145 .createInstance(
Ci.nsIMutableArray);
146 var propertyArray =
Cc[
"@songbirdnest.com/moz/xpcom/threadsafe-array;1"]
147 .createInstance(
Ci.nsIMutableArray);
148 var
ioService =
Cc[
"@mozilla.org/network/io-service;1"]
149 .getService(
Ci.nsIIOService);
150 for (var
i = 0;
i < gResultInformation.length;
i++) {
153 newFile = appendPathToDirectory(newFile,
154 gResultInformation[
i].originalFileName);
155 toAdd.appendElement(ioService.newFileURI(newFile),
false);
158 var props =
Cc[
"@songbirdnest.com/Songbird/Properties/MutablePropertyArray;1"]
159 .createInstance(
Ci.sbIMutablePropertyArray);
160 props.appendProperty(SB_NS +
"contentLength",
i + 1);
161 props.appendProperty(SB_NS +
"trackNumber",
i + 1);
162 propertyArray.appendElement(props,
false);
165 aLibrary.batchCreateMediaItems(toAdd, propertyArray);
178 function checkItem(aMediaItem, aResultInformationIndex, aShouldHaveOriginal) {
180 var current = aMediaItem.contentSrc;
181 if (!(current instanceof
Ci.nsIFileURL)) {
182 log(
"item [" + current.spec +
"] is not a file URL!");
185 current = current.file;
189 var expFolder = gResultInformation[aResultInformationIndex].expectedFolder;
190 expected = appendPathToDirectory(expected, expFolder);
191 expected.append(gResultInformation[aResultInformationIndex].expectedFileName);
195 if (!current.equals(expected)) {
196 log(
"current value ["+ current.path +
197 "] is not expectd value [" + expected.path +
"]!");
203 var origName = gResultInformation[aResultInformationIndex].originalFileName;
204 original = appendPathToDirectory(original, origName);
206 if (!original.exists() && aShouldHaveOriginal) {
207 log(
"original doesn't exist, but expected!");
209 }
else if (original.exists() && !aShouldHaveOriginal) {
210 log(
"original exists, but expected to be removed!");
221 function checkDeletedItem(aMediaItem) {
222 var fileURI = aMediaItem.contentSrc.QueryInterface(
Ci.nsIFileURL);
223 if (fileURI instanceof
Ci.nsIFileURL) {
224 var
file = fileURI.file;
225 return !file.exists();
234 this._added = Components.classes[
"@songbirdnest.com/moz/xpcom/threadsafe-array;1"]
235 .createInstance(Components.interfaces.nsIMutableArray);
245 onItemAdded:
function onItemAdded(list, item, index) {
246 this._added.appendElement( item,
false );
251 onBeforeItemRemoved:
function onBeforeItemRemoved(list, item, index) {
255 onAfterItemRemoved:
function onAfterItemRemoved(list, item, index) {
259 onItemUpdated:
function onItemUpdated(list, item, properties) {
263 onItemMoved:
function onItemMoved(list, fromIndex, toIndex) {
267 onBatchBegin:
function onBatchBegin(list) {
270 onBatchEnd:
function onBatchEnd(list) {
272 onBeforeListCleared:
function onBeforeListCleared() {
275 onListCleared:
function onListCleared() {
288 folder.copyTo(tempFolder, tempName);
289 folder = tempFolder.clone();
290 folder.append(tempName);
298 function appendPathToDirectory(directory,
path) {
299 var nodes =
path.split(
"/");
300 for ( var
i = 0, end = nodes.length;
i < end;
i++ )
302 directory.append( nodes[
i ] );
316 gTempFolder = Components.classes[
"@mozilla.org/file/directory_service;1"]
317 .getService(Components.interfaces.nsIProperties)
318 .get(
"TmpD", Components.interfaces.nsIFile);
319 gTempFolder.append(
"songbird_mediamanager_tests.tmp");
320 gTempFolder.createUnique(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0777);
329 if (gTempFolder && gTempFolder.exists()) {
330 gTempFolder.remove(
true);
332 log(
"\n\n\nMedia Manager Test may not have performed cleanup. Temp files may exist.\n\n\n");
346 gTestLibrary.clear();
347 libraryManager.unregisterLibrary(gTestLibrary);
function assertNotEqual(aExpected, aActual, aMessage)
sbOSDControlService prototype QueryInterface
function assertEqual(aExpected, aActual, aMessage)
getService(Ci.sbIFaceplateManager)
function getCopyOfFolder(folder, tempName)
Copy the given folder to tempName, returning an nsIFile for the new location.
_getSelectedPageStyle s i
function TestMediaListListener()