27 Components.utils.import(
"resource://gre/modules/XPCOMUtils.jsm");
28 Components.utils.import(
"resource://app/jsmodules/sbLibraryUtils.jsm");
37 controller.startTest();
57 _shutdownService :
null,
64 _smartPlaylist :
null,
68 this.
_log(
"Starting mediaexport service test!");
82 var
ioService =
Cc[
"@mozilla.org/network/io-service;1"]
83 .getService(
Ci.nsIIOService);
84 var fileProtocolHandler = ioService.getProtocolHandler(
"file")
85 .QueryInterface(
Ci.nsIFileProtocolHandler);
86 for (var
i = 0;
i < this._tracks.length;
i++) {
87 var curTrackURL = this._tracks[
i];
89 fileProtocolHandler.getFileFromURLSpec(curTrackURL).path;
92 for (var
i = 0;
i < this._tracks2.length;
i++) {
93 var curTrackURL = this._tracks2[
i];
94 this._track2Paths[
i] =
95 fileProtocolHandler.getFileFromURLSpec(curTrackURL).path;
100 this._mainLibrary.clear();
106 this._shutdownService =
Cc[
"@songbirdnest.com/media-export-service;1"]
107 .getService(
Ci.sbIShutdownJob);
108 this._shutdownService.addJobProgressListener(
this);
111 this._runCurrentPhase();
116 _runCurrentPhase:
function() {
117 this.
_log(
"-> Phase " + this._phase +
" BEGIN");
120 switch (this._phase) {
131 switch (this._phase) {
133 this._addTracks(this._mainLibrary);
139 this._addSmartPlaylist();
140 this._addTracks(this._playlist);
141 this._addTracks2(this._mainLibrary);
146 this._removePlaylist();
147 this._removeSmartPlaylist();
151 this._invokeExportService();
155 _validateExportData:
function() {
156 this.
_log(
"-> Phase " + this._phase +
" VALIDATING...");
158 var shouldContinue =
true;
163 this._logTaskData(parsedTask);
165 switch (this._phase) {
168 assertEqual(parsedTask.getAddedMediaLists().length, 0);
171 assertEqual(parsedTask.getRemovedMediaLists().length, 0);
174 var addedLibraryItems = parsedTask.getAddedMediaItems()[
"#####SONGBIRD_MAIN_LIBRRAY#####"];
179 assertEqual(addedLibraryItems[0], this._trackPaths[0]);
180 assertEqual(addedLibraryItems[1], this._trackPaths[1]);
181 assertEqual(addedLibraryItems[2], this._trackPaths[2]);
187 var addedMediaLists = parsedTask.getAddedMediaLists();
189 assertEqual(addedMediaLists[0], this._playlist.name);
190 assertEqual(addedMediaLists[1], this._smartPlaylist.name);
193 var removedLists = parsedTask.getRemovedMediaLists();
197 var addedMediaItems =
198 parsedTask.getAddedMediaItems()[this._playlist.name];
201 assertEqual(addedMediaItems[0], this._trackPaths[0]);
202 assertEqual(addedMediaItems[1], this._trackPaths[1]);
203 assertEqual(addedMediaItems[2], this._trackPaths[2]);
207 parsedTask.getAddedMediaItems()[
"#####SONGBIRD_MAIN_LIBRRAY#####"];
210 assertEqual(addedMediaItems[0], this._track2Paths[0]);
211 assertEqual(addedMediaItems[1], this._track2Paths[1]);
212 assertEqual(addedMediaItems[2], this._track2Paths[2]);
217 assertEqual(parsedTask.getAddedMediaLists().length, 0);
220 var removedMediaLists = parsedTask.getRemovedMediaLists();
223 assertEqual(removedMediaLists[0], this._playlist.name);
224 assertEqual(removedMediaLists[1], this._smartPlaylist.name);
227 var hasAddedContent =
false;
228 for (var item in parsedTask.getAddedMediaItems()) {
229 hasAddedContent =
true;
230 this.
_log(
"FOUND " + item +
" as an added mediaitem ERROR!!!!");
235 shouldContinue =
false;
239 this.
_log(
"-> Phase " + this._phase +
" FINISHED");
242 taskFile.remove(
false);
246 if (shouldContinue) {
248 this._runCurrentPhase();
255 this._shutdownService.removeJobProgressListener(
this);
256 this._shutdownService =
null;
258 this.
_log(
"Test finished!");
264 _invokeExportService:
function() {
265 this.
_log(
"Export service needs to run = " +
266 this._shutdownService.needsToRunTask);
267 assertTrue(this._shutdownService.needsToRunTask);
268 this._shutdownService.startTask();
272 onJobProgress:
function(aJobProgress) {
273 if (aJobProgress.status ==
Ci.sbIJobProgress.STATUS_SUCCEEDED) {
274 this.
_log(
"Current job has STATUS_SUCCEEDED");
275 this._validateExportData();
280 _addTracks:
function(aTargetMediaList) {
281 for (var
i = 0;
i < this._tracks.length;
i++) {
283 this._mainLibrary.createMediaItem(
newURI(this._tracks[
i]));
284 aTargetMediaList.add(mediaItem);
285 this.
_log(
"Added '" + this._tracks[i] +
"'' (" +
286 mediaItem.guid +
") to '" + aTargetMediaList.name +
"'");
291 _addTracks2:
function(aTargetMediaList) {
292 for (var
i = 0;
i < this._tracks2.length;
i++) {
294 this._mainLibrary.createMediaItem(
newURI(this._tracks2[
i]));
295 aTargetMediaList.add(mediaItem);
296 this.
_log(
"Added '" + this._tracks2[i] +
"'' (" +
297 mediaItem.guid +
") to '" + aTargetMediaList.name +
"'");
301 _removeTracks:
function() {
303 this._mainLibrary.clearItems();
304 this.
_log(
"Cleared the main library of mediaitems");
308 _addPlaylist:
function() {
309 this._playlist = this._mainLibrary.createMediaList(
"simple");
310 this._playlist.name =
"TEST PLAYLIST";
313 _removePlaylist:
function() {
314 if (this._playlist) {
315 this._mainLibrary.remove(this._playlist);
320 _addSmartPlaylist:
function() {
321 this._smartPlaylist = this._mainLibrary.createMediaList(
"smart");
322 this._smartPlaylist.name =
"TEST SMARTPLAYLIST";
325 _removeSmartPlaylist:
function() {
326 if (this._smartPlaylist) {
327 this._mainLibrary.remove(this._smartPlaylist);
332 _logTaskData:
function(aTaskData)
334 var addedMediaLists =
"ADDED MEDIALISTS:";
335 var removedMediaLists =
"REMOVED MEDIALISTS";
336 var addedMediaItems =
"ADDED MEDIAITEMS";
338 for (var
i = 0;
i < aTaskData.getAddedMediaLists().length;
i++) {
339 addedMediaLists +=
"\n - " + aTaskData.getAddedMediaLists()[
i];
341 for (var
i = 0;
i < aTaskData.getRemovedMediaLists().length;
i++) {
342 removedMediaLists +=
"\n - " + aTaskData.getRemovedMediaLists()[
i];
344 for (var curMediaListName in aTaskData.getAddedMediaItems()) {
345 addedMediaItems +=
"\n - " + curMediaListName;
347 var curListArray = aTaskData.getAddedMediaItems()[curMediaListName];
348 for (var j = 0; j < curListArray.length; j++) {
349 addedMediaItems +=
"\n * " + curListArray[j];
353 this.
_log(addedMediaLists);
354 this.
_log(removedMediaLists);
355 this.
_log(addedMediaItems);
359 _log:
function(aString) {
360 dump(
"----------------------------------------------------------\n");
361 dump(
" " + aString +
"\n");
362 dump(
"----------------------------------------------------------\n");
function sleep(ms, suppressOutput)
function newAppRelativeFile(path)
sbOSDControlService prototype QueryInterface
function assertTrue(aTest, aMessage)
function assertEqual(aExpected, aActual, aMessage)
function newURI(aURLString)
function assertFalse(aTest, aMessage)
function _log(aMsg, aMenuID)
Javascript wrappers for common library tasks.
_getSelectedPageStyle s i