test_bug7406.js
Go to the documentation of this file.
1 /*
2 //
3 // BEGIN SONGBIRD GPL
4 //
5 // This file is part of the Songbird web player.
6 //
7 // Copyright(c) 2005-2008 POTI, Inc.
8 // http://songbirdnest.com
9 //
10 // This file may be licensed under the terms of of the
11 // GNU General Public License Version 2 (the "GPL").
12 //
13 // Software distributed under the License is distributed
14 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
15 // express or implied. See the GPL for the specific language
16 // governing rights and limitations.
17 //
18 // You should have received a copy of the GPL along with this
19 // program. If not, go to http://www.gnu.org/licenses/gpl.html
20 // or write to the Free Software Foundation, Inc.,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 //
23 // END SONGBIRD GPL
24 //
25 */
26 
32 var count = 0;
33 var gServer;
34 
35 function runTest () {
36  var NUM_JOBS = 10;
37  var NUM_ITEMADD_LOOPS = 2;
38 
39  var port = getTestServerPortNumber();
40 
41  gServer = Cc["@mozilla.org/server/jshttp;1"].createInstance(Ci.nsIHttpServer);
42 
43  gServer.start(port);
44  gServer.registerDirectory("/", getFile("."));
45 
46  var prefix = "http://localhost:" + port + "/files/";
47 
48  var library = createNewLibrary( "test_metadatajob" );
49 
50  var urls = [
51  "file:///media/sdb1/steve/old/steve/fakemp3s/Sigur%20R%C3%B3s/%C3%81g%C3%A6tis%20Byrjun/1%20Intro.mp3",
52  "file:///media/sdb1/steve/old/steve/fakemp3s/Sigur%20R%C3%B3s/%C3%81g%C3%A6tis%20Byrjun/2%20Svefn-G-Englar.mp3",
53  "file:///media/sdb1/steve/old/steve/fakemp3s/Sigur%20R%C3%B3s/%C3%81g%C3%A6tis%20Byrjun/3%20Star%C3%A1lfur.mp3",
54  "file:///media/sdb1/steve/old/steve/fakemp3s/Sigur%20R%C3%B3s/%C3%81g%C3%A6tis%20Byrjun/4%20Flugufrelsarinn.mp3",
55  "file:///media/sdb1/steve/old/steve/fakemp3s/Sigur%20R%C3%B3s/%C3%81g%C3%A6tis%20Byrjun/5%20Ny%20Batteri.mp3",
56  prefix + "MP3_ID3v1.mp3",
57  prefix + "MP3_ID3v23.mp3",
58  prefix + "FLAC.flac"
59  ];
60 
61  gFileMetadataService = Components.classes["@songbirdnest.com/Songbird/FileMetadataService;1"]
62  .getService(Components.interfaces.sbIFileMetadataService);
63 
64  for (var i = 0; i < NUM_JOBS; i++) {
65  var a = Components.classes["@songbirdnest.com/moz/xpcom/threadsafe-array;1"]
66  .createInstance(Components.interfaces.nsIMutableArray);
67  for (var k = 0; k < NUM_ITEMADD_LOOPS; k++) {
68  for (var j = 0; j < urls.length; j++) {
69  a.appendElement(library.createMediaItem(newURI(urls[j]), null, true), false);
70  }
71  }
72 
73  var job = gFileMetadataService.read(a);
74 
75  // Set an observer to know when we complete
76  job.addJobProgressListener( onComplete );
77  count++;
78  log("length = " + a.length + " count = " + count);
79  }
80 
81  testPending();
82 
83 }
84 
85 function onComplete(job) {
86  if (job.status == Components.interfaces.sbIJobProgress.STATUS_RUNNING) {
87  return;
88  }
89 
90  job.removeJobProgressListener(onComplete);
91 
92  log("done = " + count);
93  count--;
94  if (count == 0) {
95  gServer.stop();
96  testFinished(); // Complete the testing
97  }
98 }
99 
100 function getFile(fileName) {
101  var file = Cc["@mozilla.org/file/directory_service;1"]
102  .getService(Ci.nsIProperties)
103  .get("resource:app", Ci.nsIFile);
104  file = file.clone();
105  file.append("testharness");
106  file.append("metadatamanager");
107  file.append(fileName);
108  return file;
109 }
const Cc
function onComplete(job)
Definition: test_bug7406.js:85
function log(s)
function testFinished()
function createNewLibrary(databaseGuid, databaseLocation)
var count
Definition: test_bug7406.js:32
function runTest()
Advanced DataRemote unit tests.
Definition: test_bug7406.js:35
return null
Definition: FeedWriter.js:1143
function newURI(aURLString)
function getFile(fileName)
const Ci
function getTestServerPortNumber()
_getSelectedPageStyle s i
var gFileMetadataService
Test file.
Definition: test_bug7406.js:31
var gServer
Definition: test_bug7406.js:33
var file
function testPending()