|
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_queryCLIP_provisioned() { |
|
30 let workerHelper = _getWorker(); |
|
31 let worker = workerHelper.worker; |
|
32 let context = worker.ContextPool._contexts[0]; |
|
33 |
|
34 context.Buf.readInt32 = function fakeReadUint32() { |
|
35 return context.Buf.int32Array.pop(); |
|
36 }; |
|
37 |
|
38 context.RIL.queryCLIP = function fakeQueryCLIP(options) { |
|
39 context.Buf.int32Array = [ |
|
40 1, // CLIP provisioned. |
|
41 1 // Length. |
|
42 ]; |
|
43 context.RIL[REQUEST_QUERY_CLIP](1, { |
|
44 rilRequestError: ERROR_SUCCESS |
|
45 }); |
|
46 }; |
|
47 |
|
48 context.RIL.queryCLIP({}); |
|
49 |
|
50 let postedMessage = workerHelper.postedMessage; |
|
51 |
|
52 do_check_eq(postedMessage.errorMsg, undefined); |
|
53 do_check_true(postedMessage.success); |
|
54 do_check_eq(postedMessage.provisioned, 1); |
|
55 run_next_test(); |
|
56 }); |
|
57 |
|
58 add_test(function test_getCLIP_error_generic_failure_invalid_length() { |
|
59 let workerHelper = _getWorker(); |
|
60 let worker = workerHelper.worker; |
|
61 let context = worker.ContextPool._contexts[0]; |
|
62 |
|
63 context.Buf.readInt32 = function fakeReadUint32() { |
|
64 return context.Buf.int32Array.pop(); |
|
65 }; |
|
66 |
|
67 context.RIL.queryCLIP = function fakeQueryCLIP(options) { |
|
68 context.Buf.int32Array = [ |
|
69 1, // CLIP provisioned. |
|
70 0 // Length. |
|
71 ]; |
|
72 context.RIL[REQUEST_QUERY_CLIP](1, { |
|
73 rilRequestError: ERROR_SUCCESS |
|
74 }); |
|
75 }; |
|
76 |
|
77 context.RIL.queryCLIP({}); |
|
78 |
|
79 let postedMessage = workerHelper.postedMessage; |
|
80 |
|
81 do_check_eq(postedMessage.errorMsg, "GenericFailure"); |
|
82 do_check_false(postedMessage.success); |
|
83 run_next_test(); |
|
84 }); |