Bug 766822 - WebTelephony: add tests for hanging up dialing/alerting/holding calls. r=philikon
authorHsinyi Tsai <htsai@mozilla.com>
Wed, 04 Jul 2012 13:46:11 +0800
changeset 98816 5c3fea9f6da6720e9f4222ac402cf56fdec9db97
parent 98815 da0f71229ea5c7e59b0fd789f0cf1d5beafe64e0
child 98817 01a48ccbd15e79b9284ae33be868a7529858e8cb
push id23085
push userryanvm@gmail.com
push dateTue, 10 Jul 2012 22:39:59 +0000
treeherdermozilla-central@340764f48ed2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersphilikon
bugs766822
milestone16.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 766822 - WebTelephony: add tests for hanging up dialing/alerting/holding calls. r=philikon
dom/telephony/Telephony.cpp
dom/telephony/TelephonyCall.cpp
dom/telephony/test/marionette/manifest.ini
dom/telephony/test/marionette/test_outgoing_hangup_alerting.js
dom/telephony/test/marionette/test_outgoing_hangup_held.js
--- a/dom/telephony/Telephony.cpp
+++ b/dom/telephony/Telephony.cpp
@@ -414,16 +414,20 @@ Telephony::CallStateChanged(PRUint32 aCa
 
     // See if this should replace our current active call.
     if (aIsActive) {
       if (aCallState == nsIRadioInterfaceLayer::CALL_STATE_DISCONNECTED) {
         mActiveCall = nsnull;
       } else {
         mActiveCall = modifiedCall;
       }
+    } else {
+      if (mActiveCall && mActiveCall->CallIndex() == aCallIndex) {
+        mActiveCall = nsnull;
+      }
     }
 
     // Change state.
     modifiedCall->ChangeState(aCallState);
 
     return NS_OK;
   }
 
--- a/dom/telephony/TelephonyCall.cpp
+++ b/dom/telephony/TelephonyCall.cpp
@@ -227,22 +227,16 @@ NS_IMETHODIMP
 TelephonyCall::HangUp()
 {
   if (mCallState == nsIRadioInterfaceLayer::CALL_STATE_DISCONNECTING ||
       mCallState == nsIRadioInterfaceLayer::CALL_STATE_DISCONNECTED) {
     NS_WARNING("HangUp on previously disconnected call ignored!");
     return NS_OK;
   }
 
-  if (mCallState == nsIRadioInterfaceLayer::CALL_STATE_HOLDING ||
-      mCallState == nsIRadioInterfaceLayer::CALL_STATE_HELD) {
-    NS_WARNING("HangUp on non-active call ignored!");
-    return NS_OK;
-  }
-
   nsresult rv = mCallState == nsIRadioInterfaceLayer::CALL_STATE_INCOMING ?
                 mTelephony->RIL()->RejectCall(mCallIndex) :
                 mTelephony->RIL()->HangUp(mCallIndex);
   NS_ENSURE_SUCCESS(rv, rv);
 
   ChangeStateInternal(nsIRadioInterfaceLayer::CALL_STATE_DISCONNECTING, true);
   return NS_OK;
 }
--- a/dom/telephony/test/marionette/manifest.ini
+++ b/dom/telephony/test/marionette/manifest.ini
@@ -3,14 +3,16 @@ b2g = true
 browser = false
 qemu = true
 
 [test_incoming_answer_hangup.js]
 [test_incoming_reject.js]
 [test_outgoing_answer_hangup.js]
 [test_incoming_answer_hangup_oncallschanged.js]
 [test_outgoing_answer_hangup_oncallschanged.js]
+[test_outgoing_hangup_alerting.js]
+[test_outgoing_hangup_held.js]
 # Bug 761533
 #[test_outgoing_badNumber.js]
 #expectedfailure = true
 #[test_outgoing_busy.js]
 #expectedfailure = true
 [test_outgoing_reject.js]
new file mode 100644
--- /dev/null
+++ b/dom/telephony/test/marionette/test_outgoing_hangup_alerting.js
@@ -0,0 +1,89 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+MARIONETTE_TIMEOUT = 10000;
+
+const WHITELIST_PREF = "dom.telephony.app.phone.url";
+SpecialPowers.setCharPref(WHITELIST_PREF, window.location.href);
+
+let telephony = window.navigator.mozTelephony;
+let number = "5555552368";
+let outgoing;
+let calls;
+
+function verifyInitialState() {
+  log("Verifying initial state.");
+  ok(telephony);
+  is(telephony.active, null);
+  ok(telephony.calls);
+  is(telephony.calls.length, 0);
+  calls = telephony.calls;
+
+  runEmulatorCmd("gsm list", function(result) {
+    log("Initial call list: " + result);
+    is(result[0], "OK");
+    dial();
+  });
+}
+
+function dial() {
+  log("Make an outgoing call.");
+
+  outgoing = telephony.dial(number);
+  ok(outgoing);
+  is(outgoing.number, number);
+  is(outgoing.state, "dialing");
+
+  is(outgoing, telephony.active);
+  //ok(telephony.calls === calls); // bug 717414
+  is(telephony.calls.length, 1);
+  is(telephony.calls[0], outgoing);
+
+  outgoing.onalerting = function onalerting(event) {
+    log("Received 'alerting' call event.");
+    runEmulatorCmd("gsm list", function(result) {
+      log("Call list is now: " + result);
+      is(result[0], "outbound to  " + number + " : ringing");
+      is(result[1], "OK");
+      hangUp();
+    });
+  };
+}
+
+function hangUp() {
+  log("Hang up the outgoing call.");
+
+  let gotDisconnecting = false;
+
+  outgoing.ondisconnecting = function ondisconnecting(event) {
+    log("Received 'disconnecting' call event.");
+    is(outgoing, event.call);
+    is(outgoing.state, "disconnecting");
+    gotDisconnecting = true;
+  };
+
+  outgoing.ondisconnected = function ondisconnected(event) {
+    log("Received 'disconnected' call event.");
+    is(outgoing, event.call);
+    is(outgoing.state, "disconnected");
+    ok(gotDisconnecting);
+
+    is(telephony.active, null);
+    is(telephony.calls.length, 0);
+
+    runEmulatorCmd("gsm list", function(result) {
+      log("Call list is now: " + result);
+      is(result[0], "OK");
+      cleanUp();
+    });
+  };
+
+  outgoing.hangUp();
+};
+
+function cleanUp() {
+  SpecialPowers.clearUserPref(WHITELIST_PREF);
+  finish();
+}
+
+verifyInitialState();
new file mode 100644
--- /dev/null
+++ b/dom/telephony/test/marionette/test_outgoing_hangup_held.js
@@ -0,0 +1,136 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+MARIONETTE_TIMEOUT = 10000;
+
+const WHITELIST_PREF = "dom.telephony.app.phone.url";
+SpecialPowers.setCharPref(WHITELIST_PREF, window.location.href);
+
+let telephony = window.navigator.mozTelephony;
+let number = "5555552368";
+let outgoing;
+let calls;
+
+function verifyInitialState() {
+  log("Verifying initial state.");
+  ok(telephony);
+  is(telephony.active, null);
+  ok(telephony.calls);
+  is(telephony.calls.length, 0);
+  calls = telephony.calls;
+
+  runEmulatorCmd("gsm list", function(result) {
+    log("Initial call list: " + result);
+    is(result[0], "OK");
+    dial();
+  });
+}
+
+function dial() {
+  log("Make an outgoing call.");
+
+  outgoing = telephony.dial(number);
+  ok(outgoing);
+  is(outgoing.number, number);
+  is(outgoing.state, "dialing");
+
+  is(outgoing, telephony.active);
+  //ok(telephony.calls === calls); // bug 717414
+  is(telephony.calls.length, 1);
+  is(telephony.calls[0], outgoing);
+
+  runEmulatorCmd("gsm list", function(result) {
+    log("Call list is now: " + result);
+    is(result[0], "outbound to  " + number + " : unknown");
+    is(result[1], "OK");
+    answer();
+  });
+}
+
+function answer() {
+  log("Answering the outgoing call.");
+
+  // We get no "connecting" event when the remote party answers the call.
+
+  outgoing.onconnected = function onconnected(event) {
+    log("Received 'connected' call event.");
+    is(outgoing, event.call);
+    is(outgoing.state, "connected");
+
+    is(outgoing, telephony.active);
+
+    runEmulatorCmd("gsm list", function(result) {
+      log("Call list is now: " + result);
+      is(result[0], "outbound to  " + number + " : active");
+      is(result[1], "OK");
+      hold();
+    });
+  };
+  runEmulatorCmd("gsm accept " + number);
+};
+
+function hold() {
+  log("Holding the outgoing call.");
+
+  outgoing.onholding = function onholding(event) {
+    log("Received 'holding' call event.");
+    is(outgoing, event.call);
+    is(outgoing.state, "holding");
+
+    is(outgoing, telephony.active);
+  };
+
+  outgoing.onheld = function onheld(event) {
+    log("Received 'held' call event.");
+    is(outgoing, event.call);
+    is(outgoing.state, "held");
+
+    is(telephony.active, null);
+    is(telephony.calls.length, 1);
+
+    runEmulatorCmd("gsm list", function(result) {
+      log("Call list is now: " + result);
+      is(result[0], "outbound to  " + number + " : held");
+      is(result[1], "OK");
+      hangUp();
+    });
+  };
+  outgoing.hold();
+}
+
+function hangUp() {
+  log("Hanging up the outgoing call.");
+
+  let gotDisconnecting = false;
+  outgoing.ondisconnecting = function ondisconnecting(event) {
+    log("Received disconnecting call event.");
+    is(outgoing, event.call);
+    is(outgoing.state, "disconnecting");
+    gotDisconnecting = true;
+  };
+
+  outgoing.ondisconnected = function ondisconnected(event) {
+    log("Received 'disconnected' call event.");
+    is(outgoing, event.call);
+    is(outgoing.state, "disconnected");
+    ok(gotDisconnecting);
+
+    is(telephony.active, null);
+    is(telephony.calls.length, 0);
+
+    runEmulatorCmd("gsm list", function(result) {
+      log("Call list is now: " + result);
+      is(result[0], "OK");
+      cleanUp();
+    });
+  };
+
+  outgoing.hangUp();
+}
+
+function cleanUp() {
+  SpecialPowers.clearUserPref(WHITELIST_PREF);
+  finish();
+}
+
+verifyInitialState();