dom/icc/tests/marionette/stk_helper.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/icc/tests/marionette/stk_helper.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,64 @@
     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 +let iccManager = navigator.mozIccManager;
    1.12 +ok(iccManager instanceof MozIccManager,
    1.13 +   "iccManager is instanceof " + iccManager.constructor);
    1.14 +
    1.15 +// TODO: Bug 932650 - B2G RIL: WebIccManager API - add marionette tests for
    1.16 +//                    multi-sim
    1.17 +// In single sim scenario, there is only one sim card, we can use below way to
    1.18 +// check iccId and get icc object. But in multi-sim, the index of iccIds may
    1.19 +// not map to sim slot directly, we should have a better way to handle this.
    1.20 +let iccIds = iccManager.iccIds;
    1.21 +ok(Array.isArray(iccIds), "iccIds is an array");
    1.22 +ok(iccIds.length > 0, "iccIds.length is " + iccIds.length);
    1.23 +
    1.24 +let iccId = iccIds[0];
    1.25 +is(iccId, "89014103211118510720", "iccId is " + iccId);
    1.26 +
    1.27 +let icc = iccManager.getIccById(iccId);
    1.28 +ok(icc instanceof MozIcc, "icc is instanceof " + icc.constructor);
    1.29 +
    1.30 +let pendingEmulatorCmdCount = 0;
    1.31 +function sendStkPduToEmulator(command, func, expect) {
    1.32 +  ++pendingEmulatorCmdCount;
    1.33 +
    1.34 +  runEmulatorCmd(command, function(result) {
    1.35 +    --pendingEmulatorCmdCount;
    1.36 +    is(result[0], "OK");
    1.37 +  });
    1.38 +
    1.39 +  icc.onstkcommand = function(evt) {
    1.40 +    if (expect) {
    1.41 +      func(evt.command, expect);
    1.42 +    } else {
    1.43 +      func(evt.command);
    1.44 +    }
    1.45 +  }
    1.46 +}
    1.47 +
    1.48 +function runNextTest() {
    1.49 +  let test = tests.pop();
    1.50 +  if (!test) {
    1.51 +    cleanUp();
    1.52 +    return;
    1.53 +  }
    1.54 +
    1.55 +  let command = "stk pdu " + test.command;
    1.56 +  sendStkPduToEmulator(command, test.func, test.expect);
    1.57 +}
    1.58 +
    1.59 +function cleanUp() {
    1.60 +  if (pendingEmulatorCmdCount) {
    1.61 +    window.setTimeout(cleanUp, 100);
    1.62 +    return;
    1.63 +  }
    1.64 +
    1.65 +  SpecialPowers.removePermission("mobileconnection", document);
    1.66 +  finish();
    1.67 +}

mercurial