|
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_setVoicePrivacyMode_success() { |
|
30 let workerHelper = _getWorker(); |
|
31 let worker = workerHelper.worker; |
|
32 let context = worker.ContextPool._contexts[0]; |
|
33 |
|
34 context.RIL.setVoicePrivacyMode = function fakeSetVoicePrivacyMode(options) { |
|
35 context.RIL[REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE](0, { |
|
36 rilRequestError: ERROR_SUCCESS |
|
37 }); |
|
38 }; |
|
39 |
|
40 context.RIL.setVoicePrivacyMode({ |
|
41 enabled: true |
|
42 }); |
|
43 |
|
44 let postedMessage = workerHelper.postedMessage; |
|
45 |
|
46 do_check_eq(postedMessage.errorMsg, undefined); |
|
47 |
|
48 run_next_test(); |
|
49 }); |
|
50 |
|
51 add_test(function test_setVoicePrivacyMode_generic_failure() { |
|
52 let workerHelper = _getWorker(); |
|
53 let worker = workerHelper.worker; |
|
54 let context = worker.ContextPool._contexts[0]; |
|
55 |
|
56 context.RIL.setVoicePrivacyMode = function fakeSetVoicePrivacyMode(options) { |
|
57 context.RIL[REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE](0, { |
|
58 rilRequestError: ERROR_GENERIC_FAILURE |
|
59 }); |
|
60 }; |
|
61 |
|
62 context.RIL.setVoicePrivacyMode({ |
|
63 enabled: true |
|
64 }); |
|
65 |
|
66 let postedMessage = workerHelper.postedMessage; |
|
67 |
|
68 do_check_eq(postedMessage.errorMsg, "GenericFailure"); |
|
69 |
|
70 run_next_test(); |
|
71 }); |
|
72 |
|
73 add_test(function test_queryVoicePrivacyMode_success_enabled_true() { |
|
74 let workerHelper = _getWorker(); |
|
75 let worker = workerHelper.worker; |
|
76 let context = worker.ContextPool._contexts[0]; |
|
77 |
|
78 context.Buf.readInt32List = function fakeReadUint32List() { |
|
79 return [1]; |
|
80 }; |
|
81 |
|
82 context.RIL.queryVoicePrivacyMode = function fakeQueryVoicePrivacyMode(options) { |
|
83 context.RIL[REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE](1, { |
|
84 rilRequestError: ERROR_SUCCESS |
|
85 }); |
|
86 }; |
|
87 |
|
88 context.RIL.queryVoicePrivacyMode(); |
|
89 |
|
90 let postedMessage = workerHelper.postedMessage; |
|
91 |
|
92 do_check_eq(postedMessage.errorMsg, undefined); |
|
93 do_check_true(postedMessage.enabled); |
|
94 run_next_test(); |
|
95 }); |
|
96 |
|
97 add_test(function test_queryVoicePrivacyMode_success_enabled_false() { |
|
98 let workerHelper = _getWorker(); |
|
99 let worker = workerHelper.worker; |
|
100 let context = worker.ContextPool._contexts[0]; |
|
101 |
|
102 context.Buf.readInt32List = function fakeReadUint32List() { |
|
103 return [0]; |
|
104 }; |
|
105 |
|
106 context.RIL.queryVoicePrivacyMode = function fakeQueryVoicePrivacyMode(options) { |
|
107 context.RIL[REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE](1, { |
|
108 rilRequestError: ERROR_SUCCESS |
|
109 }); |
|
110 }; |
|
111 |
|
112 context.RIL.queryVoicePrivacyMode(); |
|
113 |
|
114 let postedMessage = workerHelper.postedMessage; |
|
115 |
|
116 do_check_eq(postedMessage.errorMsg, undefined); |
|
117 do_check_false(postedMessage.enabled); |
|
118 run_next_test(); |
|
119 }); |