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