1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/system/gonk/tests/test_ril_worker_cellbroadcast_config.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,173 @@ 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 +add_test(function test_ril_worker_cellbroadcast_activate() { 1.14 + let worker = newWorker({ 1.15 + postRILMessage: function(id, parcel) { 1.16 + // Do nothing 1.17 + }, 1.18 + postMessage: function(message) { 1.19 + // Do nothing 1.20 + } 1.21 + }); 1.22 + let context = worker.ContextPool._contexts[0]; 1.23 + 1.24 + let parcelTypes = []; 1.25 + let org_newParcel = context.Buf.newParcel; 1.26 + context.Buf.newParcel = function(type, options) { 1.27 + parcelTypes.push(type); 1.28 + org_newParcel.apply(this, arguments); 1.29 + }; 1.30 + 1.31 + function setup(isCdma) { 1.32 + context.RIL._isCdma = isCdma; 1.33 + context.RIL.cellBroadcastDisabled = false; 1.34 + context.RIL.mergedCellBroadcastConfig = [1, 2, 4, 7]; // 1, 4-6 1.35 + parcelTypes = []; 1.36 + } 1.37 + 1.38 + function test(isCdma, expectedRequest) { 1.39 + setup(isCdma); 1.40 + context.RIL.setCellBroadcastDisabled({disabled: true}); 1.41 + // Makesure that request parcel is sent out. 1.42 + do_check_neq(parcelTypes.indexOf(expectedRequest), -1); 1.43 + do_check_eq(context.RIL.cellBroadcastDisabled, true); 1.44 + } 1.45 + 1.46 + test(false, REQUEST_GSM_SMS_BROADCAST_ACTIVATION); 1.47 + test(true, REQUEST_CDMA_SMS_BROADCAST_ACTIVATION); 1.48 + 1.49 + run_next_test(); 1.50 +}); 1.51 + 1.52 +add_test(function test_ril_worker_cellbroadcast_config() { 1.53 + let currentParcel; 1.54 + let worker = newWorker({ 1.55 + postRILMessage: function(id, parcel) { 1.56 + currentParcel = parcel; 1.57 + }, 1.58 + postMessage: function(message) { 1.59 + // Do nothing 1.60 + } 1.61 + }); 1.62 + let context = worker.ContextPool._contexts[0]; 1.63 + 1.64 + function U32ArrayFromParcelArray(pa) { 1.65 + do_print(pa); 1.66 + let out = []; 1.67 + for (let i = 0; i < pa.length; i += 4) { 1.68 + let data = pa[i] + (pa[i+1] << 8) + (pa[i+2] << 16) + (pa[i+3] << 24); 1.69 + out.push(data); 1.70 + } 1.71 + return out; 1.72 + } 1.73 + 1.74 + function test(isCdma, configs, expected) { 1.75 + let parcelType = isCdma ? REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG 1.76 + : REQUEST_GSM_SET_BROADCAST_SMS_CONFIG; 1.77 + 1.78 + let found = false; 1.79 + worker.postRILMessage = function(id, parcel) { 1.80 + u32Parcel = U32ArrayFromParcelArray(Array.slice(parcel)); 1.81 + if (u32Parcel[1] != parcelType) { 1.82 + return; 1.83 + } 1.84 + 1.85 + found = true; 1.86 + // Check parcel. Data start from 4th word (32bit) 1.87 + do_check_eq(u32Parcel.slice(3).toString(), expected); 1.88 + }; 1.89 + 1.90 + context.RIL._isCdma = isCdma; 1.91 + context.RIL.setSmsBroadcastConfig(configs); 1.92 + 1.93 + // Makesure that request parcel is sent out. 1.94 + do_check_true(found); 1.95 + } 1.96 + 1.97 + // (GSM) RIL writes the following data to outgoing parcel: 1.98 + // nums [(from, to, 0, 0xFF, 1), ... ] 1.99 + test(false, 1.100 + [1, 2, 4, 7] /* 1, 4-6 */, 1.101 + ["2", "1,2,0,255,1", "4,7,0,255,1"].join()); 1.102 + 1.103 + // (CDMA) RIL writes the following data to outgoing parcel: 1.104 + // nums [(id, 0, 1), ... ] 1.105 + test(true, 1.106 + [1, 2, 4, 7] /* 1, 4-6 */, 1.107 + ["4", "1,0,1", "4,0,1", "5,0,1", "6,0,1"].join()); 1.108 + 1.109 + run_next_test(); 1.110 +}); 1.111 + 1.112 +add_test(function test_ril_worker_cellbroadcast_merge_config() { 1.113 + let worker = newWorker({ 1.114 + postRILMessage: function(id, parcel) { 1.115 + // Do nothing 1.116 + }, 1.117 + postMessage: function(message) { 1.118 + // Do nothing 1.119 + } 1.120 + }); 1.121 + let context = worker.ContextPool._contexts[0]; 1.122 + 1.123 + function test(isCdma, configs, expected) { 1.124 + context.RIL._isCdma = isCdma; 1.125 + context.RIL.cellBroadcastConfigs = configs; 1.126 + context.RIL._mergeAllCellBroadcastConfigs(); 1.127 + do_check_eq(context.RIL.mergedCellBroadcastConfig.toString(), expected); 1.128 + } 1.129 + 1.130 + let configs = { 1.131 + MMI: [1, 2, 4, 7], // 1, 4-6 1.132 + CBMI: [6, 9], // 6-8 1.133 + CBMID: [8, 11], // 8-10 1.134 + CBMIR: [10, 13] // 10-12 1.135 + }; 1.136 + 1.137 + test(false, configs, "1,2,4,13"); 1.138 + test(true, configs, "1,2,4,7"); 1.139 + 1.140 + run_next_test(); 1.141 +}); 1.142 + 1.143 +add_test(function test_ril_worker_cellbroadcast_set_search_list() { 1.144 + let worker = newWorker({ 1.145 + postRILMessage: function(id, parcel) { 1.146 + // Do nothing 1.147 + }, 1.148 + postMessage: function(message) { 1.149 + // Do nothing 1.150 + } 1.151 + }); 1.152 + 1.153 + let context = worker.ContextPool._contexts[0]; 1.154 + 1.155 + function test(aIsCdma, aSearchList, aExpected) { 1.156 + context.RIL._isCdma = aIsCdma; 1.157 + 1.158 + let options = { searchList: aSearchList }; 1.159 + context.RIL.setCellBroadcastSearchList(options); 1.160 + // Enforce the MMI result to string for comparison. 1.161 + do_check_eq("" + context.RIL.cellBroadcastConfigs.MMI, aExpected); 1.162 + do_check_eq(options.success, true); 1.163 + } 1.164 + 1.165 + let searchListStr = "1,2,3,4"; 1.166 + let searchList = { gsm: "1,2,3,4", cdma: "5,6,7,8" }; 1.167 + 1.168 + test(false, searchListStr, "1,2,2,3,3,4,4,5"); 1.169 + test(true, searchListStr, "1,2,2,3,3,4,4,5"); 1.170 + test(false, searchList, "1,2,2,3,3,4,4,5"); 1.171 + test(true, searchList, "5,6,6,7,7,8,8,9"); 1.172 + test(false, null, "null"); 1.173 + test(true, null, "null"); 1.174 + 1.175 + run_next_test(); 1.176 +});