|
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 // Calling line identification restriction constants. |
|
7 |
|
8 // Uses subscription default value. |
|
9 const CLIR_DEFAULT = 0; |
|
10 // Restricts CLI presentation. |
|
11 const CLIR_INVOCATION = 1; |
|
12 // Allows CLI presentation. |
|
13 const CLIR_SUPPRESSION = 2; |
|
14 |
|
15 function run_test() { |
|
16 run_next_test(); |
|
17 } |
|
18 |
|
19 function _getWorker() { |
|
20 let _postedMessage; |
|
21 let _worker = newWorker({ |
|
22 postRILMessage: function(data) { |
|
23 }, |
|
24 postMessage: function(message) { |
|
25 _postedMessage = message; |
|
26 } |
|
27 }); |
|
28 return { |
|
29 get postedMessage() { |
|
30 return _postedMessage; |
|
31 }, |
|
32 get worker() { |
|
33 return _worker; |
|
34 } |
|
35 }; |
|
36 } |
|
37 |
|
38 add_test(function test_setCLIR_success() { |
|
39 let workerHelper = _getWorker(); |
|
40 let worker = workerHelper.worker; |
|
41 let context = worker.ContextPool._contexts[0]; |
|
42 |
|
43 context.RIL.setCLIR = function fakeSetCLIR(options) { |
|
44 context.RIL[REQUEST_SET_CLIR](0, { |
|
45 rilMessageType: "setCLIR", |
|
46 rilRequestError: ERROR_SUCCESS |
|
47 }); |
|
48 }; |
|
49 |
|
50 context.RIL.setCLIR({ |
|
51 clirMode: CLIR_DEFAULT |
|
52 }); |
|
53 |
|
54 let postedMessage = workerHelper.postedMessage; |
|
55 |
|
56 do_check_eq(postedMessage.errorMsg, undefined); |
|
57 do_check_true(postedMessage.success); |
|
58 |
|
59 run_next_test(); |
|
60 }); |
|
61 |
|
62 add_test(function test_setCLIR_generic_failure() { |
|
63 let workerHelper = _getWorker(); |
|
64 let worker = workerHelper.worker; |
|
65 let context = worker.ContextPool._contexts[0]; |
|
66 |
|
67 context.RIL.setCLIR = function fakeSetCLIR(options) { |
|
68 context.RIL[REQUEST_SET_CLIR](0, { |
|
69 rilMessageType: "setCLIR", |
|
70 rilRequestError: ERROR_GENERIC_FAILURE |
|
71 }); |
|
72 }; |
|
73 |
|
74 context.RIL.setCLIR({ |
|
75 clirMode: CLIR_DEFAULT |
|
76 }); |
|
77 |
|
78 let postedMessage = workerHelper.postedMessage; |
|
79 |
|
80 do_check_eq(postedMessage.errorMsg, "GenericFailure"); |
|
81 do_check_false(postedMessage.success); |
|
82 |
|
83 run_next_test(); |
|
84 }); |
|
85 |
|
86 add_test(function test_getCLIR_n0_m1() { |
|
87 let workerHelper = _getWorker(); |
|
88 let worker = workerHelper.worker; |
|
89 let context = worker.ContextPool._contexts[0]; |
|
90 |
|
91 context.Buf.readInt32 = function fakeReadUint32() { |
|
92 return context.Buf.int32Array.pop(); |
|
93 }; |
|
94 |
|
95 context.RIL.getCLIR = function fakeGetCLIR(options) { |
|
96 context.Buf.int32Array = [ |
|
97 1, // Presentation indicator is used according to the subscription |
|
98 // of the CLIR service. |
|
99 0, // CLIR provisioned in permanent mode. |
|
100 2 // Length. |
|
101 ]; |
|
102 context.RIL[REQUEST_GET_CLIR](1, { |
|
103 rilMessageType: "setCLIR", |
|
104 rilRequestError: ERROR_SUCCESS |
|
105 }); |
|
106 }; |
|
107 |
|
108 context.RIL.getCLIR({}); |
|
109 |
|
110 let postedMessage = workerHelper.postedMessage; |
|
111 |
|
112 do_check_eq(postedMessage.errorMsg, undefined); |
|
113 do_check_true(postedMessage.success); |
|
114 do_check_eq(postedMessage.n, 0); |
|
115 do_check_eq(postedMessage.m, 1); |
|
116 run_next_test(); |
|
117 }); |
|
118 |
|
119 add_test(function test_getCLIR_error_generic_failure_invalid_length() { |
|
120 let workerHelper = _getWorker(); |
|
121 let worker = workerHelper.worker; |
|
122 let context = worker.ContextPool._contexts[0]; |
|
123 |
|
124 context.Buf.readInt32 = function fakeReadUint32() { |
|
125 return context.Buf.int32Array.pop(); |
|
126 }; |
|
127 |
|
128 context.RIL.getCLIR = function fakeGetCLIR(options) { |
|
129 context.Buf.int32Array = [ |
|
130 1, // Presentation indicator is used according to the subscription |
|
131 // of the CLIR service. |
|
132 0, // CLIR provisioned in permanent mode. |
|
133 0 // Length (invalid one). |
|
134 ]; |
|
135 context.RIL[REQUEST_GET_CLIR](1, { |
|
136 rilMessageType: "setCLIR", |
|
137 rilRequestError: ERROR_SUCCESS |
|
138 }); |
|
139 }; |
|
140 |
|
141 context.RIL.getCLIR({}); |
|
142 |
|
143 let postedMessage = workerHelper.postedMessage; |
|
144 |
|
145 do_check_eq(postedMessage.errorMsg, "GenericFailure"); |
|
146 do_check_false(postedMessage.success); |
|
147 run_next_test(); |
|
148 }); |