Bug 1191237 - Part 2: Stablize |test_TelephonyUtils.js|. r=aknow
authorBen Hsu <driftersprt@gmail.com>
Thu, 06 Aug 2015 10:26:00 +0200
changeset 288430 8fdce5ed302ae77e6a6c0b1bf3c190018e27aef7
parent 288429 9ba92e1ffa2d21377c984922cf6d5e855ab788bd
child 288431 b37ca53168cf1c1425e99577347dda3968008777
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaknow
bugs1191237
milestone42.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 1191237 - Part 2: Stablize |test_TelephonyUtils.js|. r=aknow
dom/telephony/test/marionette/test_TelephonyUtils.js
--- a/dom/telephony/test/marionette/test_TelephonyUtils.js
+++ b/dom/telephony/test/marionette/test_TelephonyUtils.js
@@ -28,25 +28,28 @@ function dial() {
   return new Promise(resolve => {
     TelephonyService.dial(0, number, false, {
       QueryInterface: XPCOMUtils.generateQI([Ci.nsITelephonyDialCallback]),
       notifyDialCallSuccess: function() { resolve(); }
     });
   });
 }
 
-function waitForStateChanged() {
+function waitForStateChanged(aPredicate) {
   return new Promise(resolve => {
     let listener = {
       QueryInterface: XPCOMUtils.generateQI([Ci.nsITelephonyListener]),
 
       callStateChanged: function(length, allInfo) {
-        resolve(allInfo);
-        TelephonyService.unregisterListener(listener);
+        if (aPredicate(allInfo)) {
+          resolve(allInfo);
+          TelephonyService.unregisterListener(listener);
+        }
       },
+
       conferenceCallStateChanged: function() {},
       supplementaryServiceNotification: function() {},
       notifyError: function() {},
       notifyCdmaCallWaiting: function() {},
       notifyConferenceError: function() {}
     };
 
     TelephonyService.registerListener(listener);
@@ -63,29 +66,36 @@ function test_noCall()   {
 function test_oneCall() {
   log("== test_oneCall ==");
 
   return dial()
     .then(() => {
       is(TelephonyUtils.hasAnyCalls(), true, "hasAnyCalls");
       is(TelephonyUtils.hasConnectedCalls(), false, "hasConnectedCalls");
     })
+    .then(() => waitForStateChanged(aAllInfo => {
+      return aAllInfo[0].callState === Ci.nsITelephonyService.CALL_STATE_ALERTING;
+    }))
     .then(() => {
-      let p = waitForStateChanged();
+      let p = waitForStateChanged(aAllInfo => {
+        return aAllInfo[0].callState === Ci.nsITelephonyService.CALL_STATE_CONNECTED;
+      });
       emulator.runCmd("gsm accept " + number);
       return p;
     })
-    .then(allInfo => {
-      is(allInfo[0].callState, Ci.nsITelephonyService.CALL_STATE_CONNECTED);
+    .then(() => {
       is(TelephonyUtils.hasAnyCalls(), true, "hasAnyCalls");
       is(TelephonyUtils.hasConnectedCalls(), true, "hasConnectedCalls");
     })
     .then(() => {
       let p = TelephonyUtils.waitForNoCalls();
       emulator.runCmd("gsm cancel " + number);
       return p;
     });
 }
 
-test_noCall()
-  .then(test_oneCall)
-  .catch(error => ok(false, "Promise reject: " + error))
-  .then(finish);
+startTest(function() {
+  return Promise.resolve()
+    .then(test_noCall)
+    .then(test_oneCall)
+    .catch(error => ok(false, "Promise reject: " + error))
+    .then(finish);
+});