dom/telephony/test/marionette/test_outgoing_radio_off.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/telephony/test/marionette/test_outgoing_radio_off.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,71 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +MARIONETTE_TIMEOUT = 60000;
     1.8 +MARIONETTE_HEAD_JS = 'head.js';
     1.9 +
    1.10 +let connection;
    1.11 +
    1.12 +function setRadioEnabled(enabled, callback) {
    1.13 +  let request  = connection.setRadioEnabled(enabled);
    1.14 +  let desiredRadioState = enabled ? 'enabled' : 'disabled';
    1.15 +
    1.16 +  let pending = ['onradiostatechange', 'onsuccess'];
    1.17 +  let done = callback;
    1.18 +
    1.19 +  connection.onradiostatechange = function() {
    1.20 +    let state = connection.radioState;
    1.21 +    log("Received 'radiostatechange' event, radioState: " + state);
    1.22 +
    1.23 +    if (state == desiredRadioState) {
    1.24 +      gReceivedPending('onradiostatechange', pending, done);
    1.25 +    }
    1.26 +  };
    1.27 +
    1.28 +  request.onsuccess = function onsuccess() {
    1.29 +    gReceivedPending('onsuccess', pending, done);
    1.30 +  };
    1.31 +
    1.32 +  request.onerror = function onerror() {
    1.33 +    ok(false, "setRadioEnabled should be ok");
    1.34 +  };
    1.35 +}
    1.36 +
    1.37 +function dial(number) {
    1.38 +  // Verify initial state before dial.
    1.39 +  ok(telephony);
    1.40 +  is(telephony.active, null);
    1.41 +  ok(telephony.calls);
    1.42 +  is(telephony.calls.length, 0);
    1.43 +
    1.44 +  log("Make an outgoing call.");
    1.45 +
    1.46 +  telephony.dial(number).then(null, cause => {
    1.47 +    log("Received promise 'reject'");
    1.48 +
    1.49 +    is(telephony.active, null);
    1.50 +    is(telephony.calls.length, 0);
    1.51 +    is(cause, "RadioNotAvailable");
    1.52 +
    1.53 +    emulator.run("gsm list", function(result) {
    1.54 +      log("Initial call list: " + result);
    1.55 +      is(result[0], "OK");
    1.56 +
    1.57 +      setRadioEnabled(true, cleanUp);
    1.58 +    });
    1.59 +  });
    1.60 +}
    1.61 +
    1.62 +function cleanUp() {
    1.63 +  finish();
    1.64 +}
    1.65 +
    1.66 +startTestWithPermissions(['mobileconnection'], function() {
    1.67 +  connection = navigator.mozMobileConnections[0];
    1.68 +  ok(connection instanceof MozMobileConnection,
    1.69 +     "connection is instanceof " + connection.constructor);
    1.70 +
    1.71 +  setRadioEnabled(false, function() {
    1.72 +    dial("0912345678");
    1.73 +  });
    1.74 +});

mercurial