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