Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
4 subscriptLoader.loadSubScript("resource://gre/modules/ril_consts.js", this);
6 // Calling line identification restriction constants.
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;
15 function run_test() {
16 run_next_test();
17 }
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 }
38 add_test(function test_setCLIR_success() {
39 let workerHelper = _getWorker();
40 let worker = workerHelper.worker;
41 let context = worker.ContextPool._contexts[0];
43 context.RIL.setCLIR = function fakeSetCLIR(options) {
44 context.RIL[REQUEST_SET_CLIR](0, {
45 rilMessageType: "setCLIR",
46 rilRequestError: ERROR_SUCCESS
47 });
48 };
50 context.RIL.setCLIR({
51 clirMode: CLIR_DEFAULT
52 });
54 let postedMessage = workerHelper.postedMessage;
56 do_check_eq(postedMessage.errorMsg, undefined);
57 do_check_true(postedMessage.success);
59 run_next_test();
60 });
62 add_test(function test_setCLIR_generic_failure() {
63 let workerHelper = _getWorker();
64 let worker = workerHelper.worker;
65 let context = worker.ContextPool._contexts[0];
67 context.RIL.setCLIR = function fakeSetCLIR(options) {
68 context.RIL[REQUEST_SET_CLIR](0, {
69 rilMessageType: "setCLIR",
70 rilRequestError: ERROR_GENERIC_FAILURE
71 });
72 };
74 context.RIL.setCLIR({
75 clirMode: CLIR_DEFAULT
76 });
78 let postedMessage = workerHelper.postedMessage;
80 do_check_eq(postedMessage.errorMsg, "GenericFailure");
81 do_check_false(postedMessage.success);
83 run_next_test();
84 });
86 add_test(function test_getCLIR_n0_m1() {
87 let workerHelper = _getWorker();
88 let worker = workerHelper.worker;
89 let context = worker.ContextPool._contexts[0];
91 context.Buf.readInt32 = function fakeReadUint32() {
92 return context.Buf.int32Array.pop();
93 };
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 };
108 context.RIL.getCLIR({});
110 let postedMessage = workerHelper.postedMessage;
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 });
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];
124 context.Buf.readInt32 = function fakeReadUint32() {
125 return context.Buf.int32Array.pop();
126 };
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 };
141 context.RIL.getCLIR({});
143 let postedMessage = workerHelper.postedMessage;
145 do_check_eq(postedMessage.errorMsg, "GenericFailure");
146 do_check_false(postedMessage.success);
147 run_next_test();
148 });