33 Components.utils.import(
"resource://app/jsmodules/ArrayConverter.jsm");
35 var databaseGUID =
"test_simplemedialistnotifications";
38 var item = library.createMediaItem(
newURI(
"http://foo.example.com/"));
39 var list = library.createMediaList(
"simple");
42 library.addListener(libraryListener,
false);
44 list.addListener(listListener,
false);
47 var prop =
"http://songbirdnest.com/data/1.0#albumName";
48 item.setProperty(prop,
"foo");
49 assertTrue(item.equals(libraryListener.updatedItem));
52 libraryListener.reset();
58 assertTrue(item.equals(listListener.added[0].item));
61 libraryListener.reset();
64 var anotheritem = library.createMediaItem(
newURI(
"http://foo.example.com/1"));
65 list.add(anotheritem);
66 assertTrue(anotheritem.equals(listListener.added[0].item));
69 libraryListener.reset();
72 var otheritem2 = library.createMediaItem(
newURI(
"http://foo.example.com/2"));
73 var otheritem3 = library.createMediaItem(
newURI(
"http://foo.example.com/3"));
74 var e = ArrayConverter.enumerator([otheritem2, otheritem3]);
76 assertTrue(otheritem2.equals(listListener.added[0].item));
78 assertTrue(otheritem3.equals(listListener.added[1].item));
81 libraryListener.reset();
84 var otheritem4 = library.createMediaItem(
newURI(
"http://foo.example.com/4"));
85 list.insertBefore(2, otheritem4);
86 assertTrue(otheritem4.equals(listListener.added[0].item));
89 libraryListener.reset();
92 var otheritem5 = library.createMediaItem(
newURI(
"http://foo.example.com/5"));
93 var otheritem6 = library.createMediaItem(
newURI(
"http://foo.example.com/6"));
94 var e = ArrayConverter.enumerator([otheritem5, otheritem6]);
95 list.insertSomeBefore(3, e);
96 assertTrue(otheritem5.equals(listListener.added[0].item));
98 assertTrue(otheritem6.equals(listListener.added[1].item));
101 libraryListener.reset();
102 listListener.reset();
104 item.setProperty(prop,
"foo");
106 assertTrue(item.equals(libraryListener.updatedItem));
107 assertTrue(item.equals(listListener.updatedItem));
111 var item1 = library.createMediaItem(
newURI(
"http://foo.example.com/"));
112 var item2 = library.createMediaItem(
newURI(
"http://foo.example.com/"));
113 var item3 = library.createMediaItem(
newURI(
"http://foo.example.com/"));
114 var item4 = library.createMediaItem(
newURI(
"http://foo.example.com/"));
120 libraryListener.reset();
121 listListener.reset();
124 list.moveBefore(2, 0);
125 assertEqual(listListener.movedItemFromIndex[0], 2);
127 assertEqual(libraryListener.movedItemFromIndex.length, 0);
128 assertEqual(libraryListener.movedItemToIndex.length, 0);
130 libraryListener.reset();
131 listListener.reset();
134 list.moveBefore(0, 3);
135 assertEqual(listListener.movedItemFromIndex[0], 0);
137 assertEqual(libraryListener.movedItemFromIndex.length, 0);
138 assertEqual(libraryListener.movedItemToIndex.length, 0);
140 libraryListener.reset();
141 listListener.reset();
145 assertEqual(listListener.movedItemFromIndex[0], 1);
147 assertEqual(libraryListener.movedItemFromIndex.length, 0);
148 assertEqual(libraryListener.movedItemToIndex.length, 0);
150 libraryListener.reset();
151 listListener.reset();
155 list.moveSomeBefore(a, a.length, 0);
156 assertEqual(listListener.movedItemFromIndex[0], 2);
158 assertEqual(listListener.movedItemFromIndex[1], 3);
160 assertEqual(libraryListener.movedItemFromIndex.length, 0);
161 assertEqual(libraryListener.movedItemToIndex.length, 0);
163 libraryListener.reset();
164 listListener.reset();
168 list.moveSomeBefore(a, a.length, 3);
169 assertEqual(listListener.movedItemFromIndex[0], 0);
171 assertEqual(listListener.movedItemFromIndex[1], 0);
173 assertEqual(libraryListener.movedItemFromIndex.length, 0);
174 assertEqual(libraryListener.movedItemToIndex.length, 0);
176 libraryListener.reset();
177 listListener.reset();
181 list.moveSomeLast(a, a.length);
182 assertEqual(listListener.movedItemFromIndex[0], 0);
184 assertEqual(listListener.movedItemFromIndex[1], 0);
188 libraryListener.reset();
189 listListener.reset();
192 library.remove(item);
193 assertTrue(item.equals(libraryListener.removedBefore[0].item));
194 assertTrue(item.equals(libraryListener.removedAfter[0].item));
199 item1 = library.createMediaItem(
newURI(
"http://foo.example.com/r1"));
200 item2 = library.createMediaItem(
newURI(
"http://foo.example.com/r2"));
201 item3 = library.createMediaItem(
newURI(
"http://foo.example.com/r3"));
202 item4 = library.createMediaItem(
newURI(
"http://foo.example.com/r4"));
203 var item5 = library.createMediaItem(
newURI(
"http://foo.example.com/r5"));
204 var item6 = library.createMediaItem(
newURI(
"http://foo.example.com/r6"));
211 libraryListener.reset();
212 listListener.reset();
216 assertEqual(libraryListener.removedBefore.length, 0);
217 assertEqual(libraryListener.removedAfter.length, 0);
218 assertTrue(item4.equals(listListener.removedBefore[0].item));
219 assertEqual(listListener.removedBefore[0].index, 3);
220 assertTrue(item4.equals(listListener.removedAfter[0].item));
221 assertEqual(listListener.removedAfter[0].index, 3);
223 libraryListener.reset();
224 listListener.reset();
228 var oldIndex = library.indexOf(item2, 0);
229 library.remove(item2);
231 assertTrue(item2.equals(libraryListener.removedBefore[0].item));
232 assertEqual(libraryListener.removedBefore[0].index, oldIndex);
233 assertTrue(item2.equals(libraryListener.removedAfter[0].item));
234 assertEqual(libraryListener.removedAfter[0].index, oldIndex);
236 assertTrue(item2.equals(listListener.removedBefore[0].item));
237 assertEqual(listListener.removedBefore[0].index, 1);
238 assertTrue(item2.equals(listListener.removedAfter[0].item));
239 assertEqual(listListener.removedAfter[0].index, 1);
241 libraryListener.reset();
242 listListener.reset();
244 var e = ArrayConverter.enumerator([item5, item6]);
247 assertTrue(item5.equals(listListener.removedBefore[0].item));
248 assertEqual(listListener.removedBefore[0].index, 2);
249 assertTrue(item5.equals(listListener.removedAfter[0].item));
250 assertEqual(listListener.removedAfter[0].index, 2);
252 assertTrue(item6.equals(listListener.removedBefore[1].item));
253 assertEqual(listListener.removedBefore[1].index, 3);
254 assertTrue(item6.equals(listListener.removedAfter[1].item));
255 assertEqual(listListener.removedAfter[1].index, 3);
257 libraryListener.reset();
258 listListener.reset();
260 list.removeByIndex(1);
261 assertTrue(item3.equals(listListener.removedBefore[0].item));
262 assertEqual(listListener.removedBefore[0].index, 1);
263 assertTrue(item3.equals(listListener.removedAfter[0].item));
264 assertEqual(listListener.removedAfter[0].index, 1);
267 item = library.createMediaItem(
newURI(
"http://foo.example.com/"));
269 libraryListener.reset();
270 listListener.reset();
276 libraryListener.reset();
277 listListener.reset();
283 item = library.createMediaItem(
newURI(
"http://foo.example.com/"));
284 list = library.createMediaList(
"simple");
285 list.addListener(listListener,
false);
287 libraryListener.reset();
288 listListener.reset();
291 library.runInBatchMode(
function() {});
293 assertTrue(library.equals(libraryListener.batchBeginList));
294 assertTrue(library.equals(libraryListener.batchEndList));
298 libraryListener.reset();
299 listListener.reset();
301 list.runInBatchMode(
function() {});
304 assertTrue(list.equals(listListener.batchBeginList));
305 assertTrue(list.equals(listListener.batchEndList));
307 list.removeListener(listListener);
308 library.removeListener(libraryListener);
311 var databaseGUID2 =
"test_simplemedialistnotifications2";
313 var list2 = library2.createMediaList(
"simple");
316 library2.addListener(libraryListener2,
false);
320 assertEqual(item.contentSrc.spec, libraryListener2.added[0].item.contentSrc.spec);
321 assertFalse(item.equals(libraryListener2.added[0].item));
322 assertTrue(libraryListener2.added[0].item.library.equals(library2));
324 library2.remove(libraryListener2.added[0].item);
325 libraryListener2.reset();
328 list2.addListener(listListener2,
false);
332 assertEqual(item.contentSrc.spec, libraryListener2.added[0].item.contentSrc.spec);
333 assertFalse(item.equals(libraryListener2.added[0].item));
334 assertEqual(item.contentSrc.spec, listListener2.added[0].item.contentSrc.spec);
335 assertFalse(item.equals(listListener2.added[0].item));
338 assertTrue(libraryListener2.added[0].list.library.equals(library2));
339 assertTrue(libraryListener2.added[0].item.library.equals(library2));
340 assertTrue(listListener2.added[0].list.library.equals(library2));
341 assertTrue(listListener2.added[0].item.library.equals(library2));
343 libraryListener2.reset();
344 listListener2.reset();
348 assertEqual(item.contentSrc.spec, listListener2.added[0].item.contentSrc.spec);
349 assertFalse(item.equals(listListener2.added[0].item));
351 libraryListener2.reset();
352 listListener2.reset();
353 list2.removeListener(listListener2);
354 library2.removeListener(libraryListener2);
357 var listToCopy = library.createMediaList(
"simple");
358 listToCopy.add(item);
363 onItemAdded:
function onItemAdded(list, item) {
364 this.adds.push({list: list, item: item});
365 if (item instanceof
Ci.sbIMediaList) {
366 var l = item.QueryInterface(
Ci.sbIMediaList);
367 l.addListener(
this,
false);
368 this.listened.push(l);
372 onBatchBegin:
function onBatchBegin(list) {
374 onBatchEnd:
function onBatchEnd(list) {
377 this.listened.forEach(
function(e) {
378 e.removeListener(
this);
384 library2.addListener(listener,
false);
386 var copiedList = library2.copyMediaList(
"simple", listToCopy,
false);
391 assertTrue(listener.adds[0].list.equals(library2));
392 assertTrue(listener.adds[0].item.equals(copiedList));
393 assertTrue(listener.adds[0].item.library.equals(library2));
396 assertTrue(listener.adds[1].list.equals(library2));
397 assertTrue(listener.adds[1].item.library.equals(library2));
400 assertTrue(listener.adds[2].list.equals(copiedList));
401 assertTrue(listener.adds[2].list.library.equals(library2));
402 assertTrue(listener.adds[2].item.equals(listener.adds[1].item));
403 assertTrue(listener.adds[2].item.library.equals(library2));
406 list2 = library2.createMediaList(
"simple");
408 list2.addListener(listListener2,
false);
409 list2.add(library2.createMediaItem(
newURI(
"http://bar.com/1.mp3")));
410 list2.add(library2.createMediaItem(
newURI(
"http://bar.com/2.mp3")));
413 listListener2.reset();
416 var foreignItem = library.createMediaItem(
newURI(
"http://foo.example.com/f.mp3"));
417 list2.insertBefore(1, foreignItem);
420 assertTrue(listener.adds[0].list.equals(library2));
421 assertTrue(listener.adds[0].list.library.equals(library2));
422 assertTrue(listener.adds[0].item.library.equals(library2));
423 assertEqual(listener.adds[0].item.contentSrc.spec, foreignItem.contentSrc.spec);
426 assertTrue(listListener2.added[0].list.equals(list2));
427 assertTrue(listListener2.added[0].list.library.equals(library2));
428 assertTrue(listListener2.added[0].item.library.equals(library2));
429 assertTrue(listListener2.added[0].item.equals(listener.adds[0].item));
432 listListener2.reset();
434 var foreignItem2 = library.createMediaItem(
newURI(
"http://foo.example.com/f2.mp3"));
435 var foreignItem3 = library.createMediaItem(
newURI(
"http://foo.example.com/f3.mp3"));
436 var e = ArrayConverter.enumerator([foreignItem2, foreignItem3]);
437 list2.insertSomeBefore(1, e);
440 assertTrue(listener.adds[0].list.equals(library2));
441 assertTrue(listener.adds[0].list.library.equals(library2));
442 assertTrue(listener.adds[0].item.library.equals(library2));
443 assertEqual(listener.adds[0].item.contentSrc.spec, foreignItem2.contentSrc.spec);
445 assertTrue(listener.adds[1].list.equals(library2));
446 assertTrue(listener.adds[1].list.library.equals(library2));
447 assertTrue(listener.adds[1].item.library.equals(library2));
448 assertEqual(listener.adds[1].item.contentSrc.spec, foreignItem3.contentSrc.spec);
451 assertTrue(listListener2.added[0].list.equals(list2));
452 assertTrue(listListener2.added[0].list.library.equals(library2));
453 assertTrue(listListener2.added[0].item.library.equals(library2));
454 assertTrue(listListener2.added[0].item.equals(listener.adds[0].item));
456 assertTrue(listListener2.added[1].list.equals(list2));
457 assertTrue(listListener2.added[1].list.library.equals(library2));
458 assertTrue(listListener2.added[1].item.library.equals(library2));
459 assertTrue(listListener2.added[1].item.equals(listener.adds[1].item));
463 library2.removeListener(listener);
464 list2.removeListener(listListener2);
function assertTrue(aTest, aMessage)
function assertEqual(aExpected, aActual, aMessage)
function createLibrary(databaseGuid, databaseLocation)
function newURI(aURLString)
function assertFalse(aTest, aMessage)
function TestMediaListListener()