1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/system/gonk/tests/test_ril_worker_ruim.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,354 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +subscriptLoader.loadSubScript("resource://gre/modules/ril_consts.js", this); 1.8 + 1.9 +function run_test() { 1.10 + run_next_test(); 1.11 +} 1.12 + 1.13 +/** 1.14 + * Helper function. 1.15 + */ 1.16 +function newUint8Worker() { 1.17 + let worker = newWorker(); 1.18 + let context = worker.ContextPool._contexts[0]; 1.19 + let index = 0; // index for read 1.20 + let buf = []; 1.21 + 1.22 + context.Buf.writeUint8 = function(value) { 1.23 + buf.push(value); 1.24 + }; 1.25 + 1.26 + context.Buf.readUint8 = function() { 1.27 + return buf[index++]; 1.28 + }; 1.29 + 1.30 + context.Buf.seekIncoming = function(offset) { 1.31 + index += offset; 1.32 + }; 1.33 + 1.34 + worker.debug = do_print; 1.35 + 1.36 + return worker; 1.37 +} 1.38 + 1.39 +/** 1.40 + * Verify RUIM Service. 1.41 + */ 1.42 +add_test(function test_is_ruim_service_available() { 1.43 + let worker = newWorker(); 1.44 + let context = worker.ContextPool._contexts[0]; 1.45 + context.RIL._isCdma = true; 1.46 + context.RIL.appType = CARD_APPTYPE_RUIM; 1.47 + 1.48 + function test_table(cst, geckoService, enabled) { 1.49 + context.RIL.iccInfoPrivate.cst = cst; 1.50 + do_check_eq(context.ICCUtilsHelper.isICCServiceAvailable(geckoService), 1.51 + enabled); 1.52 + } 1.53 + 1.54 + test_table([0x0, 0x0, 0x0, 0x0, 0x03], "SPN", true); 1.55 + test_table([0x0, 0x0, 0x0, 0x03, 0x0], "SPN", false); 1.56 + test_table([0x0, 0x0C, 0x0, 0x0, 0x0], "ENHANCED_PHONEBOOK", true); 1.57 + test_table([0x0, 0x0, 0x0, 0x0, 0x0], "ENHANCED_PHONEBOOK", false); 1.58 + 1.59 + run_next_test(); 1.60 +}); 1.61 + 1.62 +/** 1.63 + * Verify EF_PATH for RUIM file. 1.64 + */ 1.65 +add_test(function test_ruim_file_path_id() { 1.66 + let worker = newWorker(); 1.67 + let context = worker.ContextPool._contexts[0]; 1.68 + let RIL = context.RIL; 1.69 + let ICCFileHelper = context.ICCFileHelper; 1.70 + 1.71 + RIL.appType = CARD_APPTYPE_RUIM; 1.72 + do_check_eq(ICCFileHelper.getEFPath(ICC_EF_CSIM_CST), 1.73 + EF_PATH_MF_SIM + EF_PATH_DF_CDMA); 1.74 + 1.75 + run_next_test(); 1.76 +}); 1.77 + 1.78 +add_test(function test_fetch_ruim_recodes() { 1.79 + let worker = newWorker(); 1.80 + let context = worker.ContextPool._contexts[0]; 1.81 + let RIL = context.RIL; 1.82 + let ruimHelper = context.RuimRecordHelper; 1.83 + 1.84 + function testFetchRuimRecordes(expectCalled) { 1.85 + let ifCalled = []; 1.86 + 1.87 + ruimHelper.getIMSI_M = function() { 1.88 + ifCalled.push("getIMSI_M"); 1.89 + }; 1.90 + 1.91 + ruimHelper.readCST = function() { 1.92 + ifCalled.push("readCST"); 1.93 + }; 1.94 + 1.95 + ruimHelper.readCDMAHome = function() { 1.96 + ifCalled.push("readCDMAHome"); 1.97 + }; 1.98 + 1.99 + RIL.getCdmaSubscription = function() { 1.100 + ifCalled.push("getCdmaSubscription"); 1.101 + }; 1.102 + 1.103 + ruimHelper.fetchRuimRecords(); 1.104 + 1.105 + for (let i = 0; i < expectCalled.length; i++ ) { 1.106 + if (ifCalled[i] != expectCalled[i]) { 1.107 + do_print(expectCalled[i] + " is not called."); 1.108 + do_check_true(false); 1.109 + } 1.110 + } 1.111 + } 1.112 + 1.113 + let expectCalled = ["getIMSI_M", "readCST", "readCDMAHome", 1.114 + "getCdmaSubscription"]; 1.115 + testFetchRuimRecordes(expectCalled); 1.116 + 1.117 + run_next_test(); 1.118 +}); 1.119 + 1.120 +/** 1.121 + * Verify RuimRecordHelper.decodeIMSIValue 1.122 + */ 1.123 +add_test(function test_decode_imsi_value() { 1.124 + let worker = newUint8Worker(); 1.125 + let context = worker.ContextPool._contexts[0]; 1.126 + 1.127 + function testDecodeImsiValue(encoded, length, expect) { 1.128 + let decoded = context.RuimRecordHelper.decodeIMSIValue(encoded, length); 1.129 + 1.130 + do_check_eq(expect, decoded); 1.131 + } 1.132 + 1.133 + testDecodeImsiValue( 99, 2, "00"); 1.134 + testDecodeImsiValue( 90, 2, "01"); 1.135 + testDecodeImsiValue( 19, 2, "20"); 1.136 + testDecodeImsiValue( 23, 2, "34"); 1.137 + testDecodeImsiValue(999, 3, "000"); 1.138 + testDecodeImsiValue(990, 3, "001"); 1.139 + testDecodeImsiValue(909, 3, "010"); 1.140 + testDecodeImsiValue( 99, 3, "100"); 1.141 + testDecodeImsiValue(901, 3, "012"); 1.142 + testDecodeImsiValue( 19, 3, "120"); 1.143 + testDecodeImsiValue( 91, 3, "102"); 1.144 + testDecodeImsiValue(199, 3, "200"); 1.145 + testDecodeImsiValue(123, 3, "234"); 1.146 + testDecodeImsiValue(578, 3, "689"); 1.147 + 1.148 + run_next_test(); 1.149 +}); 1.150 + 1.151 +/** 1.152 + * Verify RuimRecordHelper.getIMSI_M 1.153 + */ 1.154 +add_test(function test_get_imsi_m() { 1.155 + let worker = newUint8Worker(); 1.156 + let context = worker.ContextPool._contexts[0]; 1.157 + let helper = context.GsmPDUHelper; 1.158 + let buf = context.Buf; 1.159 + let io = context.ICCIOHelper; 1.160 + 1.161 + function testDecodeImsi(encodedImsi, expectedImsi) { 1.162 + io.loadTransparentEF = function fakeLoadTransparentEF(options) { 1.163 + // Write data size 1.164 + buf.writeInt32(encodedImsi.length * 2); 1.165 + 1.166 + // Write imsi 1.167 + for (let i = 0; i < encodedImsi.length; i++) { 1.168 + helper.writeHexOctet(encodedImsi[i]); 1.169 + } 1.170 + 1.171 + // Write string delimiter 1.172 + buf.writeStringDelimiter(encodedImsi.length * 2); 1.173 + 1.174 + if (options.callback) { 1.175 + options.callback(options); 1.176 + } 1.177 + }; 1.178 + 1.179 + context.RuimRecordHelper.getIMSI_M(); 1.180 + let imsi = context.RIL.iccInfoPrivate.imsi; 1.181 + 1.182 + do_check_eq(expectedImsi, imsi) 1.183 + } 1.184 + 1.185 + let imsi_1 = "466050081062861"; 1.186 + testDecodeImsi([0x0, 0xe5, 0x03, 0xee, 0xca, 0x17, 0x5e, 0x80, 0x63, 0x01], imsi_1); 1.187 + 1.188 + let imsi_2 = "460038351175976"; 1.189 + testDecodeImsi([0x0, 0xd4, 0x02, 0x61, 0x97, 0x01, 0x5c, 0x80, 0x67, 0x01], imsi_2); 1.190 + 1.191 + run_next_test(); 1.192 +}); 1.193 + 1.194 +/** 1.195 + * Verify RuimRecordHelper.readCDMAHome 1.196 + */ 1.197 +add_test(function test_read_cdmahome() { 1.198 + let worker = newUint8Worker(); 1.199 + let context = worker.ContextPool._contexts[0]; 1.200 + let helper = context.GsmPDUHelper; 1.201 + let buf = context.Buf; 1.202 + let io = context.ICCIOHelper; 1.203 + 1.204 + io.loadLinearFixedEF = function fakeLoadLinearFixedEF(options) { 1.205 + let cdmaHome = [0xc1, 0x34, 0xff, 0xff, 0x00]; 1.206 + 1.207 + // Write data size 1.208 + buf.writeInt32(cdmaHome.length * 2); 1.209 + 1.210 + // Write cdma home file. 1.211 + for (let i = 0; i < cdmaHome.length; i++) { 1.212 + helper.writeHexOctet(cdmaHome[i]); 1.213 + } 1.214 + 1.215 + // Write string delimiter 1.216 + buf.writeStringDelimiter(cdmaHome.length * 2); 1.217 + 1.218 + // We just have 1 test record. 1.219 + 1.220 + options.totalRecords = 1; 1.221 + if (options.callback) { 1.222 + options.callback(options); 1.223 + } 1.224 + }; 1.225 + 1.226 + function testCdmaHome(expectedSystemIds, expectedNetworkIds) { 1.227 + context.RuimRecordHelper.readCDMAHome(); 1.228 + let cdmaHome = context.RIL.cdmaHome; 1.229 + for (let i = 0; i < expectedSystemIds.length; i++) { 1.230 + do_check_eq(cdmaHome.systemId[i], expectedSystemIds[i]); 1.231 + do_check_eq(cdmaHome.networkId[i], expectedNetworkIds[i]); 1.232 + } 1.233 + do_check_eq(cdmaHome.systemId.length, expectedSystemIds.length); 1.234 + do_check_eq(cdmaHome.networkId.length, expectedNetworkIds.length); 1.235 + } 1.236 + 1.237 + testCdmaHome([13505], [65535]); 1.238 + 1.239 + run_next_test(); 1.240 +}); 1.241 + 1.242 +/** 1.243 + * Verify reading CDMA EF_SPN 1.244 + */ 1.245 +add_test(function test_read_cdmaspn() { 1.246 + let worker = newUint8Worker(); 1.247 + let context = worker.ContextPool._contexts[0]; 1.248 + let helper = context.GsmPDUHelper; 1.249 + let buf = context.Buf; 1.250 + let io = context.ICCIOHelper; 1.251 + 1.252 + function testReadSpn(file, expectedSpn, expectedDisplayCondition) { 1.253 + io.loadTransparentEF = function fakeLoadTransparentEF(options) { 1.254 + // Write data size 1.255 + buf.writeInt32(file.length * 2); 1.256 + 1.257 + // Write file. 1.258 + for (let i = 0; i < file.length; i++) { 1.259 + helper.writeHexOctet(file[i]); 1.260 + } 1.261 + 1.262 + // Write string delimiter 1.263 + buf.writeStringDelimiter(file.length * 2); 1.264 + 1.265 + if (options.callback) { 1.266 + options.callback(options); 1.267 + } 1.268 + }; 1.269 + 1.270 + context.RuimRecordHelper.readSPN(); 1.271 + do_check_eq(context.RIL.iccInfo.spn, expectedSpn); 1.272 + do_check_eq(context.RIL.iccInfoPrivate.spnDisplayCondition, 1.273 + expectedDisplayCondition); 1.274 + } 1.275 + 1.276 + testReadSpn([0x01, 0x04, 0x06, 0x4e, 0x9e, 0x59, 0x2a, 0x96, 1.277 + 0xfb, 0x4f, 0xe1, 0xff, 0xff, 0xff, 0xff, 0xff, 1.278 + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 1.279 + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 1.280 + 0xff, 0xff, 0xff], 1.281 + String.fromCharCode(0x4e9e) + 1.282 + String.fromCharCode(0x592a) + 1.283 + String.fromCharCode(0x96fb) + 1.284 + String.fromCharCode(0x4fe1), 1.285 + 0x1); 1.286 + 1.287 + // Test when there's no tailing 0xff in spn string. 1.288 + testReadSpn([0x01, 0x04, 0x06, 0x4e, 0x9e, 0x59, 0x2a, 0x96, 1.289 + 0xfb, 0x4f, 0xe1], 1.290 + String.fromCharCode(0x4e9e) + 1.291 + String.fromCharCode(0x592a) + 1.292 + String.fromCharCode(0x96fb) + 1.293 + String.fromCharCode(0x4fe1), 1.294 + 0x1); 1.295 + 1.296 + run_next_test(); 1.297 +}); 1.298 + 1.299 +/** 1.300 + * Verify display condition for CDMA. 1.301 + */ 1.302 +add_test(function test_cdma_spn_display_condition() { 1.303 + let worker = newWorker({ 1.304 + postRILMessage: function(data) { 1.305 + // Do nothing 1.306 + }, 1.307 + postMessage: function(message) { 1.308 + // Do nothing 1.309 + } 1.310 + }); 1.311 + let context = worker.ContextPool._contexts[0]; 1.312 + let RIL = context.RIL; 1.313 + let ICCUtilsHelper = context.ICCUtilsHelper; 1.314 + 1.315 + // Set cdma. 1.316 + RIL._isCdma = true; 1.317 + 1.318 + // Test updateDisplayCondition runs before any of SIM file is ready. 1.319 + do_check_eq(ICCUtilsHelper.updateDisplayCondition(), true); 1.320 + do_check_eq(RIL.iccInfo.isDisplayNetworkNameRequired, true); 1.321 + do_check_eq(RIL.iccInfo.isDisplaySpnRequired, false); 1.322 + 1.323 + // Test with value. 1.324 + function testDisplayCondition(ruimDisplayCondition, 1.325 + homeSystemIds, homeNetworkIds, 1.326 + currentSystemId, currentNetworkId, 1.327 + expectUpdateDisplayCondition, 1.328 + expectIsDisplaySPNRequired) { 1.329 + RIL.iccInfoPrivate.spnDisplayCondition = ruimDisplayCondition; 1.330 + RIL.cdmaHome = { 1.331 + systemId: homeSystemIds, 1.332 + networkId: homeNetworkIds 1.333 + }; 1.334 + RIL.voiceRegistrationState.cell = { 1.335 + cdmaSystemId: currentSystemId, 1.336 + cdmaNetworkId: currentNetworkId 1.337 + }; 1.338 + 1.339 + do_check_eq(ICCUtilsHelper.updateDisplayCondition(), expectUpdateDisplayCondition); 1.340 + do_check_eq(RIL.iccInfo.isDisplayNetworkNameRequired, false); 1.341 + do_check_eq(RIL.iccInfo.isDisplaySpnRequired, expectIsDisplaySPNRequired); 1.342 + }; 1.343 + 1.344 + // SPN is not required when ruimDisplayCondition is false. 1.345 + testDisplayCondition(0x0, [123], [345], 123, 345, true, false); 1.346 + 1.347 + // System id and network id are all match. 1.348 + testDisplayCondition(0x1, [123], [345], 123, 345, true, true); 1.349 + 1.350 + // Network is 65535, we should only need to match system id. 1.351 + testDisplayCondition(0x1, [123], [65535], 123, 345, false, true); 1.352 + 1.353 + // Not match. 1.354 + testDisplayCondition(0x1, [123], [456], 123, 345, true, false); 1.355 + 1.356 + run_next_test(); 1.357 +});