summaryrefslogtreecommitdiffstats
path: root/dom/system/gonk/tests/test_ril_worker_icc_ICCIOHelper.js
blob: e690b1206e2fe037de926241cafd22b9ed2ccc21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

subscriptLoader.loadSubScript("resource://gre/modules/ril_consts.js", this);

function run_test() {
  run_next_test();
}

/**
 * Verify ICCIOHelper.loadLinearFixedEF with recordSize.
 */
add_test(function test_load_linear_fixed_ef() {
  let worker = newUint8Worker();
  let context = worker.ContextPool._contexts[0];
  let ril = context.RIL;
  let io = context.ICCIOHelper;

  io.getResponse = function fakeGetResponse(options) {
    // When recordSize is provided, loadLinearFixedEF should call iccIO directly.
    ok(false);
    run_next_test();
  };

  ril.iccIO = function fakeIccIO(options) {
    ok(true);
    run_next_test();
  };

  io.loadLinearFixedEF({recordSize: 0x20});
});

/**
 * Verify ICCIOHelper.loadLinearFixedEF without recordSize.
 */
add_test(function test_load_linear_fixed_ef() {
  let worker = newUint8Worker();
  let context = worker.ContextPool._contexts[0];
  let ril = context.RIL;
  let io = context.ICCIOHelper;

  io.getResponse = function fakeGetResponse(options) {
    ok(true);
    run_next_test();
  };

  ril.iccIO = function fakeIccIO(options) {
    // When recordSize is not provided, loadLinearFixedEF should call getResponse.
    ok(false);
    run_next_test();
  };

  io.loadLinearFixedEF({});
});

/**
 * Verify ICC IO Error.
 */
add_test(function test_process_icc_io_error() {
  let worker = newUint8Worker();
  let context = worker.ContextPool._contexts[0];
  let buf = context.Buf;

  function do_test(sw1, sw2, expectedErrorMsg) {
    let called = false;
    function errorCb(errorMsg) {
      called = true;
      equal(errorMsg, expectedErrorMsg);
    }

    // Write sw1 and sw2 to buffer.
    buf.writeInt32(sw1);
    buf.writeInt32(sw2);

    context.RIL[REQUEST_SIM_IO](0, {fileId: 0xffff,
                                    command: 0xff,
                                    onerror: errorCb});

    // onerror callback should be triggered.
    ok(called);
  }

  let TEST_DATA = [
    // [sw1, sw2, expectError]
    [ICC_STATUS_ERROR_COMMAND_NOT_ALLOWED, 0xff, GECKO_ERROR_GENERIC_FAILURE],
    [ICC_STATUS_ERROR_WRONG_PARAMETERS, 0xff, GECKO_ERROR_GENERIC_FAILURE],
  ];

  for (let i = 0; i < TEST_DATA.length; i++) {
    do_test.apply(null, TEST_DATA[i]);
  }

  run_next_test();
});

/**
 * Verify ICCIOHelper.processICCIOGetResponse for EF_TYPE_TRANSPARENT.
 */
add_test(function test_icc_io_get_response_for_transparent_structure() {
  let worker = newUint8Worker();
  let context = worker.ContextPool._contexts[0];
  let buf = context.Buf;
  let iccioHelper = context.ICCIOHelper;
  let pduHelper = context.GsmPDUHelper;

  let responseArray = [
    // SIM response.
    [0x00, 0x00, 0x00, 0x0A, 0x2F, 0xE2, 0x04, 0x00, 0x0A, 0xA0, 0xAA, 0x00,
     0x02, 0x00, 0x00],
    // USIM response.
    [0x62, 0x22, 0x82, 0x02, 0x41, 0x21, 0x83, 0x02, 0x2F, 0xE2, 0xA5, 0x09,
     0xC1, 0x04, 0x40, 0x0F, 0xF5, 0x55, 0x92, 0x01, 0x00, 0x8A, 0x01, 0x05,
     0x8B, 0x03, 0x2F, 0x06, 0x0B, 0x80, 0x02, 0x00, 0x0A, 0x88, 0x01, 0x10]
  ];

  for (let i = 0; i < responseArray.length; i++) {
    let strLen = responseArray[i].length * 2;
    buf.writeInt32(strLen);
    for (let j = 0; j < responseArray[i].length; j++) {
      pduHelper.writeHexOctet(responseArray[i][j]);
    }
    buf.writeStringDelimiter(strLen);

    let options = {fileId: ICC_EF_ICCID,
                   structure: EF_STRUCTURE_TRANSPARENT};
    iccioHelper.processICCIOGetResponse(options);

    equal(options.fileSize, 0x0A);
  }

  run_next_test();
});

/**
 * Verify ICCIOHelper.processICCIOGetResponse for EF_TYPE_LINEAR_FIXED.
 */
add_test(function test_icc_io_get_response_for_linear_fixed_structure() {
  let worker = newUint8Worker();
  let context = worker.ContextPool._contexts[0];
  let buf = context.Buf;
  let iccioHelper = context.ICCIOHelper;
  let pduHelper = context.GsmPDUHelper;

  let responseArray = [
    // SIM response.
    [0x00, 0x00, 0x00, 0x1A, 0x6F, 0x40, 0x04, 0x00, 0x11, 0xA0, 0xAA, 0x00,
     0x02, 0x01, 0x1A],
    // USIM response.
    [0x62, 0x1E, 0x82, 0x05, 0x42, 0x21, 0x00, 0x1A, 0x01, 0x83, 0x02, 0x6F,
     0x40, 0xA5, 0x03, 0x92, 0x01, 0x00, 0x8A, 0x01, 0x07, 0x8B, 0x03, 0x6F,
     0x06, 0x02, 0x80, 0x02, 0x00, 0x1A, 0x88, 0x00]
  ];

  for (let i = 0; i < responseArray.length; i++) {
    let strLen = responseArray[i].length * 2;
    buf.writeInt32(strLen);
    for (let j = 0; j < responseArray[i].length; j++) {
      pduHelper.writeHexOctet(responseArray[i][j]);
    }
    buf.writeStringDelimiter(strLen);

    let options = {fileId: ICC_EF_MSISDN,
                   structure: EF_STRUCTURE_LINEAR_FIXED};
    iccioHelper.processICCIOGetResponse(options);

    equal(options.fileSize, 0x1A);
    equal(options.recordSize, 0x1A);
    equal(options.totalRecords, 0x01);
  }

  run_next_test();
});