33 var gEventTarget =
null;
44 this._testURIArray = [];
50 onIndexUpdated:
function (index) {
51 this._indexChange =
true;
54 onQueueOperationStarted:
function() {},
56 onQueueOperationCompleted:
function(
aCount) {
61 testAdd:
function (
num) {
62 var
uris = this._generateURIs(
num);
63 for (let
i = 0;
i < uris.length;
i++)
64 this._testURIArray.push(uris[
i]);
65 var items = this._generateItems(uris);
67 gPQS.mediaList.add(items[0]);
69 gPQS.mediaList.addSome(ArrayConverter.enumerator(items));
74 testRemove:
function (indexArray) {
77 for (let
i = indexArray.length - 1;
i > -1 ;
i--) {
78 if (indexArray[
i] < this._testIndex)
80 this._testURIArray.splice(indexArray[
i], 1);
82 var items = this._getItemsByIndexes(indexArray);
83 if (indexArray.length == 1) {
84 gPQS.mediaList.remove(items[0]);
86 gPQS.mediaList.removeSome(ArrayConverter.enumerator(items));
92 testQueueNext:
function (
num) {
93 var
uris = this._generateURIs(
num);
94 for (let
i = 0;
i < uris.length;
i++)
95 this._testURIArray.splice(
this._testIndex +
i, 0, uris[
i]);
96 var items = this._generateItems(uris);
98 gPQS.queueNext(items[0]);
100 let simpleList = gLib.createMediaList(
"simple");
101 simpleList.addSome(ArrayConverter.enumerator(items));
102 gPQS.queueNext(simpleList);
107 testQueueLast:
function (
num) {
108 var
uris = this._generateURIs(
num);
109 for (let
i = 0;
i < uris.length;
i++)
110 this._testURIArray.push(uris[
i]);
111 var items = this._generateItems(uris);
113 gPQS.queueLast(items[0]);
115 let simpleList = gLib.createMediaList(
"simple");
116 simpleList.addSome(ArrayConverter.enumerator(items));
117 gPQS.queueLast(simpleList);
122 testQueueSomeBefore:
function(
num,
pos) {
123 var
uris = this._generateURIs(
num);
124 for (let
i = 0;
i < uris.length;
i++)
125 this._testURIArray.splice(
pos +
i, 0, uris[
i]);
126 if (
pos <= this._testIndex)
127 this._testIndex +=
num;
128 var items = this._generateItems(uris);
129 gPQS.queueSomeBefore(
pos, ArrayConverter.enumerator(items));
134 testQueueSomeNext:
function(
num) {
135 var
uris = this._generateURIs(
num);
136 for (let
i = 0;
i < uris.length;
i++)
137 this._testURIArray.splice(
this._testIndex +
i, 0, uris[
i]);
138 var items = this._generateItems(uris);
139 gPQS.queueSomeNext(ArrayConverter.enumerator(items));
144 testQueueSomeLast:
function(
num) {
145 var
uris = this._generateURIs(
num);
146 for (let
i = 0;
i < uris.length;
i++)
147 this._testURIArray.push(uris[
i]);
148 var items = this._generateItems(uris);
149 gPQS.queueSomeLast(ArrayConverter.enumerator(items));
154 testClearHistory:
function () {
155 if (this._testIndex > 0)
156 this._testURIArray.splice(0, this._testIndex);
162 testClearAll:
function () {
164 this._testURIArray.length = 0;
170 testSetIndex:
function (
pos) {
172 this._testIndex = Math.min(
pos, gPQS.mediaList.length);
177 testSetSequencer:
function (
pos) {
178 return this.testSetIndex(
pos);
180 gMM.sequencer.view = gPQS.mediaList.createView();
181 while (gMM.sequencer.viewPosition <
pos)
182 gMM.sequencer.next();
183 while (gMM.sequencer.viewPosition >
pos)
184 gMM.sequencer.previous();
185 gMM.sequencer.stop();
186 this._testIndex =
pos;
191 testInsertBefore:
function (
num,
pos) {
192 var
uris = this._generateURIs(
num);
193 for (let
i = 0;
i < uris.length;
i++)
194 this._testURIArray.splice(
pos +
i, 0, uris[
i]);
195 if (
pos <= this._testIndex)
196 this._testIndex +=
num;
197 var items = this._generateItems(uris);
199 gPQS.mediaList.insertBefore(
pos, items[0]);
201 gPQS.mediaList.insertSomeBefore(
pos, ArrayConverter.enumerator(items));
206 testMoveBefore:
function (indexArray,
pos) {
209 var movingIndex = -1;
210 var newURIArray = [];
212 for (let
i = 0;
i < indexArray.length;
i++) {
213 if (indexArray[
i] == this._testIndex) {
215 this._testIndex = -1;
217 uris[
i] = this._testURIArray[indexArray[
i]];
218 this._testURIArray[indexArray[
i]] =
null;
220 for (let
i = 0;
i <
pos;
i++) {
221 if (
i == this._testIndex)
222 finalIndex = newURIArray.length;
223 if (this._testURIArray[
i])
224 newURIArray.push(this._testURIArray[i]);
226 for (let
i = 0;
i < uris.length;
i++) {
227 if (
i == movingIndex)
228 finalIndex = newURIArray.length;
229 newURIArray.push(uris[
i]);
231 for (let
i = pos;
i < this._testURIArray.length;
i++) {
232 if (
i == this._testIndex)
233 finalIndex = newURIArray.length;
234 if (this._testURIArray[
i])
235 newURIArray.push(this._testURIArray[i]);
237 this._testURIArray = newURIArray;
238 this._testIndex = finalIndex;
239 if (indexArray.length == 1) {
240 gPQS.mediaList.moveBefore(indexArray[0], pos);
242 gPQS.mediaList.moveSomeBefore(indexArray, indexArray.length, pos);
247 testMoveLast:
function (indexArray) {
250 var movingIndex = -1;
251 var newURIArray = [];
253 for (let
i = 0;
i < indexArray.length;
i++) {
254 if (indexArray[
i] == this._testIndex) {
256 this._testIndex = -1;
258 uris[
i] = this._testURIArray[indexArray[
i]];
259 this._testURIArray[indexArray[
i]] =
null;
261 for (let
i = 0;
i < this._testURIArray.length;
i++) {
262 if (
i == this._testIndex)
263 finalIndex = newURIArray.length;
264 if (this._testURIArray[
i])
265 newURIArray.push(this._testURIArray[i]);
267 for (let
i = 0;
i < uris.length;
i++) {
268 if (
i == movingIndex)
269 finalIndex = newURIArray.length;
270 newURIArray.push(uris[
i]);
272 this._testURIArray = newURIArray;
273 this._testIndex = finalIndex;
274 if (indexArray.length == 1) {
275 gPQS.mediaList.moveLast(indexArray[0]);
277 gPQS.mediaList.moveSomeLast(indexArray, indexArray.length);
282 _generateItems:
function (
uris) {
284 for (var
i = 0;
i <
uris.length;
i++)
285 items[
i] = gLib.createMediaItem(
uris[
i]);
289 _generateURIs:
function (
num) {
291 for (var
i = 0;
i <
num;
i++)
292 uris[
i] =
newURI(
"http://test.com/test" + this._nextUri++);
296 _getItemsByIndexes:
function (indexArray) {
297 var items =
new Array(indexArray.length)
298 for (let
i = 0;
i < indexArray.length;
i++)
299 items[
i] = gPQS.mediaList.getItemByIndex(indexArray[
i]);
303 _verifyList:
function () {
304 assertEqual(gPQS.mediaList.length,
this._testURIArray.length);
306 if (this._testIndex != this._prevTestIndex) {
308 this._indexChange =
false;
309 this._prevTestIndex = this._testIndex;
311 for (var
i = 0;
i < this._testURIArray.length;
i++) {
313 gPQS.mediaList.getItemByIndex(
i)[
"contentSrc"]) );
319 Components.utils.import(
"resource://app/jsmodules/ArrayConverter.jsm");
324 .getService(
Ci.sbILibraryManager);
325 libraryManager.registerLibrary(gLib,
false);
328 gPQS =
Cc[
"@songbirdnest.com/Songbird/playqueue/service;1"]
329 .getService(
Ci.sbIPlayQueueService);
332 if (!gPQS.mediaList.isEmpty) {
333 var backupList = gLib.copyMediaList(
"simple",
336 var backupIndex = gPQS.index;
339 gPQS.addListener(testFixture);
341 gMM =
Cc[
"@songbirdnest.com/Songbird/Mediacore/Manager;1"]
342 .getService(
Ci.sbIMediacoreManager);
346 testFixture.testAdd(1);
347 testFixture.testQueueNext(1);
348 testFixture.testSetSequencer(1);
350 testFixture.testQueueLast(1);
351 testFixture.testClearHistory();
352 testFixture.testSetIndex(gPQS.index + 1);
353 testFixture.testRemove([1]);
354 testFixture.testSetIndex(gPQS.index + 1);
355 testFixture.testQueueNext(1);
356 testFixture.testClearAll();
360 testFixture.testAdd(5);
361 testFixture.testSetIndex(2);
362 testFixture.testRemove([0,1,2]);
365 testFixture.testAdd(5);
366 testFixture.testSetIndex(2);
367 testFixture.testRemove([0,2,3]);
370 testFixture.testAdd(5);
371 testFixture.testSetIndex(2);
372 testFixture.testRemove([1,2,3]);
375 testFixture.testAdd(5);
376 testFixture.testSetIndex(2);
377 testFixture.testRemove([2,3,4]);
381 testFixture.testAdd(5);
382 testFixture.testSetIndex(4);
383 testFixture.testQueueNext(5);
386 testFixture.testAdd(5);
387 testFixture.testSetIndex(4);
388 testFixture.testQueueLast(5);
392 testFixture.testAdd(5);
393 testFixture.testSetIndex(3);
394 testFixture.testQueueSomeBefore(5, 2);
397 testFixture.testAdd(5);
398 testFixture.testSetIndex(3);
399 testFixture.testQueueSomeBefore(5, 3);
402 testFixture.testAdd(5);
403 testFixture.testSetIndex(3);
404 testFixture.testQueueSomeBefore(5, 4);
408 testFixture.testQueueSomeNext(3);
409 testFixture.testSetIndex(2);
410 testFixture.testQueueSomeNext(1);
411 testFixture.testQueueSomeLast(3);
412 testFixture.testSetIndex(7);
413 testFixture.testQueueSomeLast(1);
416 assertTrue(gPQS.mediaList instanceof
Ci.sbIOrderableMediaList);
419 testFixture.testAdd(5);
420 testFixture.testSetIndex(3);
421 testFixture.testInsertBefore(5, 2);
424 testFixture.testAdd(5);
425 testFixture.testSetIndex(3);
426 testFixture.testInsertBefore(5, 3);
429 testFixture.testAdd(5);
430 testFixture.testSetIndex(3);
431 testFixture.testInsertBefore(5, 4);
434 testFixture.testAdd(5);
435 testFixture.testSetIndex(2);
436 testFixture.testMoveBefore([0,1,2], 2);
439 testFixture.testAdd(5);
440 testFixture.testSetIndex(2);
441 testFixture.testMoveBefore([0,1,3], 2);
444 testFixture.testAdd(5);
445 testFixture.testSetIndex(2);
446 testFixture.testMoveBefore([2,3,4], 0);
449 testFixture.testAdd(5);
450 testFixture.testSetIndex(2);
451 testFixture.testMoveLast([0,1]);
454 testFixture.testAdd(5);
455 testFixture.testSetIndex(2);
456 testFixture.testMoveLast([0,1,2,3]);
459 testFixture.testAdd(5);
460 testFixture.testSetIndex(2);
461 testFixture.testMoveLast([2,3,4]);
467 gPQS.removeListener(testFixture);
471 gPQS.mediaList.addAll(backupList);
472 gPQS.index = backupIndex;
474 libraryManager.unregisterLibrary(gLib);
function assertNotEqual(aExpected, aActual, aMessage)
function assertTrue(aTest, aMessage)
function assertEqual(aExpected, aActual, aMessage)
function runTest()
Test file.
function createLibrary(databaseGuid, databaseLocation)
function newURI(aURLString)
restoreHistoryPrecursor aCount
_getSelectedPageStyle s i