dom/telephony/test/marionette/test_outgoing_answer_radio_off.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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 });

mercurial