dom/telephony/test/marionette/test_outgoing_already_held.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* Any copyright is dedicated to the Public Domain.
     2  * http://creativecommons.org/publicdomain/zero/1.0/ */
     4 MARIONETTE_TIMEOUT = 60000;
     5 MARIONETTE_HEAD_JS = 'head.js';
     7 let inNumber = "5555551111";
     8 let outNumber = "5555552222";
     9 let incomingCall;
    10 let outgoingCall;
    12 function simulateIncoming() {
    13   log("Simulating an incoming call.");
    15   telephony.onincoming = function onincoming(event) {
    16     log("Received 'incoming' call event.");
    17     incomingCall = event.call;
    18     ok(incomingCall);
    19     is(incomingCall.number, inNumber);
    20     is(incomingCall.state, "incoming");
    22     is(telephony.calls.length, 1);
    23     is(telephony.calls[0], incomingCall);
    25     // Wait for emulator to catch up before continuing
    26     waitFor(verifyCallList,function() {
    27       return(rcvdEmulatorCallback);
    28     });
    29   };
    31   let rcvdEmulatorCallback = false;
    32   emulator.run("gsm call " + inNumber, function(result) {
    33     is(result[0], "OK", "emulator callback");
    34     rcvdEmulatorCallback = true;
    35   });
    36 }
    38 function verifyCallList(){
    39   emulator.run("gsm list", function(result) {
    40     log("Call list is now: " + result);
    41     is(result[0], "inbound from " + inNumber + " : incoming");
    42     is(result[1], "OK");
    43     answerIncoming();
    44   });
    45 }
    47 function answerIncoming() {
    48   log("Answering the incoming call.");
    50   let gotConnecting = false;
    51   incomingCall.onconnecting = function onconnectingIn(event) {
    52     log("Received 'connecting' call event for original (incoming) call.");
    53     is(incomingCall, event.call);
    54     is(incomingCall.state, "connecting");
    55     gotConnecting = true;
    56   };
    58   incomingCall.onconnected = function onconnectedIn(event) {
    59     log("Received 'connected' call event for original (incoming) call.");
    60     is(incomingCall, event.call);
    61     is(incomingCall.state, "connected");
    62     ok(gotConnecting);
    64     is(incomingCall, telephony.active);
    66     emulator.run("gsm list", function(result) {
    67       log("Call list is now: " + result);
    68       is(result[0], "inbound from " + inNumber + " : active");
    69       is(result[1], "OK");
    70       holdCall();
    71     });
    72   };
    73   incomingCall.answer();
    74 }
    76 // Put the original (incoming) call on hold
    77 function holdCall(){
    78   log("Putting the original (incoming) call on hold.");
    80   let gotHolding = false;
    81   incomingCall.onholding = function onholding(event) {
    82     log("Received 'holding' call event");
    83     is(incomingCall, event.call);
    84     is(incomingCall.state, "holding");
    85     gotHolding = true;
    86   };
    88   incomingCall.onheld = function onheld(event) {
    89     log("Received 'held' call event");
    90     is(incomingCall, event.call);
    91     is(incomingCall.state, "held");
    92     ok(gotHolding);
    94     is(telephony.active, null);
    95     is(telephony.calls.length, 1);
    96     is(telephony.calls[0], incomingCall);
    98     emulator.run("gsm list", function(result) {
    99       log("Call list is now: " + result);
   100       is(result[0], "inbound from " + inNumber + " : held");
   101       is(result[1], "OK");
   102       dial();
   103     });
   104   };
   105   incomingCall.hold();
   106 }
   108 // With one call on hold, make outgoing call
   109 function dial() {
   110   log("Making an outgoing call (while have one call already held).");
   112   telephony.dial(outNumber).then(call => {
   113     outgoingCall = call;
   114     ok(outgoingCall);
   115     is(outgoingCall.number, outNumber);
   116     is(outgoingCall.state, "dialing");
   118     is(outgoingCall, telephony.active);
   119     is(telephony.calls.length, 2);
   120     is(telephony.calls[0], incomingCall);
   121     is(telephony.calls[1], outgoingCall);
   123     outgoingCall.onalerting = function onalerting(event) {
   124       log("Received 'onalerting' call event.");
   125       is(outgoingCall, event.call);
   126       is(outgoingCall.state, "alerting");
   128       emulator.run("gsm list", function(result) {
   129         log("Call list is now: " + result);
   130         is(result[0], "inbound from " + inNumber + " : held");
   131         is(result[1], "outbound to  " + outNumber + " : ringing");
   132         is(result[2], "OK");
   133         answerOutgoing();
   134       });
   135     };
   136   });
   137 }
   139 // Have the outgoing call answered
   140 function answerOutgoing() {
   141   log("Answering the outgoing/2nd call");
   143   // We get no "connecting" event when the remote party answers the call.
   144   outgoingCall.onconnected = function onconnectedOut(event) {
   145     log("Received 'connected' call event for outgoing/2nd call.");
   146     is(outgoingCall, event.call);
   147     is(outgoingCall.state, "connected");
   149     is(outgoingCall, telephony.active);
   151     // Wait for emulator to catch up before continuing
   152     waitFor(checkCallList,function() {
   153       return(rcvdEmulatorCallback);
   154     });
   155   };
   157   let rcvdEmulatorCallback = false;
   158   emulator.run("gsm accept " + outNumber, function(result) {
   159     is(result[0], "OK", "emulator callback");
   160     rcvdEmulatorCallback = true;
   161   });
   162 }
   164 function checkCallList(){
   165   emulator.run("gsm list", function(result) {
   166     log("Call list is now: " + result);
   167     is(result[0], "inbound from " + inNumber + " : held");
   168     is(result[1], "outbound to  " + outNumber + " : active");
   169     is(result[2], "OK");
   170     hangUpIncoming();
   171   });
   172 }
   174 // Hang-up the original incoming call, which is now held
   175 function hangUpIncoming() {
   176   log("Hanging up the original incoming (now held) call.");
   178   let gotDisconnecting = false;
   179   incomingCall.ondisconnecting = function ondisconnectingIn(event) {
   180     log("Received 'disconnecting' call event for original (incoming) call.");
   181     is(incomingCall, event.call);
   182     is(incomingCall.state, "disconnecting");
   183     gotDisconnecting = true;
   184   };
   186   incomingCall.ondisconnected = function ondisconnectedIn(event) {
   187     log("Received 'disconnected' call event for original (incoming) call.");
   188     is(incomingCall, event.call);
   189     is(incomingCall.state, "disconnected");
   190     ok(gotDisconnecting);
   192     // Now back to one call
   193     is(telephony.active, outgoingCall);
   194     is(telephony.calls.length, 1);
   195     is(telephony.calls[0], outgoingCall);
   197     emulator.run("gsm list", function(result) {
   198       log("Call list is now: " + result);
   199       is(result[0], "outbound to  " + outNumber + " : active");
   200       is(result[1], "OK");
   201       hangUpOutgoing();
   202     });
   203   };
   204   incomingCall.hangUp();
   205 }
   207 // Hang-up the remaining (outgoing) call
   208 function hangUpOutgoing() {
   209   log("Hanging up the remaining (outgoing) call.");
   211   let gotDisconnecting = false;
   212   outgoingCall.ondisconnecting = function ondisconnectingOut(event) {
   213     log("Received 'disconnecting' call event for remaining (outgoing) call.");
   214     is(outgoingCall, event.call);
   215     is(outgoingCall.state, "disconnecting");
   216     gotDisconnecting = true;
   217   };
   219   outgoingCall.ondisconnected = function ondisconnectedOut(event) {
   220     log("Received 'disconnected' call event for remaining (outgoing) call.");
   221     is(outgoingCall, event.call);
   222     is(outgoingCall.state, "disconnected");
   223     ok(gotDisconnecting);
   225     // Now no calls
   226     is(telephony.active, null);
   227     is(telephony.calls.length, 0);
   229     emulator.run("gsm list", function(result) {
   230       log("Call list is now: " + result);
   231       is(result[0], "OK");
   232       cleanUp();
   233     });
   234   };
   235   outgoingCall.hangUp();
   236 }
   238 function cleanUp() {
   239   telephony.onincoming = null;
   240   finish();
   241 }
   243 startTest(function() {
   244   simulateIncoming();
   245 });

mercurial