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
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | subscriptLoader.loadSubScript("resource://gre/modules/ril_consts.js", this); |
michael@0 | 5 | |
michael@0 | 6 | // Calling line identification restriction constants. |
michael@0 | 7 | |
michael@0 | 8 | // Uses subscription default value. |
michael@0 | 9 | const CLIR_DEFAULT = 0; |
michael@0 | 10 | // Restricts CLI presentation. |
michael@0 | 11 | const CLIR_INVOCATION = 1; |
michael@0 | 12 | // Allows CLI presentation. |
michael@0 | 13 | const CLIR_SUPPRESSION = 2; |
michael@0 | 14 | |
michael@0 | 15 | function run_test() { |
michael@0 | 16 | run_next_test(); |
michael@0 | 17 | } |
michael@0 | 18 | |
michael@0 | 19 | function _getWorker() { |
michael@0 | 20 | let _postedMessage; |
michael@0 | 21 | let _worker = newWorker({ |
michael@0 | 22 | postRILMessage: function(data) { |
michael@0 | 23 | }, |
michael@0 | 24 | postMessage: function(message) { |
michael@0 | 25 | _postedMessage = message; |
michael@0 | 26 | } |
michael@0 | 27 | }); |
michael@0 | 28 | return { |
michael@0 | 29 | get postedMessage() { |
michael@0 | 30 | return _postedMessage; |
michael@0 | 31 | }, |
michael@0 | 32 | get worker() { |
michael@0 | 33 | return _worker; |
michael@0 | 34 | } |
michael@0 | 35 | }; |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | add_test(function test_setCLIR_success() { |
michael@0 | 39 | let workerHelper = _getWorker(); |
michael@0 | 40 | let worker = workerHelper.worker; |
michael@0 | 41 | let context = worker.ContextPool._contexts[0]; |
michael@0 | 42 | |
michael@0 | 43 | context.RIL.setCLIR = function fakeSetCLIR(options) { |
michael@0 | 44 | context.RIL[REQUEST_SET_CLIR](0, { |
michael@0 | 45 | rilMessageType: "setCLIR", |
michael@0 | 46 | rilRequestError: ERROR_SUCCESS |
michael@0 | 47 | }); |
michael@0 | 48 | }; |
michael@0 | 49 | |
michael@0 | 50 | context.RIL.setCLIR({ |
michael@0 | 51 | clirMode: CLIR_DEFAULT |
michael@0 | 52 | }); |
michael@0 | 53 | |
michael@0 | 54 | let postedMessage = workerHelper.postedMessage; |
michael@0 | 55 | |
michael@0 | 56 | do_check_eq(postedMessage.errorMsg, undefined); |
michael@0 | 57 | do_check_true(postedMessage.success); |
michael@0 | 58 | |
michael@0 | 59 | run_next_test(); |
michael@0 | 60 | }); |
michael@0 | 61 | |
michael@0 | 62 | add_test(function test_setCLIR_generic_failure() { |
michael@0 | 63 | let workerHelper = _getWorker(); |
michael@0 | 64 | let worker = workerHelper.worker; |
michael@0 | 65 | let context = worker.ContextPool._contexts[0]; |
michael@0 | 66 | |
michael@0 | 67 | context.RIL.setCLIR = function fakeSetCLIR(options) { |
michael@0 | 68 | context.RIL[REQUEST_SET_CLIR](0, { |
michael@0 | 69 | rilMessageType: "setCLIR", |
michael@0 | 70 | rilRequestError: ERROR_GENERIC_FAILURE |
michael@0 | 71 | }); |
michael@0 | 72 | }; |
michael@0 | 73 | |
michael@0 | 74 | context.RIL.setCLIR({ |
michael@0 | 75 | clirMode: CLIR_DEFAULT |
michael@0 | 76 | }); |
michael@0 | 77 | |
michael@0 | 78 | let postedMessage = workerHelper.postedMessage; |
michael@0 | 79 | |
michael@0 | 80 | do_check_eq(postedMessage.errorMsg, "GenericFailure"); |
michael@0 | 81 | do_check_false(postedMessage.success); |
michael@0 | 82 | |
michael@0 | 83 | run_next_test(); |
michael@0 | 84 | }); |
michael@0 | 85 | |
michael@0 | 86 | add_test(function test_getCLIR_n0_m1() { |
michael@0 | 87 | let workerHelper = _getWorker(); |
michael@0 | 88 | let worker = workerHelper.worker; |
michael@0 | 89 | let context = worker.ContextPool._contexts[0]; |
michael@0 | 90 | |
michael@0 | 91 | context.Buf.readInt32 = function fakeReadUint32() { |
michael@0 | 92 | return context.Buf.int32Array.pop(); |
michael@0 | 93 | }; |
michael@0 | 94 | |
michael@0 | 95 | context.RIL.getCLIR = function fakeGetCLIR(options) { |
michael@0 | 96 | context.Buf.int32Array = [ |
michael@0 | 97 | 1, // Presentation indicator is used according to the subscription |
michael@0 | 98 | // of the CLIR service. |
michael@0 | 99 | 0, // CLIR provisioned in permanent mode. |
michael@0 | 100 | 2 // Length. |
michael@0 | 101 | ]; |
michael@0 | 102 | context.RIL[REQUEST_GET_CLIR](1, { |
michael@0 | 103 | rilMessageType: "setCLIR", |
michael@0 | 104 | rilRequestError: ERROR_SUCCESS |
michael@0 | 105 | }); |
michael@0 | 106 | }; |
michael@0 | 107 | |
michael@0 | 108 | context.RIL.getCLIR({}); |
michael@0 | 109 | |
michael@0 | 110 | let postedMessage = workerHelper.postedMessage; |
michael@0 | 111 | |
michael@0 | 112 | do_check_eq(postedMessage.errorMsg, undefined); |
michael@0 | 113 | do_check_true(postedMessage.success); |
michael@0 | 114 | do_check_eq(postedMessage.n, 0); |
michael@0 | 115 | do_check_eq(postedMessage.m, 1); |
michael@0 | 116 | run_next_test(); |
michael@0 | 117 | }); |
michael@0 | 118 | |
michael@0 | 119 | add_test(function test_getCLIR_error_generic_failure_invalid_length() { |
michael@0 | 120 | let workerHelper = _getWorker(); |
michael@0 | 121 | let worker = workerHelper.worker; |
michael@0 | 122 | let context = worker.ContextPool._contexts[0]; |
michael@0 | 123 | |
michael@0 | 124 | context.Buf.readInt32 = function fakeReadUint32() { |
michael@0 | 125 | return context.Buf.int32Array.pop(); |
michael@0 | 126 | }; |
michael@0 | 127 | |
michael@0 | 128 | context.RIL.getCLIR = function fakeGetCLIR(options) { |
michael@0 | 129 | context.Buf.int32Array = [ |
michael@0 | 130 | 1, // Presentation indicator is used according to the subscription |
michael@0 | 131 | // of the CLIR service. |
michael@0 | 132 | 0, // CLIR provisioned in permanent mode. |
michael@0 | 133 | 0 // Length (invalid one). |
michael@0 | 134 | ]; |
michael@0 | 135 | context.RIL[REQUEST_GET_CLIR](1, { |
michael@0 | 136 | rilMessageType: "setCLIR", |
michael@0 | 137 | rilRequestError: ERROR_SUCCESS |
michael@0 | 138 | }); |
michael@0 | 139 | }; |
michael@0 | 140 | |
michael@0 | 141 | context.RIL.getCLIR({}); |
michael@0 | 142 | |
michael@0 | 143 | let postedMessage = workerHelper.postedMessage; |
michael@0 | 144 | |
michael@0 | 145 | do_check_eq(postedMessage.errorMsg, "GenericFailure"); |
michael@0 | 146 | do_check_false(postedMessage.success); |
michael@0 | 147 | run_next_test(); |
michael@0 | 148 | }); |