dom/icc/tests/marionette/test_icc_contact.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/icc/tests/marionette/test_icc_contact.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,115 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +MARIONETTE_TIMEOUT = 60000;
     1.8 +MARIONETTE_HEAD_JS = "icc_header.js";
     1.9 +
    1.10 +const EMULATOR_ICCID = "89014103211118510720";
    1.11 +
    1.12 +function testReadContacts(type) {
    1.13 +  let request = icc.readContacts(type);
    1.14 +  request.onsuccess = function onsuccess() {
    1.15 +    let contacts = request.result;
    1.16 +
    1.17 +    is(Array.isArray(contacts), true);
    1.18 +
    1.19 +    is(contacts[0].name[0], "Mozilla");
    1.20 +    is(contacts[0].tel[0].value, "15555218201");
    1.21 +    is(contacts[0].id, EMULATOR_ICCID + "1");
    1.22 +
    1.23 +    is(contacts[1].name[0], "Saßê黃");
    1.24 +    is(contacts[1].tel[0].value, "15555218202");
    1.25 +    is(contacts[1].id, EMULATOR_ICCID + "2");
    1.26 +
    1.27 +    is(contacts[2].name[0], "Fire 火");
    1.28 +    is(contacts[2].tel[0].value, "15555218203");
    1.29 +    is(contacts[2].id, EMULATOR_ICCID + "3");
    1.30 +
    1.31 +    is(contacts[3].name[0], "Huang 黃");
    1.32 +    is(contacts[3].tel[0].value, "15555218204");
    1.33 +    is(contacts[3].id, EMULATOR_ICCID + "4");
    1.34 +
    1.35 +    taskHelper.runNext();
    1.36 +  };
    1.37 +
    1.38 +  request.onerror = function onerror() {
    1.39 +    ok(false, "Cannot get " + type + " contacts");
    1.40 +    taskHelper.runNext();
    1.41 +  };
    1.42 +}
    1.43 +
    1.44 +function testAddContact(type, pin2) {
    1.45 +  let contact = new mozContact({
    1.46 +    name: ["add"],
    1.47 +    tel: [{value: "0912345678"}],
    1.48 +    email:[]
    1.49 +  });
    1.50 +
    1.51 +  let updateRequest = icc.updateContact(type, contact, pin2);
    1.52 +
    1.53 +  updateRequest.onsuccess = function onsuccess() {
    1.54 +    let updatedContact = updateRequest.result;
    1.55 +    ok(updatedContact, "updateContact should have retuend a mozContact.");
    1.56 +    ok(updatedContact.id.startsWith(EMULATOR_ICCID),
    1.57 +       "The returned mozContact has wrong id.");
    1.58 +
    1.59 +    // Get ICC contact for checking new contact
    1.60 +
    1.61 +    let getRequest = icc.readContacts(type);
    1.62 +
    1.63 +    getRequest.onsuccess = function onsuccess() {
    1.64 +      let contacts = getRequest.result;
    1.65 +
    1.66 +      // There are 4 SIM contacts which are harded in emulator
    1.67 +      is(contacts.length, 5);
    1.68 +
    1.69 +      is(contacts[4].name[0], "add");
    1.70 +      is(contacts[4].tel[0].value, "0912345678");
    1.71 +
    1.72 +      taskHelper.runNext();
    1.73 +    };
    1.74 +
    1.75 +    getRequest.onerror = function onerror() {
    1.76 +      ok(false, "Cannot get " + type + " contacts: " + getRequest.error.name);
    1.77 +      taskHelper.runNext();
    1.78 +    };
    1.79 +  };
    1.80 +
    1.81 +  updateRequest.onerror = function onerror() {
    1.82 +    if (type === "fdn" && pin2 === undefined) {
    1.83 +      ok(updateRequest.error.name === "SimPin2",
    1.84 +         "expected error when pin2 is not provided");
    1.85 +    } else {
    1.86 +      ok(false, "Cannot add " + type + " contact: " + updateRequest.error.name);
    1.87 +    }
    1.88 +    taskHelper.runNext();
    1.89 +  };
    1.90 +}
    1.91 +
    1.92 +/* Test read adn contacts */
    1.93 +taskHelper.push(function testReadAdnContacts() {
    1.94 +  testReadContacts("adn");
    1.95 +});
    1.96 +
    1.97 +/* Test add adn contacts */
    1.98 +taskHelper.push(function testAddAdnContact() {
    1.99 +  testAddContact("adn");
   1.100 +});
   1.101 +
   1.102 +/* Test read fdn contacts */
   1.103 +taskHelper.push(function testReadAdnContacts() {
   1.104 +  testReadContacts("fdn");
   1.105 +});
   1.106 +
   1.107 +/* Test add fdn contacts */
   1.108 +taskHelper.push(function testReadAdnContacts() {
   1.109 +  testAddContact("fdn", "0000");
   1.110 +});
   1.111 +
   1.112 +/* Test add fdn contacts without passing pin2 */
   1.113 +taskHelper.push(function testReadAdnContacts() {
   1.114 +  testAddContact("fdn");
   1.115 +});
   1.116 +
   1.117 +// Start test
   1.118 +taskHelper.runNext();

mercurial