dom/telephony/test/marionette/test_incoming_answer_remote_hangup.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/telephony/test/marionette/test_incoming_answer_remote_hangup.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,91 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +MARIONETTE_TIMEOUT = 60000;
     1.8 +MARIONETTE_HEAD_JS = 'head.js';
     1.9 +
    1.10 +let inNumber = "5555551111";
    1.11 +let incomingCall;
    1.12 +
    1.13 +function simulateIncoming() {
    1.14 +  log("Simulating an incoming call.");
    1.15 +
    1.16 +  telephony.onincoming = function onincoming(event) {
    1.17 +    log("Received 'incoming' call event.");
    1.18 +    incomingCall = event.call;
    1.19 +    ok(incomingCall);
    1.20 +    is(incomingCall.number, inNumber);
    1.21 +    is(incomingCall.state, "incoming");
    1.22 +
    1.23 +    is(telephony.calls.length, 1);
    1.24 +    is(telephony.calls[0], incomingCall);
    1.25 +
    1.26 +    emulator.run("gsm list", function(result) {
    1.27 +      log("Call list is now: " + result);
    1.28 +      is(result[0], "inbound from " + inNumber + " : incoming");
    1.29 +      is(result[1], "OK");
    1.30 +      answerIncoming();
    1.31 +    });
    1.32 +  };
    1.33 +  emulator.run("gsm call " + inNumber);
    1.34 +}
    1.35 +
    1.36 +function answerIncoming() {
    1.37 +  log("Answering the incoming call.");
    1.38 +
    1.39 +  let gotConnecting = false;
    1.40 +  incomingCall.onconnecting = function onconnectingIn(event) {
    1.41 +    log("Received 'connecting' call event for incoming call.");
    1.42 +    is(incomingCall, event.call);
    1.43 +    is(incomingCall.state, "connecting");
    1.44 +    gotConnecting = true;
    1.45 +  };
    1.46 +
    1.47 +  incomingCall.onconnected = function onconnectedIn(event) {
    1.48 +    log("Received 'connected' call event for incoming call.");
    1.49 +    is(incomingCall, event.call);
    1.50 +    is(incomingCall.state, "connected");
    1.51 +    ok(gotConnecting);
    1.52 +
    1.53 +    is(incomingCall, telephony.active);
    1.54 +
    1.55 +    emulator.run("gsm list", function(result) {
    1.56 +      log("Call list is now: " + result);
    1.57 +      is(result[0], "inbound from " + inNumber + " : active");
    1.58 +      is(result[1], "OK");
    1.59 +      remoteHangUp();
    1.60 +    });
    1.61 +  };
    1.62 +  incomingCall.answer();
    1.63 +}
    1.64 +
    1.65 +function remoteHangUp() {
    1.66 +  log("Hanging up the call (remotely)");
    1.67 +
    1.68 +  // We get no 'disconnecting' event when remote party hangs-up the call
    1.69 +
    1.70 +  incomingCall.ondisconnected = function ondisconnected(event) {
    1.71 +    log("Received 'disconnected' call event.");
    1.72 +    is(incomingCall, event.call);
    1.73 +    is(incomingCall.state, "disconnected");
    1.74 +
    1.75 +    is(telephony.active, null);
    1.76 +    is(telephony.calls.length, 0);
    1.77 +
    1.78 +    emulator.run("gsm list", function(result) {
    1.79 +      log("Call list is now: " + result);
    1.80 +      is(result[0], "OK");
    1.81 +      cleanUp();
    1.82 +    });
    1.83 +  };
    1.84 +  emulator.run("gsm cancel " + inNumber);
    1.85 +}
    1.86 +
    1.87 +function cleanUp() {
    1.88 +  telephony.onincoming = null;
    1.89 +  finish();
    1.90 +}
    1.91 +
    1.92 +startTest(function() {
    1.93 +  simulateIncoming();
    1.94 +});

mercurial