RetroZilla/embedding/qa/jstests/nsIPrefBranchTest.txt

142 lines
3.8 KiB
Plaintext
Raw Normal View History

2015-10-21 05:03:22 +02:00
<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("browser.startup.");
// verifying the attribute root.
alert("root: " + nsIPrefBranchObj.root);
// checking getPrefType method.
var prefType = nsIPrefBranchObj.getPrefType("homepage");
alert("prefType: " + prefType);
// checking getBoolPref method.
var boo = nsIPrefBranchObj.getBoolPref("homepage_override.1");
alert("boo: " + boo);
// checking setBoolPref method.
nsIPrefBranchObj.setBoolPref("homepage_override.1", 0);
nsIPrefServiceObj.savePrefFile(null);
// checking getCharPref method.
var result = nsIPrefBranchObj.getCharPref("homepage");
alert("charPref: " + result);
// checking setCharPref method.
nsIPrefBranchObj.setCharPref("homepage", "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("homepage_override.1");
nsIPrefServiceObj.savePrefFile(null);
*/
// checking lockPref method.
var boo = nsIPrefBranchObj.prefIsLocked("homepage_override.1");
alert ("prefIsLocked: " + boo);
nsIPrefBranchObj.lockPref("homepage_override.1");
nsIPrefServiceObj.savePrefFile(null);
// checking prefIsLocked method.
var boo = nsIPrefBranchObj.prefIsLocked("homepage_override.1");
alert ("prefIsLocked: " + boo);
/*
nsIPrefBranchObj.setBoolPref("homepage_override.1", 0);
nsIPrefServiceObj.savePrefFile(null);
*/
// checking unlockPref method.
nsIPrefBranchObj.unlockPref("homepage_override.1");
nsIPrefServiceObj.savePrefFile(null);
alert("parefIsLocked: " + nsIPrefBranchObj.prefIsLocked("homepage_override.1"));
// 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(null , 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>