test_manager.js
Go to the documentation of this file.
1 /*
2  *=BEGIN SONGBIRD GPL
3  *
4  * This file is part of the Songbird web player.
5  *
6  * Copyright(c) 2005-2009 POTI, Inc.
7  * http://www.songbirdnest.com
8  *
9  * This file may be licensed under the terms of of the
10  * GNU General Public License Version 2 (the "GPL").
11  *
12  * Software distributed under the License is distributed
13  * on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
14  * express or implied. See the GPL for the specific language
15  * governing rights and limitations.
16  *
17  * You should have received a copy of the GPL along with this
18  * program. If not, go to http://www.gnu.org/licenses/gpl.html
19  * or write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  *=END SONGBIRD GPL
23  */
24 
29 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
30 Components.utils.import("resource://app/jsmodules/sbProperties.jsm");
31 
32 var gMLM;
35 
36 var testListener = {
37  QueryInterface: XPCOMUtils.generateQI([
38  Ci.sbICDDeviceListener,
39  Ci.sbIJobProgressListener
40  ]),
41 
42  // sbICDDeviceListener
43  onMediaInserted: function(cdDevice) {
44  assertEqual(cdDevice.isDiscInserted, true,
45  "Expected CD device to be inserted");
46 
47  // get the test provider
48  var provider = gMLM.getProvider("TestProvider");
49 
50  // lookup the disc
51  var job = provider.queryDisc(cdDevice.discTOC);
52  // if the job was already finished, then just trigger the listener
53  // otherwise add the listener and wait
54  if (job.status == Ci.sbIJobProgress.STATUS_SUCCEEDED)
55  this.onJobProgress(job);
56  else
57  job.addJobProgressListener(this);
58  },
59 
60  onDeviceRemoved: function(cdDevice) {},
61  onMediaEjected: function(cdDevice) {},
62 
63  // sbIJobProgressListener
64  onJobProgress: function(job) {
65  if (job.status != Ci.sbIJobProgress.STATUS_SUCCEEDED)
66  return;
67 
68  // The check below does an implicit QueryInterface call, it is necessary
69  // before accessing sbIMetadataLookupJob properties
70  assertEqual(job instanceof Ci.sbIMetadataLookupJob, true,
71  "Expected sbIMetadataLookupJob instance. Got: " + job);
72 
73  // output the # of results found
74  var numResults = job.mlNumResults;
75  assertEqual(numResults > 0, true,
76  "Expected at least 1 result. Got: " + numResults);
77 
78  log("Got " + numResults + " results");
79  // enumerate the various results
80  var results = job.getMetadataResults();
81  while (results.hasMoreElements()) {
82  var a = results.getNext().QueryInterface(Ci.sbIMetadataAlbumDetail);
83  log("This album has " + a.tracks.length + " tracks");
84  var albumName = a.properties.getPropertyValue(SBProperties.albumName);
85  assertEqual(albumName, "Midnight Rock Disc 1",
86  "Expected album name to be 'Midnight Rock Disc 1', actual " +
87  "was: " + albumName);
88  var artistName = a.properties.getPropertyValue(SBProperties.artistName);
89  assertEqual(artistName, "Various",
90  "Expected artist name to be 'Various', actual was: " +
91  artistName);
92  assertEqual(a.tracks.length, 15, "Expected 15 tracks");
93  }
94 
95  // eject the disc
96  gMockController.ejectMedia(testListener.device,
97  Ci.sbIMockCDDeviceController.MOCK_MEDIA_DISC_MIDNIGHT_ROCK);
98 
99  job.removeJobProgressListener(this);
100  gMockSvc.removeListener(this);
101  testFinished();
102  }
103 }
104 
105 function runTest () {
106  // Get the media lookup manager and mock CD service/controller
107  gMLM = Cc["@songbirdnest.com/Songbird/MetadataLookup/manager;1"]
108  .getService(Ci.sbIMetadataLookupManager);
109  gMockSvc = Cc["@songbirdnest.com/device/cd/mock-cddevice-service;1"]
110  .getService(Ci.sbICDDeviceService);
111  gMockController = Cc["@songbirdnest.com/device/cd/mock-cddevice-service;1"]
112  .getService(Ci.sbIMockCDDeviceController);
113 
114  gMockSvc.registerListener(testListener);
115  var cd0 = gMockSvc.getDevice(0);
116 
117  testListener.device = cd0;
118  // insert "All That You Can't Leave Behind"
119  gMockController.insertMedia(cd0,
120  Ci.sbIMockCDDeviceController.MOCK_MEDIA_DISC_MIDNIGHT_ROCK);
121 
122  testPending();
123 }
124 
var gMockController
Definition: test_manager.js:34
const Cc
function runTest()
Test file.
Definition: test_manager.js:29
var gMockSvc
Definition: test_manager.js:33
function log(s)
function testFinished()
sbOSDControlService prototype QueryInterface
function assertEqual(aExpected, aActual, aMessage)
var gMLM
Definition: test_manager.js:32
var testListener
const Ci
function testPending()