Wed, 31 Dec 2014 06:09:35 +0100
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_HEAD_JS = 'head.js'; |
michael@0 | 5 | MARIONETTE_TIMEOUT = 60000; |
michael@0 | 6 | |
michael@0 | 7 | let incomingCall; |
michael@0 | 8 | let inNumber = "5555551111"; |
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 | gotConnecting = false; |
michael@0 | 37 | incomingCall.onstatechange = function statechangeconnect(event) { |
michael@0 | 38 | log("Received 'onstatechange' call event."); |
michael@0 | 39 | is(incomingCall, event.call); |
michael@0 | 40 | if(!gotConnecting){ |
michael@0 | 41 | is(incomingCall.state, "connecting"); |
michael@0 | 42 | gotConnecting = true; |
michael@0 | 43 | } else { |
michael@0 | 44 | is(incomingCall.state, "connected"); |
michael@0 | 45 | is(telephony.active, incomingCall); |
michael@0 | 46 | is(telephony.calls.length, 1); |
michael@0 | 47 | is(telephony.calls[0], incomingCall); |
michael@0 | 48 | |
michael@0 | 49 | emulator.run("gsm list", function(result) { |
michael@0 | 50 | log("Call list is now: " + result); |
michael@0 | 51 | is(result[0], "inbound from " + inNumber + " : active"); |
michael@0 | 52 | is(result[1], "OK"); |
michael@0 | 53 | hold(); |
michael@0 | 54 | }); |
michael@0 | 55 | } |
michael@0 | 56 | }; |
michael@0 | 57 | incomingCall.answer(); |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | function hold() { |
michael@0 | 61 | log("Putting the call on hold."); |
michael@0 | 62 | |
michael@0 | 63 | let gotHolding = false; |
michael@0 | 64 | incomingCall.onstatechange = function onstatechangehold(event) { |
michael@0 | 65 | log("Received 'onstatechange' call event."); |
michael@0 | 66 | is(incomingCall, event.call); |
michael@0 | 67 | if(!gotHolding){ |
michael@0 | 68 | is(incomingCall.state, "holding"); |
michael@0 | 69 | gotHolding = true; |
michael@0 | 70 | } else { |
michael@0 | 71 | is(incomingCall.state, "held"); |
michael@0 | 72 | is(telephony.active, null); |
michael@0 | 73 | is(telephony.calls.length, 1); |
michael@0 | 74 | is(telephony.calls[0], incomingCall); |
michael@0 | 75 | |
michael@0 | 76 | emulator.run("gsm list", function(result) { |
michael@0 | 77 | log("Call list is now: " + result); |
michael@0 | 78 | is(result[0], "inbound from " + inNumber + " : held"); |
michael@0 | 79 | is(result[1], "OK"); |
michael@0 | 80 | resume(); |
michael@0 | 81 | }); |
michael@0 | 82 | } |
michael@0 | 83 | }; |
michael@0 | 84 | incomingCall.hold(); |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | function resume() { |
michael@0 | 88 | log("Resuming the held call."); |
michael@0 | 89 | |
michael@0 | 90 | let gotResuming = false; |
michael@0 | 91 | incomingCall.onstatechange = function onstatechangeresume(event) { |
michael@0 | 92 | log("Received 'onstatechange' call event."); |
michael@0 | 93 | is(incomingCall, event.call); |
michael@0 | 94 | if(!gotResuming){ |
michael@0 | 95 | is(incomingCall.state, "resuming"); |
michael@0 | 96 | gotResuming = true; |
michael@0 | 97 | } else { |
michael@0 | 98 | is(incomingCall.state, "connected"); |
michael@0 | 99 | is(telephony.active, incomingCall); |
michael@0 | 100 | is(telephony.calls.length, 1); |
michael@0 | 101 | is(telephony.calls[0], incomingCall); |
michael@0 | 102 | |
michael@0 | 103 | emulator.run("gsm list", function(result) { |
michael@0 | 104 | log("Call list is now: " + result); |
michael@0 | 105 | is(result[0], "inbound from " + inNumber + " : active"); |
michael@0 | 106 | is(result[1], "OK"); |
michael@0 | 107 | hangUp(); |
michael@0 | 108 | }); |
michael@0 | 109 | } |
michael@0 | 110 | }; |
michael@0 | 111 | incomingCall.resume(); |
michael@0 | 112 | } |
michael@0 | 113 | |
michael@0 | 114 | function hangUp() { |
michael@0 | 115 | log("Hanging up the incoming call (local hang-up)."); |
michael@0 | 116 | |
michael@0 | 117 | let gotDisconnecting = false; |
michael@0 | 118 | incomingCall.onstatechange = function onstatechangedisconnect(event) { |
michael@0 | 119 | log("Received 'onstatechange' call event."); |
michael@0 | 120 | is(incomingCall, event.call); |
michael@0 | 121 | if(!gotDisconnecting){ |
michael@0 | 122 | is(incomingCall.state, "disconnecting"); |
michael@0 | 123 | gotDisconnecting = true; |
michael@0 | 124 | } else { |
michael@0 | 125 | is(incomingCall.state, "disconnected"); |
michael@0 | 126 | is(telephony.active, null); |
michael@0 | 127 | is(telephony.calls.length, 0); |
michael@0 | 128 | |
michael@0 | 129 | emulator.run("gsm list", function(result) { |
michael@0 | 130 | log("Call list is now: " + result); |
michael@0 | 131 | is(result[0], "OK"); |
michael@0 | 132 | cleanUp(); |
michael@0 | 133 | }); |
michael@0 | 134 | } |
michael@0 | 135 | }; |
michael@0 | 136 | incomingCall.hangUp(); |
michael@0 | 137 | } |
michael@0 | 138 | |
michael@0 | 139 | function cleanUp() { |
michael@0 | 140 | telephony.onincoming = null; |
michael@0 | 141 | finish(); |
michael@0 | 142 | } |
michael@0 | 143 | |
michael@0 | 144 | startTest(function() { |
michael@0 | 145 | simulateIncoming(); |
michael@0 | 146 | }); |