dom/telephony/test/marionette/test_incoming_hold_resume.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.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 * http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 MARIONETTE_TIMEOUT = 60000;
michael@0 5 MARIONETTE_HEAD_JS = 'head.js';
michael@0 6
michael@0 7 let number = "5555551234";
michael@0 8 let connectedCalls;
michael@0 9 let incomingCall;
michael@0 10
michael@0 11 function simulateIncoming() {
michael@0 12 log("Simulating an incoming call.");
michael@0 13
michael@0 14 telephony.onincoming = function onincoming(event) {
michael@0 15 log("Received 'incoming' call event.");
michael@0 16 incomingCall = event.call;
michael@0 17 ok(incomingCall);
michael@0 18 is(incomingCall.number, number);
michael@0 19 is(incomingCall.state, "incoming");
michael@0 20
michael@0 21 is(telephony.calls.length, 1);
michael@0 22 is(telephony.calls[0], incomingCall);
michael@0 23
michael@0 24 emulator.run("gsm list", function(result) {
michael@0 25 log("Call list is now: " + result);
michael@0 26 is(result[0], "inbound from " + number + " : incoming");
michael@0 27 is(result[1], "OK");
michael@0 28 answer();
michael@0 29 });
michael@0 30 };
michael@0 31 emulator.run("gsm call " + number);
michael@0 32 }
michael@0 33
michael@0 34 function answer() {
michael@0 35 log("Answering the incoming call.");
michael@0 36
michael@0 37 let gotConnecting = false;
michael@0 38 incomingCall.onconnecting = function onconnecting(event) {
michael@0 39 log("Received 'connecting' call event.");
michael@0 40 is(incomingCall, event.call);
michael@0 41 is(incomingCall.state, "connecting");
michael@0 42 gotConnecting = true;
michael@0 43 };
michael@0 44
michael@0 45 incomingCall.onconnected = function onconnected(event) {
michael@0 46 log("Received 'connected' call event.");
michael@0 47 is(incomingCall, event.call);
michael@0 48 is(incomingCall.state, "connected");
michael@0 49 ok(gotConnecting);
michael@0 50
michael@0 51 is(incomingCall, telephony.active);
michael@0 52
michael@0 53 emulator.run("gsm list", function(result) {
michael@0 54 log("Call list is now: " + result);
michael@0 55 is(result[0], "inbound from " + number + " : active");
michael@0 56 is(result[1], "OK");
michael@0 57 hold();
michael@0 58 });
michael@0 59 };
michael@0 60 incomingCall.answer();
michael@0 61 }
michael@0 62
michael@0 63 function hold() {
michael@0 64 log("Putting the call on hold.");
michael@0 65
michael@0 66 let gotHolding = false;
michael@0 67 incomingCall.onholding = function onholding(event) {
michael@0 68 log("Received 'holding' call event");
michael@0 69 is(incomingCall, event.call);
michael@0 70 is(incomingCall.state, "holding");
michael@0 71 gotHolding = true;
michael@0 72 };
michael@0 73
michael@0 74 incomingCall.onheld = function onheld(event) {
michael@0 75 log("Received 'held' call event");
michael@0 76 is(incomingCall, event.call);
michael@0 77 is(incomingCall.state, "held");
michael@0 78 ok(gotHolding);
michael@0 79
michael@0 80 is(telephony.active, null);
michael@0 81 is(telephony.calls.length, 1);
michael@0 82 is(telephony.calls[0], incomingCall);
michael@0 83
michael@0 84 emulator.run("gsm list", function(result) {
michael@0 85 log("Call list is now: " + result);
michael@0 86 is(result[0], "inbound from " + number + " : held");
michael@0 87 is(result[1], "OK");
michael@0 88 // Wait on hold for a couple of seconds
michael@0 89 log("Pausing 2 seconds while on hold");
michael@0 90 setTimeout(resume, 2000);
michael@0 91 });
michael@0 92 };
michael@0 93 incomingCall.hold();
michael@0 94 }
michael@0 95
michael@0 96 function resume() {
michael@0 97 log("Resuming the held call.");
michael@0 98
michael@0 99 let gotResuming = false;
michael@0 100 incomingCall.onresuming = function onresuming(event) {
michael@0 101 log("Received 'resuming' call event");
michael@0 102 is(incomingCall, event.call);
michael@0 103 is(incomingCall.state, "resuming");
michael@0 104 gotResuming = true;
michael@0 105 };
michael@0 106
michael@0 107 incomingCall.onconnected = function onconnected(event) {
michael@0 108 log("Received 'connected' call event");
michael@0 109 is(incomingCall, event.call);
michael@0 110 is(incomingCall.state, "connected");
michael@0 111 ok(gotResuming);
michael@0 112
michael@0 113 is(incomingCall, telephony.active);
michael@0 114 is(telephony.calls.length, 1);
michael@0 115 is(telephony.calls[0], incomingCall);
michael@0 116
michael@0 117 emulator.run("gsm list", function(result) {
michael@0 118 log("Call list is now: " + result);
michael@0 119 is(result[0], "inbound from " + number + " : active");
michael@0 120 is(result[1], "OK");
michael@0 121 hangUp();
michael@0 122 });
michael@0 123 };
michael@0 124 incomingCall.resume();
michael@0 125 }
michael@0 126
michael@0 127 function hangUp() {
michael@0 128 log("Hanging up the incoming call.");
michael@0 129
michael@0 130 let gotDisconnecting = false;
michael@0 131 incomingCall.ondisconnecting = function ondisconnecting(event) {
michael@0 132 log("Received 'disconnecting' call event.");
michael@0 133 is(incomingCall, event.call);
michael@0 134 is(incomingCall.state, "disconnecting");
michael@0 135 gotDisconnecting = true;
michael@0 136 };
michael@0 137
michael@0 138 incomingCall.ondisconnected = function ondisconnected(event) {
michael@0 139 log("Received 'disconnected' call event.");
michael@0 140 is(incomingCall, event.call);
michael@0 141 is(incomingCall.state, "disconnected");
michael@0 142 ok(gotDisconnecting);
michael@0 143
michael@0 144 is(telephony.active, null);
michael@0 145 is(telephony.calls.length, 0);
michael@0 146
michael@0 147 emulator.run("gsm list", function(result) {
michael@0 148 log("Call list is now: " + result);
michael@0 149 is(result[0], "OK");
michael@0 150 cleanUp();
michael@0 151 });
michael@0 152 };
michael@0 153 incomingCall.hangUp();
michael@0 154 }
michael@0 155
michael@0 156 function cleanUp() {
michael@0 157 telephony.onincoming = null;
michael@0 158 finish();
michael@0 159 }
michael@0 160
michael@0 161 startTest(function() {
michael@0 162 simulateIncoming();
michael@0 163 });

mercurial