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"};
96 var diffingService =
Cc[
"@songbirdnest.com/Songbird/Library/DiffingService;1"]
97 .getService(
Ci.sbILibraryDiffingService);
99 var sourceDBGUID =
"test_multilist_source";
100 var destinationDBGUID =
"test_multilist_destination";
107 var itemA = sourceLibrary.createMediaItem(itemAURI,
112 var itemB = destinationLibrary.createMediaItem(itemBURI,
117 var itemC = sourceLibrary.createMediaItem(itemCURI,
122 var itemD = destinationLibrary.createMediaItem(itemDURI,
127 var itemE = sourceLibrary.createMediaItem(itemEURI,
132 var itemEE = destinationLibrary.createMediaItem(itemEEURI,
138 var itemF = destinationLibrary.createMediaItem(itemFURI,
146 var sourceMediaListA = sourceLibrary.createMediaList(
"simple");
147 sourceMediaListA.name =
"The List";
148 sourceMediaListA.add(itemA);
149 sourceMediaListA.add(itemB);
150 sourceMediaListA.add(itemC);
151 sourceMediaListA.add(itemE);
152 sourceMediaListA.add(itemE);
155 var sourceMediaListB = sourceLibrary.createMediaList(
"simple");
156 sourceMediaListB.name =
"The Wrong Name";
157 sourceMediaListB.add(itemA);
158 sourceMediaListB.add(itemC);
159 sourceMediaListB.add(itemD);
160 sourceMediaListB.add(itemEE);
161 sourceMediaListB.add(itemD);
163 var sourceMediaLists =
Cc[
"@songbirdnest.com/moz/xpcom/threadsafe-array;1"]
164 .createInstance(
Ci.nsIMutableArray);
165 sourceMediaLists.appendElement(sourceMediaListA,
false);
166 sourceMediaLists.appendElement(sourceMediaListB,
false);
168 var libraryChangeset = diffingService.createMultiChangeset(sourceMediaLists,
171 var sourceLists = libraryChangeset.sourceLists;
172 assertEqual(sourceLists.length, 2,
"There should only be two source lists!");
174 var sourceList = sourceLists.queryElementAt(0,
Ci.sbIMediaList);
177 "Source list should be equal to the source media list!");
179 sourceList = sourceLists.queryElementAt(1,
Ci.sbIMediaList);
182 "Source list should be equal to the source media list!");
184 var destinationList = libraryChangeset.destinationList;
187 "Destination list should be equal to destination library!");
189 var changes = libraryChangeset.changes;
190 log(
"There are " + changes.length +
" changes present in the changeset.");
193 var addedListOps = 0;
194 var addedChanges = [];
197 var deletedChanges = [];
200 var movedChanges = [];
205 var changesEnum = changes.enumerate();
206 while(changesEnum.hasMoreElements()) {
207 var changeSupports = changesEnum.getNext();
208 var change = changeSupports.QueryInterface(
Ci.sbILibraryChange);
210 switch(change.operation) {
211 case Ci.sbIChangeOperation.ADDED:
213 if (change.itemIsList)
215 addedChanges.push(change);
217 case Ci.sbIChangeOperation.DELETED:
219 deletedChanges.push(change);
221 case Ci.sbIChangeOperation.MODIFIED:
224 case Ci.sbIChangeOperation.MOVED:
226 movedChanges.push(change);
233 log(
"There are " + addedOps +
" added operations.");
234 assertEqual(addedOps, 4,
"There should be 4 added operations");
236 log(
"There are " + addedListOps +
" added list operations.");
237 assertEqual(addedListOps, 2,
"There should be 2 added list operations");
239 log(
"There are " + deletedOps +
" deleted operations.");
240 assertEqual(deletedOps, 1,
"There should be 1 deleted operations");
242 log(
"There are " + modifiedOps +
" modified operations.");
243 assertEqual(modifiedOps, 1,
"There should 1 modified operations");
245 log(
"There are " + movedOps +
" moved operations.");
246 assertEqual(movedOps, 0,
"There should be 0 moved operations.");
function appendPropertiesToArray(aProperties, aPropertyArray)
function createPropertyArray()
function assertEqual(aExpected, aActual, aMessage)
function runTest()
Advanced DataRemote unit tests.
function createLibrary(databaseGuid, databaseLocation)
function makeItACopy(source, destination)