33 Components.utils.import(
"resource://app/jsmodules/ArrayConverter.jsm");
34 Components.utils.import(
"resource://app/jsmodules/sbProperties.jsm");
36 var databaseGUID =
"test_librarynotifications";
40 var databaseGUID2 =
"test_simplemedialistnotifications2";
45 library.addListener(libraryListener,
false);
48 var item1 = library.createMediaItem(
newURI(
"http://foo.com/1"));
49 assertTrue(libraryListener.added[0].list.equals(library));
50 assertTrue(libraryListener.added[0].item.equals(item1));
51 assertEqual(libraryListener.added[0].index, library.length - 1);
53 libraryListener.reset();
55 var item2 = library.createMediaItem(
newURI(
"http://foo.com/2"));
56 assertTrue(libraryListener.added[0].list.equals(library));
57 assertTrue(libraryListener.added[0].item.equals(item2));
58 assertEqual(libraryListener.added[0].index, library.length - 1);
60 libraryListener.reset();
62 var list1 = library.createMediaList(
"simple");
63 assertTrue(libraryListener.added[0].list.equals(library));
64 assertTrue(libraryListener.added[0].item.equals(list1));
65 assertEqual(libraryListener.added[0].index, library.length - 1);
67 libraryListener.reset();
69 var otheritem1 = library2.createMediaItem(
newURI(
"http://foo.com/1"));
70 library.add(otheritem1);
71 assertTrue(libraryListener.added[0].list.equals(library));
72 assertEqual(libraryListener.added[0].index, library.length - 1);
74 libraryListener.reset();
76 var otheritem2 = library2.createMediaItem(
newURI(
"http://foo.com/2"));
77 var otheritem3 = library2.createMediaItem(
newURI(
"http://foo.com/3"));
78 var e = ArrayConverter.enumerator([otheritem2, otheritem3]);
80 assertTrue(libraryListener.added[0].list.equals(library));
81 assertEqual(libraryListener.added[0].index, library.length - 2);
82 assertTrue(libraryListener.added[1].list.equals(library));
83 assertEqual(libraryListener.added[1].index, library.length - 1);
85 libraryListener.reset();
87 var items = library.batchCreateMediaItems(
88 ArrayConverter.nsIArray([
89 newURI(
"http://foo.com/4"),
92 assertTrue(libraryListener.added[0].list.equals(library));
93 assertTrue(libraryListener.added[0].item.equals(
94 items.queryElementAt(0,
Ci.sbIMediaItem)));
95 assertEqual(libraryListener.added[0].index, library.length - 2);
96 assertTrue(libraryListener.added[1].list.equals(library));
97 assertTrue(libraryListener.added[1].item.equals(
98 items.queryElementAt(1,
Ci.sbIMediaItem)));
99 assertEqual(libraryListener.added[1].index, library.length - 1);
101 libraryListener.reset();
104 library.remove(item2);
105 assertTrue(libraryListener.removedBefore[0].list.equals(library));
106 assertTrue(libraryListener.removedBefore[0].item.equals(item2));
107 assertEqual(libraryListener.removedBefore[0].index, 1);
108 assertTrue(libraryListener.removedAfter[0].list.equals(library));
109 assertTrue(libraryListener.removedAfter[0].item.equals(item2));
110 assertEqual(libraryListener.removedAfter[0].index, 1);
112 libraryListener.reset();
114 var item6 = library.createMediaItem(
newURI(
"http://foo.com/6"));
115 var item7 = library.createMediaItem(
newURI(
"http://foo.com/7"));
116 var item8 = library.createMediaItem(
newURI(
"http://foo.com/8"));
117 e = ArrayConverter.enumerator([item6, item7, item8]);
118 library.removeSome(e);
119 assertTrue(libraryListener.removedBefore[0].list.equals(library));
120 assertTrue(libraryListener.removedBefore[0].item.equals(item6));
121 assertEqual(libraryListener.removedBefore[0].index, 7);
122 assertTrue(libraryListener.removedAfter[0].list.equals(library));
123 assertTrue(libraryListener.removedAfter[0].item.equals(item6));
124 assertEqual(libraryListener.removedAfter[0].index, 7);
125 assertTrue(libraryListener.removedBefore[1].list.equals(library));
126 assertTrue(libraryListener.removedBefore[1].item.equals(item7));
127 assertEqual(libraryListener.removedBefore[1].index, 7);
128 assertTrue(libraryListener.removedAfter[1].list.equals(library));
129 assertTrue(libraryListener.removedAfter[1].item.equals(item7));
130 assertEqual(libraryListener.removedAfter[1].index, 7);
131 assertTrue(libraryListener.removedBefore[2].list.equals(library));
132 assertTrue(libraryListener.removedBefore[2].item.equals(item8));
133 assertEqual(libraryListener.removedBefore[2].index, 7);
134 assertTrue(libraryListener.removedAfter[2].list.equals(library));
135 assertTrue(libraryListener.removedAfter[2].item.equals(item8));
136 assertEqual(libraryListener.removedAfter[2].index, 7);
138 library.removeListener(libraryListener);
function assertTrue(aTest, aMessage)
function assertEqual(aExpected, aActual, aMessage)
function runTest()
Test file.
function createLibrary(databaseGuid, databaseLocation)
function newURI(aURLString)
function TestMediaListListener()