Bug 1084389 - Do not wrap the DOMRequest in a promise in Bluetooth tests; r=echou
authorEhsan Akhgari <ehsan@mozilla.com>
Mon, 20 Oct 2014 09:08:33 -0400
changeset 211322 57ed7482de8033b9d161c4d69a5af5a1eb7e3064
parent 211321 ec0ccbcbb95ffb1d820c5959793b302ca315a83a
child 211323 ae49e79844e01f48352da02c6e81f84194dfc12f
push id27673
push userkwierso@gmail.com
push dateTue, 21 Oct 2014 01:57:45 +0000
treeherdermozilla-central@29fbfc1b31aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersechou
bugs1084389
milestone36.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1084389 - Do not wrap the DOMRequest in a promise in Bluetooth tests; r=echou DOMRequest now has a .then() method compatible with Promise.
dom/bluetooth/tests/marionette/head.js
--- a/dom/bluetooth/tests/marionette/head.js
+++ b/dom/bluetooth/tests/marionette/head.js
@@ -88,43 +88,16 @@ function runEmulatorCmdSafe(aCommand) {
       deferred.reject(aResult);
     }
   });
 
   return deferred.promise;
 }
 
 /**
- * Wrap DOMRequest onsuccess/onerror events to Promise resolve/reject.
- *
- * Fulfill params: A DOMEvent.
- * Reject params: A DOMEvent.
- *
- * @param aRequest
- *        A DOMRequest instance.
- *
- * @return A deferred promise.
- */
-function wrapDomRequestAsPromise(aRequest) {
-  let deferred = Promise.defer();
-
-  ok(aRequest instanceof DOMRequest,
-     "aRequest is instanceof " + aRequest.constructor);
-
-  aRequest.onsuccess = function(aEvent) {
-    deferred.resolve(aEvent);
-  };
-  aRequest.onerror = function(aEvent) {
-    deferred.reject(aEvent);
-  };
-
-  return deferred.promise;
-}
-
-/**
  * Add a Bluetooth remote device to scatternet and set its properties.
  *
  * Use QEMU command 'bt remote add' to add a virtual Bluetooth remote
  * and set its properties by setEmulatorDeviceProperty().
  *
  * Fulfill params:
  *   result -- bluetooth address of the remote device.
  * Reject params: (none)
@@ -241,26 +214,25 @@ function getEmulatorDeviceProperty(aAddr
  * @param aAdapter
  *        A BluetoothAdapter which is used to interact with local BT device.
  *
  * @return A deferred promise.
  */
 function startDiscovery(aAdapter) {
   let request = aAdapter.startDiscovery();
 
-  return wrapDomRequestAsPromise(request)
-    .then(function resolve() {
+  return request.then(function resolve() {
       // TODO (bug 892207): Make Bluetooth APIs available for 3rd party apps.
       //     Currently, discovering state wouldn't change immediately here.
       //     We would turn on this check when the redesigned API are landed.
       // is(aAdapter.discovering, false, "BluetoothAdapter.discovering");
       log("  Start discovery - Success");
-    }, function reject(aEvent) {
+    }, function reject(aError) {
       ok(false, "Start discovery - Fail");
-      throw aEvent.target.error;
+      throw aError;
     });
 }
 
 /**
  * Stop discovering Bluetooth devices.
  *
  * Allows the device's adapter to stop seeking for remote devices.
  *
@@ -270,26 +242,25 @@ function startDiscovery(aAdapter) {
  * @param aAdapter
  *        A BluetoothAdapter which is used to interact with local BT device.
  *
  * @return A deferred promise.
  */
 function stopDiscovery(aAdapter) {
   let request = aAdapter.stopDiscovery();
 
-  return wrapDomRequestAsPromise(request)
-    .then(function resolve() {
+  return request.then(function resolve() {
       // TODO (bug 892207): Make Bluetooth APIs available for 3rd party apps.
       //     Currently, discovering state wouldn't change immediately here.
       //     We would turn on this check when the redesigned API are landed.
       // is(aAdapter.discovering, false, "BluetoothAdapter.discovering");
       log("  Stop discovery - Success");
-    }, function reject(aEvent) {
+    }, function reject(aError) {
       ok(false, "Stop discovery - Fail");
-      throw aEvent.target.error;
+      throw aError;
     });
 }
 
 /**
  * Wait for 'devicefound' event of specified devices.
  *
  * Resolve if that every specified devices has been found.  Never reject.
  *
@@ -358,22 +329,21 @@ function startDiscoveryAndWaitDevicesFou
  * @param aDeviceAddress
  *        The string of remote Bluetooth address with format xx:xx:xx:xx:xx:xx.
  *
  * @return A deferred promise.
  */
 function pair(aAdapter, aDeviceAddress) {
   let request = aAdapter.pair(aDeviceAddress);
 
-  return wrapDomRequestAsPromise(request)
-    .then(function resolve() {
+  return request.then(function resolve() {
       log("  Pair - Success");
-    }, function reject(aEvent) {
+    }, function reject(aError) {
       ok(false, "Pair - Fail");
-      throw aEvent.target.error;
+      throw aError;
     });
 }
 
 /**
  * Remove the paired device from the paired device list.
  *
  * Remove the paired device from the paired device list of the device's adapter.
  *
@@ -385,22 +355,21 @@ function pair(aAdapter, aDeviceAddress) 
  * @param aDeviceAddress
  *        The string of remote Bluetooth address with format xx:xx:xx:xx:xx:xx.
  *
  * @return A deferred promise.
  */
 function unpair(aAdapter, aDeviceAddress) {
   let request = aAdapter.unpair(aDeviceAddress);
 
-  return wrapDomRequestAsPromise(request)
-    .then(function resolve() {
+  return request.then(function resolve() {
       log("  Unpair - Success");
-    }, function reject(aEvent) {
+    }, function reject(aError) {
       ok(false, "Unpair - Fail");
-      throw aEvent.target.error;
+      throw aError;
     });
 }
 
 /**
  * Start pairing a remote device and wait for "pairedstatuschanged" event.
  *
  * Start pairing a remote device with the device's adapter and wait for
  * "pairedstatuschanged" event.
@@ -435,24 +404,23 @@ function pairDeviceAndWait(aAdapter, aDe
  * @param aAdapter
  *        A BluetoothAdapter which is used to interact with local BT device.
  *
  * @return A deferred promise.
  */
 function getPairedDevices(aAdapter) {
   let request = aAdapter.getPairedDevices();
 
-  return wrapDomRequestAsPromise(request)
-    .then(function resolve() {
+  return request.then(function resolve() {
       log("  getPairedDevices - Success");
       let pairedDevices = request.result.slice();
       return pairedDevices;
-    }, function reject(aEvent) {
+    }, function reject(aError) {
       ok(false, "getPairedDevices - Fail");
-      throw aEvent.target.error;
+      throw aError;
     });
 }
 
 /**
  * Get mozSettings value specified by @aKey.
  *
  * Resolve if that mozSettings value is retrieved successfully, reject
  * otherwise.
@@ -464,23 +432,22 @@ function getPairedDevices(aAdapter) {
  * @param aKey
  *        A string.
  *
  * @return A deferred promise.
  */
 function getSettings(aKey) {
   let request = navigator.mozSettings.createLock().get(aKey);
 
-  return wrapDomRequestAsPromise(request)
-    .then(function resolve(aEvent) {
+  return request.then(function resolve(aValue) {
       ok(true, "getSettings(" + aKey + ")");
-      return aEvent.target.result[aKey];
-    }, function reject(aEvent) {
+      return aValue[aKey];
+    }, function reject(aError) {
       ok(false, "getSettings(" + aKey + ")");
-      throw aEvent.target.error;
+      throw aError;
     });
 }
 
 /**
  * Set mozSettings values.
  *
  * Resolve if that mozSettings value is set successfully, reject otherwise.
  *