dom/telephony/test/marionette/test_swap_held_and_active.js

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

mercurial