Bug 1004152 - Delay telephony.dial for 1s in test cases. r=hsinyi, a=test-only
authorSzu-Yu Chen [:aknow] <szchen@mozilla.com>
Wed, 07 May 2014 01:52:00 -0400
changeset 199098 4de789de4abc32c215becefc8bb0ebd5143bfd54
parent 199097 4c247bfe9d75c38ff58c3166281e1fd53d5b1678
child 199099 f578c5b407d9694fa3c0bf99166a070ec866d2ed
push id3624
push userasasaki@mozilla.com
push dateMon, 09 Jun 2014 21:49:01 +0000
treeherdermozilla-beta@b1a5da15899a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershsinyi, test-only
bugs1004152
milestone31.0a2
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
@@ -43,16 +43,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() {
   /**
    * @return Promise
    */
   function clearCalls() {
@@ -1104,27 +1134,29 @@ 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();
     conference = telephony.conferenceGroup;
     ok(conference);
     return gClearCalls().then(gCheckInitialState);
   }
 
   // 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);