dom/telephony/test/marionette/test_incoming_answer_hangup_oncallschanged.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 number = "5555552368";
     8 let incoming;
    10 function simulateIncoming() {
    11   log("Simulating an incoming call.");
    13   telephony.oncallschanged = function oncallschanged(event) {
    14     log("Received 'callschanged' event.");
    16     if (!event.call) {
    17       log("Notifying calls array is loaded. No call information accompanies.");
    18       return;
    19     }
    21     telephony.oncallschanged = null;
    23     incoming = event.call;
    24     ok(incoming);
    25     is(incoming.number, number);
    26     is(incoming.state, "incoming");
    28     is(telephony.calls.length, 1);
    29     is(telephony.calls[0], incoming);
    31     emulator.run("gsm list", function(result) {
    32       log("Call list is now: " + result);
    33       is(result[0], "inbound from " + number + " : incoming");
    34       is(result[1], "OK");
    35       answer();
    36     });
    37   };
    39   emulator.run("gsm call " + number);
    40 }
    42 function answer() {
    43   log("Answering the incoming call.");
    45   let gotConnecting = false;
    46   incoming.onconnecting = function onconnecting(event) {
    47     log("Received 'connecting' call event.");
    48     is(incoming, event.call);
    49     is(incoming.state, "connecting");
    51     // Incoming call is not 'active' until its state becomes 'connected'.
    52     isnot(incoming, telephony.active);
    53     gotConnecting = true;
    54   };
    56   incoming.onconnected = function onconnected(event) {
    57     log("Received 'connected' call event.");
    58     is(incoming, event.call);
    59     is(incoming.state, "connected");
    60     ok(gotConnecting);
    62     is(incoming, telephony.active);
    64     emulator.run("gsm list", function(result) {
    65       log("Call list is now: " + result);
    66       is(result[0], "inbound from " + number + " : active");
    67       is(result[1], "OK");
    68       hangUp();
    69     });
    70   };
    71   incoming.answer();
    72 }
    74 function hangUp() {
    75   log("Hanging up the incoming call.");
    77   // Should received 'diconnecting', 'callschanged', 'disconnected' events in
    78   // order.
    79   let gotDisconnecting = false;
    80   let gotCallschanged = false;
    82   incoming.ondisconnecting = function ondisconnecting(event) {
    83     log("Received 'disconnecting' call event.");
    84     is(incoming, event.call);
    85     is(incoming.state, "disconnecting");
    86     gotDisconnecting = true;
    87   };
    89   telephony.oncallschanged = function oncallschanged(event) {
    90     log("Received 'callschanged' event.");
    92     if (!event.call) {
    93       log("Notifying calls array is loaded. No call information accompanies.");
    94       return;
    95     }
    97     is(incoming, event.call);
    98     is(incoming.state, "disconnected");
    99     is(telephony.active, null);
   100     is(telephony.calls.length, 0);
   101     gotCallschanged = true;
   102   };
   104   incoming.ondisconnected = function ondisconnected(event) {
   105     log("Received 'disconnected' call event.");
   106     is(incoming, event.call);
   107     is(incoming.state, "disconnected");
   108     ok(gotDisconnecting);
   109     ok(gotCallschanged);
   111     is(telephony.active, null);
   112     is(telephony.calls.length, 0);
   114     emulator.run("gsm list", function(result) {
   115       log("Call list is now: " + result);
   116       is(result[0], "OK");
   117       cleanUp();
   118     });
   119   };
   121   incoming.hangUp();
   122 }
   124 function cleanUp() {
   125   telephony.oncallschanged = null;
   126   finish();
   127 }
   129 startTest(function() {
   130   simulateIncoming();
   131 });

mercurial