39 for (var
name in aParams) {
42 val = aBag.getProperty(
name);
44 log(
'Failed to get property "' +
name +
'"');
48 if (typeof(aParams[
name]) ==
"object" &&
"wrappedJSObject" in aParams[name])
49 val = val.wrappedJSObject;
52 'property "' + name +
'" not equal');
53 log(
'"' + name +
'" is ' + val);
58 let device = Components.classes[
"@songbirdnest.com/Songbird/Device/DeviceTester/MockDevice;1"]
59 .createInstance(Components.interfaces.sbIDevice);
64 assertEqual(
"" + device.id,
"" + device.id,
"device ID not equal");
65 assertEqual(
"" + device.controllerId,
"" + device.controllerId,
"controller ID not equal");
78 fail(
"Re-connected device");
92 device.QueryInterface(Components.interfaces.sbIDeviceEventTarget);
94 if (
event.type ==
Ci.sbIDeviceEvent.EVENT_DEVICE_REMOVED) {
99 device.removeEventListener(handler);
106 device.removeEventListener(handler);
120 log(
"Device removed event fired");
139 test_properties(device);
147 function continueTest()
150 if (!device.connected)
155 var operation =
"test_library";
156 test_library(device);
157 operation =
"test_sync_settings";
158 test_sync_settings(device);
166 if (device.connected)
174 if (device.connected)
178 test_request(device, continueTest);
186 if (device.connected) {
196 device.addEventListener(handler);
202 fail(
"Re-disconnected device should not fail");
207 function test_prefs(device) {
209 assertTrue(typeof(device.getPreference(
"hello")) ==
"undefined");
211 device.setPreference(
"world", 3);
213 assertEqual(typeof(device.getPreference(
"world")),
"number");
214 device.setPreference(
"world",
"goat");
215 assertEqual(device.getPreference(
"world"),
"goat");
216 assertEqual(typeof(device.getPreference(
"world")),
"string");
217 device.setPreference(
"world",
true);
219 assertEqual(typeof(device.getPreference(
"world")),
"boolean");
221 with (Components.interfaces.sbIDevice) {
222 device.setPreference(
"state", 0);
224 device.setPreference(
"state", 1);
226 device.setPreference(
"state", 2);
228 device.setPreference(
"state", 3);
230 device.setPreference(
"state", 4);
232 device.setPreference(
"state", 5);
234 device.setPreference(
"state", 6);
236 device.setPreference(
"state", 7);
238 device.setPreference(
"state", 8);
240 device.setPreference(
"state", 9);
242 device.setPreference(
"state", 10);
247 function test_event(device) {
251 device.QueryInterface(Components.interfaces.sbIDeviceEventTarget);
252 var wasFired =
false;
253 var handler =
function handler() { wasFired =
true; }
254 device.addEventListener(handler);
255 var
event = Components.classes[
"@songbirdnest.com/Songbird/DeviceManager;2"]
256 .getService(Components.interfaces.sbIDeviceManager2)
258 device.dispatchEvent(
event);
259 assertTrue(wasFired,
"event handler not called");
261 device.removeEventListener(handler);
264 function test_request(device, continueAction) {
267 device.QueryInterface(
Ci.sbIMockDevice);
271 item.wrappedJSObject = item;
273 list.wrappedJSObject = list;
275 data.wrappedJSObject =
data;
276 var params = { item: item,
284 function requestCheck() {
287 request = device.popRequest();
295 if (request.getProperty(
"requestType") >= 0x20000000) {
297 log(
"item transfer ID: " + request.getProperty(
"itemTransferID"));
298 assertTrue(request.getProperty(
"itemTransferID") > 3,
299 "Obviously bad item transfer ID");
307 if (++retryCount > 60) {
308 fail(
"Failed in waiting for request");
317 function test_library(device) {
321 device.content.libraries.queryElementAt(0,
Ci.sbIDeviceLibrary).device);
323 device.content.libraries.queryElementAt(0,
Ci.sbIDeviceLibrary)));
326 function test_set_and_verify(device, audio, video, image)
328 let syncSettings = device.defaultLibrary.syncSettings;
330 log(
"Changing management types to " + audio +
", " + video +
", " + image);
333 syncSettings = device.defaultLibrary.syncSettings;
335 let audioSyncSettings = syncSettings.getMediaSettings(
336 Ci.sbIDeviceLibrary.MEDIATYPE_AUDIO);
337 let videoSyncSettings = syncSettings.getMediaSettings(
338 Ci.sbIDeviceLibrary.MEDIATYPE_VIDEO);
339 let imageSyncSettings = syncSettings.getMediaSettings(
340 Ci.sbIDeviceLibrary.MEDIATYPE_IMAGE);
343 audioSyncSettings.mgmtType = audio;
345 videoSyncSettings.mgmtType = video;
347 imageSyncSettings.mgmtType = image;
350 device.defaultLibrary.syncSettings = syncSettings;
353 syncSettings = device.defaultLibrary.syncSettings;
355 Ci.sbIDeviceLibrary.MEDIATYPE_AUDIO).mgmtType,
358 Ci.sbIDeviceLibrary.MEDIATYPE_VIDEO).mgmtType,
361 Ci.sbIDeviceLibrary.MEDIATYPE_IMAGE).mgmtType,
363 log(
"Checked Sync settings back");
366 function test_sync_settings(device) {
367 log(
"Testing initial mode");
368 let syncSettings = device.defaultLibrary.syncSettings;
370 log(
"Changing management type to all");
371 test_set_and_verify(device,
372 Ci.sbIDeviceLibraryMediaSyncSettings.SYNC_MGMT_ALL,
373 Ci.sbIDeviceLibraryMediaSyncSettings.SYNC_MGMT_ALL,
374 Ci.sbIDeviceLibraryMediaSyncSettings.SYNC_MGMT_ALL);
376 log(
"Changign management type to none");
377 test_set_and_verify(device,
378 Ci.sbIDeviceLibraryMediaSyncSettings.SYNC_MGMT_NONE,
379 Ci.sbIDeviceLibraryMediaSyncSettings.SYNC_MGMT_NONE,
380 Ci.sbIDeviceLibraryMediaSyncSettings.SYNC_MGMT_NONE);
383 function test_properties(device) {
384 var properties = device.properties;
386 log(
"friendlyName: " + properties.friendlyName);
387 assertEqual(properties.friendlyName,
"Testing Device");
388 log(
"serialNumber: " + properties.serialNumber);
389 assertEqual(properties.serialNumber,
"ACME-9000-0001-2000-3000");
390 log(
"modelNumber: " + properties.modelNumber);
392 log(
"vendorName: " + properties.vendorName);
394 log(
"firmwareVersion: " + properties.firmwareVersion);
395 assertEqual(properties.firmwareVersion,
"1.0.0.0");
397 properties.friendlyName =
"New Friendly Test Device";
398 assertEqual(properties.friendlyName,
"New Friendly Test Device");
402 var bag =
Cc[
"@mozilla.org/hash-property-bag;1"]
403 .createInstance(
Ci.nsIWritablePropertyBag);
404 for (var
name in aParams) {
405 bag.setProperty(
name, aParams[
name]);
sbOSDControlService prototype QueryInterface
function assertTrue(aTest, aMessage)
function assertEqual(aExpected, aActual, aMessage)
function checkPropertyBag(aBag, aParams)
Device tests - Mock device.
this _dialogInput val(dateText)
function assertFalse(aTest, aMessage)
function doTimeout(delay, func)
function createPropertyBag(aParams)