dom/telephony/test/marionette/test_incoming_hold_resume.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_hold_resume.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,163 @@
     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 number = "5555551234";
    1.11 +let connectedCalls;
    1.12 +let incomingCall;
    1.13 +
    1.14 +function simulateIncoming() {
    1.15 +  log("Simulating an incoming call.");
    1.16 +
    1.17 +  telephony.onincoming = function onincoming(event) {
    1.18 +    log("Received 'incoming' call event.");
    1.19 +    incomingCall = event.call;
    1.20 +    ok(incomingCall);
    1.21 +    is(incomingCall.number, number);
    1.22 +    is(incomingCall.state, "incoming");
    1.23 +
    1.24 +    is(telephony.calls.length, 1);
    1.25 +    is(telephony.calls[0], incomingCall);
    1.26 +
    1.27 +    emulator.run("gsm list", function(result) {
    1.28 +      log("Call list is now: " + result);
    1.29 +      is(result[0], "inbound from " + number + " : incoming");
    1.30 +      is(result[1], "OK");
    1.31 +      answer();
    1.32 +    });
    1.33 +  };
    1.34 +  emulator.run("gsm call " + number);
    1.35 +}
    1.36 +
    1.37 +function answer() {
    1.38 +  log("Answering the incoming call.");
    1.39 +
    1.40 +  let gotConnecting = false;
    1.41 +  incomingCall.onconnecting = function onconnecting(event) {
    1.42 +    log("Received 'connecting' call event.");
    1.43 +    is(incomingCall, event.call);
    1.44 +    is(incomingCall.state, "connecting");
    1.45 +    gotConnecting = true;
    1.46 +  };
    1.47 +
    1.48 +  incomingCall.onconnected = function onconnected(event) {
    1.49 +    log("Received 'connected' call event.");
    1.50 +    is(incomingCall, event.call);
    1.51 +    is(incomingCall.state, "connected");
    1.52 +    ok(gotConnecting);
    1.53 +
    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 " + number + " : active");
    1.59 +      is(result[1], "OK");
    1.60 +      hold();
    1.61 +    });
    1.62 +  };
    1.63 +  incomingCall.answer();
    1.64 +}
    1.65 +
    1.66 +function hold() {
    1.67 +  log("Putting the call on hold.");
    1.68 +
    1.69 +  let gotHolding = false;
    1.70 +  incomingCall.onholding = function onholding(event) {
    1.71 +    log("Received 'holding' call event");
    1.72 +    is(incomingCall, event.call);
    1.73 +    is(incomingCall.state, "holding");
    1.74 +    gotHolding = true;
    1.75 +  };
    1.76 +
    1.77 +  incomingCall.onheld = function onheld(event) {
    1.78 +    log("Received 'held' call event");
    1.79 +    is(incomingCall, event.call);
    1.80 +    is(incomingCall.state, "held");
    1.81 +    ok(gotHolding);
    1.82 +
    1.83 +    is(telephony.active, null);
    1.84 +    is(telephony.calls.length, 1);
    1.85 +    is(telephony.calls[0], incomingCall);
    1.86 +
    1.87 +    emulator.run("gsm list", function(result) {
    1.88 +      log("Call list is now: " + result);
    1.89 +      is(result[0], "inbound from " + number + " : held");
    1.90 +      is(result[1], "OK");
    1.91 +      // Wait on hold for a couple of seconds
    1.92 +      log("Pausing 2 seconds while on hold");
    1.93 +      setTimeout(resume, 2000);
    1.94 +    });
    1.95 +  };
    1.96 +  incomingCall.hold();
    1.97 +}
    1.98 +
    1.99 +function resume() {
   1.100 +  log("Resuming the held call.");
   1.101 +
   1.102 +  let gotResuming = false;
   1.103 +  incomingCall.onresuming = function onresuming(event) {
   1.104 +    log("Received 'resuming' call event");
   1.105 +    is(incomingCall, event.call);
   1.106 +    is(incomingCall.state, "resuming");
   1.107 +    gotResuming = true;
   1.108 +  };
   1.109 +
   1.110 +  incomingCall.onconnected = function onconnected(event) {
   1.111 +    log("Received 'connected' call event");
   1.112 +    is(incomingCall, event.call);
   1.113 +    is(incomingCall.state, "connected");
   1.114 +    ok(gotResuming);
   1.115 +
   1.116 +    is(incomingCall, telephony.active);
   1.117 +    is(telephony.calls.length, 1);
   1.118 +    is(telephony.calls[0], incomingCall);
   1.119 +
   1.120 +    emulator.run("gsm list", function(result) {
   1.121 +      log("Call list is now: " + result);
   1.122 +      is(result[0], "inbound from " + number + " : active");
   1.123 +      is(result[1], "OK");
   1.124 +      hangUp();
   1.125 +    });
   1.126 +  };
   1.127 +  incomingCall.resume();
   1.128 +}
   1.129 +
   1.130 +function hangUp() {
   1.131 +  log("Hanging up the incoming call.");
   1.132 +
   1.133 +  let gotDisconnecting = false;
   1.134 +  incomingCall.ondisconnecting = function ondisconnecting(event) {
   1.135 +    log("Received 'disconnecting' call event.");
   1.136 +    is(incomingCall, event.call);
   1.137 +    is(incomingCall.state, "disconnecting");
   1.138 +    gotDisconnecting = true;
   1.139 +  };
   1.140 +
   1.141 +  incomingCall.ondisconnected = function ondisconnected(event) {
   1.142 +    log("Received 'disconnected' call event.");
   1.143 +    is(incomingCall, event.call);
   1.144 +    is(incomingCall.state, "disconnected");
   1.145 +    ok(gotDisconnecting);
   1.146 +
   1.147 +    is(telephony.active, null);
   1.148 +    is(telephony.calls.length, 0);
   1.149 +
   1.150 +    emulator.run("gsm list", function(result) {
   1.151 +      log("Call list is now: " + result);
   1.152 +      is(result[0], "OK");
   1.153 +      cleanUp();
   1.154 +    });
   1.155 +  };
   1.156 +  incomingCall.hangUp();
   1.157 +}
   1.158 +
   1.159 +function cleanUp() {
   1.160 +  telephony.onincoming = null;
   1.161 +  finish();
   1.162 +}
   1.163 +
   1.164 +startTest(function() {
   1.165 +  simulateIncoming();
   1.166 +});

mercurial