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 | function setRadioEnabled(enabled) { |
michael@0 | 8 | log("Set radio enabled: " + enabled + "."); |
michael@0 | 9 | |
michael@0 | 10 | let desiredRadioState = enabled ? 'enabled' : 'disabled'; |
michael@0 | 11 | let deferred = Promise.defer(); |
michael@0 | 12 | let connection = navigator.mozMobileConnections[0]; |
michael@0 | 13 | |
michael@0 | 14 | connection.onradiostatechange = function() { |
michael@0 | 15 | let state = connection.radioState; |
michael@0 | 16 | log("Received 'radiostatechange' event, radioState: " + state); |
michael@0 | 17 | |
michael@0 | 18 | // We are waiting for 'desiredRadioState.' Ignore any transient state. |
michael@0 | 19 | if (state === desiredRadioState) { |
michael@0 | 20 | connection.onradiostatechange = null; |
michael@0 | 21 | deferred.resolve(); |
michael@0 | 22 | } |
michael@0 | 23 | }; |
michael@0 | 24 | connection.setRadioEnabled(enabled); |
michael@0 | 25 | |
michael@0 | 26 | return deferred.promise; |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | function dial(number) { |
michael@0 | 30 | log("Make an outgoing call."); |
michael@0 | 31 | |
michael@0 | 32 | let deferred = Promise.defer(); |
michael@0 | 33 | telephony.dial(number).then(call => { |
michael@0 | 34 | ok(call); |
michael@0 | 35 | is(call.number, number); |
michael@0 | 36 | is(call.state, "dialing"); |
michael@0 | 37 | |
michael@0 | 38 | call.onalerting = function(event) { |
michael@0 | 39 | log("Received 'onalerting' call event."); |
michael@0 | 40 | call.onalerting = null; |
michael@0 | 41 | is(call, event.call); |
michael@0 | 42 | is(call.state, "alerting"); |
michael@0 | 43 | deferred.resolve(call); |
michael@0 | 44 | }; |
michael@0 | 45 | }); |
michael@0 | 46 | |
michael@0 | 47 | return deferred.promise; |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | function remoteAnswer(call) { |
michael@0 | 51 | log("Remote answering the call."); |
michael@0 | 52 | |
michael@0 | 53 | let deferred = Promise.defer(); |
michael@0 | 54 | |
michael@0 | 55 | call.onconnected = function(event) { |
michael@0 | 56 | log("Received 'connected' call event."); |
michael@0 | 57 | call.onconnected = null; |
michael@0 | 58 | is(call, event.call); |
michael@0 | 59 | is(call.state, "connected"); |
michael@0 | 60 | deferred.resolve(call); |
michael@0 | 61 | }; |
michael@0 | 62 | emulator.run("gsm accept " + call.number); |
michael@0 | 63 | |
michael@0 | 64 | return deferred.promise; |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | function disableRadioAndWaitForCallEvent(call) { |
michael@0 | 68 | log("Disable radio and wait for call event."); |
michael@0 | 69 | |
michael@0 | 70 | let deferred = Promise.defer(); |
michael@0 | 71 | |
michael@0 | 72 | call.ondisconnected = function(event) { |
michael@0 | 73 | log("Received 'disconnected' call event."); |
michael@0 | 74 | call.ondisconnected = null; |
michael@0 | 75 | is(call, event.call); |
michael@0 | 76 | is(call.state, "disconnected"); |
michael@0 | 77 | deferred.resolve(); |
michael@0 | 78 | }; |
michael@0 | 79 | navigator.mozMobileConnections[0].setRadioEnabled(false); |
michael@0 | 80 | |
michael@0 | 81 | return deferred.promise; |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | /** |
michael@0 | 85 | * Make an outgoing call then power off radio. |
michael@0 | 86 | */ |
michael@0 | 87 | function testOutgoingCallRadioOff() { |
michael@0 | 88 | log("= testOutgoingCallRadioOff ="); |
michael@0 | 89 | let number = "0912345000"; |
michael@0 | 90 | |
michael@0 | 91 | return Promise.resolve() |
michael@0 | 92 | .then(() => dial(number)) |
michael@0 | 93 | .then(call => remoteAnswer(call)) |
michael@0 | 94 | .then(call => disableRadioAndWaitForCallEvent(call)) |
michael@0 | 95 | .then(() => setRadioEnabled(true)); |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | // Start test |
michael@0 | 99 | startTestWithPermissions(['mobileconnection'], function() { |
michael@0 | 100 | testOutgoingCallRadioOff() |
michael@0 | 101 | .then(null, () => { |
michael@0 | 102 | ok(false, "promise rejects during test."); |
michael@0 | 103 | }) |
michael@0 | 104 | .then(finish); |
michael@0 | 105 | }); |