dom/system/gonk/tests/test_ril_worker_cf.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 subscriptLoader.loadSubScript("resource://gre/modules/ril_consts.js", this);
     6 function run_test() {
     7   run_next_test();
     8 }
    10 function toaFromString(number) {
    11   let worker = newWorker({
    12     postRILMessage: function(data) {
    13       // Do nothing
    14     },
    15     postMessage: function(message) {
    16       // Do nothing
    17     }
    18   });
    19   let context = worker.ContextPool._contexts[0];
    20   return context.RIL._toaFromString(number);
    21 }
    23 add_test(function test_toaFromString_empty() {
    24   let retval = toaFromString("");
    26   do_check_eq(retval, TOA_UNKNOWN);
    28   run_next_test();
    29 });
    31 add_test(function test_toaFromString_undefined() {
    32   let retval = toaFromString();
    34   do_check_eq(retval, TOA_UNKNOWN);
    36   run_next_test();
    37 });
    39 add_test(function test_toaFromString_unknown() {
    40   let retval = toaFromString("666222333");
    42   do_check_eq(retval, TOA_UNKNOWN);
    44   run_next_test();
    45 });
    47 add_test(function test_toaFromString_international() {
    48   let retval = toaFromString("+34666222333");
    50   do_check_eq(retval, TOA_INTERNATIONAL);
    52   run_next_test();
    53 });
    55 function _getWorker() {
    56   let _postedMessage;
    57   let _worker = newWorker({
    58     postRILMessage: function(data) {
    59     },
    60     postMessage: function(message) {
    61       _postedMessage = message;
    62     }
    63   });
    64   return {
    65     get postedMessage() {
    66       return _postedMessage;
    67     },
    68     get worker() {
    69       return _worker;
    70     }
    71   };
    72 }
    74 add_test(function test_setCallForward_unconditional() {
    75   let workerHelper = _getWorker();
    76   let worker = workerHelper.worker;
    77   let context = worker.ContextPool._contexts[0];
    79   context.RIL.setCallForward = function fakeSetCallForward(options) {
    80     context.RIL[REQUEST_SET_CALL_FORWARD](0, {
    81       rilRequestError: ERROR_SUCCESS
    82     });
    83   };
    85   context.RIL.setCallForward({
    86     action: Ci.nsIDOMMozMobileCFInfo.CALL_FORWARD_ACTION_REGISTRATION,
    87     reason: Ci.nsIDOMMozMobileCFInfo.CALL_FORWARD_REASON_UNCONDITIONAL,
    88     serviceClass: ICC_SERVICE_CLASS_VOICE,
    89     number: "666222333",
    90     timeSeconds: 10
    91   });
    93   let postedMessage = workerHelper.postedMessage;
    95   do_check_eq(postedMessage.errorMsg, GECKO_ERROR_SUCCESS);
    96   do_check_true(postedMessage.success);
    98   run_next_test();
    99 });
   101 add_test(function test_queryCallForwardStatus_unconditional() {
   102   let workerHelper = _getWorker();
   103   let worker = workerHelper.worker;
   104   let context = worker.ContextPool._contexts[0];
   106   context.RIL.setCallForward = function fakeSetCallForward(options) {
   107     context.RIL[REQUEST_SET_CALL_FORWARD](0, {
   108       rilRequestError: ERROR_SUCCESS
   109     });
   110   };
   112   context.Buf.readInt32 = function fakeReadUint32() {
   113     return context.Buf.int32Array.pop();
   114   };
   116   context.Buf.readString = function fakeReadString() {
   117     return "+34666222333";
   118   };
   120   context.RIL.queryCallForwardStatus = function fakeQueryCallForward(options) {
   121     context.Buf.int32Array = [
   122       0,   // rules.timeSeconds
   123       145, // rules.toa
   124       49,  // rules.serviceClass
   125       Ci.nsIDOMMozMobileCFInfo.CALL_FORWARD_REASON_UNCONDITIONAL, // rules.reason
   126       1,   // rules.active
   127       1    // rulesLength
   128     ];
   129     context.RIL[REQUEST_QUERY_CALL_FORWARD_STATUS](1, {
   130       rilRequestError: ERROR_SUCCESS
   131     });
   132   };
   134   context.RIL.queryCallForwardStatus({
   135     action: Ci.nsIDOMMozMobileCFInfo.CALL_FORWARD_ACTION_QUERY_STATUS,
   136     reason: Ci.nsIDOMMozMobileCFInfo.CALL_FORWARD_REASON_UNCONDITIONAL,
   137     serviceClass: ICC_SERVICE_CLASS_VOICE,
   138     number: "666222333",
   139     timeSeconds: 10
   140   });
   142   let postedMessage = workerHelper.postedMessage;
   144   do_check_eq(postedMessage.errorMsg, GECKO_ERROR_SUCCESS);
   145   do_check_true(postedMessage.success);
   146   do_check_true(Array.isArray(postedMessage.rules));
   147   do_print(postedMessage.rules.length);
   148   do_check_eq(postedMessage.rules.length, 1);
   149   do_check_true(postedMessage.rules[0].active);
   150   do_check_eq(postedMessage.rules[0].reason,
   151               Ci.nsIDOMMozMobileCFInfo.CALL_FORWARD_REASON_UNCONDITIONAL);
   152   do_check_eq(postedMessage.rules[0].number, "+34666222333");
   153   run_next_test();
   154 });

mercurial