31 Components.utils.import(
"resource://app/jsmodules/sbProperties.jsm");
33 var
ios =
Cc[
"@mozilla.org/network/io-service;1"].getService(
Ci.nsIIOService);
35 var databaseGUID =
"test_batchcreateifnotexist";
38 var toAdd =
Cc[
"@songbirdnest.com/moz/xpcom/threadsafe-array;1"]
39 .createInstance(
Ci.nsIMutableArray);
40 var propertyArray =
Cc[
"@songbirdnest.com/moz/xpcom/threadsafe-array;1"]
41 .createInstance(
Ci.nsIMutableArray);
42 for (var
i = 1;
i < 101;
i++) {
43 toAdd.appendElement(
newURI(
"file:///foo/" +
i +
".mp3"),
false);
45 Cc[
"@songbirdnest.com/Songbird/Properties/MutablePropertyArray;1"]
46 .createInstance(
Ci.sbIMutablePropertyArray);
47 props.appendProperty(SBProperties.contentLength,
i);
48 props.appendProperty(SBProperties.trackNumber,
i);
49 propertyArray.appendElement(props,
false);
53 library.addListener(libraryListener);
55 var resultItemArray = {};
56 var itemsCreated = library.batchCreateMediaItemsIfNotExist(toAdd,
59 resultItemArray = resultItemArray.value;
62 var e = itemsCreated.enumerate();
63 while(e.hasMoreElements()) {
64 var itemCreated = e.getNext().QueryInterface(
Ci.nsIVariant);
68 e = resultItemArray.enumerate();
69 while(e.hasMoreElements()) {
70 var item = e.getNext();
74 onEnumerationBegin:
function() {
76 onEnumeratedItem:
function(list, item) {
78 return Ci.sbIMediaListEnumerationListener.CANCEL;
80 onEnumerationEnd:
function() {
84 library.enumerateItemsByProperty(SBProperties.contentURL,
87 Ci.sbIMediaList.ENUMERATIONTYPE_SNAPSHOT);
91 assertEqual(listener._item.getProperty(SBProperties.contentLength),
92 item.getProperty(SBProperties.contentLength));
93 assertEqual(listener._item.getProperty(SBProperties.trackNumber),
94 item.getProperty(SBProperties.trackNumber));
99 for (var
i = 1;
i < 101;
i++) {
100 assertEqual(libraryListener.added[
i - 1].item.contentSrc.spec,
101 "file:///foo/" +
i +
".mp3");
103 libraryListener.reset();
106 toAdd =
Cc[
"@songbirdnest.com/moz/xpcom/threadsafe-array;1"]
107 .createInstance(
Ci.nsIMutableArray);
108 propertyArray =
Cc[
"@songbirdnest.com/moz/xpcom/threadsafe-array;1"]
109 .createInstance(
Ci.nsIMutableArray);
110 for (var
i = 1;
i < 101;
i++) {
111 toAdd.appendElement(
newURI(
"file:///foo/duplicate.mp3"),
false);
113 Cc[
"@songbirdnest.com/Songbird/Properties/MutablePropertyArray;1"]
114 .createInstance(
Ci.sbIMutablePropertyArray);
115 props.appendProperty(SBProperties.contentLength,
i);
116 props.appendProperty(SBProperties.trackNumber,
i);
117 propertyArray.appendElement(props,
false);
120 resultItemArray = {};
121 itemsCreated = library.batchCreateMediaItemsIfNotExist(toAdd,
124 resultItemArray = resultItemArray.value;
127 var firstItem =
true;
128 e = itemsCreated.enumerate();
129 while(e.hasMoreElements()) {
130 var itemCreated = e.getNext().QueryInterface(
Ci.nsIVariant);
140 e = resultItemArray.enumerate();
141 while(e.hasMoreElements()) {
142 var item = e.getNext();
143 assertEqual(item.contentSrc.spec,
"file:///foo/duplicate.mp3");
148 assertEqual(libraryListener.added[0].item.contentSrc.spec,
149 "file:///foo/duplicate.mp3");
151 library.removeListener(libraryListener);
function assertTrue(aTest, aMessage)
function assertEqual(aExpected, aActual, aMessage)
function createLibrary(databaseGuid, databaseLocation)
function newURI(aURLString)
function assertFalse(aTest, aMessage)
_getSelectedPageStyle s i
function TestMediaListListener()
function runTest()
Test file.