|
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 _getWorker() { |
|
11 let _postedMessage; |
|
12 let _worker = newWorker({ |
|
13 postRILMessage: function(data) { |
|
14 }, |
|
15 postMessage: function(message) { |
|
16 _postedMessage = message; |
|
17 } |
|
18 }); |
|
19 return { |
|
20 get postedMessage() { |
|
21 return _postedMessage; |
|
22 }, |
|
23 get worker() { |
|
24 return _worker; |
|
25 } |
|
26 }; |
|
27 } |
|
28 |
|
29 add_test(function test_setCallWaiting_success() { |
|
30 let workerHelper = _getWorker(); |
|
31 let worker = workerHelper.worker; |
|
32 let context = worker.ContextPool._contexts[0]; |
|
33 |
|
34 context.RIL.setCallWaiting = function fakeSetCallWaiting(options) { |
|
35 context.RIL[REQUEST_SET_CALL_WAITING](0, { |
|
36 rilRequestError: ERROR_SUCCESS |
|
37 }); |
|
38 }; |
|
39 |
|
40 context.RIL.setCallWaiting({ |
|
41 enabled: true |
|
42 }); |
|
43 |
|
44 let postedMessage = workerHelper.postedMessage; |
|
45 |
|
46 do_check_eq(postedMessage.errorMsg, undefined); |
|
47 do_check_true(postedMessage.success); |
|
48 |
|
49 run_next_test(); |
|
50 }); |
|
51 |
|
52 add_test(function test_setCallWaiting_generic_failure() { |
|
53 let workerHelper = _getWorker(); |
|
54 let worker = workerHelper.worker; |
|
55 let context = worker.ContextPool._contexts[0]; |
|
56 |
|
57 context.RIL.setCallWaiting = function fakeSetCallWaiting(options) { |
|
58 context.RIL[REQUEST_SET_CALL_WAITING](0, { |
|
59 rilRequestError: ERROR_GENERIC_FAILURE |
|
60 }); |
|
61 }; |
|
62 |
|
63 context.RIL.setCallWaiting({ |
|
64 enabled: true |
|
65 }); |
|
66 |
|
67 let postedMessage = workerHelper.postedMessage; |
|
68 |
|
69 do_check_eq(postedMessage.errorMsg, "GenericFailure"); |
|
70 do_check_false(postedMessage.success); |
|
71 |
|
72 run_next_test(); |
|
73 }); |
|
74 |
|
75 add_test(function test_queryCallWaiting_success_enabled_true() { |
|
76 let workerHelper = _getWorker(); |
|
77 let worker = workerHelper.worker; |
|
78 let context = worker.ContextPool._contexts[0]; |
|
79 |
|
80 context.Buf.readInt32 = function fakeReadUint32() { |
|
81 return context.Buf.int32Array.pop(); |
|
82 }; |
|
83 |
|
84 context.RIL.queryCallWaiting = function fakeQueryCallWaiting(options) { |
|
85 context.Buf.int32Array = [ |
|
86 1, // serviceClass |
|
87 1, // enabled |
|
88 1 // length |
|
89 ]; |
|
90 context.RIL[REQUEST_QUERY_CALL_WAITING](1, { |
|
91 rilRequestError: ERROR_SUCCESS |
|
92 }); |
|
93 }; |
|
94 |
|
95 context.RIL.queryCallWaiting({}); |
|
96 |
|
97 let postedMessage = workerHelper.postedMessage; |
|
98 |
|
99 do_check_eq(postedMessage.errorMsg, undefined); |
|
100 do_check_true(postedMessage.success); |
|
101 do_check_eq(postedMessage.length, 1); |
|
102 do_check_true(postedMessage.enabled); |
|
103 run_next_test(); |
|
104 }); |
|
105 |
|
106 add_test(function test_queryCallWaiting_success_enabled_false() { |
|
107 let workerHelper = _getWorker(); |
|
108 let worker = workerHelper.worker; |
|
109 let context = worker.ContextPool._contexts[0]; |
|
110 |
|
111 context.Buf.readInt32 = function fakeReadUint32() { |
|
112 return context.Buf.int32Array.pop(); |
|
113 }; |
|
114 |
|
115 context.RIL.queryCallWaiting = function fakeQueryCallWaiting(options) { |
|
116 context.Buf.int32Array = [ |
|
117 1, // serviceClass |
|
118 0, // enabled |
|
119 1 // length |
|
120 ]; |
|
121 context.RIL[REQUEST_QUERY_CALL_WAITING](1, { |
|
122 rilRequestError: ERROR_SUCCESS |
|
123 }); |
|
124 }; |
|
125 |
|
126 context.RIL.queryCallWaiting({}); |
|
127 |
|
128 let postedMessage = workerHelper.postedMessage; |
|
129 |
|
130 do_check_eq(postedMessage.errorMsg, undefined); |
|
131 do_check_true(postedMessage.success); |
|
132 do_check_eq(postedMessage.length, 1); |
|
133 do_check_false(postedMessage.enabled); |
|
134 run_next_test(); |
|
135 }); |