summaryrefslogtreecommitdiffstats
path: root/dom/system/gonk/tests/test_ril_worker_cellbroadcast_umts.js
blob: 0380c4122ef17acd0f4ff58bf9184053b82fa2ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/* 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 buildHexStr(aNum, aNumSemiOctets) {
  let str = aNum.toString(16);
  while (str.length < aNumSemiOctets) {
    str = "0" + str;
  }
  return str;
}

/**
 * Verify GsmPDUHelper#readUmtsCbMessage with numOfPages from 1 to 15.
 */
add_test(function test_GsmPDUHelper_readUmtsCbMessage_MultiParts() {
  let CB_UMTS_MESSAGE_PAGE_SIZE = 82;
  let CB_MAX_CONTENT_PER_PAGE_7BIT = 93;
  let workerHelper = newInterceptWorker(),
      worker = workerHelper.worker,
      context = worker.ContextPool._contexts[0],
      GsmPDUHelper = context.GsmPDUHelper;

  function test_MultiParts(aNumOfPages) {
    let pdu = buildHexStr(CB_UMTS_MESSAGE_TYPE_CBS, 2) // msg_type
            + buildHexStr(0, 4) // skip msg_id
            + buildHexStr(0, 4) // skip SN
            + buildHexStr(0, 2) // skip dcs
            + buildHexStr(aNumOfPages, 2); // set num_of_pages
    for (let i = 1; i <= aNumOfPages; i++) {
      pdu = pdu + buildHexStr(0, CB_UMTS_MESSAGE_PAGE_SIZE * 2)
                + buildHexStr(CB_UMTS_MESSAGE_PAGE_SIZE, 2); // msg_info_length
    }

    worker.onRILMessage(0, newIncomingParcel(-1,
                           RESPONSE_TYPE_UNSOLICITED,
                           UNSOLICITED_RESPONSE_NEW_BROADCAST_SMS,
                           hexStringToParcelByteArrayData(pdu)));

    let postedMessage = workerHelper.postedMessage;
    equal("cellbroadcast-received", postedMessage.rilMessageType);
    equal(postedMessage.fullBody.length,
                aNumOfPages * CB_MAX_CONTENT_PER_PAGE_7BIT);
  }

  [1, 5, 15].forEach(function(i) {
    test_MultiParts(i);
  });

  run_next_test();
});

/**
 * Verify GsmPDUHelper#readUmtsCbMessage with 8bit encoded.
 */
add_test(function test_GsmPDUHelper_readUmtsCbMessage_Binary() {
  let CB_UMTS_MESSAGE_PAGE_SIZE = 82;
  let CB_MAX_CONTENT_PER_PAGE_7BIT = 93;
  let TEXT_BINARY = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
                  + "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
                  + "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
                  + "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
                  + "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
                  + "FFFF";
  let workerHelper = newInterceptWorker(),
      worker = workerHelper.worker,
      context = worker.ContextPool._contexts[0],
      GsmPDUHelper = context.GsmPDUHelper;

  function test_MultiPartsBinary(aNumOfPages) {
    let pdu = buildHexStr(CB_UMTS_MESSAGE_TYPE_CBS, 2) // msg_type
            + buildHexStr(0, 4) // skip msg_id
            + buildHexStr(0, 4) // skip SN
            + buildHexStr(68, 2) // set DCS to 8bit data
            + buildHexStr(aNumOfPages, 2); // set num_of_pages
    for (let i = 1; i <= aNumOfPages; i++) {
      pdu = pdu + TEXT_BINARY
                + buildHexStr(CB_UMTS_MESSAGE_PAGE_SIZE, 2); // msg_info_length
    }

    worker.onRILMessage(0, newIncomingParcel(-1,
                           RESPONSE_TYPE_UNSOLICITED,
                           UNSOLICITED_RESPONSE_NEW_BROADCAST_SMS,
                           hexStringToParcelByteArrayData(pdu)));

    let postedMessage = workerHelper.postedMessage;
    equal("cellbroadcast-received", postedMessage.rilMessageType);
    equal(postedMessage.fullData.length,
                aNumOfPages * CB_UMTS_MESSAGE_PAGE_SIZE);
    for (let i = 0; i < postedMessage.fullData.length; i++) {
      equal(postedMessage.fullData[i], 255);
    }
  }

  [1, 5, 15].forEach(function(i) {
    test_MultiPartsBinary(i);
  });

  run_next_test();
});