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");
52 var
ios =
Cc[
"@mozilla.org/network/io-service;1"].getService(
Ci.nsIIOService);
54 var itemAURI = ios.newURI(
"file:///alpha.mp3",
null,
null);
56 { artistName:
"A", albumName:
"Alpha", trackName:
"Track Alpha", trackNumber:
"1",
year:
"2000"};
58 var itemBURI = ios.newURI(
"file:///ecto.mp3",
null,
null);
60 { artistName:
"E", albumName:
"Ecto", trackName:
"Track Ecto", trackNumber:
"2",
year:
"2004"};
62 var itemCURI = ios.newURI(
"file:///beta.mp3",
null,
null);
64 { artistName:
"B", albumName:
"Beta", trackName:
"Track Beta", trackNumber:
"2",
year:
"2001"};
66 var itemDURI = ios.newURI(
"file:///cent.mp3",
null,
null);
68 { artistName:
"C", albumName:
"Cent", trackName:
"Track Cent", trackNumber:
"3",
year:
"2002", composerName:
"Centos" };
70 var itemEURI = ios.newURI(
"file:///femto.mp3",
null,
null);
72 { artistName:
"F", albumName:
"Femto", trackName:
"Track Femto", trackNumber:
"7",
year:
"1998", genre:
"electronic" };
74 var itemEEURI = ios.newURI(
"file:///femto.mp3",
null,
null);
75 var itemEEProperties =
76 { artistName:
"Full", albumName:
"Femto", trackName:
"Track Femto Super", trackNumber:
"7",
year:
"1998", genre:
"techno" };
78 var itemFURI = ios.newURI(
"file:///delta.mp3",
null,
null);
80 { artistName:
"D", albumName:
"Delta", trackName:
"Track Delta", trackNumber:
"5",
year:
"2008"};
83 var diffingService =
Cc[
"@songbirdnest.com/Songbird/Library/DiffingService;1"]
84 .getService(
Ci.sbILibraryDiffingService);
86 var sourceDBGUID =
"test_medialist_source";
87 var destinationDBGUID =
"test_medialist_destination";
94 var itemA = sourceLibrary.createMediaItem(itemAURI,
99 var itemB = destinationLibrary.createMediaItem(itemBURI,
104 var itemC = sourceLibrary.createMediaItem(itemCURI,
109 var itemD = destinationLibrary.createMediaItem(itemDURI,
114 var itemE = sourceLibrary.createMediaItem(itemEURI,
119 var itemEE = destinationLibrary.createMediaItem(itemEEURI,
125 var itemF = destinationLibrary.createMediaItem(itemFURI,
128 var itemsAdded = [itemB, itemE];
129 var itemsAddedProperties = [itemBProperties, itemEProperties];
131 var itemsDeleted = [itemD, itemD];
132 var itemsDeletedProperties = [itemDProperties, itemDProperties];
134 var sourceMediaList = sourceLibrary.createMediaList(
"simple");
135 var destinationMediaList = destinationLibrary.createMediaList(
"simple");
137 sourceMediaList.name =
"The List";
138 destinationMediaList.name =
"The Wrong Name";
140 sourceMediaList.add(itemA);
141 sourceMediaList.add(itemB);
142 sourceMediaList.add(itemC);
143 sourceMediaList.add(itemE);
144 sourceMediaList.add(itemF);
145 sourceMediaList.add(itemE);
147 destinationMediaList.add(itemA);
148 destinationMediaList.add(itemC);
149 destinationMediaList.add(itemD);
150 destinationMediaList.add(itemEE);
151 destinationMediaList.add(itemF);
152 destinationMediaList.add(itemD);
154 var libraryChangeset = diffingService.createChangeset(sourceMediaList,
155 destinationMediaList);
157 var sourceLists = libraryChangeset.sourceLists;
158 assertEqual(sourceLists.length, 1,
"There should only be one source list!");
160 var sourceList = sourceLists.queryElementAt(0,
Ci.sbIMediaList);
163 "Source list should be equal to the source media list!");
165 var destinationList = libraryChangeset.destinationList;
167 destinationMediaList,
168 "Destination list should be equal to destination media list!");
170 var changes = libraryChangeset.changes;
171 log(
"There are " + changes.length +
" changes present in the changeset.");
174 var addedChanges = [];
177 var deletedChanges = [];
180 var movedChanges = [];
185 var changesEnum = changes.enumerate();
187 while(changesEnum.hasMoreElements()) {
188 var change = changesEnum.getNext().QueryInterface(
Ci.sbILibraryChange);
190 switch(change.operation) {
191 case Ci.sbIChangeOperation.ADDED:
193 addedChanges.push(change);
195 case Ci.sbIChangeOperation.DELETED:
197 deletedChanges.push(change);
199 case Ci.sbIChangeOperation.MODIFIED:
202 case Ci.sbIChangeOperation.MOVED:
204 movedChanges.push(change);
211 log(
"There are " + addedOps +
" added operations.");
212 assertEqual(addedOps, 2,
"There should be 2 added operations");
214 log(
"There are " + deletedOps +
" deleted operations.");
215 assertEqual(deletedOps, 2,
"There should be 2 deleted operations");
217 log(
"There are " + modifiedOps +
" modified operations.");
218 assertEqual(modifiedOps, 1,
"There should 1 modified operations");
220 log(
"There are " + movedOps +
" moved operations.");
221 assertEqual(movedOps, 6,
"There should be 6 moved operations.");
224 var propertyChange =
null;
225 var propertyChangesEnum =
null;
227 for(i = 0; i < addedChanges.length; ++
i) {
228 propertyChangesEnum = addedChanges[
i].properties.enumerate();
229 while(propertyChangesEnum.hasMoreElements()) {
230 propertyChange = propertyChangesEnum.getNext().QueryInterface(
Ci.sbIPropertyChange);
231 if(typeof(itemsAddedProperties[i][propertyChange.id]) !=
'undefined') {
232 assertEqual(itemsAddedProperties[i][propertyChange.id],
233 propertyChange.newValue,
234 "Value is not what is expected!");
239 for(i = 0; i < deletedChanges.length; ++
i) {
242 "Items should be equal!");
244 propertyChangesEnum = deletedChanges[
i].properties;
248 Cr.NS_ERROR_NOT_AVAILABLE,
249 "There should be no property changes available for deleted operations!");
253 for(i = 0; i < movedChanges.length; ++
i) {
255 propertyChangesEnum = movedChanges[
i].properties.enumerate();
257 var totalPropertyChanges = 0;
258 while(propertyChangesEnum.hasMoreElements()) {
259 propertyChange = propertyChangesEnum.getNext().QueryInterface(
Ci.sbIPropertyChange);
263 "The property id should always be 'http://songbirdnest.com/data/1.0#ordinal'");
267 "The ordinal of the item is not correct!");
269 ++totalPropertyChanges;
274 "There should only be one property change for moved operations!");
function assertEqual(aExpected, aActual, aMessage)
function createLibrary(databaseGuid, databaseLocation)
_getSelectedPageStyle s i