dom/system/gonk/tests/test_ril_worker_ssn.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/system/gonk/tests/test_ril_worker_ssn.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,119 @@
     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 _getWorker() {
    1.14 +  let _postedMessage;
    1.15 +  let _worker = newWorker({
    1.16 +    postRILMessage: function(data) {
    1.17 +    },
    1.18 +    postMessage: function(message) {
    1.19 +      _postedMessage = message;
    1.20 +    }
    1.21 +  });
    1.22 +  return {
    1.23 +    get postedMessage() {
    1.24 +      return _postedMessage;
    1.25 +    },
    1.26 +    get worker() {
    1.27 +      return _worker;
    1.28 +    }
    1.29 +  };
    1.30 +}
    1.31 +
    1.32 +add_test(function test_notification() {
    1.33 +  let workerHelper = _getWorker();
    1.34 +  let worker = workerHelper.worker;
    1.35 +  let context = worker.ContextPool._contexts[0];
    1.36 +
    1.37 +  function Call(callIndex, number) {
    1.38 +    this.callIndex = callIndex;
    1.39 +    this.number = number;
    1.40 +  }
    1.41 +
    1.42 +  Call.prototype = {
    1.43 +    // Should use CALL_STATE_ACTIVE.
    1.44 +    // Any new outgoing call (state = dialing or alerting) will be drop if there
    1.45 +    // is no pending outgoing call created before.
    1.46 +    state: CALL_STATE_ACTIVE,
    1.47 +    //callIndex: 0,
    1.48 +    toa: 0,
    1.49 +    isMpty: false,
    1.50 +    isMT: false,
    1.51 +    als: 0,
    1.52 +    isVoice: true,
    1.53 +    isVoicePrivacy: false,
    1.54 +    //number: null,
    1.55 +    numberPresentation: 0,
    1.56 +    name: null,
    1.57 +    namePresentation: 0,
    1.58 +    uusInfo: null
    1.59 +  };
    1.60 +
    1.61 +  let oneCall = {
    1.62 +    0: new Call(0, '00000')
    1.63 +  };
    1.64 +
    1.65 +  let twoCalls = {
    1.66 +    0: new Call(0, '00000'),
    1.67 +    1: new Call(1, '11111')
    1.68 +  };
    1.69 +
    1.70 +  function testNotification(calls, code, number, resultNotification,
    1.71 +                            resultCallIndex) {
    1.72 +
    1.73 +    let testInfo = {calls: calls, code: code, number: number,
    1.74 +                    resultNotification: resultNotification,
    1.75 +                    resultCallIndex: resultCallIndex};
    1.76 +    do_print('Test case info: ' + JSON.stringify(testInfo));
    1.77 +
    1.78 +    // Set current calls.
    1.79 +    context.RIL._processCalls(calls);
    1.80 +
    1.81 +    let notificationInfo = {
    1.82 +      notificationType: 1,  // MT
    1.83 +      code: code,
    1.84 +      index: 0,
    1.85 +      type: 0,
    1.86 +      number: number
    1.87 +    };
    1.88 +
    1.89 +    context.RIL._processSuppSvcNotification(notificationInfo);
    1.90 +
    1.91 +    let postedMessage = workerHelper.postedMessage;
    1.92 +    do_check_eq(postedMessage.rilMessageType, 'suppSvcNotification');
    1.93 +    do_check_eq(postedMessage.notification, resultNotification);
    1.94 +    do_check_eq(postedMessage.callIndex, resultCallIndex);
    1.95 +
    1.96 +    // Clear all existed calls.
    1.97 +    context.RIL._processCalls(null);
    1.98 +  }
    1.99 +
   1.100 +  testNotification(oneCall, SUPP_SVC_NOTIFICATION_CODE2_PUT_ON_HOLD, null,
   1.101 +                   GECKO_SUPP_SVC_NOTIFICATION_REMOTE_HELD, 0);
   1.102 +
   1.103 +  testNotification(oneCall, SUPP_SVC_NOTIFICATION_CODE2_RETRIEVED, null,
   1.104 +                   GECKO_SUPP_SVC_NOTIFICATION_REMOTE_RESUMED, 0);
   1.105 +
   1.106 +  testNotification(twoCalls, SUPP_SVC_NOTIFICATION_CODE2_PUT_ON_HOLD, null,
   1.107 +                   GECKO_SUPP_SVC_NOTIFICATION_REMOTE_HELD, -1);
   1.108 +
   1.109 +  testNotification(twoCalls, SUPP_SVC_NOTIFICATION_CODE2_RETRIEVED, null,
   1.110 +                   GECKO_SUPP_SVC_NOTIFICATION_REMOTE_RESUMED, -1);
   1.111 +
   1.112 +  testNotification(twoCalls, SUPP_SVC_NOTIFICATION_CODE2_PUT_ON_HOLD, '00000',
   1.113 +                   GECKO_SUPP_SVC_NOTIFICATION_REMOTE_HELD, 0);
   1.114 +
   1.115 +  testNotification(twoCalls, SUPP_SVC_NOTIFICATION_CODE2_PUT_ON_HOLD, '11111',
   1.116 +                   GECKO_SUPP_SVC_NOTIFICATION_REMOTE_HELD, 1);
   1.117 +
   1.118 +  testNotification(twoCalls, SUPP_SVC_NOTIFICATION_CODE2_PUT_ON_HOLD, '22222',
   1.119 +                   GECKO_SUPP_SVC_NOTIFICATION_REMOTE_HELD, -1);
   1.120 +
   1.121 +  run_next_test();
   1.122 +});

mercurial