33 Components.utils.import(
"resource://app/jsmodules/sbProperties.jsm");
34 Components.utils.import(
"resource://app/jsmodules/sbLibraryUtils.jsm");
42 "NoTags": { trackName:
"",
49 audioExpectedIdentity:
null,
50 videoExpectedIdentity:
null},
51 "OnlyName": { trackName:
"OnlyAName",
58 audioExpectedIdentity:
"edW9P0emhROCprpy6YdiXg==",
59 videoExpectedIdentity:
"8DHNDFkX6afo03hmmInR6w==" },
60 "Tagged": { trackName:
"A fully tagged track",
61 artistName:
"with an artist name",
62 albumName:
"and an album name",
63 genre:
"and even a genre",
64 producerName:
"some producer",
67 audioExpectedIdentity:
"4C9SB69gL6pB/NZ/2UQbsw==",
68 videoExpectedIdentity:
"gPL0UOMSMv08yHcuLA+peg==" },
69 "ForeignChar": { trackName:
"太陽",
71 albumName:
"moment 〜もぉめんと〜",
73 producerName:
"まちあわせ",
76 audioExpectedIdentity:
"1giivr/B90byHVMftVlFmQ==",
77 videoExpectedIdentity:
"Ki4O6mqLlA+cNCHutxjVOw=="}
85 log(
"Testing Identity Service:");
88 gIdentityService =
Cc[
"@songbirdnest.com/Songbird/IdentityService;1"]
89 .getService(
Ci.sbIIdentityService);
94 for (var dataName in gTestData) {
95 var currData = gTestData[dataName];
99 Cc[
"@songbirdnest.com/Songbird/Properties/MutablePropertyArray;1"]
100 .createInstance(
Ci.sbIMutablePropertyArray);
101 props.appendProperty(SBProperties.trackName, currData.trackName);
102 props.appendProperty(SBProperties.artistName, currData.artistName);
103 props.appendProperty(SBProperties.albumName, currData.albumName);
104 props.appendProperty(SBProperties.genre, currData.genre);
105 props.appendProperty(SBProperties.producerName, currData.producerName);
106 props.appendProperty(SBProperties.contentType, contentType);
107 var newItem = gTestLibrary.createMediaItem
108 (
newURI(
"http://foo.test.com/" +
109 dataName +
"_" + contentType),
111 currData[contentType +
"MediaItem"] = newItem;
116 testCalculateIdentity();
117 testSaveAndGetItemWithSameIdentity();
118 gTestLibrary.clear();
126 function testHashString() {
127 log(
"Testing sbIIdentityService.hashString...");
131 var testString =
"hello, world";
132 var expectedHash =
"5NfxtO0uQtFYmPSyewGdpA==";
133 var actualHash = gIdentityService.hashString(testString);
145 for (var dataName in gTestData) {
146 var currData = gTestData[dataName];
151 var identityProperties = [];
152 identityProperties.push(contentType);
153 identityProperties.push(currData.trackName);
154 identityProperties.push(currData.artistName);
155 identityProperties.push(currData.albumName);
156 identityProperties.push(currData.genre);
158 var metadataString = identityProperties.join(
SEPARATOR);
163 var hasMetadata = (metadataString.length >
164 (contentType.length + identityProperties.length - 1));
166 var expectedMetadataHash = currData[contentType +
"ExpectedIdentity"];
171 var actualMetadataHash = ((hasMetadata) ?
172 gIdentityService.hashString(metadataString) :
174 assertEqual(actualMetadataHash, expectedMetadataHash);
180 function testCalculateIdentity() {
181 log(
"Testing sbIIdentityService.calculateIdentity...");
185 for (var dataName in gTestData) {
186 var currData = gTestData[dataName];
190 var testMediaItem = currData[contentType +
"MediaItem"];
191 var expectedHash = currData[contentType +
"ExpectedIdentity"];
192 var actualMediaItemHash = gIdentityService.calculateIdentityForMediaItem
198 testMediaItem.setProperty(SBProperties.producerName,
"A new producer!");
199 var irrelevantChangeHash =
200 gIdentityService.calculateIdentityForMediaItem(testMediaItem);
206 var otherContentType = (contentType ==
"video") ?
"audio" :
"video";
207 testMediaItem.setProperty(SBProperties.contentType, otherContentType);
209 var actualContentTypeSwitchHash =
210 gIdentityService.calculateIdentityForMediaItem(testMediaItem);
212 var expectedContentTypeSwitchHash =
213 currData[otherContentType +
"ExpectedIdentity"];
214 assertEqual(actualContentTypeSwitchHash, expectedContentTypeSwitchHash);
217 testMediaItem.setProperty(SBProperties.contentType, contentType);
218 actualMediaItemHash = gIdentityService.calculateIdentityForMediaItem
226 function testSaveAndGetItemWithSameIdentity() {
227 log(
"Testing sbIIdentityService saving and retrieving items by identity...");
243 var finishedCount = 0;
244 for (var dataName in gTestData) {
245 var currData = gTestData[dataName];
248 var testMediaItem = currData[contentType +
"MediaItem"];
249 var expectedHash = currData[contentType +
"ExpectedIdentity"];
255 if (expectedHash !=
null) {
257 var found = secondaryLibrary.containsItemWithSameIdentity(testMediaItem);
263 found = gTestLibrary.containsItemWithSameIdentity(testMediaItem);
270 Cc[
"@songbirdnest.com/Songbird/Properties/MutablePropertyArray;1"]
271 .createInstance(
Ci.sbIMutablePropertyArray);
272 props.appendProperty(SBProperties.trackName, currData.trackName);
273 props.appendProperty(SBProperties.artistName, currData.artistName);
274 props.appendProperty(SBProperties.albumName, currData.albumName);
275 props.appendProperty(SBProperties.genre, currData.genre);
276 props.appendProperty(SBProperties.producerName, currData.producerName);
277 props.appendProperty(SBProperties.contentType, contentType);
278 var secondaryItem = secondaryLibrary.createMediaItem
279 (
newURI(
"http://foo.secondarytest.com/" +
280 dataName +
"_" + contentType),
285 found = secondaryLibrary.containsItemWithSameIdentity(testMediaItem);
290 found = gTestLibrary.containsItemWithSameIdentity(secondaryItem);
294 var hashPropID = SBProperties.metadataHashIdentity;
295 var testIdentity = testMediaItem.getProperty(hashPropID);
296 var foundItems =
null;
298 foundItems = gTestLibrary.getItemsByProperty(hashPropID,
302 if (e.result == Components.results.NS_ERROR_NOT_AVAILABLE) {
310 'could not find item using identity and getItemsByProperty()');
314 var foundItems = secondaryLibrary.getItemsWithSameIdentity(testMediaItem);
316 assertEqual(foundItems.queryElementAt(0,
Ci.sbIMediaItem).guid, secondaryItem.guid);
318 foundItems = gTestLibrary.getItemsWithSameIdentity(secondaryItem);
320 assertEqual(foundItems.queryElementAt(0,
Ci.sbIMediaItem).guid, testMediaItem.guid);
324 gIdentityService.saveIdentityToMediaItem(secondaryItem,
"finished");
325 var foundItems = secondaryLibrary.getItemsWithSameIdentity(testMediaItem);
331 secondaryLibrary.clear();
function assertTrue(aTest, aMessage)
function assertEqual(aExpected, aActual, aMessage)
function createLibrary(databaseGuid, databaseLocation)
function newURI(aURLString)