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