test_controller_registrar.js
Go to the documentation of this file.
1 /* vim: set sw=2 :miv */
2 /*
3 //
4 // BEGIN SONGBIRD GPL
5 //
6 // This file is part of the Songbird web player.
7 //
8 // Copyright(c) 2005-2008 POTI, Inc.
9 // http://songbirdnest.com
10 //
11 // This file may be licensed under the terms of of the
12 // GNU General Public License Version 2 (the "GPL").
13 //
14 // Software distributed under the License is distributed
15 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
16 // express or implied. See the GPL for the specific language
17 // governing rights and limitations.
18 //
19 // You should have received a copy of the GPL along with this
20 // program. If not, go to http://www.gnu.org/licenses/gpl.html
21 // or write to the Free Software Foundation, Inc.,
22 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 //
24 // END SONGBIRD GPL
25 //
26 */
27 
32 Components.utils.import("resource://app/jsmodules/ArrayConverter.jsm");
33 var gUUIDGenerator = Components.classes["@mozilla.org/uuid-generator;1"]
34  .createInstance(Components.interfaces.nsIUUIDGenerator);
35 
36 
37 function DummyController(aParam) {
38  this.wrappedJSObject = this;
39  this.name = aParam;
40  this.id = gUUIDGenerator.generateUUID();
41 }
42 
43 function runTest () {
44  var manager = Components.classes["@songbirdnest.com/Songbird/DeviceManager;2"]
45  .getService(Components.interfaces.sbIDeviceManager2);
46 
47  var params = [];
48 
49  var defaultControllers = ArrayConverter.JSArray(manager.controllers);
50  var defaultControllerCount = defaultControllers.length;
51 
52  for each (defaultController in defaultControllers) {
53  defaultController.QueryInterface(Components.interfaces.sbIDeviceController);
54  params.push(defaultController.name);
55  }
56 
57  // register some dummy controllers
58  for (var i = 0; i < 1000; ++i) {
59  // generate some sort of unique id
60  var param = (params.length * 65537 + 7) % 3000;
61  params.push("" + param);
62  manager.registerController(new DummyController(param));
63  }
64 
65  // put in a special controller to test getController
66  var controller = new DummyController(0);
67  manager.registerController(controller);
68 
69  // fill in some more dummy data
70  for (var i = 0; i < 1000; ++i) {
71  // generate some sort of unique id
72  var param = (params.length * 65537 + 7) % 3000;
73  params.push("" + param);
74  manager.registerController(new DummyController(param));
75  }
76 
77  // test getController
78  var returnedController = manager.getController(controller.id);
79  assertTrue(controller === returnedController.wrappedJSObject,
80  "failed to get controller:" +
81  controller.name + " / " + returnedController.name);
82  manager.unregisterController(controller);
83 
84  // read them out and make sure everything's accounted for
85  var controllers = ArrayConverter.JSArray(manager.controllers);
86  assertTrue(controllers.length == params.length, "expected controllers to be registered");
87  for each (controller in controllers) {
88  controller.QueryInterface(Components.interfaces.sbIDeviceController);
89  var index = params.indexOf(controller.name);
90  assertTrue(index >= 0, "Looking for param " + controller.name + "\n" + uneval(params));
91  params.splice(index, 1);
92  manager.unregisterController(controller);
93  }
94  assertTrue(params.length == 0, "params not empty: " + uneval(params));
95  assertTrue(manager.controllers.length == 0, "devices not unregistered");
96 }
97 
function runTest()
Advanced DataRemote unit tests.
function assertTrue(aTest, aMessage)
function DummyController(aParam)
var gUUIDGenerator
_getSelectedPageStyle s i