Bug 972730 - Avoid disabling BT before the BT adapter is initialized in marionette test. r=echou, f=vicamo
authorJamin Liu <jaliu@mozilla.com>
Mon, 03 Mar 2014 10:20:24 -0500
changeset 171532 b07a62b9c5abd804b5c3131532fa9a5c0afc6b7c
parent 171531 a6cf1f99cfbe83223eb2da9317206737b798ecaa
child 171533 b5a2f2935808afe45bb408729cbfea7da750ea03
push id5158
push userryanvm@gmail.com
push dateMon, 03 Mar 2014 15:20:02 +0000
treeherderb2g-inbound@b07a62b9c5ab [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersechou
bugs972730
milestone30.0a1
Bug 972730 - Avoid disabling BT before the BT adapter is initialized in marionette test. r=echou, f=vicamo The current Bluetooth API can't allow user to disable BT before the BT adapter is initialized. In practice, We block the clicking event in gaia layer to prevent user to turn off BT before BT enable procedure complete. If we use marionette test to force emulator turn on and turn off BT in a short period of time, it may crash emulator. Listen to 'adapteradded' event rather than 'enabled' as the end of BT enable to make sure we wouldn't disable BT when it's not ready.
dom/bluetooth/tests/marionette/test_dom_BluetoothManager_enabled.js
--- a/dom/bluetooth/tests/marionette/test_dom_BluetoothManager_enabled.js
+++ b/dom/bluetooth/tests/marionette/test_dom_BluetoothManager_enabled.js
@@ -6,24 +6,28 @@
 
 MARIONETTE_TIMEOUT = 60000;
 MARIONETTE_HEAD_JS = 'head.js';
 
 function waitEitherEnabledOrDisabled() {
   let deferred = Promise.defer();
 
   function onEnabledDisabled(aEvent) {
-    bluetoothManager.removeEventListener("enabled", onEnabledDisabled);
+    bluetoothManager.removeEventListener("adapteradded", onEnabledDisabled);
     bluetoothManager.removeEventListener("disabled", onEnabledDisabled);
 
     ok(true, "Got event " + aEvent.type);
-    deferred.resolve(aEvent.type === "enabled");
+    deferred.resolve(aEvent.type === "adapteradded");
   }
 
-  bluetoothManager.addEventListener("enabled", onEnabledDisabled);
+  // Listen 'adapteradded' rather than 'enabled' since the current API can't
+  // disable BT before the BT adapter is initialized.
+  // We should listen to 'enabled' when gecko can handle the case I mentioned
+  // above, please refer to the follow-up bug 973482.
+  bluetoothManager.addEventListener("adapteradded", onEnabledDisabled);
   bluetoothManager.addEventListener("disabled", onEnabledDisabled);
 
   return deferred.promise;
 }
 
 function test(aEnabled) {
   log("Testing 'bluetooth.enabled' => " + aEnabled);
 
@@ -34,17 +38,17 @@ function test(aEnabled) {
     .then(function(aResults) {
       /* aResults is an array of two elements:
        *   [ <result of setBluetoothEnabled>,
        *     <result of waitEitherEnabledOrDisabled> ]
        */
       log("  Examine results " + JSON.stringify(aResults));
 
       is(bluetoothManager.enabled, aEnabled, "bluetoothManager.enabled");
-      is(aResults[1], aEnabled, "'enabled' event received");
+      is(aResults[1], aEnabled, "'adapteradded' event received");
 
       if (bluetoothManager.enabled === aEnabled && aResults[1] === aEnabled) {
         deferred.resolve();
       } else {
         deferred.reject();
       }
     });