1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/system/gonk/tests/test_ril_worker_clir.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,148 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +subscriptLoader.loadSubScript("resource://gre/modules/ril_consts.js", this); 1.8 + 1.9 +// Calling line identification restriction constants. 1.10 + 1.11 +// Uses subscription default value. 1.12 +const CLIR_DEFAULT = 0; 1.13 +// Restricts CLI presentation. 1.14 +const CLIR_INVOCATION = 1; 1.15 +// Allows CLI presentation. 1.16 +const CLIR_SUPPRESSION = 2; 1.17 + 1.18 +function run_test() { 1.19 + run_next_test(); 1.20 +} 1.21 + 1.22 +function _getWorker() { 1.23 + let _postedMessage; 1.24 + let _worker = newWorker({ 1.25 + postRILMessage: function(data) { 1.26 + }, 1.27 + postMessage: function(message) { 1.28 + _postedMessage = message; 1.29 + } 1.30 + }); 1.31 + return { 1.32 + get postedMessage() { 1.33 + return _postedMessage; 1.34 + }, 1.35 + get worker() { 1.36 + return _worker; 1.37 + } 1.38 + }; 1.39 +} 1.40 + 1.41 +add_test(function test_setCLIR_success() { 1.42 + let workerHelper = _getWorker(); 1.43 + let worker = workerHelper.worker; 1.44 + let context = worker.ContextPool._contexts[0]; 1.45 + 1.46 + context.RIL.setCLIR = function fakeSetCLIR(options) { 1.47 + context.RIL[REQUEST_SET_CLIR](0, { 1.48 + rilMessageType: "setCLIR", 1.49 + rilRequestError: ERROR_SUCCESS 1.50 + }); 1.51 + }; 1.52 + 1.53 + context.RIL.setCLIR({ 1.54 + clirMode: CLIR_DEFAULT 1.55 + }); 1.56 + 1.57 + let postedMessage = workerHelper.postedMessage; 1.58 + 1.59 + do_check_eq(postedMessage.errorMsg, undefined); 1.60 + do_check_true(postedMessage.success); 1.61 + 1.62 + run_next_test(); 1.63 +}); 1.64 + 1.65 +add_test(function test_setCLIR_generic_failure() { 1.66 + let workerHelper = _getWorker(); 1.67 + let worker = workerHelper.worker; 1.68 + let context = worker.ContextPool._contexts[0]; 1.69 + 1.70 + context.RIL.setCLIR = function fakeSetCLIR(options) { 1.71 + context.RIL[REQUEST_SET_CLIR](0, { 1.72 + rilMessageType: "setCLIR", 1.73 + rilRequestError: ERROR_GENERIC_FAILURE 1.74 + }); 1.75 + }; 1.76 + 1.77 + context.RIL.setCLIR({ 1.78 + clirMode: CLIR_DEFAULT 1.79 + }); 1.80 + 1.81 + let postedMessage = workerHelper.postedMessage; 1.82 + 1.83 + do_check_eq(postedMessage.errorMsg, "GenericFailure"); 1.84 + do_check_false(postedMessage.success); 1.85 + 1.86 + run_next_test(); 1.87 +}); 1.88 + 1.89 +add_test(function test_getCLIR_n0_m1() { 1.90 + let workerHelper = _getWorker(); 1.91 + let worker = workerHelper.worker; 1.92 + let context = worker.ContextPool._contexts[0]; 1.93 + 1.94 + context.Buf.readInt32 = function fakeReadUint32() { 1.95 + return context.Buf.int32Array.pop(); 1.96 + }; 1.97 + 1.98 + context.RIL.getCLIR = function fakeGetCLIR(options) { 1.99 + context.Buf.int32Array = [ 1.100 + 1, // Presentation indicator is used according to the subscription 1.101 + // of the CLIR service. 1.102 + 0, // CLIR provisioned in permanent mode. 1.103 + 2 // Length. 1.104 + ]; 1.105 + context.RIL[REQUEST_GET_CLIR](1, { 1.106 + rilMessageType: "setCLIR", 1.107 + rilRequestError: ERROR_SUCCESS 1.108 + }); 1.109 + }; 1.110 + 1.111 + context.RIL.getCLIR({}); 1.112 + 1.113 + let postedMessage = workerHelper.postedMessage; 1.114 + 1.115 + do_check_eq(postedMessage.errorMsg, undefined); 1.116 + do_check_true(postedMessage.success); 1.117 + do_check_eq(postedMessage.n, 0); 1.118 + do_check_eq(postedMessage.m, 1); 1.119 + run_next_test(); 1.120 +}); 1.121 + 1.122 +add_test(function test_getCLIR_error_generic_failure_invalid_length() { 1.123 + let workerHelper = _getWorker(); 1.124 + let worker = workerHelper.worker; 1.125 + let context = worker.ContextPool._contexts[0]; 1.126 + 1.127 + context.Buf.readInt32 = function fakeReadUint32() { 1.128 + return context.Buf.int32Array.pop(); 1.129 + }; 1.130 + 1.131 + context.RIL.getCLIR = function fakeGetCLIR(options) { 1.132 + context.Buf.int32Array = [ 1.133 + 1, // Presentation indicator is used according to the subscription 1.134 + // of the CLIR service. 1.135 + 0, // CLIR provisioned in permanent mode. 1.136 + 0 // Length (invalid one). 1.137 + ]; 1.138 + context.RIL[REQUEST_GET_CLIR](1, { 1.139 + rilMessageType: "setCLIR", 1.140 + rilRequestError: ERROR_SUCCESS 1.141 + }); 1.142 + }; 1.143 + 1.144 + context.RIL.getCLIR({}); 1.145 + 1.146 + let postedMessage = workerHelper.postedMessage; 1.147 + 1.148 + do_check_eq(postedMessage.errorMsg, "GenericFailure"); 1.149 + do_check_false(postedMessage.success); 1.150 + run_next_test(); 1.151 +});