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