dom/system/gonk/tests/test_ril_worker_ruim.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

     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 /**
    11  * Helper function.
    12  */
    13 function newUint8Worker() {
    14   let worker = newWorker();
    15   let context = worker.ContextPool._contexts[0];
    16   let index = 0; // index for read
    17   let buf = [];
    19   context.Buf.writeUint8 = function(value) {
    20     buf.push(value);
    21   };
    23   context.Buf.readUint8 = function() {
    24     return buf[index++];
    25   };
    27   context.Buf.seekIncoming = function(offset) {
    28     index += offset;
    29   };
    31   worker.debug = do_print;
    33   return worker;
    34 }
    36 /**
    37  * Verify RUIM Service.
    38  */
    39 add_test(function test_is_ruim_service_available() {
    40   let worker = newWorker();
    41   let context = worker.ContextPool._contexts[0];
    42   context.RIL._isCdma = true;
    43   context.RIL.appType = CARD_APPTYPE_RUIM;
    45   function test_table(cst, geckoService, enabled) {
    46     context.RIL.iccInfoPrivate.cst = cst;
    47     do_check_eq(context.ICCUtilsHelper.isICCServiceAvailable(geckoService),
    48                 enabled);
    49   }
    51   test_table([0x0, 0x0, 0x0, 0x0, 0x03], "SPN", true);
    52   test_table([0x0, 0x0, 0x0, 0x03, 0x0], "SPN", false);
    53   test_table([0x0, 0x0C, 0x0, 0x0, 0x0], "ENHANCED_PHONEBOOK", true);
    54   test_table([0x0, 0x0,  0x0, 0x0, 0x0], "ENHANCED_PHONEBOOK", false);
    56   run_next_test();
    57 });
    59 /**
    60  * Verify EF_PATH for RUIM file.
    61  */
    62 add_test(function test_ruim_file_path_id() {
    63   let worker = newWorker();
    64   let context = worker.ContextPool._contexts[0];
    65   let RIL = context.RIL;
    66   let ICCFileHelper = context.ICCFileHelper;
    68   RIL.appType = CARD_APPTYPE_RUIM;
    69   do_check_eq(ICCFileHelper.getEFPath(ICC_EF_CSIM_CST),
    70               EF_PATH_MF_SIM + EF_PATH_DF_CDMA);
    72   run_next_test();
    73 });
    75 add_test(function test_fetch_ruim_recodes() {
    76   let worker = newWorker();
    77   let context = worker.ContextPool._contexts[0];
    78   let RIL = context.RIL;
    79   let ruimHelper = context.RuimRecordHelper;
    81   function testFetchRuimRecordes(expectCalled) {
    82     let ifCalled = [];
    84     ruimHelper.getIMSI_M = function() {
    85       ifCalled.push("getIMSI_M");
    86     };
    88     ruimHelper.readCST = function() {
    89       ifCalled.push("readCST");
    90     };
    92     ruimHelper.readCDMAHome = function() {
    93       ifCalled.push("readCDMAHome");
    94     };
    96     RIL.getCdmaSubscription = function() {
    97       ifCalled.push("getCdmaSubscription");
    98     };
   100     ruimHelper.fetchRuimRecords();
   102     for (let i = 0; i < expectCalled.length; i++ ) {
   103       if (ifCalled[i] != expectCalled[i]) {
   104         do_print(expectCalled[i] + " is not called.");
   105         do_check_true(false);
   106       }
   107     }
   108   }
   110   let expectCalled = ["getIMSI_M", "readCST", "readCDMAHome",
   111                       "getCdmaSubscription"];
   112   testFetchRuimRecordes(expectCalled);
   114   run_next_test();
   115 });
   117 /**
   118  * Verify RuimRecordHelper.decodeIMSIValue
   119  */
   120 add_test(function test_decode_imsi_value() {
   121   let worker = newUint8Worker();
   122   let context = worker.ContextPool._contexts[0];
   124   function testDecodeImsiValue(encoded, length, expect) {
   125     let decoded = context.RuimRecordHelper.decodeIMSIValue(encoded, length);
   127     do_check_eq(expect, decoded);
   128   }
   130   testDecodeImsiValue( 99, 2, "00");
   131   testDecodeImsiValue( 90, 2, "01");
   132   testDecodeImsiValue( 19, 2, "20");
   133   testDecodeImsiValue( 23, 2, "34");
   134   testDecodeImsiValue(999, 3, "000");
   135   testDecodeImsiValue(990, 3, "001");
   136   testDecodeImsiValue(909, 3, "010");
   137   testDecodeImsiValue( 99, 3, "100");
   138   testDecodeImsiValue(901, 3, "012");
   139   testDecodeImsiValue( 19, 3, "120");
   140   testDecodeImsiValue( 91, 3, "102");
   141   testDecodeImsiValue(199, 3, "200");
   142   testDecodeImsiValue(123, 3, "234");
   143   testDecodeImsiValue(578, 3, "689");
   145   run_next_test();
   146 });
   148 /**
   149  * Verify RuimRecordHelper.getIMSI_M
   150  */
   151 add_test(function test_get_imsi_m() {
   152   let worker = newUint8Worker();
   153   let context = worker.ContextPool._contexts[0];
   154   let helper = context.GsmPDUHelper;
   155   let buf    = context.Buf;
   156   let io     = context.ICCIOHelper;
   158   function testDecodeImsi(encodedImsi, expectedImsi) {
   159     io.loadTransparentEF = function fakeLoadTransparentEF(options) {
   160       // Write data size
   161       buf.writeInt32(encodedImsi.length * 2);
   163       // Write imsi
   164       for (let i = 0; i < encodedImsi.length; i++) {
   165         helper.writeHexOctet(encodedImsi[i]);
   166       }
   168       // Write string delimiter
   169       buf.writeStringDelimiter(encodedImsi.length * 2);
   171       if (options.callback) {
   172         options.callback(options);
   173       }
   174     };
   176     context.RuimRecordHelper.getIMSI_M();
   177     let imsi = context.RIL.iccInfoPrivate.imsi;
   179     do_check_eq(expectedImsi, imsi)
   180   }
   182   let imsi_1 = "466050081062861";
   183   testDecodeImsi([0x0, 0xe5, 0x03, 0xee, 0xca, 0x17, 0x5e, 0x80, 0x63, 0x01], imsi_1);
   185   let imsi_2 = "460038351175976";
   186   testDecodeImsi([0x0, 0xd4, 0x02, 0x61, 0x97, 0x01, 0x5c, 0x80, 0x67, 0x01], imsi_2);
   188   run_next_test();
   189 });
   191 /**
   192  * Verify RuimRecordHelper.readCDMAHome
   193  */
   194 add_test(function test_read_cdmahome() {
   195   let worker = newUint8Worker();
   196   let context = worker.ContextPool._contexts[0];
   197   let helper = context.GsmPDUHelper;
   198   let buf    = context.Buf;
   199   let io     = context.ICCIOHelper;
   201   io.loadLinearFixedEF = function fakeLoadLinearFixedEF(options)  {
   202     let cdmaHome = [0xc1, 0x34, 0xff, 0xff, 0x00];
   204     // Write data size
   205     buf.writeInt32(cdmaHome.length * 2);
   207     // Write cdma home file.
   208     for (let i = 0; i < cdmaHome.length; i++) {
   209       helper.writeHexOctet(cdmaHome[i]);
   210     }
   212     // Write string delimiter
   213     buf.writeStringDelimiter(cdmaHome.length * 2);
   215     // We just have 1 test record.
   217     options.totalRecords = 1;
   218     if (options.callback) {
   219       options.callback(options);
   220     }
   221   };
   223   function testCdmaHome(expectedSystemIds, expectedNetworkIds) {
   224     context.RuimRecordHelper.readCDMAHome();
   225     let cdmaHome = context.RIL.cdmaHome;
   226     for (let i = 0; i < expectedSystemIds.length; i++) {
   227       do_check_eq(cdmaHome.systemId[i], expectedSystemIds[i]);
   228       do_check_eq(cdmaHome.networkId[i], expectedNetworkIds[i]);
   229     }
   230     do_check_eq(cdmaHome.systemId.length, expectedSystemIds.length);
   231     do_check_eq(cdmaHome.networkId.length, expectedNetworkIds.length);
   232   }
   234   testCdmaHome([13505], [65535]);
   236   run_next_test();
   237 });
   239 /**
   240  * Verify reading CDMA EF_SPN
   241  */
   242 add_test(function test_read_cdmaspn() {
   243   let worker = newUint8Worker();
   244   let context = worker.ContextPool._contexts[0];
   245   let helper = context.GsmPDUHelper;
   246   let buf    = context.Buf;
   247   let io     = context.ICCIOHelper;
   249   function testReadSpn(file, expectedSpn, expectedDisplayCondition) {
   250     io.loadTransparentEF = function fakeLoadTransparentEF(options)  {
   251       // Write data size
   252       buf.writeInt32(file.length * 2);
   254       // Write file.
   255       for (let i = 0; i < file.length; i++) {
   256         helper.writeHexOctet(file[i]);
   257       }
   259       // Write string delimiter
   260       buf.writeStringDelimiter(file.length * 2);
   262       if (options.callback) {
   263         options.callback(options);
   264       }
   265     };
   267     context.RuimRecordHelper.readSPN();
   268     do_check_eq(context.RIL.iccInfo.spn, expectedSpn);
   269     do_check_eq(context.RIL.iccInfoPrivate.spnDisplayCondition,
   270                 expectedDisplayCondition);
   271   }
   273   testReadSpn([0x01, 0x04, 0x06, 0x4e, 0x9e, 0x59, 0x2a, 0x96,
   274                0xfb, 0x4f, 0xe1, 0xff, 0xff, 0xff, 0xff, 0xff,
   275                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
   276                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
   277                0xff, 0xff, 0xff],
   278               String.fromCharCode(0x4e9e) +
   279               String.fromCharCode(0x592a) +
   280               String.fromCharCode(0x96fb) +
   281               String.fromCharCode(0x4fe1),
   282               0x1);
   284   // Test when there's no tailing 0xff in spn string.
   285   testReadSpn([0x01, 0x04, 0x06, 0x4e, 0x9e, 0x59, 0x2a, 0x96,
   286                0xfb, 0x4f, 0xe1],
   287               String.fromCharCode(0x4e9e) +
   288               String.fromCharCode(0x592a) +
   289               String.fromCharCode(0x96fb) +
   290               String.fromCharCode(0x4fe1),
   291               0x1);
   293   run_next_test();
   294 });
   296 /**
   297  * Verify display condition for CDMA.
   298  */
   299 add_test(function test_cdma_spn_display_condition() {
   300   let worker = newWorker({
   301     postRILMessage: function(data) {
   302       // Do nothing
   303     },
   304     postMessage: function(message) {
   305       // Do nothing
   306     }
   307   });
   308   let context = worker.ContextPool._contexts[0];
   309   let RIL = context.RIL;
   310   let ICCUtilsHelper = context.ICCUtilsHelper;
   312   // Set cdma.
   313   RIL._isCdma = true;
   315   // Test updateDisplayCondition runs before any of SIM file is ready.
   316   do_check_eq(ICCUtilsHelper.updateDisplayCondition(), true);
   317   do_check_eq(RIL.iccInfo.isDisplayNetworkNameRequired, true);
   318   do_check_eq(RIL.iccInfo.isDisplaySpnRequired, false);
   320   // Test with value.
   321   function testDisplayCondition(ruimDisplayCondition,
   322                                 homeSystemIds, homeNetworkIds,
   323                                 currentSystemId, currentNetworkId,
   324                                 expectUpdateDisplayCondition,
   325                                 expectIsDisplaySPNRequired) {
   326     RIL.iccInfoPrivate.spnDisplayCondition = ruimDisplayCondition;
   327     RIL.cdmaHome = {
   328       systemId: homeSystemIds,
   329       networkId: homeNetworkIds
   330     };
   331     RIL.voiceRegistrationState.cell = {
   332       cdmaSystemId: currentSystemId,
   333       cdmaNetworkId: currentNetworkId
   334     };
   336     do_check_eq(ICCUtilsHelper.updateDisplayCondition(), expectUpdateDisplayCondition);
   337     do_check_eq(RIL.iccInfo.isDisplayNetworkNameRequired, false);
   338     do_check_eq(RIL.iccInfo.isDisplaySpnRequired, expectIsDisplaySPNRequired);
   339   };
   341   // SPN is not required when ruimDisplayCondition is false.
   342   testDisplayCondition(0x0, [123], [345], 123, 345, true, false);
   344   // System id and network id are all match.
   345   testDisplayCondition(0x1, [123], [345], 123, 345, true, true);
   347   // Network is 65535, we should only need to match system id.
   348   testDisplayCondition(0x1, [123], [65535], 123, 345, false, true);
   350   // Not match.
   351   testDisplayCondition(0x1, [123], [456], 123, 345, true, false);
   353   run_next_test();
   354 });

mercurial