|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 subscriptLoader.loadSubScript("resource://gre/modules/ril_consts.js", this); |
|
5 |
|
6 function run_test() { |
|
7 run_next_test(); |
|
8 } |
|
9 |
|
10 /** |
|
11 * Helper function. |
|
12 */ |
|
13 function newUint8Worker() { |
|
14 let worker = newWorker(); |
|
15 let context = worker.ContextPool._contexts[0]; |
|
16 let index = 0; // index for read |
|
17 let buf = []; |
|
18 |
|
19 context.Buf.writeUint8 = function(value) { |
|
20 buf.push(value); |
|
21 }; |
|
22 |
|
23 context.Buf.readUint8 = function() { |
|
24 return buf[index++]; |
|
25 }; |
|
26 |
|
27 context.Buf.seekIncoming = function(offset) { |
|
28 index += offset; |
|
29 }; |
|
30 |
|
31 worker.debug = do_print; |
|
32 |
|
33 return worker; |
|
34 } |
|
35 |
|
36 /** |
|
37 * Verify RUIM Service. |
|
38 */ |
|
39 add_test(function test_is_ruim_service_available() { |
|
40 let worker = newWorker(); |
|
41 let context = worker.ContextPool._contexts[0]; |
|
42 context.RIL._isCdma = true; |
|
43 context.RIL.appType = CARD_APPTYPE_RUIM; |
|
44 |
|
45 function test_table(cst, geckoService, enabled) { |
|
46 context.RIL.iccInfoPrivate.cst = cst; |
|
47 do_check_eq(context.ICCUtilsHelper.isICCServiceAvailable(geckoService), |
|
48 enabled); |
|
49 } |
|
50 |
|
51 test_table([0x0, 0x0, 0x0, 0x0, 0x03], "SPN", true); |
|
52 test_table([0x0, 0x0, 0x0, 0x03, 0x0], "SPN", false); |
|
53 test_table([0x0, 0x0C, 0x0, 0x0, 0x0], "ENHANCED_PHONEBOOK", true); |
|
54 test_table([0x0, 0x0, 0x0, 0x0, 0x0], "ENHANCED_PHONEBOOK", false); |
|
55 |
|
56 run_next_test(); |
|
57 }); |
|
58 |
|
59 /** |
|
60 * Verify EF_PATH for RUIM file. |
|
61 */ |
|
62 add_test(function test_ruim_file_path_id() { |
|
63 let worker = newWorker(); |
|
64 let context = worker.ContextPool._contexts[0]; |
|
65 let RIL = context.RIL; |
|
66 let ICCFileHelper = context.ICCFileHelper; |
|
67 |
|
68 RIL.appType = CARD_APPTYPE_RUIM; |
|
69 do_check_eq(ICCFileHelper.getEFPath(ICC_EF_CSIM_CST), |
|
70 EF_PATH_MF_SIM + EF_PATH_DF_CDMA); |
|
71 |
|
72 run_next_test(); |
|
73 }); |
|
74 |
|
75 add_test(function test_fetch_ruim_recodes() { |
|
76 let worker = newWorker(); |
|
77 let context = worker.ContextPool._contexts[0]; |
|
78 let RIL = context.RIL; |
|
79 let ruimHelper = context.RuimRecordHelper; |
|
80 |
|
81 function testFetchRuimRecordes(expectCalled) { |
|
82 let ifCalled = []; |
|
83 |
|
84 ruimHelper.getIMSI_M = function() { |
|
85 ifCalled.push("getIMSI_M"); |
|
86 }; |
|
87 |
|
88 ruimHelper.readCST = function() { |
|
89 ifCalled.push("readCST"); |
|
90 }; |
|
91 |
|
92 ruimHelper.readCDMAHome = function() { |
|
93 ifCalled.push("readCDMAHome"); |
|
94 }; |
|
95 |
|
96 RIL.getCdmaSubscription = function() { |
|
97 ifCalled.push("getCdmaSubscription"); |
|
98 }; |
|
99 |
|
100 ruimHelper.fetchRuimRecords(); |
|
101 |
|
102 for (let i = 0; i < expectCalled.length; i++ ) { |
|
103 if (ifCalled[i] != expectCalled[i]) { |
|
104 do_print(expectCalled[i] + " is not called."); |
|
105 do_check_true(false); |
|
106 } |
|
107 } |
|
108 } |
|
109 |
|
110 let expectCalled = ["getIMSI_M", "readCST", "readCDMAHome", |
|
111 "getCdmaSubscription"]; |
|
112 testFetchRuimRecordes(expectCalled); |
|
113 |
|
114 run_next_test(); |
|
115 }); |
|
116 |
|
117 /** |
|
118 * Verify RuimRecordHelper.decodeIMSIValue |
|
119 */ |
|
120 add_test(function test_decode_imsi_value() { |
|
121 let worker = newUint8Worker(); |
|
122 let context = worker.ContextPool._contexts[0]; |
|
123 |
|
124 function testDecodeImsiValue(encoded, length, expect) { |
|
125 let decoded = context.RuimRecordHelper.decodeIMSIValue(encoded, length); |
|
126 |
|
127 do_check_eq(expect, decoded); |
|
128 } |
|
129 |
|
130 testDecodeImsiValue( 99, 2, "00"); |
|
131 testDecodeImsiValue( 90, 2, "01"); |
|
132 testDecodeImsiValue( 19, 2, "20"); |
|
133 testDecodeImsiValue( 23, 2, "34"); |
|
134 testDecodeImsiValue(999, 3, "000"); |
|
135 testDecodeImsiValue(990, 3, "001"); |
|
136 testDecodeImsiValue(909, 3, "010"); |
|
137 testDecodeImsiValue( 99, 3, "100"); |
|
138 testDecodeImsiValue(901, 3, "012"); |
|
139 testDecodeImsiValue( 19, 3, "120"); |
|
140 testDecodeImsiValue( 91, 3, "102"); |
|
141 testDecodeImsiValue(199, 3, "200"); |
|
142 testDecodeImsiValue(123, 3, "234"); |
|
143 testDecodeImsiValue(578, 3, "689"); |
|
144 |
|
145 run_next_test(); |
|
146 }); |
|
147 |
|
148 /** |
|
149 * Verify RuimRecordHelper.getIMSI_M |
|
150 */ |
|
151 add_test(function test_get_imsi_m() { |
|
152 let worker = newUint8Worker(); |
|
153 let context = worker.ContextPool._contexts[0]; |
|
154 let helper = context.GsmPDUHelper; |
|
155 let buf = context.Buf; |
|
156 let io = context.ICCIOHelper; |
|
157 |
|
158 function testDecodeImsi(encodedImsi, expectedImsi) { |
|
159 io.loadTransparentEF = function fakeLoadTransparentEF(options) { |
|
160 // Write data size |
|
161 buf.writeInt32(encodedImsi.length * 2); |
|
162 |
|
163 // Write imsi |
|
164 for (let i = 0; i < encodedImsi.length; i++) { |
|
165 helper.writeHexOctet(encodedImsi[i]); |
|
166 } |
|
167 |
|
168 // Write string delimiter |
|
169 buf.writeStringDelimiter(encodedImsi.length * 2); |
|
170 |
|
171 if (options.callback) { |
|
172 options.callback(options); |
|
173 } |
|
174 }; |
|
175 |
|
176 context.RuimRecordHelper.getIMSI_M(); |
|
177 let imsi = context.RIL.iccInfoPrivate.imsi; |
|
178 |
|
179 do_check_eq(expectedImsi, imsi) |
|
180 } |
|
181 |
|
182 let imsi_1 = "466050081062861"; |
|
183 testDecodeImsi([0x0, 0xe5, 0x03, 0xee, 0xca, 0x17, 0x5e, 0x80, 0x63, 0x01], imsi_1); |
|
184 |
|
185 let imsi_2 = "460038351175976"; |
|
186 testDecodeImsi([0x0, 0xd4, 0x02, 0x61, 0x97, 0x01, 0x5c, 0x80, 0x67, 0x01], imsi_2); |
|
187 |
|
188 run_next_test(); |
|
189 }); |
|
190 |
|
191 /** |
|
192 * Verify RuimRecordHelper.readCDMAHome |
|
193 */ |
|
194 add_test(function test_read_cdmahome() { |
|
195 let worker = newUint8Worker(); |
|
196 let context = worker.ContextPool._contexts[0]; |
|
197 let helper = context.GsmPDUHelper; |
|
198 let buf = context.Buf; |
|
199 let io = context.ICCIOHelper; |
|
200 |
|
201 io.loadLinearFixedEF = function fakeLoadLinearFixedEF(options) { |
|
202 let cdmaHome = [0xc1, 0x34, 0xff, 0xff, 0x00]; |
|
203 |
|
204 // Write data size |
|
205 buf.writeInt32(cdmaHome.length * 2); |
|
206 |
|
207 // Write cdma home file. |
|
208 for (let i = 0; i < cdmaHome.length; i++) { |
|
209 helper.writeHexOctet(cdmaHome[i]); |
|
210 } |
|
211 |
|
212 // Write string delimiter |
|
213 buf.writeStringDelimiter(cdmaHome.length * 2); |
|
214 |
|
215 // We just have 1 test record. |
|
216 |
|
217 options.totalRecords = 1; |
|
218 if (options.callback) { |
|
219 options.callback(options); |
|
220 } |
|
221 }; |
|
222 |
|
223 function testCdmaHome(expectedSystemIds, expectedNetworkIds) { |
|
224 context.RuimRecordHelper.readCDMAHome(); |
|
225 let cdmaHome = context.RIL.cdmaHome; |
|
226 for (let i = 0; i < expectedSystemIds.length; i++) { |
|
227 do_check_eq(cdmaHome.systemId[i], expectedSystemIds[i]); |
|
228 do_check_eq(cdmaHome.networkId[i], expectedNetworkIds[i]); |
|
229 } |
|
230 do_check_eq(cdmaHome.systemId.length, expectedSystemIds.length); |
|
231 do_check_eq(cdmaHome.networkId.length, expectedNetworkIds.length); |
|
232 } |
|
233 |
|
234 testCdmaHome([13505], [65535]); |
|
235 |
|
236 run_next_test(); |
|
237 }); |
|
238 |
|
239 /** |
|
240 * Verify reading CDMA EF_SPN |
|
241 */ |
|
242 add_test(function test_read_cdmaspn() { |
|
243 let worker = newUint8Worker(); |
|
244 let context = worker.ContextPool._contexts[0]; |
|
245 let helper = context.GsmPDUHelper; |
|
246 let buf = context.Buf; |
|
247 let io = context.ICCIOHelper; |
|
248 |
|
249 function testReadSpn(file, expectedSpn, expectedDisplayCondition) { |
|
250 io.loadTransparentEF = function fakeLoadTransparentEF(options) { |
|
251 // Write data size |
|
252 buf.writeInt32(file.length * 2); |
|
253 |
|
254 // Write file. |
|
255 for (let i = 0; i < file.length; i++) { |
|
256 helper.writeHexOctet(file[i]); |
|
257 } |
|
258 |
|
259 // Write string delimiter |
|
260 buf.writeStringDelimiter(file.length * 2); |
|
261 |
|
262 if (options.callback) { |
|
263 options.callback(options); |
|
264 } |
|
265 }; |
|
266 |
|
267 context.RuimRecordHelper.readSPN(); |
|
268 do_check_eq(context.RIL.iccInfo.spn, expectedSpn); |
|
269 do_check_eq(context.RIL.iccInfoPrivate.spnDisplayCondition, |
|
270 expectedDisplayCondition); |
|
271 } |
|
272 |
|
273 testReadSpn([0x01, 0x04, 0x06, 0x4e, 0x9e, 0x59, 0x2a, 0x96, |
|
274 0xfb, 0x4f, 0xe1, 0xff, 0xff, 0xff, 0xff, 0xff, |
|
275 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
|
276 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
|
277 0xff, 0xff, 0xff], |
|
278 String.fromCharCode(0x4e9e) + |
|
279 String.fromCharCode(0x592a) + |
|
280 String.fromCharCode(0x96fb) + |
|
281 String.fromCharCode(0x4fe1), |
|
282 0x1); |
|
283 |
|
284 // Test when there's no tailing 0xff in spn string. |
|
285 testReadSpn([0x01, 0x04, 0x06, 0x4e, 0x9e, 0x59, 0x2a, 0x96, |
|
286 0xfb, 0x4f, 0xe1], |
|
287 String.fromCharCode(0x4e9e) + |
|
288 String.fromCharCode(0x592a) + |
|
289 String.fromCharCode(0x96fb) + |
|
290 String.fromCharCode(0x4fe1), |
|
291 0x1); |
|
292 |
|
293 run_next_test(); |
|
294 }); |
|
295 |
|
296 /** |
|
297 * Verify display condition for CDMA. |
|
298 */ |
|
299 add_test(function test_cdma_spn_display_condition() { |
|
300 let worker = newWorker({ |
|
301 postRILMessage: function(data) { |
|
302 // Do nothing |
|
303 }, |
|
304 postMessage: function(message) { |
|
305 // Do nothing |
|
306 } |
|
307 }); |
|
308 let context = worker.ContextPool._contexts[0]; |
|
309 let RIL = context.RIL; |
|
310 let ICCUtilsHelper = context.ICCUtilsHelper; |
|
311 |
|
312 // Set cdma. |
|
313 RIL._isCdma = true; |
|
314 |
|
315 // Test updateDisplayCondition runs before any of SIM file is ready. |
|
316 do_check_eq(ICCUtilsHelper.updateDisplayCondition(), true); |
|
317 do_check_eq(RIL.iccInfo.isDisplayNetworkNameRequired, true); |
|
318 do_check_eq(RIL.iccInfo.isDisplaySpnRequired, false); |
|
319 |
|
320 // Test with value. |
|
321 function testDisplayCondition(ruimDisplayCondition, |
|
322 homeSystemIds, homeNetworkIds, |
|
323 currentSystemId, currentNetworkId, |
|
324 expectUpdateDisplayCondition, |
|
325 expectIsDisplaySPNRequired) { |
|
326 RIL.iccInfoPrivate.spnDisplayCondition = ruimDisplayCondition; |
|
327 RIL.cdmaHome = { |
|
328 systemId: homeSystemIds, |
|
329 networkId: homeNetworkIds |
|
330 }; |
|
331 RIL.voiceRegistrationState.cell = { |
|
332 cdmaSystemId: currentSystemId, |
|
333 cdmaNetworkId: currentNetworkId |
|
334 }; |
|
335 |
|
336 do_check_eq(ICCUtilsHelper.updateDisplayCondition(), expectUpdateDisplayCondition); |
|
337 do_check_eq(RIL.iccInfo.isDisplayNetworkNameRequired, false); |
|
338 do_check_eq(RIL.iccInfo.isDisplaySpnRequired, expectIsDisplaySPNRequired); |
|
339 }; |
|
340 |
|
341 // SPN is not required when ruimDisplayCondition is false. |
|
342 testDisplayCondition(0x0, [123], [345], 123, 345, true, false); |
|
343 |
|
344 // System id and network id are all match. |
|
345 testDisplayCondition(0x1, [123], [345], 123, 345, true, true); |
|
346 |
|
347 // Network is 65535, we should only need to match system id. |
|
348 testDisplayCondition(0x1, [123], [65535], 123, 345, false, true); |
|
349 |
|
350 // Not match. |
|
351 testDisplayCondition(0x1, [123], [456], 123, 345, true, false); |
|
352 |
|
353 run_next_test(); |
|
354 }); |