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: add_test(function test_ril_worker_cellbroadcast_activate() { michael@0: let worker = newWorker({ michael@0: postRILMessage: function(id, parcel) { 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: michael@0: let parcelTypes = []; michael@0: let org_newParcel = context.Buf.newParcel; michael@0: context.Buf.newParcel = function(type, options) { michael@0: parcelTypes.push(type); michael@0: org_newParcel.apply(this, arguments); michael@0: }; michael@0: michael@0: function setup(isCdma) { michael@0: context.RIL._isCdma = isCdma; michael@0: context.RIL.cellBroadcastDisabled = false; michael@0: context.RIL.mergedCellBroadcastConfig = [1, 2, 4, 7]; // 1, 4-6 michael@0: parcelTypes = []; michael@0: } michael@0: michael@0: function test(isCdma, expectedRequest) { michael@0: setup(isCdma); michael@0: context.RIL.setCellBroadcastDisabled({disabled: true}); michael@0: // Makesure that request parcel is sent out. michael@0: do_check_neq(parcelTypes.indexOf(expectedRequest), -1); michael@0: do_check_eq(context.RIL.cellBroadcastDisabled, true); michael@0: } michael@0: michael@0: test(false, REQUEST_GSM_SMS_BROADCAST_ACTIVATION); michael@0: test(true, REQUEST_CDMA_SMS_BROADCAST_ACTIVATION); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: add_test(function test_ril_worker_cellbroadcast_config() { michael@0: let currentParcel; michael@0: let worker = newWorker({ michael@0: postRILMessage: function(id, parcel) { michael@0: currentParcel = parcel; 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: michael@0: function U32ArrayFromParcelArray(pa) { michael@0: do_print(pa); michael@0: let out = []; michael@0: for (let i = 0; i < pa.length; i += 4) { michael@0: let data = pa[i] + (pa[i+1] << 8) + (pa[i+2] << 16) + (pa[i+3] << 24); michael@0: out.push(data); michael@0: } michael@0: return out; michael@0: } michael@0: michael@0: function test(isCdma, configs, expected) { michael@0: let parcelType = isCdma ? REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG michael@0: : REQUEST_GSM_SET_BROADCAST_SMS_CONFIG; michael@0: michael@0: let found = false; michael@0: worker.postRILMessage = function(id, parcel) { michael@0: u32Parcel = U32ArrayFromParcelArray(Array.slice(parcel)); michael@0: if (u32Parcel[1] != parcelType) { michael@0: return; michael@0: } michael@0: michael@0: found = true; michael@0: // Check parcel. Data start from 4th word (32bit) michael@0: do_check_eq(u32Parcel.slice(3).toString(), expected); michael@0: }; michael@0: michael@0: context.RIL._isCdma = isCdma; michael@0: context.RIL.setSmsBroadcastConfig(configs); michael@0: michael@0: // Makesure that request parcel is sent out. michael@0: do_check_true(found); michael@0: } michael@0: michael@0: // (GSM) RIL writes the following data to outgoing parcel: michael@0: // nums [(from, to, 0, 0xFF, 1), ... ] michael@0: test(false, michael@0: [1, 2, 4, 7] /* 1, 4-6 */, michael@0: ["2", "1,2,0,255,1", "4,7,0,255,1"].join()); michael@0: michael@0: // (CDMA) RIL writes the following data to outgoing parcel: michael@0: // nums [(id, 0, 1), ... ] michael@0: test(true, michael@0: [1, 2, 4, 7] /* 1, 4-6 */, michael@0: ["4", "1,0,1", "4,0,1", "5,0,1", "6,0,1"].join()); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: add_test(function test_ril_worker_cellbroadcast_merge_config() { michael@0: let worker = newWorker({ michael@0: postRILMessage: function(id, parcel) { 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: michael@0: function test(isCdma, configs, expected) { michael@0: context.RIL._isCdma = isCdma; michael@0: context.RIL.cellBroadcastConfigs = configs; michael@0: context.RIL._mergeAllCellBroadcastConfigs(); michael@0: do_check_eq(context.RIL.mergedCellBroadcastConfig.toString(), expected); michael@0: } michael@0: michael@0: let configs = { michael@0: MMI: [1, 2, 4, 7], // 1, 4-6 michael@0: CBMI: [6, 9], // 6-8 michael@0: CBMID: [8, 11], // 8-10 michael@0: CBMIR: [10, 13] // 10-12 michael@0: }; michael@0: michael@0: test(false, configs, "1,2,4,13"); michael@0: test(true, configs, "1,2,4,7"); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: add_test(function test_ril_worker_cellbroadcast_set_search_list() { michael@0: let worker = newWorker({ michael@0: postRILMessage: function(id, parcel) { michael@0: // Do nothing michael@0: }, michael@0: postMessage: function(message) { michael@0: // Do nothing michael@0: } michael@0: }); michael@0: michael@0: let context = worker.ContextPool._contexts[0]; michael@0: michael@0: function test(aIsCdma, aSearchList, aExpected) { michael@0: context.RIL._isCdma = aIsCdma; michael@0: michael@0: let options = { searchList: aSearchList }; michael@0: context.RIL.setCellBroadcastSearchList(options); michael@0: // Enforce the MMI result to string for comparison. michael@0: do_check_eq("" + context.RIL.cellBroadcastConfigs.MMI, aExpected); michael@0: do_check_eq(options.success, true); michael@0: } michael@0: michael@0: let searchListStr = "1,2,3,4"; michael@0: let searchList = { gsm: "1,2,3,4", cdma: "5,6,7,8" }; michael@0: michael@0: test(false, searchListStr, "1,2,2,3,3,4,4,5"); michael@0: test(true, searchListStr, "1,2,2,3,3,4,4,5"); michael@0: test(false, searchList, "1,2,2,3,3,4,4,5"); michael@0: test(true, searchList, "5,6,6,7,7,8,8,9"); michael@0: test(false, null, "null"); michael@0: test(true, null, "null"); michael@0: michael@0: run_next_test(); michael@0: });