test_mediacoremanager.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 
31 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
32 Components.utils.import("resource://app/jsmodules/ArrayConverter.jsm");
33 Components.utils.import("resource://app/jsmodules/sbProperties.jsm");
34 Components.utils.import("resource://app/jsmodules/sbLibraryUtils.jsm");
35 
36 function runTest () {
37 
38  var mediacoreManager = Cc["@songbirdnest.com/Songbird/Mediacore/Manager;1"]
39  .getService(Ci.sbIMediacoreManager);
40 
41  log("Testing basic event target functionality\n");
42  testSimpleListener(mediacoreManager);
43 
44  // TODO: XXX Remove when manager fully meets unit test requirements
45  return;
46 
47  log("Test factory logic\n");
48  var factories = mediacoreManager.factories;
49  log("Number of factories found: " + factories.length);
50 
51  for(let i = 0; i < factories.length; ++i) {
52  let factory = factories.queryElementAt(i, Ci.sbIMediacoreFactory);
53 
54  log("Factory name: " + factory.name);
55  log("Factory contract id: " + factory.contractID);
56  }
57 
58  var uri = newURI("file:///Volumes/Aus-DATA/Media/gnb_mix3.mp3");
59  var mediacoreVotingChain = mediacoreManager.voteWithURI(uri);
60 
61  var mediacore = mediacoreVotingChain.mediacoreChain.queryElementAt(0, Ci.sbIMediacore);
62 
63  // The following may throw if the interface isn't present for instanceof
64  try {
65  if(mediacore instanceof Ci.sbIQuickTimeMediacore) {
66  log("QuickTime version: " + mediacore.quickTimeVersion);
67  }
68 
69  if(mediacore instanceof Ci.sbIWindowsMediacore) {
70  log("Windows media player version: " + mediacore.windowsMediaVersion);
71  }
72  }
73  catch(e) { };
74 
75  log("Attempting to play: " + uri.spec);
76  mediacore.uri = uri;
77  mediacore.play();
78 
79  log("Attempting to seek to: " + 120000 / 1000 + "s");
80  mediacore.position = 120000;
81 
82  var vol = 0.5;
83  log("Attempting to set volume to: " + vol);
84  mediacore.volume = vol;
85 
86  sleep(25000);
87 
88  log("Attempting to pause.");
89  mediacore.pause();
90 
91  log("Attempting to stop.");
92  mediacore.stop();
93 
94  var index = 0;
95  if(factories.length > 1) {
96  index = 1;
97  }
98 
99  log("Going to attempt to play another file, with another core if possible.");
100  mediacore = mediacoreVotingChain.mediacoreChain.queryElementAt(index, Ci.sbIMediacore);
101 
102  try {
103  if(mediacore instanceof Ci.sbIQuickTimeMediacore) {
104  log("QuickTime version: " + mediacore.quickTimeVersion);
105  }
106 
107  if(mediacore instanceof Ci.sbIWindowsMediacore) {
108  log("Windows media player version: " + mediacore.windowsMediaVersion);
109  }
110  }
111  catch(e) { };
112 
113 
114  var uri2 = newURI("file:///Users/aus/Music/fluxblog.org/fujiyamiyagi_knickerbocker.mp3");
115 
116  log("Attempting to play: " + uri2.spec);
117  mediacore.uri = uri2;
118  mediacore.play();
119 
120  log("Attempting to seek to: " + 1200 / 1000 + "s");
121  mediacore.position = 1200;
122 
123  var vol = 0.8;
124  log("Attempting to set volume to: " + vol);
125  mediacore.volume = vol;
126 
127  sleep(25000);
128 
129 }
130 
134 function testListener() {
135  this.wrappedJSObject = this;
136  this.log = [];
137 }
138 
139 testListener.prototype = {
140  QueryInterface: XPCOMUtils.generateQI([Ci.sbIMediacoreEventListener]),
141  onMediacoreEvent: function(event) {
142  this.log.push(event);
143  }
144 }
145 
146 var eventIDs = [Ci.sbIMediacoreEvent.METADATA_CHANGE,
147  Ci.sbIMediacoreEvent.URI_CHANGE,
148  Ci.sbIMediacoreEvent.DURATION_CHANGE,
149  Ci.sbIMediacoreEvent.VOLUME_CHANGE,
150  Ci.sbIMediacoreEvent.MUTE_CHANGE,
151  Ci.sbIMediacoreEvent.STREAM_FOUND,
152  Ci.sbIMediacoreEvent.BUFFERING,
153  Ci.sbIMediacoreEvent.BUFFER_UNDERRUN,
154  Ci.sbIMediacoreEvent.STREAM_START,
155  Ci.sbIMediacoreEvent.STREAM_PAUSE,
156  Ci.sbIMediacoreEvent.STREAM_END];
157 
158 
159 function dummyMediacore() {
160  this.wrappedJSObject = this;
161 }
162 
163 dummyMediacore.prototype = {
164  QueryInterface: XPCOMUtils.generateQI([Ci.sbIMediacore]),
165 }
166 
167 function testSimpleListener(mediaManager) {
168  var listener = new testListener();
169 
170  mediaManager.addListener(listener);
171  for (index = 0; index < eventIDs.length; ++index) {
172  var event = mediaManager.createEvent(eventIDs[index], new dummyMediacore(), "", null);
173  mediaManager.dispatchEvent(event, false);
174  }
175  assertEqual(listener.log.length, eventIDs.length, "event received count not equal to events sent");
176  for (index = 0; index < eventIDs.length; ++index) {
177  assertEqual(listener.log[index].type, eventIDs[index], "Event type doesn't match event ID sent");
178  }
179  mediaManager.removeListener(listener);
180 }
function sleep(ms, suppressOutput)
const Cc
function log(s)
var event
sbOSDControlService prototype QueryInterface
function assertEqual(aExpected, aActual, aMessage)
return null
Definition: FeedWriter.js:1143
function newURI(aURLString)
function runTest()
Advanced DataRemote unit tests.
function testSimpleListener(async)
var uri
Definition: FeedWriter.js:1135
const Ci
_getSelectedPageStyle s i
function testListener()
function dummyMediacore()