michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: subscriptLoader.loadSubScript("resource://gre/modules/ril_consts.js", this); michael@0: michael@0: function run_test() { michael@0: run_next_test(); michael@0: } michael@0: michael@0: /** michael@0: * Helper function. michael@0: */ michael@0: function newUint8Worker() { michael@0: let worker = newWorker(); michael@0: let context = worker.ContextPool._contexts[0]; michael@0: let index = 0; // index for read michael@0: let buf = []; michael@0: michael@0: context.Buf.writeUint8 = function(value) { michael@0: buf.push(value); michael@0: }; michael@0: michael@0: context.Buf.readUint8 = function() { michael@0: return buf[index++]; michael@0: }; michael@0: michael@0: context.Buf.seekIncoming = function(offset) { michael@0: index += offset; michael@0: }; michael@0: michael@0: worker.debug = do_print; michael@0: michael@0: return worker; michael@0: } michael@0: michael@0: /** michael@0: * Verify RUIM Service. michael@0: */ michael@0: add_test(function test_is_ruim_service_available() { michael@0: let worker = newWorker(); michael@0: let context = worker.ContextPool._contexts[0]; michael@0: context.RIL._isCdma = true; michael@0: context.RIL.appType = CARD_APPTYPE_RUIM; michael@0: michael@0: function test_table(cst, geckoService, enabled) { michael@0: context.RIL.iccInfoPrivate.cst = cst; michael@0: do_check_eq(context.ICCUtilsHelper.isICCServiceAvailable(geckoService), michael@0: enabled); michael@0: } michael@0: michael@0: test_table([0x0, 0x0, 0x0, 0x0, 0x03], "SPN", true); michael@0: test_table([0x0, 0x0, 0x0, 0x03, 0x0], "SPN", false); michael@0: test_table([0x0, 0x0C, 0x0, 0x0, 0x0], "ENHANCED_PHONEBOOK", true); michael@0: test_table([0x0, 0x0, 0x0, 0x0, 0x0], "ENHANCED_PHONEBOOK", false); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: /** michael@0: * Verify EF_PATH for RUIM file. michael@0: */ michael@0: add_test(function test_ruim_file_path_id() { michael@0: let worker = newWorker(); michael@0: let context = worker.ContextPool._contexts[0]; michael@0: let RIL = context.RIL; michael@0: let ICCFileHelper = context.ICCFileHelper; michael@0: michael@0: RIL.appType = CARD_APPTYPE_RUIM; michael@0: do_check_eq(ICCFileHelper.getEFPath(ICC_EF_CSIM_CST), michael@0: EF_PATH_MF_SIM + EF_PATH_DF_CDMA); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: add_test(function test_fetch_ruim_recodes() { michael@0: let worker = newWorker(); michael@0: let context = worker.ContextPool._contexts[0]; michael@0: let RIL = context.RIL; michael@0: let ruimHelper = context.RuimRecordHelper; michael@0: michael@0: function testFetchRuimRecordes(expectCalled) { michael@0: let ifCalled = []; michael@0: michael@0: ruimHelper.getIMSI_M = function() { michael@0: ifCalled.push("getIMSI_M"); michael@0: }; michael@0: michael@0: ruimHelper.readCST = function() { michael@0: ifCalled.push("readCST"); michael@0: }; michael@0: michael@0: ruimHelper.readCDMAHome = function() { michael@0: ifCalled.push("readCDMAHome"); michael@0: }; michael@0: michael@0: RIL.getCdmaSubscription = function() { michael@0: ifCalled.push("getCdmaSubscription"); michael@0: }; michael@0: michael@0: ruimHelper.fetchRuimRecords(); michael@0: michael@0: for (let i = 0; i < expectCalled.length; i++ ) { michael@0: if (ifCalled[i] != expectCalled[i]) { michael@0: do_print(expectCalled[i] + " is not called."); michael@0: do_check_true(false); michael@0: } michael@0: } michael@0: } michael@0: michael@0: let expectCalled = ["getIMSI_M", "readCST", "readCDMAHome", michael@0: "getCdmaSubscription"]; michael@0: testFetchRuimRecordes(expectCalled); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: /** michael@0: * Verify RuimRecordHelper.decodeIMSIValue michael@0: */ michael@0: add_test(function test_decode_imsi_value() { michael@0: let worker = newUint8Worker(); michael@0: let context = worker.ContextPool._contexts[0]; michael@0: michael@0: function testDecodeImsiValue(encoded, length, expect) { michael@0: let decoded = context.RuimRecordHelper.decodeIMSIValue(encoded, length); michael@0: michael@0: do_check_eq(expect, decoded); michael@0: } michael@0: michael@0: testDecodeImsiValue( 99, 2, "00"); michael@0: testDecodeImsiValue( 90, 2, "01"); michael@0: testDecodeImsiValue( 19, 2, "20"); michael@0: testDecodeImsiValue( 23, 2, "34"); michael@0: testDecodeImsiValue(999, 3, "000"); michael@0: testDecodeImsiValue(990, 3, "001"); michael@0: testDecodeImsiValue(909, 3, "010"); michael@0: testDecodeImsiValue( 99, 3, "100"); michael@0: testDecodeImsiValue(901, 3, "012"); michael@0: testDecodeImsiValue( 19, 3, "120"); michael@0: testDecodeImsiValue( 91, 3, "102"); michael@0: testDecodeImsiValue(199, 3, "200"); michael@0: testDecodeImsiValue(123, 3, "234"); michael@0: testDecodeImsiValue(578, 3, "689"); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: /** michael@0: * Verify RuimRecordHelper.getIMSI_M michael@0: */ michael@0: add_test(function test_get_imsi_m() { michael@0: let worker = newUint8Worker(); michael@0: let context = worker.ContextPool._contexts[0]; michael@0: let helper = context.GsmPDUHelper; michael@0: let buf = context.Buf; michael@0: let io = context.ICCIOHelper; michael@0: michael@0: function testDecodeImsi(encodedImsi, expectedImsi) { michael@0: io.loadTransparentEF = function fakeLoadTransparentEF(options) { michael@0: // Write data size michael@0: buf.writeInt32(encodedImsi.length * 2); michael@0: michael@0: // Write imsi michael@0: for (let i = 0; i < encodedImsi.length; i++) { michael@0: helper.writeHexOctet(encodedImsi[i]); michael@0: } michael@0: michael@0: // Write string delimiter michael@0: buf.writeStringDelimiter(encodedImsi.length * 2); michael@0: michael@0: if (options.callback) { michael@0: options.callback(options); michael@0: } michael@0: }; michael@0: michael@0: context.RuimRecordHelper.getIMSI_M(); michael@0: let imsi = context.RIL.iccInfoPrivate.imsi; michael@0: michael@0: do_check_eq(expectedImsi, imsi) michael@0: } michael@0: michael@0: let imsi_1 = "466050081062861"; michael@0: testDecodeImsi([0x0, 0xe5, 0x03, 0xee, 0xca, 0x17, 0x5e, 0x80, 0x63, 0x01], imsi_1); michael@0: michael@0: let imsi_2 = "460038351175976"; michael@0: testDecodeImsi([0x0, 0xd4, 0x02, 0x61, 0x97, 0x01, 0x5c, 0x80, 0x67, 0x01], imsi_2); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: /** michael@0: * Verify RuimRecordHelper.readCDMAHome michael@0: */ michael@0: add_test(function test_read_cdmahome() { michael@0: let worker = newUint8Worker(); michael@0: let context = worker.ContextPool._contexts[0]; michael@0: let helper = context.GsmPDUHelper; michael@0: let buf = context.Buf; michael@0: let io = context.ICCIOHelper; michael@0: michael@0: io.loadLinearFixedEF = function fakeLoadLinearFixedEF(options) { michael@0: let cdmaHome = [0xc1, 0x34, 0xff, 0xff, 0x00]; michael@0: michael@0: // Write data size michael@0: buf.writeInt32(cdmaHome.length * 2); michael@0: michael@0: // Write cdma home file. michael@0: for (let i = 0; i < cdmaHome.length; i++) { michael@0: helper.writeHexOctet(cdmaHome[i]); michael@0: } michael@0: michael@0: // Write string delimiter michael@0: buf.writeStringDelimiter(cdmaHome.length * 2); michael@0: michael@0: // We just have 1 test record. michael@0: michael@0: options.totalRecords = 1; michael@0: if (options.callback) { michael@0: options.callback(options); michael@0: } michael@0: }; michael@0: michael@0: function testCdmaHome(expectedSystemIds, expectedNetworkIds) { michael@0: context.RuimRecordHelper.readCDMAHome(); michael@0: let cdmaHome = context.RIL.cdmaHome; michael@0: for (let i = 0; i < expectedSystemIds.length; i++) { michael@0: do_check_eq(cdmaHome.systemId[i], expectedSystemIds[i]); michael@0: do_check_eq(cdmaHome.networkId[i], expectedNetworkIds[i]); michael@0: } michael@0: do_check_eq(cdmaHome.systemId.length, expectedSystemIds.length); michael@0: do_check_eq(cdmaHome.networkId.length, expectedNetworkIds.length); michael@0: } michael@0: michael@0: testCdmaHome([13505], [65535]); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: /** michael@0: * Verify reading CDMA EF_SPN michael@0: */ michael@0: add_test(function test_read_cdmaspn() { michael@0: let worker = newUint8Worker(); michael@0: let context = worker.ContextPool._contexts[0]; michael@0: let helper = context.GsmPDUHelper; michael@0: let buf = context.Buf; michael@0: let io = context.ICCIOHelper; michael@0: michael@0: function testReadSpn(file, expectedSpn, expectedDisplayCondition) { michael@0: io.loadTransparentEF = function fakeLoadTransparentEF(options) { michael@0: // Write data size michael@0: buf.writeInt32(file.length * 2); michael@0: michael@0: // Write file. michael@0: for (let i = 0; i < file.length; i++) { michael@0: helper.writeHexOctet(file[i]); michael@0: } michael@0: michael@0: // Write string delimiter michael@0: buf.writeStringDelimiter(file.length * 2); michael@0: michael@0: if (options.callback) { michael@0: options.callback(options); michael@0: } michael@0: }; michael@0: michael@0: context.RuimRecordHelper.readSPN(); michael@0: do_check_eq(context.RIL.iccInfo.spn, expectedSpn); michael@0: do_check_eq(context.RIL.iccInfoPrivate.spnDisplayCondition, michael@0: expectedDisplayCondition); michael@0: } michael@0: michael@0: testReadSpn([0x01, 0x04, 0x06, 0x4e, 0x9e, 0x59, 0x2a, 0x96, michael@0: 0xfb, 0x4f, 0xe1, 0xff, 0xff, 0xff, 0xff, 0xff, michael@0: 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, michael@0: 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, michael@0: 0xff, 0xff, 0xff], michael@0: String.fromCharCode(0x4e9e) + michael@0: String.fromCharCode(0x592a) + michael@0: String.fromCharCode(0x96fb) + michael@0: String.fromCharCode(0x4fe1), michael@0: 0x1); michael@0: michael@0: // Test when there's no tailing 0xff in spn string. michael@0: testReadSpn([0x01, 0x04, 0x06, 0x4e, 0x9e, 0x59, 0x2a, 0x96, michael@0: 0xfb, 0x4f, 0xe1], michael@0: String.fromCharCode(0x4e9e) + michael@0: String.fromCharCode(0x592a) + michael@0: String.fromCharCode(0x96fb) + michael@0: String.fromCharCode(0x4fe1), michael@0: 0x1); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: /** michael@0: * Verify display condition for CDMA. michael@0: */ michael@0: add_test(function test_cdma_spn_display_condition() { michael@0: let worker = newWorker({ michael@0: postRILMessage: function(data) { michael@0: // Do nothing michael@0: }, michael@0: postMessage: function(message) { michael@0: // Do nothing michael@0: } michael@0: }); michael@0: let context = worker.ContextPool._contexts[0]; michael@0: let RIL = context.RIL; michael@0: let ICCUtilsHelper = context.ICCUtilsHelper; michael@0: michael@0: // Set cdma. michael@0: RIL._isCdma = true; michael@0: michael@0: // Test updateDisplayCondition runs before any of SIM file is ready. michael@0: do_check_eq(ICCUtilsHelper.updateDisplayCondition(), true); michael@0: do_check_eq(RIL.iccInfo.isDisplayNetworkNameRequired, true); michael@0: do_check_eq(RIL.iccInfo.isDisplaySpnRequired, false); michael@0: michael@0: // Test with value. michael@0: function testDisplayCondition(ruimDisplayCondition, michael@0: homeSystemIds, homeNetworkIds, michael@0: currentSystemId, currentNetworkId, michael@0: expectUpdateDisplayCondition, michael@0: expectIsDisplaySPNRequired) { michael@0: RIL.iccInfoPrivate.spnDisplayCondition = ruimDisplayCondition; michael@0: RIL.cdmaHome = { michael@0: systemId: homeSystemIds, michael@0: networkId: homeNetworkIds michael@0: }; michael@0: RIL.voiceRegistrationState.cell = { michael@0: cdmaSystemId: currentSystemId, michael@0: cdmaNetworkId: currentNetworkId michael@0: }; michael@0: michael@0: do_check_eq(ICCUtilsHelper.updateDisplayCondition(), expectUpdateDisplayCondition); michael@0: do_check_eq(RIL.iccInfo.isDisplayNetworkNameRequired, false); michael@0: do_check_eq(RIL.iccInfo.isDisplaySpnRequired, expectIsDisplaySPNRequired); michael@0: }; michael@0: michael@0: // SPN is not required when ruimDisplayCondition is false. michael@0: testDisplayCondition(0x0, [123], [345], 123, 345, true, false); michael@0: michael@0: // System id and network id are all match. michael@0: testDisplayCondition(0x1, [123], [345], 123, 345, true, true); michael@0: michael@0: // Network is 65535, we should only need to match system id. michael@0: testDisplayCondition(0x1, [123], [65535], 123, 345, false, true); michael@0: michael@0: // Not match. michael@0: testDisplayCondition(0x1, [123], [456], 123, 345, true, false); michael@0: michael@0: run_next_test(); michael@0: });