Bug 900551 - Make marionette webapi tests use transaction events for settings; r=edgar r=hchang r=dlee
☠☠ backed out by 7c97c5f7a05e ☠ ☠
authorKyle Machulis <kyle@nonpolynomial.com>
Wed, 27 Aug 2014 21:01:30 -0700
changeset 223761 b953dd5bfdaabcad3f639ef5411fd836f10fcab7
parent 223760 a2b6d7c84100055c0063e06f288db7d57a875092
child 223762 5cf1cb5fa02281b979cab1d8a5693726921e195b
push id3979
push userraliiev@mozilla.com
push dateMon, 13 Oct 2014 16:35:44 +0000
treeherdermozilla-beta@30f2cc610691 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersedgar, hchang, dlee
bugs900551
milestone34.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 900551 - Make marionette webapi tests use transaction events for settings; r=edgar r=hchang r=dlee
dom/system/gonk/tests/marionette/head.js
dom/tethering/tests/marionette/head.js
dom/wifi/test/marionette/head.js
--- a/dom/system/gonk/tests/marionette/head.js
+++ b/dom/system/gonk/tests/marionette/head.js
@@ -88,23 +88,30 @@ function getSettings(aKey, aAllowError) 
  *        A boolean value.  If set to true, an error response won't be treated
  *        as test failure.  Default: false.
  *
  * @return A deferred promise.
  */
 function setSettings(aKey, aValue, aAllowError) {
   let settings = {};
   settings[aKey] = aValue;
-  let request = window.navigator.mozSettings.createLock().set(settings);
-  return wrapDomRequestAsPromise(request)
-    .then(function resolve() {
+  let lock = window.navigator.mozSettings.createLock();
+  let request = lock.set(settings);
+  let deferred = Promise.defer();
+  lock.onsettingstransactionsuccess = function () {
       log("setSettings(" + JSON.stringify(settings) + ") - success");
-    }, function reject() {
+    deferred.resolve();
+  };
+  lock.onsettingstransactionfailure = function () {
       ok(aAllowError, "setSettings(" + JSON.stringify(settings) + ") - error");
-    });
+    // We resolve even though we've thrown an error, since the ok()
+    // will do that.
+    deferred.resolve();
+  };
+  return deferred.promise;
 }
 
 /**
  * Wait for observer event.
  *
  * Resolve if that topic event occurs.  Never reject.
  *
  * Fulfill params: the subject passed.
--- a/dom/tethering/tests/marionette/head.js
+++ b/dom/tethering/tests/marionette/head.js
@@ -150,25 +150,29 @@ let gTestSuite = (function() {
    * Fulfill params: (none)
    * Reject params: (none)
    *
    * @param aSettings
    *        An object of format |{key1: value1, key2: value2, ...}|.
    * @return A deferred promise.
    */
   function setSettings(aSettings) {
-    let request = navigator.mozSettings.createLock().set(aSettings);
-
-    return wrapDomRequestAsPromise(request)
-      .then(function resolve() {
+    let lock = window.navigator.mozSettings.createLock();
+    let request = lock.set(aSettings);
+    let deferred = Promise.defer();
+    lock.onsettingstransactionsuccess = function () {
         ok(true, "setSettings(" + JSON.stringify(aSettings) + ")");
-      }, function reject(aEvent) {
+      deferred.resolve();
+    };
+    lock.onsettingstransactionfailure = function (aEvent) {
         ok(false, "setSettings(" + JSON.stringify(aSettings) + ")");
+      deferred.reject();
         throw aEvent.target.error;
-      });
+    };
+    return deferred.promise;
   }
 
   /**
    * Set mozSettings value with only one key.
    *
    * Resolve if that mozSettings value is set successfully, reject otherwise.
    *
    * Fulfill params: (none)
@@ -533,16 +537,18 @@ let gTestSuite = (function() {
    * @return A deferred promise.
    */
   function acquirePermission() {
     let deferred = Promise.defer();
 
     let permissions = [{ 'type': 'wifi-manage', 'allow': 1, 'context': window.document },
                        { 'type': 'settings-write', 'allow': 1, 'context': window.document },
                        { 'type': 'settings-read', 'allow': 1, 'context': window.document },
+                       { 'type': 'settings-api-write', 'allow': 1, 'context': window.document },
+                       { 'type': 'settings-api-read', 'allow': 1, 'context': window.document },
                        { 'type': 'mobileconnection', 'allow': 1, 'context': window.document }];
 
     SpecialPowers.pushPermissions(permissions, function() {
       deferred.resolve();
     });
 
     return deferred.promise;
   }
--- a/dom/wifi/test/marionette/head.js
+++ b/dom/wifi/test/marionette/head.js
@@ -579,24 +579,30 @@ let gTestSuite = (function() {
    * @param aSettings
    *        An object of format |{key1: value1, key2: value2, ...}|.
    * @param aAllowError [optional]
    *        A boolean value.  If set to true, an error response won't be treated
    *        as test failure.  Default: false.
    *
    * @return A deferred promise.
    */
-  function setSettings(aSettings, aAllowError) {
-    let request = window.navigator.mozSettings.createLock().set(aSettings);
-    return wrapDomRequestAsPromise(request)
-      .then(function resolve() {
+  function setSettings(aSettings) {
+    let lock = window.navigator.mozSettings.createLock();
+    let request = lock.set(aSettings);
+    let deferred = Promise.defer();
+    lock.onsettingstransactionsuccess = function () {
         ok(true, "setSettings(" + JSON.stringify(aSettings) + ")");
-      }, function reject() {
-        ok(aAllowError, "setSettings(" + JSON.stringify(aSettings) + ")");
-      });
+      deferred.resolve();
+    };
+    lock.onsettingstransactionfailure = function (aEvent) {
+      ok(false, "setSettings(" + JSON.stringify(aSettings) + ")");
+      deferred.reject();
+      throw aEvent.target.error;
+    };
+    return deferred.promise;
   }
 
   /**
    * Set mozSettings value with only one key.
    *
    * Resolve if that mozSettings value is set successfully, reject otherwise.
    *
    * Fulfill params: (none)