dom/icc/tests/marionette/test_icc_info.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/icc/tests/marionette/test_icc_info.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,125 @@
     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 +MARIONETTE_HEAD_JS = "icc_header.js";
     1.9 +
    1.10 +function setRadioEnabled(enabled) {
    1.11 +  let connection = navigator.mozMobileConnections[0];
    1.12 +  ok(connection);
    1.13 +
    1.14 +  let request  = connection.setRadioEnabled(enabled);
    1.15 +
    1.16 +  request.onsuccess = function onsuccess() {
    1.17 +    log('setRadioEnabled: ' + enabled);
    1.18 +  };
    1.19 +
    1.20 +  request.onerror = function onerror() {
    1.21 +    ok(false, "setRadioEnabled should be ok");
    1.22 +  };
    1.23 +}
    1.24 +
    1.25 +function setEmulatorMccMnc(mcc, mnc) {
    1.26 +  let cmd = "operator set 0 Android,Android," + mcc + mnc;
    1.27 +  emulatorHelper.sendCommand(cmd, function(result) {
    1.28 +    let re = new RegExp("" + mcc + mnc + "$");
    1.29 +    ok(result[0].match(re), "MCC/MNC should be changed.");
    1.30 +  });
    1.31 +}
    1.32 +
    1.33 +/* Basic test */
    1.34 +taskHelper.push(function basicTest() {
    1.35 +  let iccInfo = icc.iccInfo;
    1.36 +
    1.37 +  // The emulator's hard coded iccid value.
    1.38 +  // See it here {B2G_HOME}/external/qemu/telephony/sim_card.c#L299.
    1.39 +  is(iccInfo.iccid, 89014103211118510720);
    1.40 +
    1.41 +  if (iccInfo instanceof Ci.nsIDOMMozGsmIccInfo) {
    1.42 +    log("Test Gsm IccInfo");
    1.43 +    is(iccInfo.iccType, "sim");
    1.44 +    is(iccInfo.spn, "Android");
    1.45 +    // The emulator's hard coded mcc and mnc codes.
    1.46 +    // See it here {B2G_HOME}/external/qemu/telephony/android_modem.c#L2465.
    1.47 +    is(iccInfo.mcc, 310);
    1.48 +    is(iccInfo.mnc, 260);
    1.49 +    // Phone number is hardcoded in MSISDN
    1.50 +    // See {B2G_HOME}/external/qemu/telephony/sim_card.c, in asimcard_io()
    1.51 +    is(iccInfo.msisdn, "15555215554");
    1.52 +  } else {
    1.53 +    log("Test Cdma IccInfo");
    1.54 +    is(iccInfo.iccType, "ruim");
    1.55 +    // MDN is hardcoded as "8587777777".
    1.56 +    // See it here {B2G_HOME}/hardware/ril/reference-ril/reference-ril.c,
    1.57 +    // in requestCdmaSubscription()
    1.58 +    is(iccInfo.mdn, "8587777777");
    1.59 +    // PRL version is hardcoded as 1.
    1.60 +    // See it here {B2G_HOME}/hardware/ril/reference-ril/reference-ril.c,
    1.61 +    // in requestCdmaSubscription()
    1.62 +    is(iccInfo.prlVersion, 1);
    1.63 +  }
    1.64 +
    1.65 +  taskHelper.runNext();
    1.66 +});
    1.67 +
    1.68 +/* Test Gsm display condition change */
    1.69 +taskHelper.push(function testGsmDisplayConditionChange() {
    1.70 +  function testSPN(mcc, mnc, expectedIsDisplayNetworkNameRequired,
    1.71 +                   expectedIsDisplaySpnRequired, callback) {
    1.72 +    icc.addEventListener("iccinfochange", function handler() {
    1.73 +      icc.removeEventListener("iccinfochange", handler);
    1.74 +      is(icc.iccInfo.isDisplayNetworkNameRequired,
    1.75 +         expectedIsDisplayNetworkNameRequired);
    1.76 +      is(icc.iccInfo.isDisplaySpnRequired,
    1.77 +         expectedIsDisplaySpnRequired);
    1.78 +      // operatorchange will be ignored if we send commands too soon.
    1.79 +      window.setTimeout(callback, 100);
    1.80 +    });
    1.81 +    // Send emulator command to change network mcc and mnc.
    1.82 +    setEmulatorMccMnc(mcc, mnc);
    1.83 +  }
    1.84 +
    1.85 +  let testCases = [
    1.86 +    // [MCC, MNC, isDisplayNetworkNameRequired, isDisplaySpnRequired]
    1.87 +    [123, 456, false, true], // Not in HPLMN.
    1.88 +    [234, 136,  true, true], // Not in HPLMN, but in PLMN specified in SPDI.
    1.89 +    [123, 456, false, true], // Not in HPLMN. Triggering iccinfochange
    1.90 +    [466,  92,  true, true], // Not in HPLMN, but in another PLMN specified in SPDI.
    1.91 +    [123, 456, false, true], // Not in HPLMN. Triggering iccinfochange
    1.92 +    [310, 260,  true, true], // inside HPLMN.
    1.93 +  ];
    1.94 +
    1.95 +  // Ignore this test if device is not in gsm mode.
    1.96 +  if (!(icc.iccInfo instanceof Ci.nsIDOMMozGsmIccInfo)) {
    1.97 +    taskHelper.runNext();
    1.98 +    return;
    1.99 +  }
   1.100 +
   1.101 +  (function do_call(index) {
   1.102 +    let next = index < (testCases.length - 1) ? do_call.bind(null, index + 1) : taskHelper.runNext.bind(taskHelper);
   1.103 +    testCases[index].push(next);
   1.104 +    testSPN.apply(null, testCases[index]);
   1.105 +  })(0);
   1.106 +});
   1.107 +
   1.108 +/* Test iccInfo when card becomes undetected */
   1.109 +taskHelper.push(function testCardIsNotReady() {
   1.110 +  // Turn off radio.
   1.111 +  setRadioEnabled(false);
   1.112 +  icc.addEventListener("iccinfochange", function oniccinfochange() {
   1.113 +    // Expect iccInfo changes to null
   1.114 +    if (icc.iccInfo === null) {
   1.115 +      icc.removeEventListener("iccinfochange", oniccinfochange);
   1.116 +      // We should restore radio status and expect to get iccdetected event.
   1.117 +      setRadioEnabled(true);
   1.118 +      iccManager.addEventListener("iccdetected", function oniccdetected(evt) {
   1.119 +        log("icc detected: " + evt.iccId);
   1.120 +        iccManager.removeEventListener("iccdetected", oniccdetected);
   1.121 +        taskHelper.runNext();
   1.122 +      });
   1.123 +    }
   1.124 +  });
   1.125 +});
   1.126 +
   1.127 +// Start test
   1.128 +taskHelper.runNext();

mercurial