68 succeedingURISpec:
"test1.mp3",
69 failingURISpec:
"nonexistent_file",
70 noDownloaderURISpec:
"about:config",
86 _testPendingIndicated:
false,
87 _allTestsComplete:
false,
96 start:
function testMediaItemDownloadService_start() {
101 this._testList.push(
function() {
return self._testDownload(); });
102 this._testList.push(
function() {
return self._testDownloadFailure(); });
103 this._testList.push(
function()
104 {
return self._testNoMatchingDownloader(); });
108 this._server =
Cc[
"@mozilla.org/server/jshttp;1"]
109 .createInstance(
Ci.nsIHttpServer);
110 this._server.start(this._serverPort);
111 this._server.registerDirectory(
"/",
getTestFile(
"."));
114 this._nextTestIndex = 0;
123 _finish:
function testMediaItemDownloadService__finish() {
125 this._allTestsComplete =
true;
128 if (this._testPendingIndicated) {
133 this._server.stop(
function() {});
141 _runNextTest:
function testMediaItemDownloadService__runNextTest() {
145 if (this._nextTestIndex >= this._testList.length) {
151 if (!this._testList[this._nextTestIndex++]()) {
154 if (!this._allTestsComplete && !this._testPendingIndicated) {
155 this._testPendingIndicated =
true;
168 _testDownload:
function testMediaItemDownloadService__testDownload() {
170 let mediaItemDownloadService =
171 Cc[
"@songbirdnest.com/Songbird/MediaItemDownloadService;1"]
172 .getService(
Ci.sbIMediaItemDownloadService);
176 let
uri =
newURI(
"http://localhost:" + this._serverPort +
177 "/" + this.succeedingURISpec);
178 let mediaItem = library.createMediaItem(uri);
183 downloader = mediaItemDownloadService.getDownloader(mediaItem,
null);
185 doFail(
"Could not get a media item downloader: " + ex);
189 let downloadSize = downloader.getDownloadSize(mediaItem,
null);
195 downloadJob = downloader.createDownloadJob(mediaItem,
null);
197 doFail(
"Could not create media item download job: " + ex);
203 onJobProgress:
function() {
204 if ((downloadJob.status ==
Ci.sbIJobProgress.STATUS_FAILED) ||
205 (downloadJob.status ==
Ci.sbIJobProgress.STATUS_SUCCEEDED)) {
206 assertEqual(downloadJob.status,
Ci.sbIJobProgress.STATUS_SUCCEEDED);
207 assertEqual(downloadJob.downloadedFile.fileSize, downloadSize);
208 downloadJob.removeJobProgressListener(
this);
209 tester._runNextTest();
213 downloadJob.addJobProgressListener(listener);
219 doFail(
"Could not start media item download: " + ex);
231 _testDownloadFailure:
232 function testMediaItemDownloadService__testDownloadFailure() {
234 let mediaItemDownloadService =
235 Cc[
"@songbirdnest.com/Songbird/MediaItemDownloadService;1"]
236 .getService(
Ci.sbIMediaItemDownloadService);
240 let
uri =
newURI(
"http://localhost:" + this._serverPort +
241 "/" + this.failingURISpec);
242 let mediaItem = library.createMediaItem(uri);
247 downloader = mediaItemDownloadService.getDownloader(mediaItem,
null);
249 doFail(
"Could not get a media item downloader: " + ex);
255 downloadJob = downloader.createDownloadJob(mediaItem,
null);
257 doFail(
"Could not create media item download job: " + ex);
263 onJobProgress:
function() {
264 if ((downloadJob.status ==
Ci.sbIJobProgress.STATUS_FAILED) ||
265 (downloadJob.status ==
Ci.sbIJobProgress.STATUS_SUCCEEDED)) {
266 assertEqual(downloadJob.status,
Ci.sbIJobProgress.STATUS_FAILED);
267 downloadJob.removeJobProgressListener(
this);
268 tester._runNextTest();
272 downloadJob.addJobProgressListener(listener);
278 doFail(
"Could not start media item download: " + ex);
290 _testNoMatchingDownloader:
291 function testMediaItemDownloadService__testNoMatchingDownloader() {
293 let mediaItemDownloadService =
294 Cc[
"@songbirdnest.com/Songbird/MediaItemDownloadService;1"]
295 .getService(
Ci.sbIMediaItemDownloadService);
299 let
uri =
newURI(this.noDownloaderURISpec);
300 let mediaItem = library.createMediaItem(uri);
306 downloader = mediaItemDownloadService.getDownloader(mediaItem,
null);
308 doFail(
"Get media item downloader exception: " + ex);
function assertTrue(aTest, aMessage)
function assertEqual(aExpected, aActual, aMessage)
function getTestFile(aFileName)
function createLibrary(databaseGuid, databaseLocation)
function newURI(aURLString)
function getTestServerPortNumber()