зеркало из https://github.com/mozilla/pjs.git
Bug 405147 Provide some basic unit tests for nsIAbDirectory. r=Neil,sr=bienvenu
This commit is contained in:
Родитель
223476d764
Коммит
391460871e
|
@ -56,5 +56,9 @@ ifndef MOZ_STATIC_MAIL_BUILD
|
|||
DIRS += build
|
||||
endif
|
||||
|
||||
ifdef ENABLE_TESTS
|
||||
DIRS += test
|
||||
endif
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
#
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public License Version
|
||||
# 1.1 (the "License"); you may not use this file except in compliance with
|
||||
# the License. You may obtain a copy of the License at
|
||||
# http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
# for the specific language governing rights and limitations under the
|
||||
# License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is
|
||||
# Mark Banner <bugzilla@standard8.plus.com>
|
||||
#
|
||||
# Portions created by the Initial Developer are Copyright (C) 2007
|
||||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||
# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
# in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
# of those above. If you wish to allow use of your version of this file only
|
||||
# under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
# use your version of this file under the terms of the MPL, indicate your
|
||||
# decision by deleting the provisions above and replace them with the notice
|
||||
# and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
# the provisions above, a recipient may use your version of this file under
|
||||
# the terms of any one of the MPL, the GPL or the LGPL.
|
||||
#
|
||||
# ***** END LICENSE BLOCK *****
|
||||
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
# Module name for xpcshell tests.
|
||||
MODULE = test_addbook
|
||||
|
||||
XPCSHELL_TESTS = unit
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/**
|
||||
* In this file we clean up the address books created during the tests.
|
||||
*/
|
||||
|
||||
var abs = [ kPABData.fileName,
|
||||
kCABData.fileName ];
|
||||
|
||||
try {
|
||||
// Now remove the directory
|
||||
if (profileDir.exists())
|
||||
profileDir.remove(true);
|
||||
}
|
||||
catch (e) {
|
||||
throw "FAILED to clean up AB tests: " + e;
|
||||
}
|
|
@ -0,0 +1,120 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* Test suite for basic address book functions - tests obtaining the (default)
|
||||
* personal address book and getting its details from the nsIAbDirectory.
|
||||
*
|
||||
* Functions/attributes not currently tested:
|
||||
* - lastModifiedDate
|
||||
* - childNodes
|
||||
* - childCards
|
||||
* - deleteDirectory
|
||||
* - hasCard
|
||||
* - hasDirectory
|
||||
* - addCard
|
||||
* - modifyCard
|
||||
* - deleteCards
|
||||
* - dropCard
|
||||
* - addressLists
|
||||
* - addMailList
|
||||
* - listNickName
|
||||
* - description
|
||||
* - editMailListToDatabase
|
||||
* - copyMailList
|
||||
* - createNewDirectory
|
||||
* - createDirectoryByURI
|
||||
*/
|
||||
|
||||
var testnum = 0;
|
||||
|
||||
// Main function for the this test so we can check both personal and
|
||||
// collected books work correctly in an easy manner.
|
||||
function check_ab(abConfig) {
|
||||
try {
|
||||
++testnum; // Test 1 - Get the directory
|
||||
|
||||
var rdf = Components.classes["@mozilla.org/rdf/rdf-service;1"]
|
||||
.getService(Components.interfaces.nsIRDFService);
|
||||
do_check_true(rdf != null);
|
||||
|
||||
var AB = rdf.GetResource(abConfig.URI)
|
||||
.QueryInterface(Components.interfaces.nsIAbDirectory);
|
||||
do_check_true(AB != null);
|
||||
|
||||
|
||||
++testnum; // Test 2 - Is it the right type?
|
||||
|
||||
do_check_true(AB instanceof Components.interfaces.nsIAbMDBDirectory);
|
||||
|
||||
|
||||
++testnum; // Test 3 - Check attributes
|
||||
|
||||
do_check_eq(AB.propertiesChromeURI, kNormalPropertiesURI);
|
||||
do_check_eq(AB.operations,
|
||||
Components.interfaces.nsIAbDirectory.opRead |
|
||||
Components.interfaces.nsIAbDirectory.opWrite |
|
||||
Components.interfaces.nsIAbDirectory.opSearch);
|
||||
do_check_eq(AB.dirName, abConfig.dirName);
|
||||
do_check_eq(AB.dirType, abConfig.dirType);
|
||||
do_check_eq(AB.fileName, abConfig.fileName);
|
||||
do_check_eq(AB.URI, abConfig.URI);
|
||||
do_check_eq(AB.position, abConfig.position);
|
||||
do_check_eq(AB.isMailList, false);
|
||||
do_check_eq(AB.isRemote, false);
|
||||
do_check_eq(AB.isSecure, false);
|
||||
do_check_eq(AB.searchDuringLocalAutocomplete, true);
|
||||
do_check_eq(AB.supportsMailingLists, true);
|
||||
do_check_eq(AB.dirPrefId, abConfig.dirPrefID);
|
||||
|
||||
|
||||
++testnum; // Test 4 - check getting default preferences
|
||||
|
||||
var gPref = Components.classes["@mozilla.org/preferences-service;1"]
|
||||
.getService(Components.interfaces.nsIPrefBranch);
|
||||
|
||||
do_check_eq(AB.getIntValue("random", 54321), 54321);
|
||||
do_check_eq(AB.getBoolValue("random", false), false);
|
||||
do_check_eq(AB.getStringValue("random", "abc"), "abc");
|
||||
do_check_eq(AB.getLocalizedStringValue("random", "xyz"), "xyz");
|
||||
|
||||
|
||||
++testnum; // Test 5 - check get/set int preferences on nsIAbDirectory
|
||||
|
||||
AB.setIntValue("inttest", 12345);
|
||||
do_check_eq(gPref.getIntPref(abConfig.dirPrefID + ".inttest"), 12345);
|
||||
do_check_eq(AB.getIntValue("inttest", -1), 12345);
|
||||
|
||||
AB.setIntValue("inttest", 123456);
|
||||
do_check_eq(gPref.getIntPref(abConfig.dirPrefID + ".inttest"), 123456);
|
||||
do_check_eq(AB.getIntValue("inttest", -2), 123456);
|
||||
|
||||
|
||||
++testnum; // Test 6 - check get/set bool preferences on nsIAbDirectory
|
||||
|
||||
AB.setBoolValue("booltest", true);
|
||||
do_check_eq(gPref.getBoolPref(abConfig.dirPrefID + ".booltest"), true);
|
||||
do_check_eq(AB.getBoolValue("booltest", false), true);
|
||||
|
||||
AB.setBoolValue("booltest", false);
|
||||
do_check_eq(gPref.getBoolPref(abConfig.dirPrefID + ".booltest"), false);
|
||||
do_check_eq(AB.getBoolValue("booltest", true), false);
|
||||
|
||||
|
||||
++testnum; // Test 7 - check get/set string preferences on nsIAbDirectory
|
||||
|
||||
AB.setStringValue("stringtest", "tyu");
|
||||
do_check_eq(gPref.getCharPref(abConfig.dirPrefID + ".stringtest"), "tyu");
|
||||
do_check_eq(AB.getStringValue("stringtest", ""), "tyu");
|
||||
|
||||
} catch (e) {
|
||||
throw "FAILED in AB \"" + abConfig.dirName + "\" in test #" +
|
||||
testnum + ": " + e;
|
||||
}
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
// Check the default personal address book
|
||||
check_ab(kPABData);
|
||||
|
||||
// Check the default collected address book
|
||||
check_ab(kCABData);
|
||||
};
|
Загрузка…
Ссылка в новой задаче