dom/icc/tests/marionette/test_icc_contact.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 MARIONETTE_TIMEOUT = 60000;
     5 MARIONETTE_HEAD_JS = "icc_header.js";
     7 const EMULATOR_ICCID = "89014103211118510720";
     9 function testReadContacts(type) {
    10   let request = icc.readContacts(type);
    11   request.onsuccess = function onsuccess() {
    12     let contacts = request.result;
    14     is(Array.isArray(contacts), true);
    16     is(contacts[0].name[0], "Mozilla");
    17     is(contacts[0].tel[0].value, "15555218201");
    18     is(contacts[0].id, EMULATOR_ICCID + "1");
    20     is(contacts[1].name[0], "Saßê黃");
    21     is(contacts[1].tel[0].value, "15555218202");
    22     is(contacts[1].id, EMULATOR_ICCID + "2");
    24     is(contacts[2].name[0], "Fire 火");
    25     is(contacts[2].tel[0].value, "15555218203");
    26     is(contacts[2].id, EMULATOR_ICCID + "3");
    28     is(contacts[3].name[0], "Huang 黃");
    29     is(contacts[3].tel[0].value, "15555218204");
    30     is(contacts[3].id, EMULATOR_ICCID + "4");
    32     taskHelper.runNext();
    33   };
    35   request.onerror = function onerror() {
    36     ok(false, "Cannot get " + type + " contacts");
    37     taskHelper.runNext();
    38   };
    39 }
    41 function testAddContact(type, pin2) {
    42   let contact = new mozContact({
    43     name: ["add"],
    44     tel: [{value: "0912345678"}],
    45     email:[]
    46   });
    48   let updateRequest = icc.updateContact(type, contact, pin2);
    50   updateRequest.onsuccess = function onsuccess() {
    51     let updatedContact = updateRequest.result;
    52     ok(updatedContact, "updateContact should have retuend a mozContact.");
    53     ok(updatedContact.id.startsWith(EMULATOR_ICCID),
    54        "The returned mozContact has wrong id.");
    56     // Get ICC contact for checking new contact
    58     let getRequest = icc.readContacts(type);
    60     getRequest.onsuccess = function onsuccess() {
    61       let contacts = getRequest.result;
    63       // There are 4 SIM contacts which are harded in emulator
    64       is(contacts.length, 5);
    66       is(contacts[4].name[0], "add");
    67       is(contacts[4].tel[0].value, "0912345678");
    69       taskHelper.runNext();
    70     };
    72     getRequest.onerror = function onerror() {
    73       ok(false, "Cannot get " + type + " contacts: " + getRequest.error.name);
    74       taskHelper.runNext();
    75     };
    76   };
    78   updateRequest.onerror = function onerror() {
    79     if (type === "fdn" && pin2 === undefined) {
    80       ok(updateRequest.error.name === "SimPin2",
    81          "expected error when pin2 is not provided");
    82     } else {
    83       ok(false, "Cannot add " + type + " contact: " + updateRequest.error.name);
    84     }
    85     taskHelper.runNext();
    86   };
    87 }
    89 /* Test read adn contacts */
    90 taskHelper.push(function testReadAdnContacts() {
    91   testReadContacts("adn");
    92 });
    94 /* Test add adn contacts */
    95 taskHelper.push(function testAddAdnContact() {
    96   testAddContact("adn");
    97 });
    99 /* Test read fdn contacts */
   100 taskHelper.push(function testReadAdnContacts() {
   101   testReadContacts("fdn");
   102 });
   104 /* Test add fdn contacts */
   105 taskHelper.push(function testReadAdnContacts() {
   106   testAddContact("fdn", "0000");
   107 });
   109 /* Test add fdn contacts without passing pin2 */
   110 taskHelper.push(function testReadAdnContacts() {
   111   testAddContact("fdn");
   112 });
   114 // Start test
   115 taskHelper.runNext();

mercurial