dom/system/gonk/tests/test_ril_worker_cellbroadcast_config.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

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 add_test(function test_ril_worker_cellbroadcast_activate() {
michael@0 11 let worker = newWorker({
michael@0 12 postRILMessage: function(id, parcel) {
michael@0 13 // Do nothing
michael@0 14 },
michael@0 15 postMessage: function(message) {
michael@0 16 // Do nothing
michael@0 17 }
michael@0 18 });
michael@0 19 let context = worker.ContextPool._contexts[0];
michael@0 20
michael@0 21 let parcelTypes = [];
michael@0 22 let org_newParcel = context.Buf.newParcel;
michael@0 23 context.Buf.newParcel = function(type, options) {
michael@0 24 parcelTypes.push(type);
michael@0 25 org_newParcel.apply(this, arguments);
michael@0 26 };
michael@0 27
michael@0 28 function setup(isCdma) {
michael@0 29 context.RIL._isCdma = isCdma;
michael@0 30 context.RIL.cellBroadcastDisabled = false;
michael@0 31 context.RIL.mergedCellBroadcastConfig = [1, 2, 4, 7]; // 1, 4-6
michael@0 32 parcelTypes = [];
michael@0 33 }
michael@0 34
michael@0 35 function test(isCdma, expectedRequest) {
michael@0 36 setup(isCdma);
michael@0 37 context.RIL.setCellBroadcastDisabled({disabled: true});
michael@0 38 // Makesure that request parcel is sent out.
michael@0 39 do_check_neq(parcelTypes.indexOf(expectedRequest), -1);
michael@0 40 do_check_eq(context.RIL.cellBroadcastDisabled, true);
michael@0 41 }
michael@0 42
michael@0 43 test(false, REQUEST_GSM_SMS_BROADCAST_ACTIVATION);
michael@0 44 test(true, REQUEST_CDMA_SMS_BROADCAST_ACTIVATION);
michael@0 45
michael@0 46 run_next_test();
michael@0 47 });
michael@0 48
michael@0 49 add_test(function test_ril_worker_cellbroadcast_config() {
michael@0 50 let currentParcel;
michael@0 51 let worker = newWorker({
michael@0 52 postRILMessage: function(id, parcel) {
michael@0 53 currentParcel = parcel;
michael@0 54 },
michael@0 55 postMessage: function(message) {
michael@0 56 // Do nothing
michael@0 57 }
michael@0 58 });
michael@0 59 let context = worker.ContextPool._contexts[0];
michael@0 60
michael@0 61 function U32ArrayFromParcelArray(pa) {
michael@0 62 do_print(pa);
michael@0 63 let out = [];
michael@0 64 for (let i = 0; i < pa.length; i += 4) {
michael@0 65 let data = pa[i] + (pa[i+1] << 8) + (pa[i+2] << 16) + (pa[i+3] << 24);
michael@0 66 out.push(data);
michael@0 67 }
michael@0 68 return out;
michael@0 69 }
michael@0 70
michael@0 71 function test(isCdma, configs, expected) {
michael@0 72 let parcelType = isCdma ? REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG
michael@0 73 : REQUEST_GSM_SET_BROADCAST_SMS_CONFIG;
michael@0 74
michael@0 75 let found = false;
michael@0 76 worker.postRILMessage = function(id, parcel) {
michael@0 77 u32Parcel = U32ArrayFromParcelArray(Array.slice(parcel));
michael@0 78 if (u32Parcel[1] != parcelType) {
michael@0 79 return;
michael@0 80 }
michael@0 81
michael@0 82 found = true;
michael@0 83 // Check parcel. Data start from 4th word (32bit)
michael@0 84 do_check_eq(u32Parcel.slice(3).toString(), expected);
michael@0 85 };
michael@0 86
michael@0 87 context.RIL._isCdma = isCdma;
michael@0 88 context.RIL.setSmsBroadcastConfig(configs);
michael@0 89
michael@0 90 // Makesure that request parcel is sent out.
michael@0 91 do_check_true(found);
michael@0 92 }
michael@0 93
michael@0 94 // (GSM) RIL writes the following data to outgoing parcel:
michael@0 95 // nums [(from, to, 0, 0xFF, 1), ... ]
michael@0 96 test(false,
michael@0 97 [1, 2, 4, 7] /* 1, 4-6 */,
michael@0 98 ["2", "1,2,0,255,1", "4,7,0,255,1"].join());
michael@0 99
michael@0 100 // (CDMA) RIL writes the following data to outgoing parcel:
michael@0 101 // nums [(id, 0, 1), ... ]
michael@0 102 test(true,
michael@0 103 [1, 2, 4, 7] /* 1, 4-6 */,
michael@0 104 ["4", "1,0,1", "4,0,1", "5,0,1", "6,0,1"].join());
michael@0 105
michael@0 106 run_next_test();
michael@0 107 });
michael@0 108
michael@0 109 add_test(function test_ril_worker_cellbroadcast_merge_config() {
michael@0 110 let worker = newWorker({
michael@0 111 postRILMessage: function(id, parcel) {
michael@0 112 // Do nothing
michael@0 113 },
michael@0 114 postMessage: function(message) {
michael@0 115 // Do nothing
michael@0 116 }
michael@0 117 });
michael@0 118 let context = worker.ContextPool._contexts[0];
michael@0 119
michael@0 120 function test(isCdma, configs, expected) {
michael@0 121 context.RIL._isCdma = isCdma;
michael@0 122 context.RIL.cellBroadcastConfigs = configs;
michael@0 123 context.RIL._mergeAllCellBroadcastConfigs();
michael@0 124 do_check_eq(context.RIL.mergedCellBroadcastConfig.toString(), expected);
michael@0 125 }
michael@0 126
michael@0 127 let configs = {
michael@0 128 MMI: [1, 2, 4, 7], // 1, 4-6
michael@0 129 CBMI: [6, 9], // 6-8
michael@0 130 CBMID: [8, 11], // 8-10
michael@0 131 CBMIR: [10, 13] // 10-12
michael@0 132 };
michael@0 133
michael@0 134 test(false, configs, "1,2,4,13");
michael@0 135 test(true, configs, "1,2,4,7");
michael@0 136
michael@0 137 run_next_test();
michael@0 138 });
michael@0 139
michael@0 140 add_test(function test_ril_worker_cellbroadcast_set_search_list() {
michael@0 141 let worker = newWorker({
michael@0 142 postRILMessage: function(id, parcel) {
michael@0 143 // Do nothing
michael@0 144 },
michael@0 145 postMessage: function(message) {
michael@0 146 // Do nothing
michael@0 147 }
michael@0 148 });
michael@0 149
michael@0 150 let context = worker.ContextPool._contexts[0];
michael@0 151
michael@0 152 function test(aIsCdma, aSearchList, aExpected) {
michael@0 153 context.RIL._isCdma = aIsCdma;
michael@0 154
michael@0 155 let options = { searchList: aSearchList };
michael@0 156 context.RIL.setCellBroadcastSearchList(options);
michael@0 157 // Enforce the MMI result to string for comparison.
michael@0 158 do_check_eq("" + context.RIL.cellBroadcastConfigs.MMI, aExpected);
michael@0 159 do_check_eq(options.success, true);
michael@0 160 }
michael@0 161
michael@0 162 let searchListStr = "1,2,3,4";
michael@0 163 let searchList = { gsm: "1,2,3,4", cdma: "5,6,7,8" };
michael@0 164
michael@0 165 test(false, searchListStr, "1,2,2,3,3,4,4,5");
michael@0 166 test(true, searchListStr, "1,2,2,3,3,4,4,5");
michael@0 167 test(false, searchList, "1,2,2,3,3,4,4,5");
michael@0 168 test(true, searchList, "5,6,6,7,7,8,8,9");
michael@0 169 test(false, null, "null");
michael@0 170 test(true, null, "null");
michael@0 171
michael@0 172 run_next_test();
michael@0 173 });

mercurial