dom/mobileconnection/tests/marionette/test_mobile_icc_change.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/mobileconnection/tests/marionette/test_mobile_icc_change.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,84 @@
     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 = 30000;
     1.8 +
     1.9 +SpecialPowers.addPermission("mobileconnection", true, document);
    1.10 +
    1.11 +// Permission changes can't change existing Navigator.prototype
    1.12 +// objects, so grab our objects from a new Navigator
    1.13 +let ifr = document.createElement("iframe");
    1.14 +let connection;
    1.15 +ifr.onload = function() {
    1.16 +  connection = ifr.contentWindow.navigator.mozMobileConnections[0];
    1.17 +  ok(connection instanceof ifr.contentWindow.MozMobileConnection,
    1.18 +     "connection is instanceof " + connection.constructor);
    1.19 +
    1.20 +  // The emulator's hard coded iccid value.
    1.21 +  // See it here {B2G_HOME}/external/qemu/telephony/sim_card.c.
    1.22 +  is(connection.iccId, 89014103211118510720);
    1.23 +
    1.24 +  runNextTest();
    1.25 +};
    1.26 +document.body.appendChild(ifr);
    1.27 +
    1.28 +function waitForIccChange(callback) {
    1.29 +  connection.addEventListener("iccchange", function handler() {
    1.30 +    connection.removeEventListener("iccchange", handler);
    1.31 +    callback();
    1.32 +  });
    1.33 +}
    1.34 +
    1.35 +function setRadioEnabled(enabled) {
    1.36 +  let request  = connection.setRadioEnabled(enabled);
    1.37 +
    1.38 +  request.onsuccess = function onsuccess() {
    1.39 +    log('setRadioEnabled: ' + enabled);
    1.40 +  };
    1.41 +
    1.42 +  request.onerror = function onerror() {
    1.43 +    ok(false, "setRadioEnabled should be ok");
    1.44 +  };
    1.45 +}
    1.46 +
    1.47 +function testIccChangeOnRadioPowerOff() {
    1.48 +  // Turn off radio
    1.49 +  setRadioEnabled(false);
    1.50 +
    1.51 +  waitForIccChange(function() {
    1.52 +    is(connection.iccId, null);
    1.53 +    runNextTest();
    1.54 +  });
    1.55 +}
    1.56 +
    1.57 +function testIccChangeOnRadioPowerOn() {
    1.58 +  // Turn on radio
    1.59 +  setRadioEnabled(true);
    1.60 +
    1.61 +  waitForIccChange(function() {
    1.62 +    // The emulator's hard coded iccid value.
    1.63 +    is(connection.iccId, 89014103211118510720);
    1.64 +    runNextTest();
    1.65 +  });
    1.66 +}
    1.67 +
    1.68 +let tests = [
    1.69 +  testIccChangeOnRadioPowerOff,
    1.70 +  testIccChangeOnRadioPowerOn
    1.71 +];
    1.72 +
    1.73 +function runNextTest() {
    1.74 +  let test = tests.shift();
    1.75 +  if (!test) {
    1.76 +    cleanUp();
    1.77 +    return;
    1.78 +  }
    1.79 +
    1.80 +  test();
    1.81 +}
    1.82 +
    1.83 +function cleanUp() {
    1.84 +  SpecialPowers.removePermission("mobileconnection", document);
    1.85 +
    1.86 +  finish();
    1.87 +}

mercurial