test_mediacoremanagereventtarget.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 
33 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
34 Components.utils.import("resource://app/jsmodules/ArrayConverter.jsm");
35 Components.utils.import("resource://app/jsmodules/sbProperties.jsm");
36 Components.utils.import("resource://app/jsmodules/sbLibraryUtils.jsm");
37 
38 function runTest () {
39 
40  var mediacoreManager = Cc["@songbirdnest.com/Songbird/Mediacore/Manager;1"]
41  .getService(Ci.sbIMediacoreManager);
42 
43  log("Testing basic event target functionality\n");
44  testSimpleListener(mediacoreManager);
45 }
46 
50 function testListener() {
51  this.wrappedJSObject = this;
52  this.log = [];
53 }
54 
55 testListener.prototype = {
56  QueryInterface: XPCOMUtils.generateQI([Ci.sbIMediacoreEventListener]),
57  onMediacoreEvent: function(event) {
58  this.log.push(event);
59  }
60 }
61 
62 var eventIDs = [Ci.sbIMediacoreEvent.METADATA_CHANGE,
63  Ci.sbIMediacoreEvent.URI_CHANGE,
64  Ci.sbIMediacoreEvent.DURATION_CHANGE,
65  Ci.sbIMediacoreEvent.VOLUME_CHANGE,
66  Ci.sbIMediacoreEvent.MUTE_CHANGE,
67  Ci.sbIMediacoreEvent.STREAM_FOUND,
68  Ci.sbIMediacoreEvent.BUFFERING,
69  Ci.sbIMediacoreEvent.BUFFER_UNDERRUN,
70  Ci.sbIMediacoreEvent.STREAM_START,
71  Ci.sbIMediacoreEvent.STREAM_PAUSE,
72  Ci.sbIMediacoreEvent.STREAM_END];
73 
74 
75 function dummyMediacore() {
76  this.wrappedJSObject = this;
77 }
78 
79 dummyMediacore.prototype = {
80  QueryInterface: XPCOMUtils.generateQI([Ci.sbIMediacore]),
81 }
82 
83 function testSimpleListener(mediaManager) {
84  var listener = new testListener();
85 
86  mediaManager.addListener(listener);
87  for (index = 0; index < eventIDs.length; ++index) {
88  var event = mediaManager.createEvent(eventIDs[index], new dummyMediacore(), "", null);
89  mediaManager.dispatchEvent(event, false);
90  }
91  assertEqual(listener.log.length, eventIDs.length, "event received count not equal to events sent");
92  for (index = 0; index < eventIDs.length; ++index) {
93  assertEqual(listener.log[index].type, eventIDs[index], "Event type doesn't match event ID sent");
94  }
95  mediaManager.removeListener(listener);
96  listener.wrappedJSObject = null;
97 }
98 
const Cc
function log(s)
var event
sbOSDControlService prototype QueryInterface
function assertEqual(aExpected, aActual, aMessage)
function dummyMediacore()
return null
Definition: FeedWriter.js:1143
function testListener()
function testSimpleListener(async)
const Ci
function runTest()
Advanced DataRemote unit tests.