browser/fuel/test/browser_ApplicationPrefs.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 // The various properties that we'll be testing
     2 var testdata = {
     3   missing: "fuel.fuel-test-missing",
     4   dummy: "fuel.fuel-test",
     5   string: "browser.active_color",
     6   integer: "permissions.default.image",
     7   boolean: "browser.underline_anchors"
     8 };
    10 function test() {
    11   // test getting nonexistent values
    12   var itemValue = Application.prefs.getValue(testdata.missing, "default");
    13   is(itemValue, "default", "Check 'Application.prefs.getValue' for nonexistent item");
    15   is(Application.prefs.get(testdata.missing), null, "Check 'Application.prefs.get' for nonexistent item");
    17   // test setting and getting a value
    18   Application.prefs.setValue(testdata.dummy, "dummy");
    19   itemValue = Application.prefs.getValue(testdata.dummy, "default");
    20   is(itemValue, "dummy", "Check 'Application.prefs.getValue' for existing item");
    22   // test for overwriting an existing value
    23   Application.prefs.setValue(testdata.dummy, "smarty");
    24   itemValue = Application.prefs.getValue(testdata.dummy, "default");
    25   is(itemValue, "smarty", "Check 'Application.prefs.getValue' for overwritten item");
    27   // test setting and getting a value
    28   Application.prefs.get(testdata.dummy).value = "dummy2";
    29   itemValue = Application.prefs.get(testdata.dummy).value;
    30   is(itemValue, "dummy2", "Check 'Application.prefs.get().value' for existing item");
    32   // test resetting a pref [since there is no default value, the pref should disappear]
    33   Application.prefs.get(testdata.dummy).reset();
    34   itemValue = Application.prefs.getValue(testdata.dummy, "default");
    35   is(itemValue, "default", "Check 'Application.prefs.getValue' for reset pref");
    37   // test to see if a non-existant property exists
    38   ok(!Application.prefs.has(testdata.dummy), "Check non-existant property for existence");
    40   // PREF: string browser.active_color == #EE0000
    42   // test to see if an existing string property exists
    43   ok(Application.prefs.has(testdata.string), "Check existing string property for existence");
    45   // test accessing a non-existant string property
    46   var val = Application.prefs.getValue(testdata.dummy, "default");
    47   is(val, "default", "Check non-existant string property for expected value");
    49   // test accessing an existing string property
    50   var val = Application.prefs.getValue(testdata.string, "default");
    51   is(val, "#EE0000", "Check existing string property for expected value");
    53   // test manipulating an existing string property
    54   Application.prefs.setValue(testdata.string, "#EF0000");
    55   var val = Application.prefs.getValue(testdata.string, "default");
    56   is(val, "#EF0000", "Set existing string property");
    58   // test getting the type of an existing string property
    59   var type = Application.prefs.get(testdata.string).type;
    60   is(type, "String", "Check 'Application.prefs.get().type' for string pref");
    62   // test resetting an existing string property
    63   Application.prefs.get(testdata.string).reset();
    64   var val = Application.prefs.getValue(testdata.string, "default");
    65   is(val, "#EE0000", "Reset existing string property");
    67   // PREF: integer permissions.default.image == 1
    69   // test to see if an existing integer property exists
    70   ok(Application.prefs.has(testdata.integer), "Check existing integer property for existence");
    72   // test accessing a non-existant integer property
    73   var val = Application.prefs.getValue(testdata.dummy, 0);
    74   is(val, 0, "Check non-existant integer property for expected value");
    76   // test accessing an existing integer property
    77   var val = Application.prefs.getValue(testdata.integer, 0);
    78   is(val, 1, "Check existing integer property for expected value");
    80   // test manipulating an existing integer property
    81   Application.prefs.setValue(testdata.integer, 0);
    82   var val = Application.prefs.getValue(testdata.integer, 1);
    83   is(val, 0, "Set existing integer property");
    85   // test getting the type of an existing integer property
    86   var type = Application.prefs.get(testdata.integer).type;
    87   is(type, "Number", "Check 'Application.prefs.get().type' for integer pref");
    89   // test resetting an existing integer property
    90   Application.prefs.get(testdata.integer).reset();
    91   var val = Application.prefs.getValue(testdata.integer, 0);
    92   is(val, 1, "Reset existing integer property");
    94   // PREF: boolean browser.underline_anchors == true
    96   // test to see if an existing boolean property exists
    97   ok(Application.prefs.has(testdata.boolean), "Check existing boolean property for existence");
    99   // test accessing a non-existant boolean property
   100   var val = Application.prefs.getValue(testdata.dummy, true);
   101   ok(val, "Check non-existant boolean property for expected value");
   103   // test accessing an existing boolean property
   104   var val = Application.prefs.getValue(testdata.boolean, false);
   105   ok(val, "Check existing boolean property for expected value");
   107   // test manipulating an existing boolean property
   108   Application.prefs.setValue(testdata.boolean, false);
   109   var val = Application.prefs.getValue(testdata.boolean, true);
   110   ok(!val, "Set existing boolean property");
   112   // test getting the type of an existing boolean property
   113   var type = Application.prefs.get(testdata.boolean).type;
   114   is(type, "Boolean", "Check 'Application.prefs.get().type' for boolean pref");
   116   // test resetting an existing boolean property
   117   Application.prefs.get(testdata.boolean).reset();
   118   var val = Application.prefs.getValue(testdata.boolean, false);
   119   ok(val, "Reset existing string property for expected value");
   121   // test getting all preferences
   122   var allPrefs = Application.prefs.all;
   123   ok(allPrefs.length >= 800, "Check 'Application.prefs.all' for the right number of preferences");
   124   ok(allPrefs[0].name.length > 0, "Check 'Application.prefs.all' for a valid name in the starting preference");
   126   // test the value of the preference root
   127   is(Application.prefs.root, "", "Check the Application preference root");
   129   // test for user changed preferences
   130   ok(Application.prefs.get("browser.shell.checkDefaultBrowser").modified, "A single preference is marked as modified.");
   131   ok(!Application.prefs.get(testdata.string).modified, "A single preference is marked as not modified.");
   133   // test for a locked preference
   134   var pref = Application.prefs.get(testdata.string);
   135   ok(!pref.locked, "A single preference should not be locked.");
   137   pref.locked = true;
   138   ok(pref.locked, "A single preference should be locked.");
   140   try {
   141     prev.value = "test value";
   143     ok(false, "A locked preference could be modified.");
   144   } catch(e){
   145     ok(true, "A locked preference should not be able to be modified.");
   146   }
   148   pref.locked = false;
   149   ok(!pref.locked, "A single preference is unlocked.");
   151   // check for change event when setting a value
   152   waitForExplicitFinish();
   153   Application.prefs.events.addListener("change", onPrefChange);
   154   Application.prefs.setValue("fuel.fuel-test", "change event");
   155 }
   157 function onPrefChange(evt) {
   158   is(evt.data, testdata.dummy, "Check 'Application.prefs.setValue' fired a change event");
   159   Application.prefs.events.removeListener("change", onPrefChange);
   161   // We are removing the old listener after adding the new listener so we can test that
   162   // removing a listener does not remove all listeners
   163   Application.prefs.get("fuel.fuel-test").events.addListener("change", onPrefChangeDummy);
   164   Application.prefs.get("fuel.fuel-test").events.addListener("change", onPrefChange2);
   165   Application.prefs.get("fuel.fuel-test").events.removeListener("change", onPrefChangeDummy);
   167   Application.prefs.setValue("fuel.fuel-test", "change event2");
   168 }
   170 function onPrefChange2(evt) {
   171   is(evt.data, testdata.dummy, "Check 'Application.prefs.setValue' fired a change event for a single preference");
   172   Application.prefs.events.removeListener("change", onPrefChange2);
   174   finish();
   175 }
   177 function onPrefChangeDummy(evt) {
   178   ok(false, "onPrefChangeDummy shouldn't be invoked!");
   179 }

mercurial