Bug 990472 - Part 3: Test case. r=hsinyi
authorSzu-Yu Chen [:aknow] <szchen@mozilla.com>
Wed, 16 Apr 2014 10:26:51 -0400
changeset 179298 f9157f73f5fce1c452b9d1a1ac1dbfa57c2f1c88
parent 179297 7d26e5a537d86ded99dfc347e542a1fb83159bde
child 179299 c7bbf1562c0e662d0380fdcf794280efa462ba74
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewershsinyi
bugs990472
milestone31.0a1
Bug 990472 - Part 3: Test case. r=hsinyi
dom/telephony/test/marionette/head.js
dom/telephony/test/marionette/manifest.ini
dom/telephony/test/marionette/test_outgoing_when_two_calls_on_line.js
--- a/dom/telephony/test/marionette/head.js
+++ b/dom/telephony/test/marionette/head.js
@@ -379,16 +379,18 @@ let emulator = (function() {
       is(call.serviceId, serviceId);
 
       call.onalerting = function onalerting(event) {
         call.onalerting = null;
         log("Received 'onalerting' call event.");
         checkEventCallState(event, call, "alerting");
         deferred.resolve(call);
       };
+    }, cause => {
+      deferred.reject(cause);
     });
 
     return deferred.promise;
   }
 
   /**
    * Answer an incoming call.
    *
@@ -439,16 +441,48 @@ let emulator = (function() {
       receive("call.onconnected");
     };
     call.answer();
 
     return deferred.promise;
   }
 
   /**
+   * Hold a call.
+   *
+   * @param call
+   *        A TelephonyCall object.
+   * @return A deferred promise.
+   */
+  function hold(call) {
+    log("Putting the call on hold.");
+
+    let deferred = Promise.defer();
+
+    let gotHolding = false;
+    call.onholding = function onholding(event) {
+      log("Received 'holding' call event");
+      call.onholding = null;
+      checkEventCallState(event, call, "holding");
+      gotHolding = true;
+    };
+
+    call.onheld = function onheld(event) {
+      log("Received 'held' call event");
+      call.onheld = null;
+      checkEventCallState(event, call, "held");
+      ok(gotHolding);
+      deferred.resolve(call);
+    };
+    call.hold();
+
+    return deferred.promise;
+  }
+
+  /**
    * Simulate an incoming call.
    *
    * @param number
    *        A string.
    * @return A deferred promise.
    */
   function remoteDial(number) {
     log("Simulating an incoming call.");
@@ -1033,16 +1067,17 @@ let emulator = (function() {
   this.gCheckInitialState = checkInitialState;
   this.gClearCalls = clearCalls;
   this.gOutCallStrPool = outCallStrPool;
   this.gInCallStrPool = inCallStrPool;
   this.gCheckState = checkState;
   this.gCheckAll = checkAll;
   this.gDial = dial;
   this.gAnswer = answer;
+  this.gHold = hold;
   this.gRemoteDial = remoteDial;
   this.gRemoteAnswer = remoteAnswer;
   this.gRemoteHangUp = remoteHangUp;
   this.gRemoteHangUpCalls = remoteHangUpCalls;
   this.gAddCallsToConference = addCallsToConference;
   this.gHoldConference = holdConference;
   this.gResumeConference = resumeConference;
   this.gRemoveCallInConference = removeCallInConference;
--- a/dom/telephony/test/marionette/manifest.ini
+++ b/dom/telephony/test/marionette/manifest.ini
@@ -51,8 +51,9 @@ disabled = Bug 821958
 [test_conference_two_calls.js]
 [test_conference_add_error.js]
 [test_conference_remove_error.js]
 [test_conference_two_hangup_one.js]
 [test_conference_two_hold_resume.js]
 [test_conference_two_remove_one.js]
 [test_conference_three_hangup_one.js]
 [test_conference_three_remove_one.js]
+[test_outgoing_when_two_calls_on_line.js]
new file mode 100644
--- /dev/null
+++ b/dom/telephony/test/marionette/test_outgoing_when_two_calls_on_line.js
@@ -0,0 +1,34 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+MARIONETTE_TIMEOUT = 60000;
+MARIONETTE_HEAD_JS = 'head.js';
+
+function testReject3rdCall() {
+  let outCall1;
+  let outCall2;
+
+  return gDial("0912345001")
+    .then(call => { outCall1 = call; })
+    .then(() => gRemoteAnswer(outCall1))
+    .then(() => gHold(outCall1))
+    .then(() => gDial("0912345002"))
+    .then(call => { outCall2 = call; })
+    .then(() => gRemoteAnswer(outCall2))
+    .then(() => gDial("0912345003"))
+    .then(call => {
+      ok(false, "The dial request should be rejected");
+    }, cause => {
+      log("Reject 3rd call, cuase: " + cause);
+      is(cause, "InvalidStateError");
+    })
+    .then(() => gRemoteHangUpCalls([outCall1, outCall2]));
+}
+
+startTest(function() {
+  testReject3rdCall()
+    .then(null, () => {
+      ok(false, 'promise rejects during test.');
+    })
+    .then(finish);
+});