30 var
SB_NS =
"http://songbirdnest.com/data/1.0#";
33 return Cc[
"@songbirdnest.com/Songbird/Properties/MutablePropertyArray;1"]
34 .createInstance(
Ci.sbIMutablePropertyArray);
46 destination.setProperty(SBProperties.originItemGuid, source.guid);
47 destination.setProperty(SBProperties.originLibraryGuid, source.library.guid);
51 Components.utils.import(
"resource://app/jsmodules/sbProperties.jsm");
53 var
ios =
Cc[
"@mozilla.org/network/io-service;1"].getService(
Ci.nsIIOService);
55 var sourceItemAddedURI = ios.newURI(
"file:///alpha.mp3",
null,
null);
56 var sourceItemAddedProperties =
57 { artistName:
"A", albumName:
"Alpha", trackName:
"Track Alpha", trackNumber:
"1",
year:
"2000"};
59 var sourceItemNotModifiedURI = ios.newURI(
"file:///ecto.mp3",
null,
null);
60 var sourceItemNotModifiedProperties =
61 { artistName:
"E", albumName:
"Ecto", trackName:
"Track Ecto", trackNumber:
"2",
year:
"2004"};
63 var destinationItemDeletedURI = ios.newURI(
"file:///beta.mp3",
null,
null);
64 var destinationItemDeletedProperties =
65 { artistName:
"B", albumName:
"Beta", trackName:
"Track Beta", trackNumber:
"2",
year:
"2001"};
67 var sourceItemModifiedURI = ios.newURI(
"file:///cent.mp3",
null,
null);
68 var sourceItemModifiedProperties =
69 { artistName:
"C", albumName:
"Cent", trackName:
"Track Cent", trackNumber:
"3",
year:
"2002", composerName:
"Centos" };
71 var destinationItemModifiedURI = sourceItemModifiedURI;
72 var destinationItemModifiedProperties =
73 { artistName:
"D", albumName:
"Delta", trackName:
"Track Delta", trackNumber:
"4",
year:
"2002", genre:
"rock" };
75 var destinationItemNotModifiedURI = ios.newURI(
"file:///ecto.mp3",
null,
null);
76 var destinationItemNotModifiedProperties =
77 { artistName:
"E", albumName:
"Ecto", trackName:
"Track Ecto", trackNumber:
"2",
year:
"2004"};
79 var diffingService =
Cc[
"@songbirdnest.com/Songbird/Library/DiffingService;1"]
80 .getService(
Ci.sbILibraryDiffingService);
82 var sourceDBGUID =
"test_library_source";
83 var destinationDBGUID =
"test_library_destination";
90 var addedItem = sourceLibrary.createMediaItem(sourceItemAddedURI,
95 var deletedItem = destinationLibrary.createMediaItem(destinationItemDeletedURI,
100 var modifiedItemA = sourceLibrary.createMediaItem(sourceItemModifiedURI,
105 var modifiedItemB = destinationLibrary.createMediaItem(destinationItemModifiedURI,
111 var sourceItemNotModified =
112 sourceLibrary.createMediaItem(sourceItemNotModifiedURI,
117 var destinationItemNotModified =
118 destinationLibrary.createMediaItem(destinationItemNotModifiedURI,
120 makeItACopy(sourceItemNotModified, destinationItemNotModified);
121 log(
"destinationItemNotModified = " + destinationItemNotModified.getProperty(SBProperties.originItemGuid) +
"\n")
123 var libraryChangeset = diffingService.createChangeset(sourceLibrary,
126 var sourceLists = libraryChangeset.sourceLists;
127 assertEqual(sourceLists.length, 1,
"There should only be one source list!");
129 var sourceList = sourceLists.queryElementAt(0,
Ci.sbILibrary);
132 "Source list should be equal to the source library!");
134 var destinationList = libraryChangeset.destinationList;
137 "Destination list should be equal to destination library!");
139 var changes = libraryChangeset.changes;
140 log(
"There are " + changes.length +
" changes present in the changeset.");
143 var addedChange =
null;
146 var deletedChange =
null;
149 var modifiedChange =
null;
153 var changesEnum = changes.enumerate();
155 while(changesEnum.hasMoreElements()) {
156 var change = changesEnum.getNext().QueryInterface(
Ci.sbILibraryChange);
158 switch(change.operation) {
159 case Ci.sbIChangeOperation.ADDED:
161 addedChange = change;
162 log(
"added " + change.sourceItem.contentSrc.spec +
"\n");
164 case Ci.sbIChangeOperation.DELETED:
166 deletedChange = change;
167 log(
"deleted " + change.destinationItem.contentSrc.spec +
"\n");
169 case Ci.sbIChangeOperation.MODIFIED:
171 modifiedChange = change;
172 log(
"modified " + change.sourceItem.contentSrc.spec +
"\n");
179 assertEqual(addedOps, 1,
"Wrong number of added operation!");
180 assertEqual(deletedOps, 1,
"Wrong number of deleted operations!");
181 assertEqual(modifiedOps, 1,
"Wrong number of modified operation!");
182 assertEqual(unknownOps, 0,
"There should _not_ be any unknown operations!");
184 var propertyChange =
null;
185 var propertyChangesEnum = addedChange.properties.enumerate();
186 while(propertyChangesEnum.hasMoreElements()) {
187 propertyChange = propertyChangesEnum.getNext().QueryInterface(
Ci.sbIPropertyChange);
188 if(typeof(sourceItemAddedProperties[propertyChange.id]) !=
'undefined') {
189 assertEqual(sourceItemAddedProperties[propertyChange.id],
190 propertyChange.newValue,
191 "Value is not what is expected!");
196 deletedChange.properties;
200 Cr.NS_ERROR_NOT_AVAILABLE,
201 "There should be no property changes available for deleted operations!");
204 propertyChangesEnum = modifiedChange.properties.enumerate();
205 while(propertyChangesEnum.hasMoreElements()) {
206 propertyChange = propertyChangesEnum.getNext().QueryInterface(
Ci.sbIPropertyChange);
208 if(typeof(sourceItemModifiedProperties[propertyChange.id]) !=
'undefined' &&
209 typeof(destinationItemModifiedProperties[propertyChange.id]) ==
'undefined') {
211 Ci.sbIChangeOperation.ADDED,
212 "Property should have been ADDED!");
215 "Old property value should be undefined!");
218 if(typeof(sourceItemModifiedProperties[propertyChange.id]) !=
'undefined' &&
219 typeof(destinationItemModifiedProperties[propertyChange.id]) !=
'undefined') {
221 destinationItemModifiedProperties[propertyChange.id],
222 "Old value and actual item value do not match when they should!");
224 Ci.sbIChangeOperation.MODIFIED,
225 "Property should have been MODIFIED!");
228 if(typeof(sourceItemModifiedProperties[propertyChange.id]) ==
'undefined' &&
229 typeof(destinationItemModifiedProperties[propertyChange.id]) !=
'undefined') {
231 Ci.sbIChangeOperation.DELETED,
232 "Property should have been DELETED!");
233 assertEqual(destinationItemModifiedProperties[propertyChange.id],
234 propertyChange.oldValue);
237 "Deleted property should _not_ have a newValue");
function createPropertyArray()
function assertEqual(aExpected, aActual, aMessage)
function runTest()
Advanced DataRemote unit tests.
function appendPropertiesToArray(aProperties, aPropertyArray)
function createLibrary(databaseGuid, databaseLocation)
function makeItACopy(source, destination)