29 var
SB_NS =
"http://songbirdnest.com/data/1.0#";
37 return this._current < this._array.length;
41 return this._array[this._current++];
45 if (!iid.equals(Components.interfaces.nsIStringEnumerator) &&
46 !iid.equals(Components.interfaces.nsISupports))
47 throw Components.results.NS_ERROR_NO_INTERFACE;
57 return this._current < this._array.length;
61 return this._array[this._current++];
65 if (!iid.equals(Components.interfaces.nsISimpleEnumerator) &&
66 !iid.equals(Components.interfaces.nsISupports))
67 throw Components.results.NS_ERROR_NO_INTERFACE;
72 var ldl = library.QueryInterface(
Ci.sbILocalDatabaseLibrary);
73 var
array =
Cc[
"@songbirdnest.com/Songbird/Library/LocalDatabase/GUIDArray;1"]
74 .createInstance(
Ci.sbILocalDatabaseGUIDArray);
75 array.databaseGUID = ldl.databaseGuid;
76 array.propertyCache = ldl.propertyCache;
83 var a = data.split(
"\n");
85 if(a.length - 1 !=
array.length) {
86 fail(
"sort failed, length wrong, got " +
array.length +
" expected " + (a.length - 1));
89 for(var
i = 0;
i < a.length - 1;
i++) {
90 var b = a[
i].split(
"\t");
91 if(
array.getGuidByIndex(
i) != b[0]) {
92 fail(
"sort failed, index " +
i +
" got " +
array.getGuidByIndex(
i) +
" expected " + b[0]);
101 var a = data.split(
"\n");
103 if(a.length - 1 !=
array.length) {
104 fail(
"length wrong, got " +
array.length +
" expected " + (a.length - 1));
107 for(var
i = 0;
i < a.length - 1;
i++) {
108 var dataValue = a[
i].split(
"\t")[0];
109 if(
array[
i] != dataValue) {
110 fail(
"sort failed, index " +
i +
" got " +
array[
i] +
" expected " + dataValue);
125 if(a.length != list.length) {
126 fail(
"compare failed, length wrong, got " + list.length +
" expected " + a.length);
129 var
listener =
new TestMediaListEnumerationListener();
131 listener.enumItemFunction =
function onItem(list, item) {
132 if (item.guid != a[
this.count]) {
133 fail(
"compare failed, index " + this.
count +
" got " + item.guid +
134 " expected " + a[
this.count]);
140 list.enumerateAllItems(listener,
Ci.sbIMediaList.ENUMERATIONTYPE_LOCKING);
150 _updatedProperties:
null,
151 _movedItemFromIndex: [],
152 _movedItemToIndex: [],
153 _batchBeginList:
null,
159 log(
"_added.length=" + this._added.length);
163 get removedBefore() {
164 return this._removedBefore;
168 return this._removedAfter;
172 return this._updatedItem;
175 get updatedProperties() {
176 return this._updatedProperties;
179 get movedItemFromIndex() {
180 return this._movedItemFromIndex;
183 get movedItemToIndex() {
184 return this._movedItemToIndex;
187 get batchBeginList() {
188 return this._batchBeginList;
192 return this._batchEndList;
196 return this._listCleared;
200 this._retval =
value;
202 reset:
function reset() {
204 this._removedBefore = [];
205 this._removedAfter = [];
206 this._updatedItem =
null;
207 this._updatedProperties =
null;
208 this._movedItemFromIndex = [];
209 this._movedItemToIndex = [];
210 this._batchBeginList =
null;
211 this._batchEndList =
null;
212 this._listCleared =
false;
213 this._retval =
false;
216 onItemAdded:
function onItemAdded(list, item, index) {
217 this._added.push({list: list, item: item, index: index});
221 onBeforeItemRemoved:
function onBeforeItemRemoved(list, item, index) {
222 this._removedBefore.push({list: list, item: item, index: index});
226 onAfterItemRemoved:
function onAfterItemRemoved(list, item, index) {
227 this._removedAfter.push({list: list, item: item, index: index});
231 onItemUpdated:
function onItemUpdated(list, item, properties) {
232 this._updatedItem = item;
233 this._updatedProperties = properties;
237 onItemMoved:
function onItemMoved(list, fromIndex, toIndex) {
238 this._movedItemFromIndex.push(fromIndex);
239 this._movedItemToIndex.push(toIndex);
243 onBatchBegin:
function onBatchBegin(list) {
244 this._batchBeginList = list;
247 onBatchEnd:
function onBatchEnd(list) {
248 this._batchEndList = list;
251 onBeforeListCleared:
function onBeforeListCleared() {
254 onListCleared:
function onListCleared() {
255 this._listCleared =
true;
259 if (!iid.equals(
Ci.sbIMediaListListener) &&
260 !iid.equals(
Ci.nsISupports))
261 throw Cr.NS_ERROR_NO_INTERFACE;
266 function TestMediaListEnumerationListener() {
269 TestMediaListEnumerationListener.prototype = {
271 _enumBeginFunction:
null,
272 _enumItemFunction:
null,
273 _enumEndFunction:
null,
274 _enumerationComplete:
false,
278 onEnumerationBegin:
function onEnumerationBegin(list) {
279 if (this._enumBeginFunction) {
280 return this._enumBeginFunction(list);
283 return Ci.sbIMediaListEnumerationListener.CONTINUE;
286 onEnumeratedItem:
function onEnumeratedItem(list, item) {
287 var retval =
Ci.sbIMediaListEnumerationListener.CONTINUE;
288 if (this._enumItemFunction)
289 retval = this._enumItemFunction(list, item);
291 if (retval ==
Ci.sbIMediaListEnumerationListener.CONTINUE) {
292 this._items.push(item);
298 onEnumerationEnd:
function onEnumerationEnd(list, result) {
299 if (this._enumEndFunction)
300 this._enumEndFunction(list, result);
301 this._result = result;
302 this._enumerationComplete =
true;
305 reset:
function reset() {
306 this._result =
Cr.NS_OK;
307 this._enumeratedItemCount = 0;
308 this._enumBeginFunction =
null;
309 this._enumItemFunction =
null;
310 this._enumEndFunction =
null;
313 this._enumerationComplete =
false;
317 if (!this._enumerationComplete)
318 throw Cr.NS_ERROR_NOT_AVAILABLE;
320 return this._index < this._items.length;
323 getNext:
function getNext() {
324 if (!this._enumerationComplete)
325 throw Cr.NS_ERROR_NOT_AVAILABLE;
327 return this._items[this._index++];
330 set enumBeginFunction(
val) {
331 this._enumBeginFunction =
val;
334 set enumItemFunction(
val) {
335 this._enumItemFunction =
val;
338 set enumEndFunction(
val) {
339 this._enumEndFunction =
val;
347 return this._items.length;
351 if (!iid.equals(
Ci.sbIMediaListEnumerationListener) &&
352 !iid.equals(
Ci.nsISimpleEnumerator) &&
353 !iid.equals(
Ci.nsISupports))
354 throw Cr.NS_ERROR_NO_INTERFACE;
359 function TestMediaListViewListener() {
361 TestMediaListViewListener.prototype = {
362 _filterChanged:
false,
363 _searchChanged:
false,
366 get filterChanged() {
367 return this._filterChanged;
370 get searchChanged() {
371 return this._searchChanged;
375 return this._sortChanged;
378 reset:
function TMLVL_reset() {
379 this._filterChanged =
false;
380 this._searchChanged =
false;
381 this._sortChanged =
false;
384 onFilterChanged:
function TMLVL_onFilterChanged(view) {
385 this._filterChanged =
true;
388 onSearchChanged:
function TMLVL_onSearchChanged(view) {
389 this._searchChanged =
true;
392 onSortChanged:
function TMLVL_onSortChanged(view) {
393 this._sortChanged =
true;
397 if (!iid.equals(Components.interfaces.sbIMediaListViewListener) &&
398 !iid.equals(Components.interfaces.nsISupportsWeakReference))
399 throw Components.results.NS_ERROR_NO_INTERFACE;
404 function readList(dataFile, index) {
407 var a = data.split(
"\n");
411 for(var
i = 0;
i < a.length - 1;
i++) {
412 b.push(a[
i].split(
"\t")[index]);
418 function loadMockDatabase() {
419 var data =
readFile(
"media_items.txt");
420 var a = data.split(
"\n");
423 "http://songbirdnest.com/data/1.0#GUID",
424 "http://songbirdnest.com/data/1.0#created",
425 "http://songbirdnest.com/data/1.0#updated",
426 "http://songbirdnest.com/data/1.0#contentURL",
427 "http://songbirdnest.com/data/1.0#contentType",
428 "http://songbirdnest.com/data/1.0#contentLength",
429 "http://songbirdnest.com/data/1.0#hidden",
430 "http://songbirdnest.com/data/1.0#isList"
435 for(var
i = 0;
i < a.length - 1;
i++) {
436 var b = a[
i].split(
"\t");
443 for(var j = 0; j < sp.length; j++) {
444 if (sp[j] ==
"http://songbirdnest.com/data/1.0#isList") {
445 if (!b[j + 1] || b[j + 1] ==
"0") {
450 item[
"http://songbirdnest.com/data/1.0#listType"] =
"1";
454 item[sp[j]] = b[j + 1];
460 "http://songbirdnest.com/data/1.0#trackName",
461 "http://songbirdnest.com/data/1.0#albumName",
462 "http://songbirdnest.com/data/1.0#artistName",
463 "http://songbirdnest.com/data/1.0#duration",
464 "http://songbirdnest.com/data/1.0#genre",
465 "http://songbirdnest.com/data/1.0#trackNumber",
466 "http://songbirdnest.com/data/1.0#year",
467 "http://songbirdnest.com/data/1.0#discNumber",
468 "http://songbirdnest.com/data/1.0#totalDiscs",
469 "http://songbirdnest.com/data/1.0#totalTracks",
470 "http://songbirdnest.com/data/1.0#lastPlayTime",
471 "http://songbirdnest.com/data/1.0#playCount",
472 "http://songbirdnest.com/data/1.0#customType",
473 "http://songbirdnest.com/data/1.0#isSortable"
476 data =
readFile(
"resource_properties.txt");
477 a = data.split(
"\n");
478 for(var
i = 0;
i < a.length - 1;
i++) {
479 var b = a[
i].split(
"\t");
481 item[props[parseInt(b[1]) - 1]] = b[2];
488 var
file =
Cc[
"@mozilla.org/file/directory_service;1"]
489 .getService(
Ci.nsIProperties)
490 .get(
"resource:app",
Ci.nsIFile);
492 file.append(
"testharness");
493 file.append(
"localdatabaselibrary");
494 file.append(fileName);
498 function execQuery(databaseGuid, sql) {
500 var dbq =
Cc[
"@songbirdnest.com/Songbird/DatabaseQuery;1"]
501 .createInstance(
Ci.sbIDatabaseQuery);
503 dbq.setDatabaseGUID(databaseGuid);
504 dbq.setAsyncQuery(
false);
508 var result = dbq.getResultObject();
509 var rows = result.getRowCount();
510 var cols = result.getColumnCount();
513 for (var
i = 0;
i < rows;
i++) {
515 for (var j = 0; j < cols; j++) {
516 r.push(result.getRowCell(
i, j));
function assertList(list, data)
sbOSDControlService prototype QueryInterface
function getFile(fileName)
this _dialogInput val(dateText)
function assertArray(array, dataFile)
function SimpleArrayEnumerator(aArray)
SimpleArrayEnumerator prototype hasMoreElements
function readList(dataFile)
function StringArrayEnumerator(aArray)
function readFile(fileName)
var SB_NS
Some globally useful stuff for the local database library tests.
_getSelectedPageStyle s i
function TestMediaListListener()
function assertSort(array, dataFile)
function makeArray(library)