head_cddevice.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 
25 //------------------------------------------------------------------------------
26 //
27 // Mock CD device test
28 //
29 //------------------------------------------------------------------------------
30 
34 var gTailCallback = [];
35 
41  const K_PREF = "metadata.lookup.default_provider";
42  const Application = Cc["@mozilla.org/fuel/application;1"]
43  .getService(Ci.fuelIApplication);
44 
45  var providerValue = Application.prefs.get(K_PREF);
46  Application.prefs.setValue(K_PREF, "TestProvider");
47  gTailCallback.push(function(){
48  if (providerValue && providerValue.value) {
49  Application.prefs.setValue(K_PREF, providerValue.value);
50  } else {
51  pref = Application.prefs.get(K_PREF);
52  if (pref) {
53  pref.reset();
54  }
55  }
56  });
57 })();
58 
59 function createPropertyBag(aParams) {
60  var bag = Cc["@mozilla.org/hash-property-bag;1"]
61  .createInstance(Ci.nsIWritablePropertyBag);
62  for (var name in aParams) {
63  bag.setProperty(name, aParams[name]);
64  }
65  return bag;
66 }
67 
68 function newTOC(aFirstTrack, aLastTrack, aLead)
69 {
70  var tocClass = Cc["@songbirdnest.com/Songbird/MockCDTOC;1"];
71  var toc = tocClass.createInstance(Ci.sbIMockCDTOC);
72  toc.initialize(aFirstTrack, aLastTrack, aLead);
73 
74  return toc;
75 }
76 
78 {
79  var toc = newTOC(1, 15, 285675);
80 
81  // tracks:
82  toc.addTocEntry(32, 309, 0, Ci.sbICDTOCEntry.TRACKMODE_AUDIO);
83  toc.addTocEntry(23260, 231, 1, Ci.sbICDTOCEntry.TRACKMODE_AUDIO);
84  toc.addTocEntry(40612, 242, 2, Ci.sbICDTOCEntry.TRACKMODE_AUDIO);
85  toc.addTocEntry(58770, 191, 3, Ci.sbICDTOCEntry.TRACKMODE_AUDIO);
86  toc.addTocEntry(73145, 310, 4, Ci.sbICDTOCEntry.TRACKMODE_AUDIO);
87  toc.addTocEntry(96415, 290, 5, Ci.sbICDTOCEntry.TRACKMODE_AUDIO);
88  toc.addTocEntry(118232, 301, 6, Ci.sbICDTOCEntry.TRACKMODE_AUDIO);
89  toc.addTocEntry(140867, 259, 7, Ci.sbICDTOCEntry.TRACKMODE_AUDIO);
90  toc.addTocEntry(160322, 316, 8, Ci.sbICDTOCEntry.TRACKMODE_AUDIO);
91  toc.addTocEntry(184085, 222, 9, Ci.sbICDTOCEntry.TRACKMODE_AUDIO);
92  toc.addTocEntry(200777, 236, 10, Ci.sbICDTOCEntry.TRACKMODE_AUDIO);
93  toc.addTocEntry(218535, 185, 11, Ci.sbICDTOCEntry.TRACKMODE_AUDIO);
94  toc.addTocEntry(232437, 211, 12, Ci.sbICDTOCEntry.TRACKMODE_AUDIO);
95  toc.addTocEntry(248320, 184, 13, Ci.sbICDTOCEntry.TRACKMODE_AUDIO);
96  toc.addTocEntry(262145, 313, 14, Ci.sbICDTOCEntry.TRACKMODE_AUDIO);
97 
98  return toc;
99 }
100 
102 {
103  var toc = newTOC(1, 1, 131072);
104  toc.addTocEntry(32, 32, 0, Ci.sbICDTOCEntry.TRACKMODE_AUDIO);
105  return toc;
106 }
107 
108 function sbCreateDevice(deviceName, toc)
109 {
110  var deviceController = Cc["@songbirdnest.com/Songbird/CDDeviceController;1"]
111  .createInstance(Ci.sbIDeviceController);
112  var cdDevice = Cc["@songbirdnest.com/Songbird/MockCDDevice;1"]
113  .createInstance(Ci.sbIMockCDDevice)
114  .QueryInterface(Ci.sbICDDevice);
115 
116  cdDevice.initialize(deviceName,
117  true,
118  false,
119  true,
120  Ci.sbIDeviceController.AUDIO_DISC_TYPE,
121  false,
122  null);
123  if (toc) {
124  cdDevice.setDiscTOC(toc);
125  }
126  var deviceParams = new Object;
127  deviceParams["sbICDDevice"] = cdDevice;
128  var sbDevice = deviceController.createDevice(createPropertyBag(deviceParams));
129  sbDevice.connect();
130  return sbDevice;
131 }
function sbCreateDevice(deviceName, toc)
const Cc
var Application
Definition: sbAboutDRM.js:37
var pref
Definition: openLocation.js:44
function sbMakeMidnightRock()
var gTailCallback
function sbMakeInstantJunk()
return null
Definition: FeedWriter.js:1143
function head_ForceLookupProvider()
const Ci
function createPropertyBag(aParams)
function newTOC(aFirstTrack, aLastTrack, aLead)