|
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 function toaFromString(number) { |
|
11 let worker = newWorker({ |
|
12 postRILMessage: function(data) { |
|
13 // Do nothing |
|
14 }, |
|
15 postMessage: function(message) { |
|
16 // Do nothing |
|
17 } |
|
18 }); |
|
19 let context = worker.ContextPool._contexts[0]; |
|
20 return context.RIL._toaFromString(number); |
|
21 } |
|
22 |
|
23 add_test(function test_toaFromString_empty() { |
|
24 let retval = toaFromString(""); |
|
25 |
|
26 do_check_eq(retval, TOA_UNKNOWN); |
|
27 |
|
28 run_next_test(); |
|
29 }); |
|
30 |
|
31 add_test(function test_toaFromString_undefined() { |
|
32 let retval = toaFromString(); |
|
33 |
|
34 do_check_eq(retval, TOA_UNKNOWN); |
|
35 |
|
36 run_next_test(); |
|
37 }); |
|
38 |
|
39 add_test(function test_toaFromString_unknown() { |
|
40 let retval = toaFromString("666222333"); |
|
41 |
|
42 do_check_eq(retval, TOA_UNKNOWN); |
|
43 |
|
44 run_next_test(); |
|
45 }); |
|
46 |
|
47 add_test(function test_toaFromString_international() { |
|
48 let retval = toaFromString("+34666222333"); |
|
49 |
|
50 do_check_eq(retval, TOA_INTERNATIONAL); |
|
51 |
|
52 run_next_test(); |
|
53 }); |
|
54 |
|
55 function _getWorker() { |
|
56 let _postedMessage; |
|
57 let _worker = newWorker({ |
|
58 postRILMessage: function(data) { |
|
59 }, |
|
60 postMessage: function(message) { |
|
61 _postedMessage = message; |
|
62 } |
|
63 }); |
|
64 return { |
|
65 get postedMessage() { |
|
66 return _postedMessage; |
|
67 }, |
|
68 get worker() { |
|
69 return _worker; |
|
70 } |
|
71 }; |
|
72 } |
|
73 |
|
74 add_test(function test_setCallForward_unconditional() { |
|
75 let workerHelper = _getWorker(); |
|
76 let worker = workerHelper.worker; |
|
77 let context = worker.ContextPool._contexts[0]; |
|
78 |
|
79 context.RIL.setCallForward = function fakeSetCallForward(options) { |
|
80 context.RIL[REQUEST_SET_CALL_FORWARD](0, { |
|
81 rilRequestError: ERROR_SUCCESS |
|
82 }); |
|
83 }; |
|
84 |
|
85 context.RIL.setCallForward({ |
|
86 action: Ci.nsIDOMMozMobileCFInfo.CALL_FORWARD_ACTION_REGISTRATION, |
|
87 reason: Ci.nsIDOMMozMobileCFInfo.CALL_FORWARD_REASON_UNCONDITIONAL, |
|
88 serviceClass: ICC_SERVICE_CLASS_VOICE, |
|
89 number: "666222333", |
|
90 timeSeconds: 10 |
|
91 }); |
|
92 |
|
93 let postedMessage = workerHelper.postedMessage; |
|
94 |
|
95 do_check_eq(postedMessage.errorMsg, GECKO_ERROR_SUCCESS); |
|
96 do_check_true(postedMessage.success); |
|
97 |
|
98 run_next_test(); |
|
99 }); |
|
100 |
|
101 add_test(function test_queryCallForwardStatus_unconditional() { |
|
102 let workerHelper = _getWorker(); |
|
103 let worker = workerHelper.worker; |
|
104 let context = worker.ContextPool._contexts[0]; |
|
105 |
|
106 context.RIL.setCallForward = function fakeSetCallForward(options) { |
|
107 context.RIL[REQUEST_SET_CALL_FORWARD](0, { |
|
108 rilRequestError: ERROR_SUCCESS |
|
109 }); |
|
110 }; |
|
111 |
|
112 context.Buf.readInt32 = function fakeReadUint32() { |
|
113 return context.Buf.int32Array.pop(); |
|
114 }; |
|
115 |
|
116 context.Buf.readString = function fakeReadString() { |
|
117 return "+34666222333"; |
|
118 }; |
|
119 |
|
120 context.RIL.queryCallForwardStatus = function fakeQueryCallForward(options) { |
|
121 context.Buf.int32Array = [ |
|
122 0, // rules.timeSeconds |
|
123 145, // rules.toa |
|
124 49, // rules.serviceClass |
|
125 Ci.nsIDOMMozMobileCFInfo.CALL_FORWARD_REASON_UNCONDITIONAL, // rules.reason |
|
126 1, // rules.active |
|
127 1 // rulesLength |
|
128 ]; |
|
129 context.RIL[REQUEST_QUERY_CALL_FORWARD_STATUS](1, { |
|
130 rilRequestError: ERROR_SUCCESS |
|
131 }); |
|
132 }; |
|
133 |
|
134 context.RIL.queryCallForwardStatus({ |
|
135 action: Ci.nsIDOMMozMobileCFInfo.CALL_FORWARD_ACTION_QUERY_STATUS, |
|
136 reason: Ci.nsIDOMMozMobileCFInfo.CALL_FORWARD_REASON_UNCONDITIONAL, |
|
137 serviceClass: ICC_SERVICE_CLASS_VOICE, |
|
138 number: "666222333", |
|
139 timeSeconds: 10 |
|
140 }); |
|
141 |
|
142 let postedMessage = workerHelper.postedMessage; |
|
143 |
|
144 do_check_eq(postedMessage.errorMsg, GECKO_ERROR_SUCCESS); |
|
145 do_check_true(postedMessage.success); |
|
146 do_check_true(Array.isArray(postedMessage.rules)); |
|
147 do_print(postedMessage.rules.length); |
|
148 do_check_eq(postedMessage.rules.length, 1); |
|
149 do_check_true(postedMessage.rules[0].active); |
|
150 do_check_eq(postedMessage.rules[0].reason, |
|
151 Ci.nsIDOMMozMobileCFInfo.CALL_FORWARD_REASON_UNCONDITIONAL); |
|
152 do_check_eq(postedMessage.rules[0].number, "+34666222333"); |
|
153 run_next_test(); |
|
154 }); |