dom/telephony/test/marionette/test_multiple_hold.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/telephony/test/marionette/test_multiple_hold.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,275 @@
     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 outNumber = "5555552222";
    1.12 +let incomingCall;
    1.13 +let outgoingCall;
    1.14 +
    1.15 +function simulateIncoming() {
    1.16 +  log("Simulating an incoming call.");
    1.17 +
    1.18 +  telephony.onincoming = function onincoming(event) {
    1.19 +    log("Received 'incoming' call event.");
    1.20 +    incomingCall = event.call;
    1.21 +    ok(incomingCall);
    1.22 +    is(incomingCall.number, inNumber);
    1.23 +    is(incomingCall.state, "incoming");
    1.24 +
    1.25 +    is(telephony.calls.length, 1);
    1.26 +    is(telephony.calls[0], incomingCall);
    1.27 +
    1.28 +    emulator.run("gsm list", function(result) {
    1.29 +      log("Call list is now: " + result);
    1.30 +      is(result[0], "inbound from " + inNumber + " : incoming");
    1.31 +      is(result[1], "OK");
    1.32 +      answerIncoming();
    1.33 +    });
    1.34 +  };
    1.35 +  emulator.run("gsm call " + inNumber);
    1.36 +}
    1.37 +
    1.38 +function answerIncoming() {
    1.39 +  log("Answering the incoming call.");
    1.40 +
    1.41 +  let gotConnecting = false;
    1.42 +  incomingCall.onconnecting = function onconnectingIn(event) {
    1.43 +    log("Received 'connecting' call event for original (incoming) call.");
    1.44 +    is(incomingCall, event.call);
    1.45 +    is(incomingCall.state, "connecting");
    1.46 +    gotConnecting = true;
    1.47 +  };
    1.48 +
    1.49 +  incomingCall.onconnected = function onconnectedIn(event) {
    1.50 +    log("Received 'connected' call event for original (incoming) call.");
    1.51 +    is(incomingCall, event.call);
    1.52 +    is(incomingCall.state, "connected");
    1.53 +    ok(gotConnecting);
    1.54 +    is(incomingCall, telephony.active);
    1.55 +
    1.56 +    emulator.run("gsm list", function(result) {
    1.57 +      log("Call list is now: " + result);
    1.58 +      is(result[0], "inbound from " + inNumber + " : active");
    1.59 +      is(result[1], "OK");
    1.60 +      holdCall();
    1.61 +    });
    1.62 +  };
    1.63 +  incomingCall.answer();
    1.64 +}
    1.65 +
    1.66 +// Put the original (incoming) call on hold
    1.67 +function holdCall() {
    1.68 +  log("Putting the original (incoming) call on hold.");
    1.69 +
    1.70 +  let gotHolding = false;
    1.71 +  incomingCall.onholding = function onholding(event) {
    1.72 +    log("Received 'holding' call event");
    1.73 +    is(incomingCall, event.call);
    1.74 +    is(incomingCall.state, "holding");
    1.75 +    gotHolding = true;
    1.76 +  };
    1.77 +
    1.78 +  incomingCall.onheld = function onheld(event) {
    1.79 +    log("Received 'held' call event");
    1.80 +    is(incomingCall, event.call);
    1.81 +    is(incomingCall.state, "held");
    1.82 +    ok(gotHolding);
    1.83 +
    1.84 +    is(telephony.active, null);
    1.85 +    is(telephony.calls.length, 1);
    1.86 +    is(telephony.calls[0], incomingCall);
    1.87 +
    1.88 +    emulator.run("gsm list", function(result) {
    1.89 +      log("Call list is now: " + result);
    1.90 +      is(result[0], "inbound from " + inNumber + " : held");
    1.91 +      is(result[1], "OK");
    1.92 +      dial();
    1.93 +    });
    1.94 +  };
    1.95 +  incomingCall.hold();
    1.96 +}
    1.97 +
    1.98 +// With one call on hold, make outgoing call
    1.99 +function dial() {
   1.100 +  log("Making an outgoing call (while have one call already held).");
   1.101 +
   1.102 +  telephony.dial(outNumber).then(call => {
   1.103 +    outgoingCall = call;
   1.104 +    ok(outgoingCall);
   1.105 +    is(outgoingCall.number, outNumber);
   1.106 +    is(outgoingCall.state, "dialing");
   1.107 +    is(outgoingCall, telephony.active);
   1.108 +    is(telephony.calls.length, 2);
   1.109 +    is(telephony.calls[0], incomingCall);
   1.110 +    is(telephony.calls[1], outgoingCall);
   1.111 +
   1.112 +    outgoingCall.onalerting = function onalerting(event) {
   1.113 +      log("Received 'onalerting' call event.");
   1.114 +      is(outgoingCall, event.call);
   1.115 +      is(outgoingCall.state, "alerting");
   1.116 +
   1.117 +      emulator.run("gsm list", function(result) {
   1.118 +        log("Call list is now: " + result);
   1.119 +        is(result[0], "inbound from " + inNumber + " : held");
   1.120 +        is(result[1], "outbound to  " + outNumber + " : ringing");
   1.121 +        is(result[2], "OK");
   1.122 +        answerOutgoing();
   1.123 +      });
   1.124 +    };
   1.125 +  });
   1.126 +}
   1.127 +
   1.128 +// Have the outgoing call answered
   1.129 +function answerOutgoing() {
   1.130 +  log("Answering the outgoing/2nd call");
   1.131 +
   1.132 +  // We get no "connecting" event when the remote party answers the call.
   1.133 +  outgoingCall.onconnected = function onconnectedOut(event) {
   1.134 +    log("Received 'connected' call event for outgoing/2nd call.");
   1.135 +    is(outgoingCall, event.call);
   1.136 +    is(outgoingCall.state, "connected");
   1.137 +    is(outgoingCall, telephony.active);
   1.138 +
   1.139 +    emulator.run("gsm list", function(result) {
   1.140 +      log("Call list is now: " + result);
   1.141 +      is(result[0], "inbound from " + inNumber + " : held");
   1.142 +      is(result[1], "outbound to  " + outNumber + " : active");
   1.143 +      is(result[2], "OK");
   1.144 +      holdSecondCall();
   1.145 +    });
   1.146 +  };
   1.147 +  emulator.run("gsm accept " + outNumber);
   1.148 +}
   1.149 +
   1.150 +// With one held call and one active, hold the active one; expect the first
   1.151 +// (held) call to automatically become active, and the 2nd call to go on hold
   1.152 +function holdSecondCall() {
   1.153 +  let firstCallReconnected = false;
   1.154 +  let secondCallHeld = false;
   1.155 +
   1.156 +  log("Putting the 2nd (outgoing) call on hold.");
   1.157 +
   1.158 +  // Since first call will become connected again, setup handler
   1.159 +  incomingCall.onconnected = function onreconnected(event) {
   1.160 +    log("Received 'connected' call event for original (incoming) call.");
   1.161 +    is(incomingCall, event.call);
   1.162 +    is(incomingCall.state, "connected");
   1.163 +    is(incomingCall, telephony.active);
   1.164 +    firstCallReconnected = true;
   1.165 +    if (firstCallReconnected && secondCallHeld) {
   1.166 +      verifyCalls();
   1.167 +    }
   1.168 +  };
   1.169 +
   1.170 +  // Handlers for holding 2nd call
   1.171 +  let gotHolding = false;
   1.172 +  outgoingCall.onholding = function onholdingOut(event) {
   1.173 +    log("Received 'holding' call event for 2nd call.");
   1.174 +    is(outgoingCall, event.call);
   1.175 +    is(outgoingCall.state, "holding");
   1.176 +    gotHolding = true;
   1.177 +  };
   1.178 +
   1.179 +  outgoingCall.onheld = function onheldOut(event) {
   1.180 +    log("Received 'held' call event for 2nd call.");
   1.181 +    is(outgoingCall, event.call);
   1.182 +    is(outgoingCall.state, "held");
   1.183 +    ok(gotHolding);
   1.184 +    secondCallHeld = true;
   1.185 +    if (firstCallReconnected && secondCallHeld) {
   1.186 +      verifyCalls();
   1.187 +    }
   1.188 +  };
   1.189 +  outgoingCall.hold();
   1.190 +}
   1.191 +
   1.192 +function verifyCalls() {
   1.193 +  is(telephony.active, incomingCall);
   1.194 +  is(telephony.calls.length, 2);
   1.195 +  is(telephony.calls[0], incomingCall);
   1.196 +  is(telephony.calls[1], outgoingCall);
   1.197 +
   1.198 +  emulator.run("gsm list", function(result) {
   1.199 +    log("Call list is now: " + result);
   1.200 +    is(result[0], "inbound from " + inNumber + " : active");
   1.201 +    is(result[1], "outbound to  " + outNumber + " : held");
   1.202 +    is(result[2], "OK");
   1.203 +    hangUpIncoming();
   1.204 +  });
   1.205 +}
   1.206 +
   1.207 +// Hang-up the original incoming call, which is now active
   1.208 +function hangUpIncoming() {
   1.209 +  log("Hanging up the original incoming (now active) call.");
   1.210 +
   1.211 +  let gotDisconnecting = false;
   1.212 +  incomingCall.ondisconnecting = function ondisconnectingIn(event) {
   1.213 +    log("Received 'disconnecting' call event for original (incoming) call.");
   1.214 +    is(incomingCall, event.call);
   1.215 +    is(incomingCall.state, "disconnecting");
   1.216 +    gotDisconnecting = true;
   1.217 +  };
   1.218 +
   1.219 +  incomingCall.ondisconnected = function ondisconnectedIn(event) {
   1.220 +    log("Received 'disconnected' call event for original (incoming) call.");
   1.221 +    is(incomingCall, event.call);
   1.222 +    is(incomingCall.state, "disconnected");
   1.223 +    ok(gotDisconnecting);
   1.224 +
   1.225 +    // Now back to one call
   1.226 +    is(telephony.active, null);
   1.227 +    is(telephony.calls.length, 1);
   1.228 +    is(telephony.calls[0], outgoingCall);
   1.229 +
   1.230 +    emulator.run("gsm list", function(result) {
   1.231 +      log("Call list is now: " + result);
   1.232 +      is(result[0], "outbound to  " + outNumber + " : held");
   1.233 +      is(result[1], "OK");
   1.234 +      hangUpOutgoing();
   1.235 +    });
   1.236 +  };
   1.237 +  incomingCall.hangUp();
   1.238 +}
   1.239 +
   1.240 +// Hang-up the remaining (outgoing) call, which is held
   1.241 +function hangUpOutgoing() {
   1.242 +  log("Hanging up the remaining (outgoing) held call.");
   1.243 +
   1.244 +  let gotDisconnecting = false;
   1.245 +  outgoingCall.ondisconnecting = function ondisconnectingOut(event) {
   1.246 +    log("Received 'disconnecting' call event for remaining (outgoing) call.");
   1.247 +    is(outgoingCall, event.call);
   1.248 +    is(outgoingCall.state, "disconnecting");
   1.249 +    gotDisconnecting = true;
   1.250 +  };
   1.251 +
   1.252 +  outgoingCall.ondisconnected = function ondisconnectedOut(event) {
   1.253 +    log("Received 'disconnected' call event for remaining (outgoing) call.");
   1.254 +    is(outgoingCall, event.call);
   1.255 +    is(outgoingCall.state, "disconnected");
   1.256 +    ok(gotDisconnecting);
   1.257 +
   1.258 +    // Now no calls
   1.259 +    is(telephony.active, null);
   1.260 +    is(telephony.calls.length, 0);
   1.261 +
   1.262 +    emulator.run("gsm list", function(result) {
   1.263 +      log("Call list is now: " + result);
   1.264 +      is(result[0], "OK");
   1.265 +      cleanUp();
   1.266 +    });
   1.267 +  };
   1.268 +  outgoingCall.hangUp();
   1.269 +}
   1.270 +
   1.271 +function cleanUp() {
   1.272 +  telephony.onincoming = null;
   1.273 +  finish();
   1.274 +}
   1.275 +
   1.276 +startTest(function() {
   1.277 +  simulateIncoming();
   1.278 +});

mercurial