pjs/embedding/qa/jstests/nsIPrefBranchTest.txt

138 строки
3.6 KiB
Plaintext

<html>
<!--
Written by Dharma.
Test last run on 05/09/01.
-->
<head>
<title> Testing nsIPrefBranch Interface </title>
<script type="text/javascript">
function getnsIPrefServiceObj()
{
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
prefObj = Components.classes["@mozilla.org/preferences-service;1"].
getService(Components.interfaces.nsIPrefService);
}
catch(e) {
alert("Exception: " + e);
}
return prefObj;
}
</script>
</head>
<body>
<script type="text/javascript">
// First get the nsIPrefService object.
var nsIPrefServiceObj = getnsIPrefServiceObj();
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
// get the nsIPrefBranch object.
// if you use getBranch() then the preference file that gets affected is prefs.js.
var nsIPrefBranchObj = nsIPrefServiceObj.getBranch("app.update.");
// verifying the attribute root.
alert("root: " + nsIPrefBranchObj.root);
// checking getPrefType method.
alert("prefType: " + nsIPrefBranchObj.getPrefType("url"));
// checking getBoolPref method.
var boo = nsIPrefBranchObj.getBoolPref("enabled");
alert("boo: " + boo);
// checking setBoolPref method.
nsIPrefBranchObj.setBoolPref("enabled", !boo);
nsIPrefServiceObj.savePrefFile(null);
// checking getCharPref method.
var updateUrl = nsIPrefBranchObj.getCharPref("url");
alert("charPref: " + updateUrl);
// checking setCharPref method.
nsIPrefBranchObj.setCharPref("url", "http://mozilla.org")
nsIPrefServiceObj.savePrefFile(null);
// checking getIntPref method.
/*
var result = nsIPrefBranchObj.getIntPref("editor.table.delete_key");
alert(result);
*/
// checking setIntPref method.
/*
nsIPrefBranchObj.setIntPref("editor.table.delete_key", 1)
nsIPrefServiceObj.savePrefFile(null);
*/
// checking clearUserPref method.
/*
nsIPrefBranchObj.clearUserPref("url");
nsIPrefServiceObj.savePrefFile(null);
*/
// checking lockPref method.
boo = nsIPrefBranchObj.prefIsLocked("url");
alert ("prefIsLocked: " + boo);
nsIPrefBranchObj.lockPref("url");
nsIPrefServiceObj.savePrefFile(null);
// checking prefIsLocked method.
var boo = nsIPrefBranchObj.prefIsLocked("url");
alert ("prefIsLocked: " + boo);
/*
nsIPrefBranchObj.setBoolPref("homepage_override.1", 0);
nsIPrefServiceObj.savePrefFile(null);
*/
// checking unlockPref method.
nsIPrefBranchObj.unlockPref("url");
nsIPrefServiceObj.savePrefFile(null);
alert("parefIsLocked: " + nsIPrefBranchObj.prefIsLocked("url"));
// checking deleteBranch
// Filed a bug related to this method. for details see the bug #80108.
// after reading the bug tried by settting the root to "font" without a dot and
// it deletes the branch.
/*
nsIPrefBranchObj.deleteBranch(null);
nsIPrefServiceObj.savePrefFile(null);
*/
// checking resetBranch
/*
nsIPrefBranchObj.resetBranch("size.fixed.x-western");
nsIPrefServiceObj.savePrefFile(null);
*/
// checking getChildList method.
var aCount = {value:0};
var childArray = nsIPrefBranchObj.getChildList("", aCount);
alert("aCount: " + aCount.value);
//alert("Array length: " + childArray.length);
alert("Array content: " + childArray.toString());
/*
var defaultName = nsIPrefBranchObj.getComplexValue("browser.search.defaultenginename" , Components.interfaces.nsIPrefLocalizedString).data;
alert(defaultName);
*/
alert("End");
}
catch(e) {
alert("Exception: " + e);
}
</script>
</body>
</html>