michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: subscriptLoader.loadSubScript("resource://gre/modules/ril_consts.js", this); michael@0: michael@0: function run_test() { michael@0: run_next_test(); michael@0: } michael@0: michael@0: function toaFromString(number) { michael@0: let worker = newWorker({ michael@0: postRILMessage: function(data) { michael@0: // Do nothing michael@0: }, michael@0: postMessage: function(message) { michael@0: // Do nothing michael@0: } michael@0: }); michael@0: let context = worker.ContextPool._contexts[0]; michael@0: return context.RIL._toaFromString(number); michael@0: } michael@0: michael@0: add_test(function test_toaFromString_empty() { michael@0: let retval = toaFromString(""); michael@0: michael@0: do_check_eq(retval, TOA_UNKNOWN); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: add_test(function test_toaFromString_undefined() { michael@0: let retval = toaFromString(); michael@0: michael@0: do_check_eq(retval, TOA_UNKNOWN); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: add_test(function test_toaFromString_unknown() { michael@0: let retval = toaFromString("666222333"); michael@0: michael@0: do_check_eq(retval, TOA_UNKNOWN); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: add_test(function test_toaFromString_international() { michael@0: let retval = toaFromString("+34666222333"); michael@0: michael@0: do_check_eq(retval, TOA_INTERNATIONAL); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: function _getWorker() { michael@0: let _postedMessage; michael@0: let _worker = newWorker({ michael@0: postRILMessage: function(data) { michael@0: }, michael@0: postMessage: function(message) { michael@0: _postedMessage = message; michael@0: } michael@0: }); michael@0: return { michael@0: get postedMessage() { michael@0: return _postedMessage; michael@0: }, michael@0: get worker() { michael@0: return _worker; michael@0: } michael@0: }; michael@0: } michael@0: michael@0: add_test(function test_setCallForward_unconditional() { michael@0: let workerHelper = _getWorker(); michael@0: let worker = workerHelper.worker; michael@0: let context = worker.ContextPool._contexts[0]; michael@0: michael@0: context.RIL.setCallForward = function fakeSetCallForward(options) { michael@0: context.RIL[REQUEST_SET_CALL_FORWARD](0, { michael@0: rilRequestError: ERROR_SUCCESS michael@0: }); michael@0: }; michael@0: michael@0: context.RIL.setCallForward({ michael@0: action: Ci.nsIDOMMozMobileCFInfo.CALL_FORWARD_ACTION_REGISTRATION, michael@0: reason: Ci.nsIDOMMozMobileCFInfo.CALL_FORWARD_REASON_UNCONDITIONAL, michael@0: serviceClass: ICC_SERVICE_CLASS_VOICE, michael@0: number: "666222333", michael@0: timeSeconds: 10 michael@0: }); michael@0: michael@0: let postedMessage = workerHelper.postedMessage; michael@0: michael@0: do_check_eq(postedMessage.errorMsg, GECKO_ERROR_SUCCESS); michael@0: do_check_true(postedMessage.success); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: add_test(function test_queryCallForwardStatus_unconditional() { michael@0: let workerHelper = _getWorker(); michael@0: let worker = workerHelper.worker; michael@0: let context = worker.ContextPool._contexts[0]; michael@0: michael@0: context.RIL.setCallForward = function fakeSetCallForward(options) { michael@0: context.RIL[REQUEST_SET_CALL_FORWARD](0, { michael@0: rilRequestError: ERROR_SUCCESS michael@0: }); michael@0: }; michael@0: michael@0: context.Buf.readInt32 = function fakeReadUint32() { michael@0: return context.Buf.int32Array.pop(); michael@0: }; michael@0: michael@0: context.Buf.readString = function fakeReadString() { michael@0: return "+34666222333"; michael@0: }; michael@0: michael@0: context.RIL.queryCallForwardStatus = function fakeQueryCallForward(options) { michael@0: context.Buf.int32Array = [ michael@0: 0, // rules.timeSeconds michael@0: 145, // rules.toa michael@0: 49, // rules.serviceClass michael@0: Ci.nsIDOMMozMobileCFInfo.CALL_FORWARD_REASON_UNCONDITIONAL, // rules.reason michael@0: 1, // rules.active michael@0: 1 // rulesLength michael@0: ]; michael@0: context.RIL[REQUEST_QUERY_CALL_FORWARD_STATUS](1, { michael@0: rilRequestError: ERROR_SUCCESS michael@0: }); michael@0: }; michael@0: michael@0: context.RIL.queryCallForwardStatus({ michael@0: action: Ci.nsIDOMMozMobileCFInfo.CALL_FORWARD_ACTION_QUERY_STATUS, michael@0: reason: Ci.nsIDOMMozMobileCFInfo.CALL_FORWARD_REASON_UNCONDITIONAL, michael@0: serviceClass: ICC_SERVICE_CLASS_VOICE, michael@0: number: "666222333", michael@0: timeSeconds: 10 michael@0: }); michael@0: michael@0: let postedMessage = workerHelper.postedMessage; michael@0: michael@0: do_check_eq(postedMessage.errorMsg, GECKO_ERROR_SUCCESS); michael@0: do_check_true(postedMessage.success); michael@0: do_check_true(Array.isArray(postedMessage.rules)); michael@0: do_print(postedMessage.rules.length); michael@0: do_check_eq(postedMessage.rules.length, 1); michael@0: do_check_true(postedMessage.rules[0].active); michael@0: do_check_eq(postedMessage.rules[0].reason, michael@0: Ci.nsIDOMMozMobileCFInfo.CALL_FORWARD_REASON_UNCONDITIONAL); michael@0: do_check_eq(postedMessage.rules[0].number, "+34666222333"); michael@0: run_next_test(); michael@0: });