Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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 inNumber = "5555551111"; |
michael@0 | 8 | let incomingCall; |
michael@0 | 9 | |
michael@0 | 10 | function simulateIncoming() { |
michael@0 | 11 | log("Simulating an incoming call."); |
michael@0 | 12 | |
michael@0 | 13 | telephony.onincoming = function onincoming(event) { |
michael@0 | 14 | log("Received 'incoming' call event."); |
michael@0 | 15 | incomingCall = event.call; |
michael@0 | 16 | ok(incomingCall); |
michael@0 | 17 | is(incomingCall.number, inNumber); |
michael@0 | 18 | is(incomingCall.state, "incoming"); |
michael@0 | 19 | |
michael@0 | 20 | is(telephony.calls.length, 1); |
michael@0 | 21 | is(telephony.calls[0], incomingCall); |
michael@0 | 22 | |
michael@0 | 23 | emulator.run("gsm list", function(result) { |
michael@0 | 24 | log("Call list is now: " + result); |
michael@0 | 25 | is(result[0], "inbound from " + inNumber + " : incoming"); |
michael@0 | 26 | is(result[1], "OK"); |
michael@0 | 27 | answerIncoming(); |
michael@0 | 28 | }); |
michael@0 | 29 | }; |
michael@0 | 30 | emulator.run("gsm call " + inNumber); |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | function answerIncoming() { |
michael@0 | 34 | log("Answering the incoming call."); |
michael@0 | 35 | |
michael@0 | 36 | let gotConnecting = false; |
michael@0 | 37 | incomingCall.onconnecting = function onconnectingIn(event) { |
michael@0 | 38 | log("Received 'connecting' call event for incoming call."); |
michael@0 | 39 | is(incomingCall, event.call); |
michael@0 | 40 | is(incomingCall.state, "connecting"); |
michael@0 | 41 | gotConnecting = true; |
michael@0 | 42 | }; |
michael@0 | 43 | |
michael@0 | 44 | incomingCall.onconnected = function onconnectedIn(event) { |
michael@0 | 45 | log("Received 'connected' call event for incoming call."); |
michael@0 | 46 | is(incomingCall, event.call); |
michael@0 | 47 | is(incomingCall.state, "connected"); |
michael@0 | 48 | ok(gotConnecting); |
michael@0 | 49 | |
michael@0 | 50 | is(incomingCall, telephony.active); |
michael@0 | 51 | |
michael@0 | 52 | emulator.run("gsm list", function(result) { |
michael@0 | 53 | log("Call list is now: " + result); |
michael@0 | 54 | is(result[0], "inbound from " + inNumber + " : active"); |
michael@0 | 55 | is(result[1], "OK"); |
michael@0 | 56 | hold(); |
michael@0 | 57 | }); |
michael@0 | 58 | }; |
michael@0 | 59 | incomingCall.answer(); |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | function hold() { |
michael@0 | 63 | log("Putting the call on hold."); |
michael@0 | 64 | |
michael@0 | 65 | let gotHolding = false; |
michael@0 | 66 | incomingCall.onholding = function onholding(event) { |
michael@0 | 67 | log("Received 'holding' call event"); |
michael@0 | 68 | is(incomingCall, event.call); |
michael@0 | 69 | is(incomingCall.state, "holding"); |
michael@0 | 70 | gotHolding = true; |
michael@0 | 71 | }; |
michael@0 | 72 | |
michael@0 | 73 | incomingCall.onheld = function onheld(event) { |
michael@0 | 74 | log("Received 'held' call event"); |
michael@0 | 75 | is(incomingCall, event.call); |
michael@0 | 76 | is(incomingCall.state, "held"); |
michael@0 | 77 | ok(gotHolding); |
michael@0 | 78 | |
michael@0 | 79 | is(telephony.active, null); |
michael@0 | 80 | is(telephony.calls.length, 1); |
michael@0 | 81 | is(telephony.calls[0], incomingCall); |
michael@0 | 82 | |
michael@0 | 83 | emulator.run("gsm list", function(result) { |
michael@0 | 84 | log("Call list is now: " + result); |
michael@0 | 85 | is(result[0], "inbound from " + inNumber + " : held"); |
michael@0 | 86 | is(result[1], "OK"); |
michael@0 | 87 | hangUp(); |
michael@0 | 88 | }); |
michael@0 | 89 | }; |
michael@0 | 90 | incomingCall.hold(); |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | function hangUp() { |
michael@0 | 94 | log("Hanging up the held call (local hang-up)."); |
michael@0 | 95 | |
michael@0 | 96 | let gotDisconnecting = false; |
michael@0 | 97 | incomingCall.ondisconnecting = function ondisconnecting(event) { |
michael@0 | 98 | log("Received 'disconnecting' call event."); |
michael@0 | 99 | is(incomingCall, event.call); |
michael@0 | 100 | is(incomingCall.state, "disconnecting"); |
michael@0 | 101 | gotDisconnecting = true; |
michael@0 | 102 | }; |
michael@0 | 103 | |
michael@0 | 104 | incomingCall.ondisconnected = function ondisconnectedOut(event) { |
michael@0 | 105 | log("Received 'disconnected' call event."); |
michael@0 | 106 | is(incomingCall, event.call); |
michael@0 | 107 | is(incomingCall.state, "disconnected"); |
michael@0 | 108 | ok(gotDisconnecting); |
michael@0 | 109 | |
michael@0 | 110 | is(telephony.active, null); |
michael@0 | 111 | is(telephony.calls.length, 0); |
michael@0 | 112 | |
michael@0 | 113 | emulator.run("gsm list", function(result) { |
michael@0 | 114 | log("Call list is now: " + result); |
michael@0 | 115 | is(result[0], "OK"); |
michael@0 | 116 | cleanUp(); |
michael@0 | 117 | }); |
michael@0 | 118 | }; |
michael@0 | 119 | incomingCall.hangUp(); |
michael@0 | 120 | } |
michael@0 | 121 | |
michael@0 | 122 | function cleanUp() { |
michael@0 | 123 | telephony.onincoming = null; |
michael@0 | 124 | finish(); |
michael@0 | 125 | } |
michael@0 | 126 | |
michael@0 | 127 | startTest(function() { |
michael@0 | 128 | simulateIncoming(); |
michael@0 | 129 | }); |