You are currently viewing a snapshot of www.mozilla.org taken on April 21, 2008. Most of this content is highly out of date (some pages haven't been updated since the project began in 1998) and exists for historical purposes only. If there are any pages on this archive site that you think should be added back to www.mozilla.org, please file a bug.



Test Plan for nsIPrefBranch interface



    The nsIPrefBranch interface provides access to users preferences. In order to test the methods in nsIPrefBranch
    interface you need to first get an nsIPrefService object and doing a getBranch on it will return a pointer to nsIPrefBranch.

    nsIPrefServiceObj = Components.classes["@mozilla.org/preferences-service;1"].
                                     getService(Components.interfaces.nsIPrefService);
    var nsIPrefBranchObj = nsIPrefServiceObj.getBranch(null);

    Now you can call the methods using the nsIPrefBranchObj object.

    To see the test cases click on the desired methods or attributes below.

    Click here to see the source code for the test case. If you download the testcase rename it to .html before opening
    it in an embedding application.

    attributes:
    root

    methods:
    getPrefType()
    getBoolPref()
    setBoolPref()
    getCharPref()
    setCharPref()
    getIntPref()
    setIntPref()
    getComplexValue()
    setComplexValue()
    clearUserPref()
    lockPref()
    prefIsLocked()
    unlockPref()
    deleteBranch()
    getChildList()
    resetBranch()

root

    Introduction:
    The root of this branch, such as "browser.startup.".

    How to use:
    var nsIPrefBranchObj = nsIPrefServiceObj.getBranch("browser.startup.");
    alert(nsIPrefBranchObj.root);
 

Case Steps Expected Results Pass/Fail Comments
1 Use the above code. The alert should display "browser.startup.". pass

    Back To Top

getPrefType()

    Introduction:
    Each preference is a name value pair. This method return a long value which represents the type of value
    the name holds. If the return value is 32 then the value is string type. If the return value is 128 then the
    value is boolen type.

    How to use:
    Variation1:
    var nsIPrefBranchObj = nsIPrefServiceObj.getBranch(null);
    var prefType = nsIPrefBranchObj.getPrefType("browser.startup.homepage");
    alert("prefType: " + prefType);
 

Case Steps Expected Results Pass/Fail Comments
1 Check with the string argument "browser.startup.homepage" string. Should bring up the alert dialog with prefType:32. pass Since "browser.startup.homepage" value is "www.mozilla.org" which is string. prefType:32 represents string.
2 Check with the string argument "browser.display.screen_resolution" string. Should bring up the alert dialog with prefType:64. pass Since "browser.display.screen_resolution" value is 96 which is integer. prefType:64 represents integer.
3 Check with the string argument "prefs.converted-to-utf8" string. Should bring up the alert dialog with prefType:128. pass Since "prefs.converted-to-utf8" value is 128 which is boolean. prefType:128 represents boolean.

    Variation2:
    var nsIPrefBranchObj = nsIPrefServiceObj.getBranch("capability.principal.");
    var prefType = nsIPrefBranchObj.getPrefType("codebase.p0.id");
    alert("prefType: " + prefType);
 

Case Steps Expected Results Pass/Fail Comments
1 Check with the string argument "codebase.p0.id" string. Should bring up the alert dialog with prefType:32. pass Since "capability.principal.codebase.p0.id" value is "file://" which is string. prefType:32 represents string.
2 Check with the string argument "homepage" string. Should bring up the alert dialog with prefType:0. pass Since "capability.principal.homepage" preference doesnot exist.prefType:0 means its invalid.

    Back To Top

getBoolPref()

    Introduction:
    If the preference value is boolean you should use this method. This method returns the value of the preference.

    How to use:
    var nsIPrefBranchObj = nsIPrefServiceObj.getBranch(null);
    var boo = nsIPrefBranchObj.getBoolPref("prefs.converted-to-utf8");
    alert("boo: " + boo);
 

Case Steps Expected Results Pass/Fail Comments
1 Check with the string argument "prefs.converted-to-utf8" string. Should bring up the alert dialog with false if "prefs.converted-to-utf8" is set to false in preferences file or with true if it was set to true. pass

    Back To Top

setBoolPref()

    Introduction:
    If the preference value is boolean you can use this method. This method sets the specified value to the specified preference. If you
    want to set to false use the value 0. If you want to set to true use value 1.

    How to use:
    var nsIPrefBranchObj = nsIPrefServiceObj.getBranch(null);
    nsIPrefBranchObj.setBoolPref("browser.startup.homepage_override.1", 0);
    nsIPrefServiceObj.savePrefFile(null);
 

Case Steps  Expected Results Pass/Fail Comments
1 Use the above code. Check the preference file to see if it updates the preference "browser.startup.
homepage_overide.1" to false.
pass

    Back To Top

getCharPref()

    Introduction:
    If the preference value is string you can use this method. This method return the value of the preference.

    How to use:
    var nsIPrefBranchObj = nsIPrefServiceObj.getBranch(null);
    var result = nsIPrefBranchObj.getCharPref("browser.startup.homepage");
    alert(result);
 

Case Steps Expected Results Pass/Fail Comments
1 Use the above code. Should bring up the alert dialog with the string "http://www.mozilla.org" if the preference for "browser.startup.homepage" was set to "http://www.mozilla.org". pass

    Back To Top

setCharPref()

    Introduction:
    If the preference value is string you can use this method. This method sets the specified value to the specified preference.

    How to use:
    var nsIPrefBranchObj = nsIPrefServiceObj.getBranch(null);
    nsIPrefBranchObj.setCharPref("browser.startup.homepage", "http://bugzilla.mozilla.org")
    nsIPrefServiceObj.savePrefFile(null);
 

Case Steps Expected Results Pass/Fail Comments
1 Use the above code. Check the preference file to see if it updates the preference "browser.startup.homepage" to "http://bugzilla.mozilla.org" pass

    Back To Top

getIntPref()

    Introduction:
    If the preference value is integer you can use this method. This method return the value of the preference.

    How to use:
    var nsIPrefBranchObj = nsIPrefServiceObj.getBranch(null);
    var result = nsIPrefBranchObj.getIntPref("editor.table.delete_key");
    alert(result);
 

Case Steps Expected Results Pass/Fail Comments
1 Use the above code. Should bring up the alert dialog with the integer value 1 if the preference for "editor.table.delete_key" was set to 1. pass

    Back To Top

setIntPref()

    Introduction:
    If the preference value is integer you can use this method. This method sets the specified value to the specified preference.

    How to use:
    var nsIPrefBranchObj = nsIPrefServiceObj.getBranch(null);
    nsIPrefBranchObj.setIntPref("editor.table.delete_key", 0)
    nsIPrefServiceObj.savePrefFile(null);
 

Case Steps Expected Results Pass/Fail Comments
1 Use the above code. Check the preference file to see if it updates the preference "editor.table.delete_key"
to value 0.
pass

    Back To Top

clearUserPref()

    Introduction:
    Resets a preference to the default value.

    How to use:
    var nsIPrefBranchObj = nsIPrefServiceObj.getBranch(null);
    nsIPrefBranchObj.clearUserPref("wallet.SchemaValueFileName");
    nsIPrefServiceObj.savePrefFile(null);
 

Case Steps Expected Results Pass/Fail Comments
1 Use the above code. It should update the preference to default value. pass

    Back To Top

getComplexValue()

    Back To Top

setComplexValue()

    Back To Top

lockPref()

    Introduction:
    Lock the preference. This method should be used for manipulating the ability to change the state of a preference.

    How to use:
    var nsIPrefBranchObj = nsIPrefServiceObj.getBranch(null);
    nsIPrefBranchObj.lockPref("prefs.converted-to-utf8");
    nsIPrefServiceObj.savePrefFile(null);
 

Case Steps Expected Results Pass/Fail Comments
1 Try to use setBoolPref method and try to change the value of it. It should not change the value of preference. fail

    Back To Top

prefIsLocked()

    Introduction:
    Checks whether the preference is Locked.

    How to use:
    var nsIPrefBranchObj = nsIPrefServiceObj.getBranch(null);
    var boo = nsIPrefBranchObj.prefIsLocked("prefs.converted-to-utf8");
    alert (boo);
 

Case Steps Expected Results Pass/Fail Comments
1 Use the above code. Returns true if the preference is locked. Returns false if the preference is unlocked. pass

    Back To Top

unlockPref()

    Introduction:
    Unlocks the preference if its locked.

    How to use:
    var nsIPrefBranchObj = nsIPrefServiceObj.getBranch(null);
    nsIPrefBranchObj.unlockPref("prefs.converted-to-utf8");
    nsIPrefServiceObj.savePrefFile(null);
 

Case Steps Expected Results Pass/Fail Comments
1 Use the above code. Should unlock the preference.You can verify whether it is unlocked by using the method prefIsLocked. pass

    Back To Top

deleteBranch()

    Introduction:
    Removes all preferences starting at the given preference prefix. Pass in null or "" to remove this branch.

    How to use:
    var nsIPrefBranchObj = nsIPrefServiceObj.getBranch("font.");
    nsIPrefBranchObj.deleteBranch("size");
    nsIPrefServiceObj.savePrefFile(null);
 

Case Steps Expected Results Pass/Fail Comments
1 Use the above code. Since the root is set "font." and "size" is passed, all of the preferences related to "font.size" such as "font.size.fixed.x-western" and "font.size.variable.x-western" will be manipulated. pass
2 Pass null or "" to deleteBranch. Since the root is set "font." and null is passed , all of the preferences related to "font" such as "font.name.sans-serif.x-western", "font.size.fixed.x-western" and "font.size.variable.x-western" will be manipulated(deleted). fail

    Back To Top

getChildList()

    Introduction:
    Returns an array of strings representing the child preferences of the branch root.

    How to use:
    var nsIPrefBranchObj = nsIPrefServiceObj.getBranch("capability.");
    var aCount = {value:0};
    var childArray = nsIPrefBranchObj.getChildList("principal" , aCount);
    alert("aCount: " + aCount.value);
    alert("Array length: " + childArray.length);
    alert("Array content: " + childArray.toString());

    Say there are two preferences in this branch - capability.principal.codebase.p0.granted and capability.principal.codebase.p0.id.
 

Case Steps Expected Result Pass/Fail Comments
1 Use the above code aCount should show 2 since there are two elements in the array. Array content should show two preferences capability.principal.codebase.p0.granted and capability.principal.codebase.p0.id. pass

    Back To Top

resetBranch()

    Introduction:
    Clears all user perferences (i.e. resets them to their default values) starting at the give preference prefix. Pass in null or "" to clear
    this  branch.

    How to use:
    This method has not yet been implemented.
 

Case Steps Expected Results Pass/Fail Comments
1

    Back To Top

    Revision History:
    Date                        Changed By              Comments

    05/12/01                                                  TestPlan written by Dharma.