Bug 1004152 - Delay telephony.dial for 1s in test cases. r=hsinyi, a=test-only
💩💩 backed out by 1c4fdb3d772d 💩 💩
authorSzu-Yu Chen [:aknow] <szchen@mozilla.com>
Wed, 07 May 2014 01:52:00 -0400
changeset 192225 ccde75e4b1af
parent 192224 adafd31af170
child 192226 f59b7498a97f
push id3532
push userryanvm@gmail.com
push date2014-05-08 15:27 +0000
Treeherderresults
reviewershsinyi, test-only
bugs1004152
milestone30.0
Bug 1004152 - Delay telephony.dial for 1s in test cases. r=hsinyi, a=test-only
dom/telephony/test/marionette/head.js
--- a/dom/telephony/test/marionette/head.js
+++ b/dom/telephony/test/marionette/head.js
@@ -42,16 +42,46 @@ let emulator = (function() {
   }
 
   return {
     run: run,
     waitFinish: waitFinish
   };
 }());
 
+// Delay 1s before each telephony.dial()
+// The workaround here should be removed after bug 1005816.
+
+let originalDial;
+
+function delayTelephonyDial() {
+  originalDial = telephony.dial;
+  telephony.dial = function(number, serviceId) {
+    let deferred = Promise.defer();
+
+    let startTime = Date.now();
+    waitFor(function() {
+      originalDial.call(telephony, number, serviceId).then(call => {
+        deferred.resolve(call);
+      }, cause => {
+        deferred.reject(cause);
+      });
+    }, function() {
+      duration = Date.now() - startTime;
+      return (duration >= 1000);
+    });
+
+    return deferred.promise;
+  };
+}
+
+function restoreTelephonyDial() {
+  telephony.dial = originalDial;
+}
+
 /**
  * Telephony related helper functions.
  */
 (function() {
   function checkInitialState() {
     log("Verify initial state.");
     ok(telephony, "telephony");
     is(telephony.active, null, "telephony.active");
@@ -102,25 +132,27 @@ function _startTest(permissions, test) {
   }
 
   function setUp() {
     log("== Test SetUp ==");
     permissionSetUp();
     // Make sure that we get the telephony after adding permission.
     telephony = window.navigator.mozTelephony;
     ok(telephony);
+    delayTelephonyDial();
     return clearCalls().then(checkInitialState);
   }
 
   // Extend finish() with tear down.
   finish = (function() {
     let originalFinish = finish;
 
     function tearDown() {
       log("== Test TearDown ==");
+      restoreTelephonyDial();
       emulator.waitFinish()
         .then(permissionTearDown)
         .then(function() {
           originalFinish.apply(this, arguments);
         });
     }
 
     return tearDown.bind(this);