Bug 600798 - Implement unit tests for importing vcards and csv files into address book. Patch originally by Evan Stratford for bug 79709, updated by Standard8 now that blocking issues are resolved. r=mconley.

This commit is contained in:
Evan Stratford 2012-08-20 16:24:11 +01:00
Родитель 3376d7768c
Коммит 9297e3de2b
9 изменённых файлов: 119 добавлений и 8 удалений

Просмотреть файл

@ -66,5 +66,29 @@
"DisplayName" : "名無しの権兵衛",
"PrimaryEmail" : "名無しの権兵衛@host.invalid"
}
],
"vcard_import" :
[
{
"DisplayName" : "John Doe",
"FirstName" : "John",
"LastName" : "Doe",
"PrimaryEmail" : "john.doe@genericemail.com"
},
{
"DisplayName" : "Jane Doe",
"FirstName" : "Jane",
"LastName" : "Doe",
"PrimaryEmail" : "jane.doe@genericemail.com"
}
],
"csv_import" :
[
{
"DisplayName" : "John Doe",
"FirstName" : "John",
"LastName" : "Doe",
"PrimaryEmail" : "johndoe@host.invalid"
}
]
}

Просмотреть файл

@ -0,0 +1,2 @@
First Name,Last Name,Display Name,Nickname,Primary Email,Secondary Email,Work Phone,Home Phone,Fax Number,Pager Number,Mobile Number,Home Address,Home Address 2,Home City,Home State,Home ZipCode,Home Country,Work Address,Work Address 2,Work City,Work State,Work ZipCode,Work Country,Job Title,Department,Organization,Web Page 1,Web Page 2,Birth Year,Birth Month,Birth Day,Custom 1,Custom 2,Custom 3,Custom 4,Notes,Screen Name,
John,Doe,John Doe,,johndoe@host.invalid,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
1 First Name Last Name Display Name Nickname Primary Email Secondary Email Work Phone Home Phone Fax Number Pager Number Mobile Number Home Address Home Address 2 Home City Home State Home ZipCode Home Country Work Address Work Address 2 Work City Work State Work ZipCode Work Country Job Title Department Organization Web Page 1 Web Page 2 Birth Year Birth Month Birth Day Custom 1 Custom 2 Custom 3 Custom 4 Notes Screen Name
2 John Doe John Doe johndoe@host.invalid

Просмотреть файл

@ -0,0 +1,12 @@
BEGIN:VCARD
VERSION:2.1
FN:John Doe
N:Doe;John;;;
EMAIL;TYPE=INTERNET:john.doe@genericemail.com
END:VCARD
BEGIN:VCARD
VERSION:2.1
FN:Jane Doe
N:Doe;Jane;;;
EMAIL;TYPE=INTERNET:jane.doe@genericemail.com
END:VCARD

Просмотреть файл

@ -0,0 +1,18 @@
BEGIN:VCARD
VERSION:2.1
FN:John Doe
N:Doe;John;;;
EMAIL;TYPE=INTERNET:john.doe@genericemail.com
END:VCARD
BEGIN:VCARD
VERSION:2.1
FN:Jane Doe
N:Doe;Jane;;;
EMAIL;TYPE=INTERNET:jane.doe@genericemail.com
END:VCARD

Просмотреть файл

@ -39,7 +39,7 @@ GenericImportHelper.prototype =
* checkProgress of child class to check the data,
*/
beginImport: function() {
do_check_true(this.mFile instanceof Ci.nsIFile && this.mFile.exists())
do_check_true(this.mFile instanceof Ci.nsIFile && this.mFile.exists());
if (this.mModuleType == "addressbook")
this.mInterface.SetData("addressLocation", this.mFile);
@ -105,7 +105,7 @@ GenericImportHelper.prototype =
*/
checkResults: function() {
}
}
};
function endsWith(string, suffix) {
return string.indexOf(suffix, string.length - suffix.length) != -1;
@ -151,13 +151,18 @@ function AbImportHelper(aFile, aModuleSearchString, aAbName, aJsonName)
"WorkState", "WorkZipCode", "WorkCountry", "JobTitle", "Department",
"Company", "BirthYear", "BirthMonth", "BirthDay", "WebPage1", "WebPage2",
"Custom1", "Custom2", "Custom3", "Custom4", "Notes", "_AimScreenName"];
// get the extra attributes supported for the given type of import
if (endsWith(this.mFile.leafName.toLowerCase(), ".ldif")) {
// LDIF: add PreferMailFormat
this.mSupportedAttributes = supportedAttributes.concat(["PreferMailFormat"]);
} else if (endsWith(this.mFile.leafName.toLowerCase(), ".csv")) {
this.mSupportedAttributes = supportedAttributes;
}
this.setFieldMap(this.getDefaultFieldMap(true));
} else if (endsWith(this.mFile.leafName.toLowerCase(), ".vcf")) {
this.mSupportedAttributes = supportedAttributes;
};
// get the "cards" from the JSON file, if necessary
if (aJsonName)
this.mJsonCards = this.getJsonCards(aJsonName);
@ -321,7 +326,7 @@ AbImportHelper.prototype =
do_check_true(arr && arr.length > 0);
return arr;
}
}
};
AbImportHelper.prototype.__proto__ = GenericImportHelper.prototype;
/**

Просмотреть файл

@ -9,6 +9,7 @@ function run_test()
.createInstance(Ci.nsISupportsString);
// get the Address Book text import interface and make sure it succeeded
var helper = new AbImportHelper(file, "Text file");
helper.setFieldMap(null);
helper.setAddressBookLocation(file);
var abInterface = helper.getInterface();

Просмотреть файл

@ -0,0 +1,20 @@
/**
* Tests importing an address book export in the LDAP data interchange (LDIF)
* format and checks the accuracy of the imported address book's cards.
* The current export contains only one card with most fields full.
*
* This test also checks for the following bugs:
* -Bug 439819: LDIF import does not include mozillahomestreet.
* -Bug 182128: Edit Card, Notes on several lines appear on one after
* export/import in text format *(only tests the import).
*/
function run_test()
{
// Due to the import code using nsIAbManager off the main thread, we need
// to ensure that it is initialized before we start the main test.
let abMgr = MailServices.ab;
let file = do_get_file("resources/basic_csv_addressbook.csv");
new AbImportHelper(file, "csv", "basic_csv_addressbook",
"csv_import").beginImport();
}

Просмотреть файл

@ -0,0 +1,27 @@
/**
* Tests importing an address book export in the LDAP data interchange (LDIF)
* format and checks the accuracy of the imported address book's cards.
* The current export contains only one card with most fields full.
*
* This test also checks for the following bugs:
* -Bug 439819: LDIF import does not include mozillahomestreet.
* -Bug 182128: Edit Card, Notes on several lines appear on one after
* export/import in text format *(only tests the import).
*/
function run_test()
{
// Due to the import code using nsIAbManager off the main thread, we need
// to ensure that it is initialized before we start the main test.
let abMgr = MailServices.ab;
// test regular import (e.g. from file exported by another mail client)
let file = do_get_file("resources/basic_vcard_addressbook.vcf");
new AbImportHelper(file, "vcf", "basic_vcard_addressbook",
"vcard_import").beginImport();
// test import against file with extra newlines (e.g. as copy-pasted by
// hand, a relatively unlikely but still reasonable use case to cover)
file = do_get_file("resources/emptylines_vcard_addressbook.vcf");
new AbImportHelper(file, "vcf", "emptylines_vcard_addressbook",
"vcard_import").beginImport();
}

Просмотреть файл

@ -4,13 +4,15 @@ tail = tail_import.js
[test_bug_263304.js]
[test_bug_437556.js]
[test_csv_GetSample.js]
[test_csv_import.js]
[test_ldif_import.js]
[test_oe_settings.js]
run-if = os == 'win'
[test_winmail.js]
run-if = os == 'win'
[test_outlook_settings.js]
run-if = os == 'win'
[test_csv_GetSample.js]
[test_utf16_csv.js]
[test_shiftjis_csv.js]
[test_utf16_csv.js]
[test_vcard_import.js]
[test_winmail.js]
run-if = os == 'win'