DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Untracked file

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
<html>
<head>
  <title>Testing Application.js</title>
  <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"></link>
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">

// The various properties that we'll be testing
var test = {
	missing: "fuel.fuel-test-missing",
	dummy: "fuel.fuel-test",
	string: "browser.active_color",
	integer: "permissions.default.image",
	boolean: "browser.blink_allowed"
};

test_Preferences();

function test_Preferences() {
  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");

  // test getting non-existing values
  var itemValue = Application.prefs.getValue(test.missing, "default");
  is(itemValue, "default", "Check 'Application.prefs.getValue' for non-existing item");
  
  is(Application.prefs.get(test.missing), null, "Check 'Application.prefs.get' for non-existing item");
  
  // test setting and getting a value
  Application.prefs.setValue(test.dummy, "dummy");
  itemValue = Application.prefs.getValue(test.dummy, "default");
  is(itemValue, "dummy", "Check 'Application.prefs.getValue' for existing item");

  // test for overwriting an existing value
  Application.prefs.setValue(test.dummy, "smarty");
  itemValue = Application.prefs.getValue(test.dummy, "default");
  is(itemValue, "smarty", "Check 'Application.prefs.getValue' for overwritten item");
  
  // test setting and getting a value
  Application.prefs.get(test.dummy).value = "dummy2";
  itemValue = Application.prefs.get(test.dummy).value;
  is(itemValue, "dummy2", "Check 'Application.prefs.get().value' for existing item");

  // test resetting a pref [since there is no default value, the pref should disappear]
  Application.prefs.get(test.dummy).reset();
  var itemValue = Application.prefs.getValue(test.dummy, "default");
  is(itemValue, "default", "Check 'Application.prefs.getValue' for reset pref");
  
  // test to see if a non-existant property exists
  ok(!Application.prefs.has(test.dummy), "Check non-existant property for existance");
  
  // PREF: string browser.active_color == #EE0000
  
  // test to see if an existing string property exists
  ok(Application.prefs.has(test.string), "Check existing string property for existance");
  
  // test accessing a non-existant string property
  var val = Application.prefs.getValue(test.dummy, "default");
  is(val, "default", "Check non-existant string property for expected value");
  
  // test accessing an existing string property
  var val = Application.prefs.getValue(test.string, "default");
  is(val, "#EE0000", "Check existing string property for expected value");
  
  // test manipulating an existing string property
  Application.prefs.setValue(test.string, "#EF0000");
  var val = Application.prefs.getValue(test.string, "default");
  is(val, "#EF0000", "Set existing string property");
  
  // test resetting an existing string property
  Application.prefs.get(test.string).reset();
  var val = Application.prefs.getValue(test.string, "default");
  is(val, "#EE0000", "Reset existing string property");
  
  // PREF: integer permissions.default.image == 1
  
  // test to see if an existing integer property exists
  ok(Application.prefs.has(test.integer), "Check existing integer property for existance");
  
  // test accessing a non-existant integer property
  var val = Application.prefs.getValue(test.dummy, 0);
  is(val, 0, "Check non-existant integer property for expected value");
  
  // test accessing an existing integer property
  var val = Application.prefs.getValue(test.integer, 0);
  is(val, 1, "Check existing integer property for expected value");

  // test manipulating an existing integer property
  Application.prefs.setValue(test.integer, 0);
  var val = Application.prefs.getValue(test.integer, 1);
  is(val, 0, "Set existing integer property");
  
  // test resetting an existing integer property
  Application.prefs.get(test.integer).reset();
  var val = Application.prefs.getValue(test.integer, 0);
  is(val, 1, "Reset existing integer property");

  // PREF: boolean browser.blink_allowed == true
  
  // test to see if an existing boolean property exists
  ok(Application.prefs.has(test.boolean), "Check existing boolean property for existance");
  
  // test accessing a non-existant boolean property
  var val = Application.prefs.getValue(test.dummy, true);
  ok(val, "Check non-existant boolean property for expected value");
  
  // test accessing an existing boolean property
  var val = Application.prefs.getValue(test.boolean, false);
  ok(val, "Check existing boolean property for expected value");
  
  // test manipulating an existing boolean property
  Application.prefs.setValue(test.boolean, false);
  var val = Application.prefs.getValue(test.boolean, true);
  ok(!val, "Set existing boolean property");
  
  // test resetting an existing boolean property
  Application.prefs.get(test.boolean).reset();
  var val = Application.prefs.getValue(test.boolean, false);
  ok(val, "Reset existing string property for expected value");
  
  // test getting all preferences
  var allPrefs = Application.prefs.all;
  ok(allPrefs.length >= 800, "Check 'Application.prefs.all' for the right number of preferences");
  is(allPrefs[0].name, "capability.policy.default.Window.parent.get", "Check 'Application.prefs.all' for the right starting preference");

  // test the value of the preference root
  is(Application.prefs.root, "", "Check the Application preference root");
  
  // test for user changed preferences
  ok(Application.prefs.get("browser.shell.checkDefaultBrowser").modified, "A single preference is marked as modified.");
  ok(!Application.prefs.get(test.string).modified, "A single preference is marked as not modified.");
  
  // test for a locked preference
  var pref = Application.prefs.get(test.string);
  ok(!pref.locked, "A single preference should not be locked.");
  
  pref.locked = true;
  ok(pref.locked, "A single preference should be locked.");
  
  try {
    prev.value = "test value";
    
    ok(false, "A locked preference should not be able to be modified.");
  } catch(e){
    ok(true, "A locked preference should not be able to be modified.");
  }
  
  pref.locked = false;
  ok(!pref.locked, "A single preference should not be locked.");
  
  // check for change event when setting a value
  SimpleTest.waitForExplicitFinish();
  Application.prefs.events.addListener("change", onPrefChange);
  Application.prefs.setValue("fuel.fuel-test", "change event");
}

function onPrefChange(evt) {
  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
  is(evt.data, test.dummy, "Check 'Application.prefs.set' fired a change event");
  Application.prefs.events.removeListener("change", onPrefChange);

  Application.prefs.get("fuel.fuel-test").events.addListener("change", onPrefChange2);
  Application.prefs.setValue("fuel.fuel-test", "change event2");
}

function onPrefChange2(evt) {
  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
  is(evt.data, test.dummy, "Check 'Application.prefs.set' fired a change event for a single preference");
  Application.prefs.events.removeListener("change", onPrefChange2);
  
  SimpleTest.finish();
}
</script>
</pre>
</body>
</html>