34 .createInstance(
Ci.nsIMutableArray);
41 .getService(
Ci.sbIMetadataManager);
45 if (aFirstArray.length != aSecondArray.length) {
49 for (var aIndex = 0; aIndex < aFirstArray.length; aIndex++) {
50 if (aFirstArray[aIndex] != aSecondArray[aIndex]) {
59 var imageFile = testFolder.clone();
60 imageFile.append(imageFileName);
62 var newMimeType =
Cc[
"@mozilla.org/mime;1"]
63 .getService(
Ci.nsIMIMEService)
64 .getTypeFromFile(imageFile);
65 var inputStream =
Cc[
"@mozilla.org/network/file-input-stream;1"]
66 .createInstance(
Ci.nsIFileInputStream);
68 inputStream.init(imageFile, 0x01, 0600, 0);
69 var stream =
Cc[
"@mozilla.org/binaryinputstream;1"]
70 .createInstance(
Ci.nsIBinaryInputStream);
71 stream.setInputStream(inputStream);
72 var size = inputStream.available();
74 var bis =
Cc[
"@mozilla.org/binaryinputstream;1"].
76 bis.setInputStream(inputStream);
77 var newImageData = bis.readByteArray(size);
79 return [newMimeType, newImageData];
82 function testWrite(testFileName, shouldPass, artType) {
83 if (typeof(artType) ==
"undefined") {
84 artType =
Ci.sbIMetadataHandler.METADATA_IMAGE_TYPE_OTHER;
89 writeFile.append(testFileName);
92 var imageFileName =
"test.png"
95 [imageMimeType, imageData] =
getImageData(imageFileName);
98 var imageFile = testFolder.clone();
99 imageFile.append(imageFileName);
103 var
handler = gFileMetadataService.getHandlerForMediaURL(localPathURI.spec);
107 handler.setImageData(artType, newImageFile.spec);
116 var testMimeType = {};
117 var testDataSize = {};
118 var testImageData = handler.getImageData(artType, testMimeType, testDataSize);
123 "Mimetype not equal: " + testFileName);
125 "Image data not equal: " + testFileName);
129 "Mimetype is equal when it should not be: " + testFileName);
130 log(
"reference image length: " + imageData.length +
" embedded image length: " + testImageData.length);
132 "Image data is equal and should not be: " + testFileName);
143 var artFiles = [
"MP3_ID3v1v22.mp3",
148 "MPEG4_Audio_Apple_Lossless.m4a"];
149 var noArtFiles = [
"MP3_NoTags.mp3",
150 "MPEG4_Audio_Apple_Lossless_NoArt.m4a",
156 for (var index in artFiles) {
158 readFile.append(artFiles[index]);
160 var
handler = gFileMetadataService.getHandlerForMediaURL(localPathURI.spec);
164 var mimeTypeOutparam = {};
166 var imageData = handler.getImageData(
Ci.sbIMetadataHandler
167 .METADATA_IMAGE_TYPE_OTHER,
174 doThrow(
"Caught exception: " + err);
180 if (artFiles[index].
match(
"\.m4a$"))
183 var mimeTypeOutparam = {};
185 var imageData = handler.getImageData(
Ci.sbIMetadataHandler
186 .METADATA_IMAGE_TYPE_CONDUCTOR,
196 for (var index in noArtFiles) {
198 readFile.append(noArtFiles[index]);
200 var
handler = gFileMetadataService.getHandlerForMediaURL(localPathURI.spec);
203 var mimeTypeOutparam = {};
205 var imageData = handler.getImageData(
Ci.sbIMetadataHandler
206 .METADATA_IMAGE_TYPE_OTHER,
223 testWrite(
"MPEG4_Audio_Apple_Lossless_NoArt.m4a",
true,
224 Ci.sbIMetadataHandler.METADATA_IMAGE_TYPE_FRONTCOVER);
function newAppRelativeFile(path)
function assertNotEqual(aExpected, aActual, aMessage)
function writeFile(file, data)
function assertTrue(aTest, aMessage)
function assertEqual(aExpected, aActual, aMessage)
function newFileURI(file)
ExtensionSchemeMatcher prototype match
function assertFalse(aTest, aMessage)
function readFile(fileName)
function getCopyOfFolder(folder, tempName)
Copy the given folder to tempName, returning an nsIFile for the new location.