1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/system/gonk/tests/test_ril_worker_cf.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,154 @@ 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 +function run_test() { 1.10 + run_next_test(); 1.11 +} 1.12 + 1.13 +function toaFromString(number) { 1.14 + let worker = newWorker({ 1.15 + postRILMessage: function(data) { 1.16 + // Do nothing 1.17 + }, 1.18 + postMessage: function(message) { 1.19 + // Do nothing 1.20 + } 1.21 + }); 1.22 + let context = worker.ContextPool._contexts[0]; 1.23 + return context.RIL._toaFromString(number); 1.24 +} 1.25 + 1.26 +add_test(function test_toaFromString_empty() { 1.27 + let retval = toaFromString(""); 1.28 + 1.29 + do_check_eq(retval, TOA_UNKNOWN); 1.30 + 1.31 + run_next_test(); 1.32 +}); 1.33 + 1.34 +add_test(function test_toaFromString_undefined() { 1.35 + let retval = toaFromString(); 1.36 + 1.37 + do_check_eq(retval, TOA_UNKNOWN); 1.38 + 1.39 + run_next_test(); 1.40 +}); 1.41 + 1.42 +add_test(function test_toaFromString_unknown() { 1.43 + let retval = toaFromString("666222333"); 1.44 + 1.45 + do_check_eq(retval, TOA_UNKNOWN); 1.46 + 1.47 + run_next_test(); 1.48 +}); 1.49 + 1.50 +add_test(function test_toaFromString_international() { 1.51 + let retval = toaFromString("+34666222333"); 1.52 + 1.53 + do_check_eq(retval, TOA_INTERNATIONAL); 1.54 + 1.55 + run_next_test(); 1.56 +}); 1.57 + 1.58 +function _getWorker() { 1.59 + let _postedMessage; 1.60 + let _worker = newWorker({ 1.61 + postRILMessage: function(data) { 1.62 + }, 1.63 + postMessage: function(message) { 1.64 + _postedMessage = message; 1.65 + } 1.66 + }); 1.67 + return { 1.68 + get postedMessage() { 1.69 + return _postedMessage; 1.70 + }, 1.71 + get worker() { 1.72 + return _worker; 1.73 + } 1.74 + }; 1.75 +} 1.76 + 1.77 +add_test(function test_setCallForward_unconditional() { 1.78 + let workerHelper = _getWorker(); 1.79 + let worker = workerHelper.worker; 1.80 + let context = worker.ContextPool._contexts[0]; 1.81 + 1.82 + context.RIL.setCallForward = function fakeSetCallForward(options) { 1.83 + context.RIL[REQUEST_SET_CALL_FORWARD](0, { 1.84 + rilRequestError: ERROR_SUCCESS 1.85 + }); 1.86 + }; 1.87 + 1.88 + context.RIL.setCallForward({ 1.89 + action: Ci.nsIDOMMozMobileCFInfo.CALL_FORWARD_ACTION_REGISTRATION, 1.90 + reason: Ci.nsIDOMMozMobileCFInfo.CALL_FORWARD_REASON_UNCONDITIONAL, 1.91 + serviceClass: ICC_SERVICE_CLASS_VOICE, 1.92 + number: "666222333", 1.93 + timeSeconds: 10 1.94 + }); 1.95 + 1.96 + let postedMessage = workerHelper.postedMessage; 1.97 + 1.98 + do_check_eq(postedMessage.errorMsg, GECKO_ERROR_SUCCESS); 1.99 + do_check_true(postedMessage.success); 1.100 + 1.101 + run_next_test(); 1.102 +}); 1.103 + 1.104 +add_test(function test_queryCallForwardStatus_unconditional() { 1.105 + let workerHelper = _getWorker(); 1.106 + let worker = workerHelper.worker; 1.107 + let context = worker.ContextPool._contexts[0]; 1.108 + 1.109 + context.RIL.setCallForward = function fakeSetCallForward(options) { 1.110 + context.RIL[REQUEST_SET_CALL_FORWARD](0, { 1.111 + rilRequestError: ERROR_SUCCESS 1.112 + }); 1.113 + }; 1.114 + 1.115 + context.Buf.readInt32 = function fakeReadUint32() { 1.116 + return context.Buf.int32Array.pop(); 1.117 + }; 1.118 + 1.119 + context.Buf.readString = function fakeReadString() { 1.120 + return "+34666222333"; 1.121 + }; 1.122 + 1.123 + context.RIL.queryCallForwardStatus = function fakeQueryCallForward(options) { 1.124 + context.Buf.int32Array = [ 1.125 + 0, // rules.timeSeconds 1.126 + 145, // rules.toa 1.127 + 49, // rules.serviceClass 1.128 + Ci.nsIDOMMozMobileCFInfo.CALL_FORWARD_REASON_UNCONDITIONAL, // rules.reason 1.129 + 1, // rules.active 1.130 + 1 // rulesLength 1.131 + ]; 1.132 + context.RIL[REQUEST_QUERY_CALL_FORWARD_STATUS](1, { 1.133 + rilRequestError: ERROR_SUCCESS 1.134 + }); 1.135 + }; 1.136 + 1.137 + context.RIL.queryCallForwardStatus({ 1.138 + action: Ci.nsIDOMMozMobileCFInfo.CALL_FORWARD_ACTION_QUERY_STATUS, 1.139 + reason: Ci.nsIDOMMozMobileCFInfo.CALL_FORWARD_REASON_UNCONDITIONAL, 1.140 + serviceClass: ICC_SERVICE_CLASS_VOICE, 1.141 + number: "666222333", 1.142 + timeSeconds: 10 1.143 + }); 1.144 + 1.145 + let postedMessage = workerHelper.postedMessage; 1.146 + 1.147 + do_check_eq(postedMessage.errorMsg, GECKO_ERROR_SUCCESS); 1.148 + do_check_true(postedMessage.success); 1.149 + do_check_true(Array.isArray(postedMessage.rules)); 1.150 + do_print(postedMessage.rules.length); 1.151 + do_check_eq(postedMessage.rules.length, 1); 1.152 + do_check_true(postedMessage.rules[0].active); 1.153 + do_check_eq(postedMessage.rules[0].reason, 1.154 + Ci.nsIDOMMozMobileCFInfo.CALL_FORWARD_REASON_UNCONDITIONAL); 1.155 + do_check_eq(postedMessage.rules[0].number, "+34666222333"); 1.156 + run_next_test(); 1.157 +});