43 var contractId =
"@songbirdnest.com/Songbird/MetadataHandler/";
46 "gstreamer":
"GStreamer;1",
50 for each (var
handler in aHandlers) {
51 var available = (contractId + MAP[
String(
handler).toLowerCase()]) in
Cc;
64 var filesToRemove = [];
74 assertEqual(file.exists(),
false,
"file_that_doesn't_exist shouldn't exist!");
80 var fakeFile =
newAppRelativeFile(
"testharness/metadatamanager/errorcases/fake-file.mp3");
83 filesToRemove.push(fakeFile);
85 var corruptFile =
newAppRelativeFile(
"testharness/metadatamanager/errorcases/corrupt.mp3");
86 corruptFile =
getCopyOfFile(corruptFile,
"corrupt-file-temp.mp3");
87 files.push(corruptFile);
88 filesToRemove.push(corruptFile);
92 files.push(
newAppRelativeFile(
"testharness/metadatamanager/errorcases/mp3-disguised-as.flac"));
95 files.push(
newAppRelativeFile(
"testharness/metadatamanager/errorcases/mp3-disguised-as.ogg"));
98 files.push(
newAppRelativeFile(
"testharness/metadatamanager/errorcases/ogg-disguised-as.m4a"));
105 readonly.permissions = 0400;
106 files.push(readonly);
107 filesToRemove.push(readonly);
110 writeonly.permissions = 0200;
112 if ((writeonly.permissions & 0777) == 0200) {
113 files.push(writeonly);
117 log(
"MetadataJob_ErrorCases: platform does not support write-only. Perms=" + (writeonly.permissions & 0777));
119 filesToRemove.push(writeonly);
122 noaccess.permissions = 0000;
123 files.push(noaccess);
124 filesToRemove.push(noaccess);
136 files.push(
newURI(
"http://localhost:12345/remote/file/that/doesnt/exist.mp3"));
144 log(
"Creating libraries");
151 log(
"Populating library2");
152 for (index = 0; index < items1.length; ++index) {
154 let item1 = library1.getItemByIndex(index);
155 let item2 = library2.getItemByIndex(index);
158 item2.contentSrc.spec,
159 "expected item " + index +
" of libraries to match");
160 item2.setProperty(SBProperties.originItemGuid, item1.guid);
161 item2.setProperty(SBProperties.originLibraryGuid, item2.library.guid);
167 "expecting number of added items in library1 to equal total number of files");
170 "expecting number of added items in library2 to equal total number of files");
180 function onLib1ReadComplete(job) {
184 if (job.status ==
Ci.sbIJobProgress.STATUS_RUNNING) {
187 job.removeJobProgressListener(onLib1ReadComplete);
193 "expected files plus retries to equal job total");
196 "expected files plus retries to equal job progress");
198 Ci.sbIJobProgress.STATUS_FAILED,
199 "expected job to be failed");
202 var propertiesToWrite = [ SBProperties.artistName,
203 SBProperties.albumName,
204 SBProperties.trackName
207 for each (var item
in items2) {
208 for each (var prop
in propertiesToWrite) {
209 item.setProperty(prop, prop);
234 if (job.status ==
Ci.sbIJobProgress.STATUS_RUNNING) {
243 for (index = 0; index < items1.length; ++index) {
244 let item1 = library1.getItemByIndex(index);
245 let item2 = library2.getItemByIndex(index);
248 item2.contentSrc.spec,
249 "expected item " + index +
" of libraries to match");
250 item2.setProperty(SBProperties.originItemGuid, item1.guid);
251 item2.setProperty(SBProperties.originLibraryGuid, item2.library.guid);
255 "expected number of items added to library to be all files");
260 "expected all but 2 items to fail");
263 "expected the total to be the number of files");
266 "expected the process to be the number of files");
268 Ci.sbIJobProgress.STATUS_FAILED,
269 "expected the job to have failed");
274 job.addJobProgressListener(onLib2ReadComplete);
288 function onLib2ReadComplete(job) {
292 if (job.status ==
Ci.sbIJobProgress.STATUS_RUNNING) {
295 job.removeJobProgressListener(onLib2ReadComplete);
299 var diffingService =
Cc[
"@songbirdnest.com/Songbird/Library/DiffingService;1"]
300 .getService(
Ci.sbILibraryDiffingService);
301 var libraryChangeset = diffingService.createChangeset(library2,
303 var changes = libraryChangeset.changes;
304 log(
"\n\n\nMetadataJob_ErrorCases: There are " + changes.length +
305 " differences between library1 and library2.\n\n");
306 var changesEnum = changes.enumerate();
311 var corruptFileURL =
newFileURI(corruptFile).spec;
312 while(changesEnum.hasMoreElements()) {
313 var change = changesEnum.getNext().QueryInterface(
Ci.sbILibraryChange);
314 var propEnum = change.properties.enumerate();
315 var
url = change.sourceItem.contentSrc.spec;
316 log(
"MetadataJob_ErrorCases: changes in " +
318 while(propEnum.hasMoreElements()) {
319 var prop = propEnum.getNext().QueryInterface(
Ci.sbIPropertyChange);
320 log(
"\t\t[" + prop.id +
"] " + prop.oldValue +
" -> " + prop.newValue +
"\n");
322 assertTrue(url == fakeFileURL || url == corruptFileURL,
323 "expected url to be either fakeFileURL or curruptFileURL");
327 "expected 2 changes");
334 "error count unexpected");
337 "expected files plus retries to equal total");
340 "expected files plus retries to equal progress");
342 Ci.sbIJobProgress.STATUS_FAILED,
343 "expected job to have failed");
358 for each (file
in filesToRemove) {
360 file.permissions = 0600;
372 job.addJobProgressListener(onLib1ReadComplete);
383 for each (var
file in files) {
384 if (!(
file instanceof
Ci.nsIURI)) {
387 items.push(library.createMediaItem(
file,
null,
true));
397 var
prefSvc =
Cc[
"@mozilla.org/preferences-service;1"]
398 .getService(
Ci.nsIPrefBranch);
399 var oldWritingEnabledPref = prefSvc.getBoolPref(
"songbird.metadata.enableWriting");
400 prefSvc.setBoolPref(
"songbird.metadata.enableWriting",
true);
401 var
array =
Cc[
"@songbirdnest.com/moz/xpcom/threadsafe-array;1"]
402 .createInstance(
Ci.nsIMutableArray);
403 for each (var item
in items) {
404 array.appendElement(item,
false);
406 manager =
Cc[
"@songbirdnest.com/Songbird/FileMetadataService;1"]
407 .getService(
Ci.sbIFileMetadataService);
409 if (type ==
"write") {
410 job = manager.write(
array, ArrayConverter.stringEnumerator(writeProperties));
412 job = manager.read(
array);
414 prefSvc.setBoolPref(
"songbird.metadata.enableWriting", oldWritingEnabledPref);
function newAppRelativeFile(path)
function assertTrue(aTest, aMessage)
function assertEqual(aExpected, aActual, aMessage)
function newFileURI(file)
function newURI(aURLString)