summaryrefslogtreecommitdiffstats
path: root/dom/system/gonk/tests/test_ril_worker_clip.js
blob: d1ce5f617947c5f4810cf180fb9fda7fa4dcbe43 (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
/* 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();
}

add_test(function test_queryCLIP_provisioned() {
  let workerHelper = newInterceptWorker();
  let worker = workerHelper.worker;
  let context = worker.ContextPool._contexts[0];

  context.Buf.readInt32 = function fakeReadUint32() {
    return context.Buf.int32Array.pop();
  };

  context.RIL.queryCLIP = function fakeQueryCLIP(options) {
    context.Buf.int32Array = [
      1,  // CLIP provisioned.
      1   // Length.
    ];
    context.RIL[REQUEST_QUERY_CLIP](1, {});
  };

  context.RIL.queryCLIP({});

  let postedMessage = workerHelper.postedMessage;

  equal(postedMessage.errorMsg, undefined);
  equal(postedMessage.provisioned, 1);
  run_next_test();
});

add_test(function test_getCLIP_error_generic_failure_invalid_length() {
  let workerHelper = newInterceptWorker();
  let worker = workerHelper.worker;
  let context = worker.ContextPool._contexts[0];

  context.Buf.readInt32 = function fakeReadUint32() {
    return context.Buf.int32Array.pop();
  };

  context.RIL.queryCLIP = function fakeQueryCLIP(options) {
    context.Buf.int32Array = [
      1,  // CLIP provisioned.
      0   // Length.
    ];
    context.RIL[REQUEST_QUERY_CLIP](1, {});
  };

  context.RIL.queryCLIP({});

  let postedMessage = workerHelper.postedMessage;

  equal(postedMessage.errorMsg, GECKO_ERROR_GENERIC_FAILURE);
  run_next_test();
});