2013-03-05 19:03:31 -08:00
|
|
|
/* Any copyright is dedicated to the Public Domain.
|
|
|
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
|
2013-10-01 03:22:07 -07:00
|
|
|
MARIONETTE_TIMEOUT = 60000;
|
2013-03-05 19:03:31 -08:00
|
|
|
|
|
|
|
SpecialPowers.addPermission("mobileconnection", true, document);
|
|
|
|
|
2013-04-08 23:30:03 -07:00
|
|
|
let icc = navigator.mozIccManager;
|
2013-03-05 19:03:31 -08:00
|
|
|
ok(icc instanceof MozIccManager, "icc is instanceof " + icc.constructor);
|
|
|
|
|
2013-06-21 02:11:23 -07:00
|
|
|
function testReadContacts(type) {
|
|
|
|
let request = icc.readContacts(type);
|
2013-03-05 18:51:40 -08:00
|
|
|
request.onsuccess = function onsuccess() {
|
2013-06-21 02:11:23 -07:00
|
|
|
let contacts = request.result;
|
2013-03-05 18:51:40 -08:00
|
|
|
|
2013-06-21 02:11:23 -07:00
|
|
|
is(Array.isArray(contacts), true);
|
2013-03-05 18:51:40 -08:00
|
|
|
|
2013-10-17 14:29:56 -07:00
|
|
|
is(contacts[0].name[0], "Mozilla");
|
2013-06-21 02:11:23 -07:00
|
|
|
is(contacts[0].tel[0].value, "15555218201");
|
2013-09-12 15:19:47 -07:00
|
|
|
is(contacts[0].id, "890141032111185107201");
|
2013-03-05 18:51:40 -08:00
|
|
|
|
2013-10-17 14:29:56 -07:00
|
|
|
is(contacts[1].name[0], "Saßê黃");
|
2013-06-21 02:11:23 -07:00
|
|
|
is(contacts[1].tel[0].value, "15555218202");
|
2013-09-12 15:19:47 -07:00
|
|
|
is(contacts[1].id, "890141032111185107202");
|
2013-03-05 18:51:40 -08:00
|
|
|
|
2013-10-17 14:29:56 -07:00
|
|
|
is(contacts[2].name[0], "Fire 火");
|
2013-06-21 02:11:23 -07:00
|
|
|
is(contacts[2].tel[0].value, "15555218203");
|
2013-09-12 15:19:47 -07:00
|
|
|
is(contacts[2].id, "890141032111185107203");
|
2013-03-05 18:51:40 -08:00
|
|
|
|
2013-10-17 14:29:56 -07:00
|
|
|
is(contacts[3].name[0], "Huang 黃");
|
2013-06-21 02:11:23 -07:00
|
|
|
is(contacts[3].tel[0].value, "15555218204");
|
2013-09-12 15:19:47 -07:00
|
|
|
is(contacts[3].id, "890141032111185107204");
|
2013-03-05 18:51:40 -08:00
|
|
|
|
|
|
|
runNextTest();
|
|
|
|
};
|
|
|
|
|
|
|
|
request.onerror = function onerror() {
|
2013-06-21 02:11:23 -07:00
|
|
|
ok(false, "Cannot get " + type + " contacts");
|
2013-03-05 18:51:40 -08:00
|
|
|
runNextTest();
|
|
|
|
};
|
|
|
|
};
|
2013-03-05 19:03:31 -08:00
|
|
|
|
2013-06-21 02:11:23 -07:00
|
|
|
function testAddContact(type, pin2) {
|
2013-10-17 14:29:56 -07:00
|
|
|
let contact = new mozContact({
|
|
|
|
name: ["add"],
|
2013-08-09 01:00:38 -07:00
|
|
|
tel: [{value: "0912345678"}],
|
|
|
|
email:[]
|
2013-03-05 19:03:31 -08:00
|
|
|
});
|
|
|
|
|
2013-06-21 02:11:23 -07:00
|
|
|
let updateRequest = icc.updateContact(type, contact, pin2);
|
2013-03-05 19:03:31 -08:00
|
|
|
|
|
|
|
updateRequest.onsuccess = function onsuccess() {
|
|
|
|
// Get ICC contact for checking new contact
|
|
|
|
|
2013-06-21 02:11:23 -07:00
|
|
|
let getRequest = icc.readContacts(type);
|
2013-03-05 19:03:31 -08:00
|
|
|
|
|
|
|
getRequest.onsuccess = function onsuccess() {
|
2013-06-21 02:11:23 -07:00
|
|
|
let contacts = getRequest.result;
|
2013-03-05 19:03:31 -08:00
|
|
|
|
|
|
|
// There are 4 SIM contacts which are harded in emulator
|
2013-06-21 02:11:23 -07:00
|
|
|
is(contacts.length, 5);
|
2013-03-05 19:03:31 -08:00
|
|
|
|
2013-10-17 14:29:56 -07:00
|
|
|
is(contacts[4].name[0], "add");
|
2013-06-21 02:11:23 -07:00
|
|
|
is(contacts[4].tel[0].value, "0912345678");
|
2013-03-05 19:03:31 -08:00
|
|
|
|
|
|
|
runNextTest();
|
|
|
|
};
|
|
|
|
|
|
|
|
getRequest.onerror = function onerror() {
|
2013-06-21 02:11:23 -07:00
|
|
|
ok(false, "Cannot get " + type + " contacts: " + getRequest.error.name);
|
2013-03-05 19:03:31 -08:00
|
|
|
runNextTest();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
updateRequest.onerror = function onerror() {
|
2013-09-12 15:09:48 -07:00
|
|
|
if (type === "fdn" && pin2 === undefined) {
|
|
|
|
ok(updateRequest.error.name === "pin2 is empty",
|
|
|
|
"expected error when pin2 is not provided");
|
|
|
|
} else {
|
|
|
|
ok(false, "Cannot add " + type + " contact: " + updateRequest.error.name);
|
|
|
|
}
|
2013-03-05 19:03:31 -08:00
|
|
|
runNextTest();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2013-06-21 02:11:23 -07:00
|
|
|
function testReadAdnContacts() {
|
|
|
|
testReadContacts("adn");
|
|
|
|
}
|
|
|
|
|
|
|
|
function testAddAdnContact() {
|
|
|
|
testAddContact("adn");
|
|
|
|
}
|
|
|
|
|
|
|
|
function testReadFdnContacts() {
|
|
|
|
testReadContacts("fdn");
|
|
|
|
}
|
|
|
|
|
|
|
|
function testAddFdnContact() {
|
|
|
|
testAddContact("fdn", "0000");
|
2013-09-12 15:09:48 -07:00
|
|
|
testAddContact("fdn");
|
2013-06-21 02:11:23 -07:00
|
|
|
}
|
|
|
|
|
2013-03-05 19:03:31 -08:00
|
|
|
let tests = [
|
2013-06-21 02:11:23 -07:00
|
|
|
testReadAdnContacts,
|
|
|
|
testAddAdnContact,
|
|
|
|
testReadFdnContacts,
|
|
|
|
testAddFdnContact
|
2013-03-05 19:03:31 -08:00
|
|
|
];
|
|
|
|
|
|
|
|
function runNextTest() {
|
|
|
|
let test = tests.pop();
|
|
|
|
if (!test) {
|
|
|
|
cleanUp();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
test();
|
|
|
|
}
|
|
|
|
|
|
|
|
function cleanUp() {
|
|
|
|
SpecialPowers.removePermission("mobileconnection", document);
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
runNextTest();
|