dom/system/gonk/tests/test_ril_worker_cf.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

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 function run_test() {
michael@0 7 run_next_test();
michael@0 8 }
michael@0 9
michael@0 10 function toaFromString(number) {
michael@0 11 let worker = newWorker({
michael@0 12 postRILMessage: function(data) {
michael@0 13 // Do nothing
michael@0 14 },
michael@0 15 postMessage: function(message) {
michael@0 16 // Do nothing
michael@0 17 }
michael@0 18 });
michael@0 19 let context = worker.ContextPool._contexts[0];
michael@0 20 return context.RIL._toaFromString(number);
michael@0 21 }
michael@0 22
michael@0 23 add_test(function test_toaFromString_empty() {
michael@0 24 let retval = toaFromString("");
michael@0 25
michael@0 26 do_check_eq(retval, TOA_UNKNOWN);
michael@0 27
michael@0 28 run_next_test();
michael@0 29 });
michael@0 30
michael@0 31 add_test(function test_toaFromString_undefined() {
michael@0 32 let retval = toaFromString();
michael@0 33
michael@0 34 do_check_eq(retval, TOA_UNKNOWN);
michael@0 35
michael@0 36 run_next_test();
michael@0 37 });
michael@0 38
michael@0 39 add_test(function test_toaFromString_unknown() {
michael@0 40 let retval = toaFromString("666222333");
michael@0 41
michael@0 42 do_check_eq(retval, TOA_UNKNOWN);
michael@0 43
michael@0 44 run_next_test();
michael@0 45 });
michael@0 46
michael@0 47 add_test(function test_toaFromString_international() {
michael@0 48 let retval = toaFromString("+34666222333");
michael@0 49
michael@0 50 do_check_eq(retval, TOA_INTERNATIONAL);
michael@0 51
michael@0 52 run_next_test();
michael@0 53 });
michael@0 54
michael@0 55 function _getWorker() {
michael@0 56 let _postedMessage;
michael@0 57 let _worker = newWorker({
michael@0 58 postRILMessage: function(data) {
michael@0 59 },
michael@0 60 postMessage: function(message) {
michael@0 61 _postedMessage = message;
michael@0 62 }
michael@0 63 });
michael@0 64 return {
michael@0 65 get postedMessage() {
michael@0 66 return _postedMessage;
michael@0 67 },
michael@0 68 get worker() {
michael@0 69 return _worker;
michael@0 70 }
michael@0 71 };
michael@0 72 }
michael@0 73
michael@0 74 add_test(function test_setCallForward_unconditional() {
michael@0 75 let workerHelper = _getWorker();
michael@0 76 let worker = workerHelper.worker;
michael@0 77 let context = worker.ContextPool._contexts[0];
michael@0 78
michael@0 79 context.RIL.setCallForward = function fakeSetCallForward(options) {
michael@0 80 context.RIL[REQUEST_SET_CALL_FORWARD](0, {
michael@0 81 rilRequestError: ERROR_SUCCESS
michael@0 82 });
michael@0 83 };
michael@0 84
michael@0 85 context.RIL.setCallForward({
michael@0 86 action: Ci.nsIDOMMozMobileCFInfo.CALL_FORWARD_ACTION_REGISTRATION,
michael@0 87 reason: Ci.nsIDOMMozMobileCFInfo.CALL_FORWARD_REASON_UNCONDITIONAL,
michael@0 88 serviceClass: ICC_SERVICE_CLASS_VOICE,
michael@0 89 number: "666222333",
michael@0 90 timeSeconds: 10
michael@0 91 });
michael@0 92
michael@0 93 let postedMessage = workerHelper.postedMessage;
michael@0 94
michael@0 95 do_check_eq(postedMessage.errorMsg, GECKO_ERROR_SUCCESS);
michael@0 96 do_check_true(postedMessage.success);
michael@0 97
michael@0 98 run_next_test();
michael@0 99 });
michael@0 100
michael@0 101 add_test(function test_queryCallForwardStatus_unconditional() {
michael@0 102 let workerHelper = _getWorker();
michael@0 103 let worker = workerHelper.worker;
michael@0 104 let context = worker.ContextPool._contexts[0];
michael@0 105
michael@0 106 context.RIL.setCallForward = function fakeSetCallForward(options) {
michael@0 107 context.RIL[REQUEST_SET_CALL_FORWARD](0, {
michael@0 108 rilRequestError: ERROR_SUCCESS
michael@0 109 });
michael@0 110 };
michael@0 111
michael@0 112 context.Buf.readInt32 = function fakeReadUint32() {
michael@0 113 return context.Buf.int32Array.pop();
michael@0 114 };
michael@0 115
michael@0 116 context.Buf.readString = function fakeReadString() {
michael@0 117 return "+34666222333";
michael@0 118 };
michael@0 119
michael@0 120 context.RIL.queryCallForwardStatus = function fakeQueryCallForward(options) {
michael@0 121 context.Buf.int32Array = [
michael@0 122 0, // rules.timeSeconds
michael@0 123 145, // rules.toa
michael@0 124 49, // rules.serviceClass
michael@0 125 Ci.nsIDOMMozMobileCFInfo.CALL_FORWARD_REASON_UNCONDITIONAL, // rules.reason
michael@0 126 1, // rules.active
michael@0 127 1 // rulesLength
michael@0 128 ];
michael@0 129 context.RIL[REQUEST_QUERY_CALL_FORWARD_STATUS](1, {
michael@0 130 rilRequestError: ERROR_SUCCESS
michael@0 131 });
michael@0 132 };
michael@0 133
michael@0 134 context.RIL.queryCallForwardStatus({
michael@0 135 action: Ci.nsIDOMMozMobileCFInfo.CALL_FORWARD_ACTION_QUERY_STATUS,
michael@0 136 reason: Ci.nsIDOMMozMobileCFInfo.CALL_FORWARD_REASON_UNCONDITIONAL,
michael@0 137 serviceClass: ICC_SERVICE_CLASS_VOICE,
michael@0 138 number: "666222333",
michael@0 139 timeSeconds: 10
michael@0 140 });
michael@0 141
michael@0 142 let postedMessage = workerHelper.postedMessage;
michael@0 143
michael@0 144 do_check_eq(postedMessage.errorMsg, GECKO_ERROR_SUCCESS);
michael@0 145 do_check_true(postedMessage.success);
michael@0 146 do_check_true(Array.isArray(postedMessage.rules));
michael@0 147 do_print(postedMessage.rules.length);
michael@0 148 do_check_eq(postedMessage.rules.length, 1);
michael@0 149 do_check_true(postedMessage.rules[0].active);
michael@0 150 do_check_eq(postedMessage.rules[0].reason,
michael@0 151 Ci.nsIDOMMozMobileCFInfo.CALL_FORWARD_REASON_UNCONDITIONAL);
michael@0 152 do_check_eq(postedMessage.rules[0].number, "+34666222333");
michael@0 153 run_next_test();
michael@0 154 });

mercurial