dom/icc/tests/marionette/stk_helper.js

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:2ead96892ce0
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 MARIONETTE_TIMEOUT = 30000;
5
6 SpecialPowers.addPermission("mobileconnection", true, document);
7
8 let iccManager = navigator.mozIccManager;
9 ok(iccManager instanceof MozIccManager,
10 "iccManager is instanceof " + iccManager.constructor);
11
12 // TODO: Bug 932650 - B2G RIL: WebIccManager API - add marionette tests for
13 // multi-sim
14 // In single sim scenario, there is only one sim card, we can use below way to
15 // check iccId and get icc object. But in multi-sim, the index of iccIds may
16 // not map to sim slot directly, we should have a better way to handle this.
17 let iccIds = iccManager.iccIds;
18 ok(Array.isArray(iccIds), "iccIds is an array");
19 ok(iccIds.length > 0, "iccIds.length is " + iccIds.length);
20
21 let iccId = iccIds[0];
22 is(iccId, "89014103211118510720", "iccId is " + iccId);
23
24 let icc = iccManager.getIccById(iccId);
25 ok(icc instanceof MozIcc, "icc is instanceof " + icc.constructor);
26
27 let pendingEmulatorCmdCount = 0;
28 function sendStkPduToEmulator(command, func, expect) {
29 ++pendingEmulatorCmdCount;
30
31 runEmulatorCmd(command, function(result) {
32 --pendingEmulatorCmdCount;
33 is(result[0], "OK");
34 });
35
36 icc.onstkcommand = function(evt) {
37 if (expect) {
38 func(evt.command, expect);
39 } else {
40 func(evt.command);
41 }
42 }
43 }
44
45 function runNextTest() {
46 let test = tests.pop();
47 if (!test) {
48 cleanUp();
49 return;
50 }
51
52 let command = "stk pdu " + test.command;
53 sendStkPduToEmulator(command, test.func, test.expect);
54 }
55
56 function cleanUp() {
57 if (pendingEmulatorCmdCount) {
58 window.setTimeout(cleanUp, 100);
59 return;
60 }
61
62 SpecialPowers.removePermission("mobileconnection", document);
63 finish();
64 }

mercurial