33 var
SB_NS =
"http://songbirdnest.com/data/1.0#";
34 var
ios =
Cc[
"@mozilla.org/network/io-service;1"].getService(
Ci.nsIIOService);
36 var databaseGUID =
"test_library";
40 var uriSpec =
"file:///foo";
43 var item1 = library.createMediaItem(uri);
45 assertEqual(item1.getProperty(SB_NS +
"contentURL"), uriSpec);
47 var created =
new Date(parseInt(item1.getProperty(SB_NS +
"created")));
48 var updated =
new Date(parseInt(item1.getProperty(SB_NS +
"updated")));
50 assertEqual(created.getTime() == updated.getTime(),
true);
56 var item2 = library.createMediaItem(uri,
null,
true);
60 assertEqual(library.getItemByGuid(item1.guid).guid, item1.guid);
61 assertEqual(library.getItemByGuid(item2.guid).guid, item2.guid);
64 library.addListener(listListener,
false);
66 var uri2 = ios.newURI(
"file:///bar",
null,
null);
67 var item3 = library.createMediaItem(uri2,
null,
true);
69 assertTrue(item3.equals(listListener.added[0].item));
71 library.remove(item1);
72 assertTrue(item1.equals(listListener.removedBefore[0].item));
73 assertTrue(item1.equals(listListener.removedAfter[0].item));
77 var hasItem4 = library.createMediaItemIfNotExist(uri2,
null, item4);
80 var uri3 = ios.newURI(
"file:///quux",
null,
null);
81 hasItem4 = library.createMediaItemIfNotExist(uri3,
null, item4);
84 library.remove(item4.value);
88 var enumerationListener =
new TestMediaListEnumerationListener();
90 var list = library.getMediaItem(
"7e8dcc95-7a1d-4bb3-9b14-d4906a9952cb");
93 list.enumerateAllItems(enumerationListener,
94 Ci.sbIMediaList.ENUMERATIONTYPE_SNAPSHOT);
96 var listCount = enumerationListener.count;
100 var removedItemCount = 0;
101 listListener.onAfterItemRemoved =
function onAfterItemRemoved(list, item) {
105 library.removeSome(enumerationListener.QueryInterface(
Ci.nsISimpleEnumerator));
111 library.removeListener(listListener);
115 list = library.getMediaItem(
"7e8dcc95-7a1d-4bb3-9b14-d4906a9952cb");
124 list = library.getMediaItem(
"7e8dcc95-7a1d-4bb3-9b14-d4906a9952cb");
125 var item = list.getItemByIndex(8);
128 list.addListener(listListener,
false);
131 library.addListener(libraryListener,
false);
133 item.contentType =
"foo/foo";
138 list.removeListener(listListener);
139 library.removeListener(libraryListener);
144 list = library.getMediaItem(
"7e8dcc95-7a1d-4bb3-9b14-d4906a9952cb");
147 list.addListener(listListener,
false);
149 item = library.getItemByGuid(
"3E63F4C2-AD99-11DB-9321-C22AB7121F49");
152 library.addListener(libraryListener,
false);
154 item.contentType =
"foo/foo";
159 list.removeListener(listListener);
160 library.removeListener(libraryListener);
164 props.appendProperty(SB_NS +
"artistName",
"a-ha");
165 props.appendProperty(SB_NS +
"albumName",
"Back in Black");
166 props.appendProperty(SB_NS +
"contentLength",
"123");
167 props.appendProperty(SB_NS +
"contentURL",
"http://www.foo.com/foo.mp3");
168 var item4 = library.createMediaItem(uri, props);
171 assertEqual(item4.getProperty(SB_NS +
"contentURL"), uriSpec);
172 assertEqual(item4.getProperty(SB_NS +
"artistName"),
"a-ha");
173 assertEqual(item4.getProperty(SB_NS +
"albumName"),
"Back in Black");
174 assertEqual(item4.getProperty(SB_NS +
"contentLength"),
"123");
177 var newItem = library.createMediaItem(uri,
null,
true);
178 var guid = newItem.guid;
180 library.remove(newItem);
184 var item = library.getItemByGuid(guid);
187 exceptionResult = e.result;
192 library.remove(newItem);
194 var databaseGUID =
"test_library_clearItems";
197 var list = library.createMediaList(
"simple");
198 var itemFoo = library.createMediaItem(uri,
null,
true);
199 var itemBar = library.createMediaItem(uri2,
null,
true);
201 var itemFooGUID = itemFoo.guid;
206 library.clearItems();
210 let deadItemFoo = library.getMediaItem(itemFooGUID);
211 throw "ERROR! Dead Item in mMediaItemInfoTable!";
216 if(e.result !=
Cr.NS_ERROR_NOT_AVAILABLE) {
221 var itemFoo2 = library.createMediaItem(uri,
null,
true);
222 var itemBar2 = library.createMediaItem(uri2,
null,
true);
224 itemFoo2.setProperty(SB_NS +
"contentType",
"video");
225 itemBar2.setProperty(SB_NS +
"contentType",
"audio");
230 library.clearItemsByType(
"audio");
235 return Cc[
"@songbirdnest.com/Songbird/Properties/MutablePropertyArray;1"]
236 .createInstance(
Ci.sbIMutablePropertyArray);
function assertNotEqual(aExpected, aActual, aMessage)
function assertTrue(aTest, aMessage)
function assertEqual(aExpected, aActual, aMessage)
function createLibrary(databaseGuid, databaseLocation)
function assertFalse(aTest, aMessage)
function runTest()
Test file.
function TestMediaListListener()
function createPropertyArray()