Bug 984919 - Part 2: Test DSDS connection conflict. r=hsinyi
authorSzu-Yu Chen (Aknow) <szchen@mozilla.com>
Tue, 01 Apr 2014 08:58:55 -0400
changeset 176377 c94dbcadec711ef208b9400ee6aa20e7ecd4f653
parent 176376 b63903e0338f96a414feb1323ce18474eb8af657
child 176378 c8be375e0c41e75b50781d6d9f1ba2da2482802d
push id5895
push userryanvm@gmail.com
push dateTue, 01 Apr 2014 12:58:03 +0000
treeherderb2g-inbound@c8be375e0c41 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershsinyi
bugs984919
milestone31.0a1
Bug 984919 - Part 2: Test DSDS connection conflict. r=hsinyi
dom/telephony/test/marionette/manifest.ini
dom/telephony/test/marionette/test_dsds_connection_conflict.js
--- a/dom/telephony/test/marionette/manifest.ini
+++ b/dom/telephony/test/marionette/manifest.ini
@@ -41,10 +41,11 @@ disabled = Bug 821927
 [test_multiple_hold.js]
 disabled = Bug 821958
 [test_outgoing_emergency_in_airplane_mode.js]
 [test_emergency_label.js]
 [test_conference.js]
 [test_dsds_default_service_id.js]
 [test_call_mute.js]
 [test_dsds_normal_call.js]
+[test_dsds_connection_conflict.js]
 [test_audiomanager_phonestate.js]
 [test_outgoing_answer_radio_off.js]
new file mode 100644
--- /dev/null
+++ b/dom/telephony/test/marionette/test_dsds_connection_conflict.js
@@ -0,0 +1,83 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+MARIONETTE_TIMEOUT = 60000;
+MARIONETTE_HEAD_JS = 'head.js';
+
+function remoteAnswer(call) {
+  log("Remote answering the call.");
+
+  let deferred = Promise.defer();
+
+  call.onconnected = function onconnected(event) {
+    log("Received 'connected' call event.");
+    call.onconnected = null;
+    deferred.resolve(call);
+  };
+  emulator.run("gsm accept " + call.number);
+
+  return deferred.promise;
+}
+
+function remoteHangUp(call) {
+  log("Remote hanging up the call.");
+
+  let deferred = Promise.defer();
+
+  call.ondisconnected = function ondisconnected(event) {
+    log("Received 'disconnected' call event.");
+    call.ondisconnected = null;
+    deferred.resolve(call);
+  };
+  emulator.run("gsm cancel " + call.number);
+
+  return deferred.promise;
+}
+
+function muxModem(id) {
+  let deferred = Promise.defer();
+
+  emulator.run("mux modem " + id, function() {
+    deferred.resolve();
+  });
+
+  return deferred.promise;
+}
+
+function testNewCallWhenOtherConnectionInUse(firstServiceId, secondServiceId) {
+  log("= testNewCallWhenOtherConnectionInUse =");
+  log("1st call on " + firstServiceId + ", 2nd call on " + secondServiceId);
+
+  let outCall;
+
+  return Promise.resolve()
+    .then(() => muxModem(firstServiceId))
+    .then(() => {
+      return telephony.dial("0912345000", firstServiceId);
+    })
+    .then(call => {
+      outCall = call;
+      is(outCall.serviceId, firstServiceId);
+    })
+    .then(() => remoteAnswer(outCall))
+    .then(() => {
+      return telephony.dial("0912345001", secondServiceId);
+    })
+    .then(() => {
+      log("The promise should not be resolved");
+      ok(false);
+    }, cause => {
+      is(cause, "OtherConnectionInUse");
+    })
+    .then(() => remoteHangUp(outCall));
+}
+
+startDSDSTest(function() {
+  testNewCallWhenOtherConnectionInUse(0, 1)
+    .then(() => testNewCallWhenOtherConnectionInUse(1, 0))
+    .then(() => muxModem(0))
+    .then(null, () => {
+      ok(false, "promise rejects during test.");
+    })
+    .then(finish);
+});