michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: MARIONETTE_TIMEOUT = 60000; michael@0: MARIONETTE_HEAD_JS = "icc_header.js"; michael@0: michael@0: const EMULATOR_ICCID = "89014103211118510720"; michael@0: michael@0: function testReadContacts(type) { michael@0: let request = icc.readContacts(type); michael@0: request.onsuccess = function onsuccess() { michael@0: let contacts = request.result; michael@0: michael@0: is(Array.isArray(contacts), true); michael@0: michael@0: is(contacts[0].name[0], "Mozilla"); michael@0: is(contacts[0].tel[0].value, "15555218201"); michael@0: is(contacts[0].id, EMULATOR_ICCID + "1"); michael@0: michael@0: is(contacts[1].name[0], "Saßê黃"); michael@0: is(contacts[1].tel[0].value, "15555218202"); michael@0: is(contacts[1].id, EMULATOR_ICCID + "2"); michael@0: michael@0: is(contacts[2].name[0], "Fire 火"); michael@0: is(contacts[2].tel[0].value, "15555218203"); michael@0: is(contacts[2].id, EMULATOR_ICCID + "3"); michael@0: michael@0: is(contacts[3].name[0], "Huang 黃"); michael@0: is(contacts[3].tel[0].value, "15555218204"); michael@0: is(contacts[3].id, EMULATOR_ICCID + "4"); michael@0: michael@0: taskHelper.runNext(); michael@0: }; michael@0: michael@0: request.onerror = function onerror() { michael@0: ok(false, "Cannot get " + type + " contacts"); michael@0: taskHelper.runNext(); michael@0: }; michael@0: } michael@0: michael@0: function testAddContact(type, pin2) { michael@0: let contact = new mozContact({ michael@0: name: ["add"], michael@0: tel: [{value: "0912345678"}], michael@0: email:[] michael@0: }); michael@0: michael@0: let updateRequest = icc.updateContact(type, contact, pin2); michael@0: michael@0: updateRequest.onsuccess = function onsuccess() { michael@0: let updatedContact = updateRequest.result; michael@0: ok(updatedContact, "updateContact should have retuend a mozContact."); michael@0: ok(updatedContact.id.startsWith(EMULATOR_ICCID), michael@0: "The returned mozContact has wrong id."); michael@0: michael@0: // Get ICC contact for checking new contact michael@0: michael@0: let getRequest = icc.readContacts(type); michael@0: michael@0: getRequest.onsuccess = function onsuccess() { michael@0: let contacts = getRequest.result; michael@0: michael@0: // There are 4 SIM contacts which are harded in emulator michael@0: is(contacts.length, 5); michael@0: michael@0: is(contacts[4].name[0], "add"); michael@0: is(contacts[4].tel[0].value, "0912345678"); michael@0: michael@0: taskHelper.runNext(); michael@0: }; michael@0: michael@0: getRequest.onerror = function onerror() { michael@0: ok(false, "Cannot get " + type + " contacts: " + getRequest.error.name); michael@0: taskHelper.runNext(); michael@0: }; michael@0: }; michael@0: michael@0: updateRequest.onerror = function onerror() { michael@0: if (type === "fdn" && pin2 === undefined) { michael@0: ok(updateRequest.error.name === "SimPin2", michael@0: "expected error when pin2 is not provided"); michael@0: } else { michael@0: ok(false, "Cannot add " + type + " contact: " + updateRequest.error.name); michael@0: } michael@0: taskHelper.runNext(); michael@0: }; michael@0: } michael@0: michael@0: /* Test read adn contacts */ michael@0: taskHelper.push(function testReadAdnContacts() { michael@0: testReadContacts("adn"); michael@0: }); michael@0: michael@0: /* Test add adn contacts */ michael@0: taskHelper.push(function testAddAdnContact() { michael@0: testAddContact("adn"); michael@0: }); michael@0: michael@0: /* Test read fdn contacts */ michael@0: taskHelper.push(function testReadAdnContacts() { michael@0: testReadContacts("fdn"); michael@0: }); michael@0: michael@0: /* Test add fdn contacts */ michael@0: taskHelper.push(function testReadAdnContacts() { michael@0: testAddContact("fdn", "0000"); michael@0: }); michael@0: michael@0: /* Test add fdn contacts without passing pin2 */ michael@0: taskHelper.push(function testReadAdnContacts() { michael@0: testAddContact("fdn"); michael@0: }); michael@0: michael@0: // Start test michael@0: taskHelper.runNext();