29 Components.utils.import(
"resource://app/jsmodules/ArrayConverter.jsm");
33 while (enumerator.hasMoreElements()) {
34 var item = enumerator.getNext().QueryInterface(
Ci.sbIMediaItem);
43 var databaseGUID =
"test_simplemedialist";
46 var list = library.getMediaItem(
"7e8dcc95-7a1d-4bb3-9b14-d4906a9952cb");
47 assertList(list,
"data_sort_sml101_ordinal_asc.txt");
49 var item = list.getItemByIndex(0);
50 assertEqual(item.guid,
"3E586C1A-AD99-11DB-9321-C22AB7121F49");
53 item = library.getMediaItem(
"3E586C1A-AD99-11DB-9321-C22AB7121F49");
54 var contains = list.contains(item);
57 item = library.getMediaItem(
"3E6DD1C2-AD99-11DB-9321-C22AB7121F49");
58 contains = list.contains(item);
61 var titleProperty =
"http://songbirdnest.com/data/1.0#trackName";
62 var albumProperty =
"http://songbirdnest.com/data/1.0#albumName";
63 var genreProperty =
"http://songbirdnest.com/data/1.0#genre";
66 var enumerationListener =
new TestMediaListEnumerationListener();
68 list.enumerateItemsByProperty(titleProperty,
"Train of Thought",
70 Ci.sbIMediaList.ENUMERATIONTYPE_LOCKING);
72 enumerationListener.reset();
74 list.enumerateItemsByProperty(albumProperty,
"Back in Black",
76 Ci.sbIMediaList.ENUMERATIONTYPE_LOCKING);
78 enumerationListener.reset();
80 list.enumerateItemsByProperty(genreProperty,
"KJaskjjbfjJDBs",
82 Ci.sbIMediaList.ENUMERATIONTYPE_LOCKING);
84 enumerationListener.reset();
87 Cc[
"@songbirdnest.com/Songbird/Properties/MutablePropertyArray;1"].
89 propertyArray.appendProperty(albumProperty,
"Back in Black");
91 list.enumerateItemsByProperties(propertyArray, enumerationListener,
92 Ci.sbIMediaList.ENUMERATIONTYPE_LOCKING);
94 enumerationListener.reset();
96 propertyArray.appendProperty(titleProperty,
"Rock and Roll Ain't Noise Pollution");
97 propertyArray.appendProperty(titleProperty,
"Shake a Leg");
99 list.enumerateItemsByProperties(propertyArray, enumerationListener,
100 Ci.sbIMediaList.ENUMERATIONTYPE_LOCKING);
102 enumerationListener.reset();
104 propertyArray.removeElementAt(1);
106 list.enumerateItemsByProperties(propertyArray, enumerationListener,
107 Ci.sbIMediaList.ENUMERATIONTYPE_LOCKING);
109 enumerationListener.reset();
112 var mediaItem = list.getItemByIndex(8);
115 var mediaItemIndex = list.indexOf(mediaItem, 0);
118 var indexOfException;
120 mediaItemIndex = list.indexOf(mediaItem, 10);
122 indexOfException = e;
124 assertEqual(indexOfException.result,
Cr.NS_ERROR_NOT_AVAILABLE);
126 var indexOfException2;
128 mediaItemIndex = list.indexOf(mediaItem, 45);
130 indexOfException2 = e;
132 assertEqual(indexOfException2.result,
Cr.NS_ERROR_INVALID_ARG);
134 var indexOfException3;
136 mediaItemIndex = list.indexOf(mediaItem);
138 indexOfException3 = e;
139 assertEqual(indexOfException3.result,
Cr.NS_ERROR_INVALID_ARG);
142 mediaItemIndex = list.lastIndexOf(mediaItem, 0);
145 var lastIndexOfException;
147 mediaItemIndex = list.lastIndexOf(mediaItem, 10);
149 lastIndexOfException = e;
151 assertEqual(lastIndexOfException.result,
Cr.NS_ERROR_NOT_AVAILABLE);
153 var lastIndexOfException2;
155 mediaItemIndex = list.lastIndexOf(mediaItem, 45);
157 lastIndexOfException2 = e;
159 assertEqual(lastIndexOfException2.result,
Cr.NS_ERROR_INVALID_ARG);
162 var
data =
readList(
"data_sort_sml101_ordinal_asc.txt");
164 list = library.getMediaItem(
"7e8dcc95-7a1d-4bb3-9b14-d4906a9952cb");
165 item = library.getMediaItem(
"3E6DD1C2-AD99-11DB-9321-C22AB7121F49");
166 var oldlength = list.length;
169 data.push(item.guid);
175 data.push(item.guid);
181 data.push(list.guid);
188 var a =
readList(
"data_sort_created_asc.txt");
191 a.forEach(
function(e) { data.push(e); });
193 assertEqual(list.length, oldlength + 3 + view.length);
196 var simpleEnumerator =
new TestMediaListEnumerationListener();
197 view.enumerateAllItems(simpleEnumerator,
198 Ci.sbIMediaList.ENUMERATIONTYPE_LOCKING);
199 list.addSome(simpleEnumerator);
201 a.forEach(
function(e) { data.push(e); });
203 assertEqual(list.length, oldlength + 3 + view.length + view.length);
205 var asyncListener = {
208 onProgress:
function(aItemsProcessed, aComplete) {
210 this._itemsProcessed = aItemsProcessed;
211 this._complete =
true;
215 onItemAdded:
function(aMediaItem) {},
219 simpleEnumerator.reset();
220 view.enumerateAllItems(simpleEnumerator,
221 Ci.sbIMediaList.ENUMERATIONTYPE_SNAPSHOT);
225 var tempArray =
Cc[
"@songbirdnest.com/moz/xpcom/threadsafe-array;1"]
226 .createInstance(
Ci.nsIMutableArray);
227 while(simpleEnumerator.hasMoreElements()) {
228 tempArray.appendElement(simpleEnumerator.getNext(),
false);
231 var tempEnumerator = tempArray.enumerate();
232 log(
"Testing addSomeAsync");
233 list.addMediaItems(tempEnumerator, asyncListener,
true);
237 log(
"Processed " + asyncListener._itemsProcessed +
" items.");
238 a.forEach(
function(e) { data.push(e); });
240 assertEqual(list.length, oldlength + 3 + (view.length * 3));
245 list = library.getMediaItem(
"7e8dcc95-7a1d-4bb3-9b14-d4906a9952cb");
246 a =
readList(
"data_sort_sml101_ordinal_asc.txt");
249 item = library.getMediaItem(
"3E6DD1C2-AD99-11DB-9321-C22AB7121F49");
250 list.insertBefore(0, item);
251 a.unshift(item.guid);
255 item = library.getMediaItem(
"3E6D8050-AD99-11DB-9321-C22AB7121F49");
256 list.insertBefore(list.length - 1, item);
257 a.splice(a.length - 1, 0, item.guid);
261 item = library.getMediaItem(
"3E6D3050-AD99-11DB-9321-C22AB7121F49");
262 list.insertBefore(list.length - 2, item);
263 a.splice(a.length - 2, 0, item.guid);
267 item = library.getMediaItem(
"3E6CDB1E-AD99-11DB-9321-C22AB7121F49");
268 list.insertBefore(list.length - 1, item);
269 a.splice(a.length - 1, 0, item.guid);
273 item = library.getMediaItem(
"3E6C8D80-AD99-11DB-9321-C22AB7121F49");
274 list.insertBefore(list.length - 2, item);
275 a.splice(a.length - 2, 0, item.guid);
280 list.insertBefore(list.length, item);
281 fail(
"NS_ERROR_INVALID_ARG not thrown");
289 items[0] = library.getMediaItem(
"3E6DD1C2-AD99-11DB-9321-C22AB7121F49");
290 items[1] = library.getMediaItem(
"3E6D8050-AD99-11DB-9321-C22AB7121F49");
291 items[2] = library.getMediaItem(
"3E6D3050-AD99-11DB-9321-C22AB7121F49");
293 a.unshift(items[2].guid);
294 a.unshift(items[1].guid);
295 a.unshift(items[0].guid);
298 list.insertSomeBeforeAsync(0,
302 a.unshift(items[2].guid);
303 a.unshift(items[1].guid);
304 a.unshift(items[0].guid);
309 list = library.getMediaItem(
"7e8dcc95-7a1d-4bb3-9b14-d4906a9952cb");
310 a =
readList(
"data_sort_sml101_ordinal_asc.txt");
313 list.moveBefore(1, 0);
314 a.unshift(a.splice(1, 1)[0]);
318 list.moveBefore(0, list.length - 1);
319 var guid = a.splice(0, 1)[0];
320 a.splice(a.length - 1, 0, guid);
325 guid = a.splice(0, 1)[0];
330 var indexes = [5, 6, 7, 8, 9];
331 list.moveSomeBefore(indexes, indexes.length, 0);
332 var b = a.splice(5, 5);
333 a.unshift(b[0], b[1], b[2], b[3], b[4]);
337 list.moveSomeLast(indexes, indexes.length);
338 var b = a.splice(5, 5);
343 var insertItems = [];
344 insertItems[0] = library.getMediaItem(
"3E6DD1C2-AD99-11DB-9321-C22AB7121F49");
345 insertItems[1] = library.getMediaItem(
"3E6D8050-AD99-11DB-9321-C22AB7121F49");
346 insertItems[2] = library.getMediaItem(
"3E6D3050-AD99-11DB-9321-C22AB7121F49");
347 var insertList = library.createMediaList(
"simple");
349 list.insertAllBefore(0, insertList);
350 a.unshift(insertItems[2].guid);
351 a.unshift(insertItems[1].guid);
352 a.unshift(insertItems[0].guid);
356 list.insertAllBefore(0, insertList);
357 a.unshift(insertItems[2].guid);
358 a.unshift(insertItems[1].guid);
359 a.unshift(insertItems[0].guid);
365 var indexes = [0, 1, 2, 3, 4, 5];
366 list.moveSomeLast(indexes, indexes.length);
372 item = library.getMediaItem(
"3E586C1A-AD99-11DB-9321-C22AB7121F49");
374 oldlength = list.length;
379 item = list.getItemByIndex(0);
380 oldlength = list.length;
382 list.removeByIndex(0);
387 var notinlist = library.createMediaItem(
newURI(
"http://foo.com/blah"));
388 list.remove(notinlist);
392 list.removeByIndex(list.length);
393 fail(
"NS_ERROR_INVALID_ARG not thrown");
400 list.getItemByIndex(0),
401 list.getItemByIndex(1),
402 list.getItemByIndex(2),
403 list.getItemByIndex(3),
404 list.getItemByIndex(4)
406 oldlength = list.length;
407 toRemove.forEach(
function(item) {
assertEqual(list.contains(item),
true); });
409 toRemove.forEach(
function(item) {
assertEqual(list.contains(item),
false); });
410 assertEqual(list.length, oldlength - toRemove.length);
418 var item1 = library.createMediaItem(
newURI(
"file:///foo"));
419 var item2 = library.createMediaItem(
newURI(
"file:///foo"));
420 list = library.createMediaList(
"simple");
422 a = [item1.guid, item2.guid, item1.guid, item2.guid];
429 list.removeByIndex(2);
430 a = [item1.guid, item2.guid, item2.guid];
433 list.removeByIndex(2);
434 a = [item1.guid, item2.guid];
438 list = library.createMediaList(
"simple");
449 a = [item1.guid, item2.guid, item1.guid, item2.guid, item2.guid, item1.guid, item2.guid, item2.guid, item2.guid];
453 a = [item2.guid, item1.guid, item2.guid, item2.guid, item1.guid, item2.guid, item2.guid, item2.guid];
457 a = [item2.guid, item2.guid, item2.guid, item1.guid, item2.guid, item2.guid, item2.guid];
461 a = [item2.guid, item2.guid, item2.guid, item2.guid, item2.guid, item2.guid];
466 let localLibraryLength = localLibrary.length;
467 foreignLibrary =
createLibrary(
"test_simplemedialist_foreign");
470 foreignLibrary.createMediaItem(
newURI(
"file:///foo1")),
471 foreignLibrary.createMediaItem(
newURI(
"file:///foo2")),
472 localLibrary.createMediaItem(
newURI(
"file:///foo3"))
474 localLibrary.add(items[1]);
475 list = localLibrary.createMediaList(
"simple");
476 list.addSome(ArrayConverter.enumerator(items));
479 assertEqual(localLibrary.length - localLibraryLength, 4);
function assertNotEqual(aExpected, aActual, aMessage)
function assertList(list, data)
function assertEqual(aExpected, aActual, aMessage)
function SimpleArrayEnumerator(aArray)
function createLibrary(databaseGuid, databaseLocation)
function newURI(aURLString)
function readList(dataFile)