47 gTempFolder = Components.classes[
"@mozilla.org/file/directory_service;1"]
48 .getService(Components.interfaces.nsIProperties)
49 .get(
"TmpD", Components.interfaces.nsIFile);
51 gTempFolder.createUnique(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0777);
63 folder.copyTo(tempFolder, tempName);
64 folder = tempFolder.clone();
65 folder.append(tempName);
78 "_temp_firmware_files"));
80 var jsHttpServer =
Cc[
"@mozilla.org/server/jshttp;1"]
81 .createInstance(
Ci.nsIHttpServer);
83 jsHttpServer.registerDirectory(
"/", testFolder.clone());
86 var handlerURLService =
Cc[
"@songbirdnest.com/mock-firmware-url-handler;1"]
87 .getService(
Ci.sbPIMockFirmwareHandlerURLService);
95 var device = Components.classes[
"@songbirdnest.com/Songbird/Device/DeviceTester/MockDevice;1"]
96 .createInstance(Components.interfaces.sbIDevice);
99 var updater = Components.classes[
"@songbirdnest.com/Songbird/Device/Firmware/Updater;1"]
100 .getService(Components.interfaces.sbIDeviceFirmwareUpdater);
103 var
handler = updater.getHandler(device, 0, 0);
108 firmwareUpdate:
null,
109 onDeviceEvent:
function(aEvent) {
111 function eventTypeToString(aType) {
112 for (let type in
Ci.sbIDeviceEvent) {
113 if (
Ci.sbIDeviceEvent[type] === aType)
116 return "0x" + (
Array(8).join(
"0") + (type>>>0).toString(16)).substr(-8);
119 log(
"event operation: " + this.op);
120 log(
"event type: " + eventTypeToString(aEvent.type));
121 log(
"event origin: " + aEvent.origin);
122 log(
"event target: " + aEvent.target);
124 var
data = aEvent.data;
125 log(
"event data: " + data);
129 if(aEvent.type ==
Ci.sbIDeviceEvent.EVENT_FIRMWARE_CFU_END) {
130 log(
"is update available: " + data);
136 if(aEvent.type ==
Ci.sbIDeviceEvent.EVENT_FIRMWARE_DOWNLOAD_START) {
137 log(
"firmware update download start");
139 else if(aEvent.type ==
Ci.sbIDeviceEvent.EVENT_FIRMWARE_DOWNLOAD_PROGRESS) {
140 log(
"firmware update download progress: " + data);
142 if(aEvent.type ==
Ci.sbIDeviceEvent.EVENT_FIRMWARE_DOWNLOAD_END) {
143 this.firmwareUpdate = data.QueryInterface(
Ci.sbIDeviceFirmwareUpdate);
144 log(
"firmware update version: " + this.firmwareUpdate.firmwareReadableVersion);
145 log(
"firmware update file path: " + this.firmwareUpdate.firmwareImageFile.path);
152 if(aEvent.type ==
Ci.sbIDeviceEvent.EVENT_FIRMWARE_UPDATE_START) {
153 log(
"firmware apply update start");
155 else if(aEvent.type ==
Ci.sbIDeviceEvent.EVENT_FIRMWARE_WRITE_START) {
156 log(
"firmware write start");
158 else if(aEvent.type ==
Ci.sbIDeviceEvent.EVENT_FIRWMARE_WRITE_PROGRESS) {
159 log(
"firmware write progress: " + data);
161 else if(aEvent.type ==
Ci.sbIDeviceEvent.EVENT_FIRMWARE_WRITE_END) {
162 log(
"firmware write end");
164 else if(aEvent.type ==
Ci.sbIDeviceEvent.EVENT_FIRMWARE_UPDATE_END) {
165 log(
"firmware apply update end");
172 log(
"unknown operation");
179 log(
"Testing 'checkForUpdate'");
182 var
eventTarget = device.QueryInterface(
Ci.sbIDeviceEventTarget);
183 eventTarget.addEventListener(listener);
185 updater.checkForUpdate(device, 0, 0,
null);
188 log(
"Testing 'downloadUpdate'");
191 updater.downloadUpdate(device,
false,
null);
194 log(
"Testing 'applyUpdate'");
197 updater.applyUpdate(device, listener.firmwareUpdate,
null);
200 updater.finalizeUpdate(device);
function newAppRelativeFile(path)
function assertNotEqual(aExpected, aActual, aMessage)
function assertTrue(aTest, aMessage)
function runTest()
Device Firmware Tests.
function assertEqual(aExpected, aActual, aMessage)
function getCopyOfFolder(folder, tempName)
Copy the given folder to tempName, returning an nsIFile for the new location.
function getTestServerPortNumber()