toolkit/content/tests/chrome/test_preferences.xul

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 <?xml version="1.0"?>
michael@0 2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
michael@0 3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
michael@0 4
michael@0 5 <window title="Preferences Window Tests"
michael@0 6 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
michael@0 7 onload="RunTest();">
michael@0 8
michael@0 9 <script type="application/javascript"
michael@0 10 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
michael@0 11
michael@0 12 <script type="application/javascript">
michael@0 13 <![CDATA[
michael@0 14 if (navigator.platform.startsWith("Mac")) {
michael@0 15 SimpleTest.expectAssertions(4);
michael@0 16 } else {
michael@0 17 SimpleTest.expectAssertions(0,1);
michael@0 18 }
michael@0 19 SimpleTest.waitForExplicitFinish();
michael@0 20
michael@0 21 const kPref = Components.classes["@mozilla.org/preferences-service;1"]
michael@0 22 .getService(Components.interfaces.nsIPrefBranch);
michael@0 23
michael@0 24 // preference values, set 1
michael@0 25 const kPrefValueSet1 =
michael@0 26 {
michael@0 27 int: 23,
michael@0 28 bool: true,
michael@0 29 string: "rheeet!",
michael@0 30 wstring_data: "日本語",
michael@0 31 unichar_data: "äöüßÄÖÜ",
michael@0 32 file_data: "/",
michael@0 33
michael@0 34 wstring: Components.classes["@mozilla.org/pref-localizedstring;1"]
michael@0 35 .createInstance(Components.interfaces.nsIPrefLocalizedString),
michael@0 36 unichar: Components.classes["@mozilla.org/supports-string;1"]
michael@0 37 .createInstance(Components.interfaces.nsISupportsString),
michael@0 38 file: Components.classes["@mozilla.org/file/local;1"]
michael@0 39 .createInstance(Components.interfaces.nsILocalFile)
michael@0 40 };
michael@0 41 kPrefValueSet1.wstring.data = kPrefValueSet1.wstring_data;
michael@0 42 kPrefValueSet1.unichar.data = kPrefValueSet1.unichar_data;
michael@0 43 SafeFileInit(kPrefValueSet1.file, kPrefValueSet1.file_data);
michael@0 44
michael@0 45 // preference values, set 2
michael@0 46 const kPrefValueSet2 =
michael@0 47 {
michael@0 48 int: 42,
michael@0 49 bool: false,
michael@0 50 string: "Mozilla",
michael@0 51 wstring_data: "헤드라인A",
michael@0 52 unichar_data: "áôùšŽ",
michael@0 53 file_data: "/home",
michael@0 54
michael@0 55 wstring: Components.classes["@mozilla.org/pref-localizedstring;1"]
michael@0 56 .createInstance(Components.interfaces.nsIPrefLocalizedString),
michael@0 57 unichar: Components.classes["@mozilla.org/supports-string;1"]
michael@0 58 .createInstance(Components.interfaces.nsISupportsString),
michael@0 59 file: Components.classes["@mozilla.org/file/local;1"]
michael@0 60 .createInstance(Components.interfaces.nsILocalFile)
michael@0 61 };
michael@0 62 kPrefValueSet2.wstring.data = kPrefValueSet2.wstring_data;
michael@0 63 kPrefValueSet2.unichar.data = kPrefValueSet2.unichar_data;
michael@0 64 SafeFileInit(kPrefValueSet2.file, kPrefValueSet2.file_data);
michael@0 65
michael@0 66
michael@0 67 function SafeFileInit(aFile, aPath)
michael@0 68 {
michael@0 69 // set file path without dying for exceptions
michael@0 70 try
michael@0 71 {
michael@0 72 aFile.initWithPath(aPath);
michael@0 73 }
michael@0 74 catch (ignored) {}
michael@0 75 }
michael@0 76
michael@0 77 function CreateEmptyPrefValueSet()
michael@0 78 {
michael@0 79 var result =
michael@0 80 {
michael@0 81 int: undefined,
michael@0 82 bool: undefined,
michael@0 83 string: undefined,
michael@0 84 wstring_data: undefined,
michael@0 85 unichar_data: undefined,
michael@0 86 file_data: undefined,
michael@0 87 wstring: undefined,
michael@0 88 unichar: undefined,
michael@0 89 file: undefined
michael@0 90 };
michael@0 91 return result;
michael@0 92 }
michael@0 93
michael@0 94 function WritePrefsToSystem(aPrefValueSet)
michael@0 95 {
michael@0 96 // write preference data via XPCOM
michael@0 97 kPref.setIntPref ("tests.static_preference_int", aPrefValueSet.int);
michael@0 98 kPref.setBoolPref("tests.static_preference_bool", aPrefValueSet.bool);
michael@0 99 kPref.setCharPref("tests.static_preference_string", aPrefValueSet.string);
michael@0 100 kPref.setComplexValue("tests.static_preference_wstring",
michael@0 101 Components.interfaces.nsIPrefLocalizedString,
michael@0 102 aPrefValueSet.wstring);
michael@0 103 kPref.setComplexValue("tests.static_preference_unichar",
michael@0 104 Components.interfaces.nsISupportsString,
michael@0 105 aPrefValueSet.unichar);
michael@0 106 kPref.setComplexValue("tests.static_preference_file",
michael@0 107 Components.interfaces.nsILocalFile,
michael@0 108 aPrefValueSet.file);
michael@0 109 }
michael@0 110
michael@0 111 function ReadPrefsFromSystem()
michael@0 112 {
michael@0 113 // read preference data via XPCOM
michael@0 114 var result = CreateEmptyPrefValueSet();
michael@0 115 try {result.int = kPref.getIntPref ("tests.static_preference_int") } catch (ignored) {};
michael@0 116 try {result.bool = kPref.getBoolPref("tests.static_preference_bool") } catch (ignored) {};
michael@0 117 try {result.string = kPref.getCharPref("tests.static_preference_string")} catch (ignored) {};
michael@0 118 try
michael@0 119 {
michael@0 120 result.wstring = kPref.getComplexValue("tests.static_preference_wstring",
michael@0 121 Components.interfaces.nsIPrefLocalizedString);
michael@0 122 result.wstring_data = result.wstring.data;
michael@0 123 }
michael@0 124 catch (ignored) {};
michael@0 125 try
michael@0 126 {
michael@0 127 result.unichar = kPref.getComplexValue("tests.static_preference_unichar",
michael@0 128 Components.interfaces.nsISupportsString);
michael@0 129 result.unichar_data = result.unichar.data;
michael@0 130 }
michael@0 131 catch (ignored) {};
michael@0 132 try
michael@0 133 {
michael@0 134 result.file = kPref.getComplexValue("tests.static_preference_file",
michael@0 135 Components.interfaces.nsILocalFile);
michael@0 136 result.file_data = result.file.data;
michael@0 137 }
michael@0 138 catch (ignored) {};
michael@0 139 return result;
michael@0 140 }
michael@0 141
michael@0 142 function GetXULElement(aPrefWindow, aID)
michael@0 143 {
michael@0 144 return aPrefWindow.document.getElementById(aID);
michael@0 145 }
michael@0 146
michael@0 147 function WritePrefsToPreferences(aPrefWindow, aPrefValueSet)
michael@0 148 {
michael@0 149 // write preference data into <preference>s
michael@0 150 GetXULElement(aPrefWindow, "tests.static_preference_int" ).value = aPrefValueSet.int;
michael@0 151 GetXULElement(aPrefWindow, "tests.static_preference_bool" ).value = aPrefValueSet.bool;
michael@0 152 GetXULElement(aPrefWindow, "tests.static_preference_string" ).value = aPrefValueSet.string;
michael@0 153 GetXULElement(aPrefWindow, "tests.static_preference_wstring").value = aPrefValueSet.wstring_data;
michael@0 154 GetXULElement(aPrefWindow, "tests.static_preference_unichar").value = aPrefValueSet.unichar_data;
michael@0 155 GetXULElement(aPrefWindow, "tests.static_preference_file" ).value = aPrefValueSet.file_data;
michael@0 156 }
michael@0 157
michael@0 158 function ReadPrefsFromPreferences(aPrefWindow)
michael@0 159 {
michael@0 160 // read preference data from <preference>s
michael@0 161 var result =
michael@0 162 {
michael@0 163 int: GetXULElement(aPrefWindow, "tests.static_preference_int" ).value,
michael@0 164 bool: GetXULElement(aPrefWindow, "tests.static_preference_bool" ).value,
michael@0 165 string: GetXULElement(aPrefWindow, "tests.static_preference_string" ).value,
michael@0 166 wstring_data: GetXULElement(aPrefWindow, "tests.static_preference_wstring").value,
michael@0 167 unichar_data: GetXULElement(aPrefWindow, "tests.static_preference_unichar").value,
michael@0 168 file_data: GetXULElement(aPrefWindow, "tests.static_preference_file" ).value,
michael@0 169 wstring: Components.classes["@mozilla.org/pref-localizedstring;1"]
michael@0 170 .createInstance(Components.interfaces.nsIPrefLocalizedString),
michael@0 171 unichar: Components.classes["@mozilla.org/supports-string;1"]
michael@0 172 .createInstance(Components.interfaces.nsISupportsString),
michael@0 173 file: Components.classes["@mozilla.org/file/local;1"]
michael@0 174 .createInstance(Components.interfaces.nsILocalFile)
michael@0 175 }
michael@0 176 result.wstring.data = result.wstring_data;
michael@0 177 result.unichar.data = result.unichar_data;
michael@0 178 SafeFileInit(result.file, result.file_data);
michael@0 179 return result;
michael@0 180 }
michael@0 181
michael@0 182 function WritePrefsToUI(aPrefWindow, aPrefValueSet)
michael@0 183 {
michael@0 184 // write preference data into UI elements
michael@0 185 GetXULElement(aPrefWindow, "static_element_int" ).value = aPrefValueSet.int;
michael@0 186 GetXULElement(aPrefWindow, "static_element_bool" ).checked = aPrefValueSet.bool;
michael@0 187 GetXULElement(aPrefWindow, "static_element_string" ).value = aPrefValueSet.string;
michael@0 188 GetXULElement(aPrefWindow, "static_element_wstring").value = aPrefValueSet.wstring_data;
michael@0 189 GetXULElement(aPrefWindow, "static_element_unichar").value = aPrefValueSet.unichar_data;
michael@0 190 GetXULElement(aPrefWindow, "static_element_file" ).value = aPrefValueSet.file_data;
michael@0 191 }
michael@0 192
michael@0 193 function ReadPrefsFromUI(aPrefWindow)
michael@0 194 {
michael@0 195 // read preference data from <preference>s
michael@0 196 var result =
michael@0 197 {
michael@0 198 int: GetXULElement(aPrefWindow, "static_element_int" ).value,
michael@0 199 bool: GetXULElement(aPrefWindow, "static_element_bool" ).checked,
michael@0 200 string: GetXULElement(aPrefWindow, "static_element_string" ).value,
michael@0 201 wstring_data: GetXULElement(aPrefWindow, "static_element_wstring").value,
michael@0 202 unichar_data: GetXULElement(aPrefWindow, "static_element_unichar").value,
michael@0 203 file_data: GetXULElement(aPrefWindow, "static_element_file" ).value,
michael@0 204 wstring: Components.classes["@mozilla.org/pref-localizedstring;1"]
michael@0 205 .createInstance(Components.interfaces.nsIPrefLocalizedString),
michael@0 206 unichar: Components.classes["@mozilla.org/supports-string;1"]
michael@0 207 .createInstance(Components.interfaces.nsISupportsString),
michael@0 208 file: Components.classes["@mozilla.org/file/local;1"]
michael@0 209 .createInstance(Components.interfaces.nsILocalFile)
michael@0 210 }
michael@0 211 result.wstring.data = result.wstring_data;
michael@0 212 result.unichar.data = result.unichar_data;
michael@0 213 SafeFileInit(result.file, result.file_data);
michael@0 214 return result;
michael@0 215 }
michael@0 216
michael@0 217
michael@0 218 function RunInstantPrefTest(aPrefWindow)
michael@0 219 {
michael@0 220 // remark: there's currently no UI element binding for files
michael@0 221
michael@0 222 // were all <preferences> correctly initialized?
michael@0 223 var expected = kPrefValueSet1;
michael@0 224 var found = ReadPrefsFromPreferences(aPrefWindow);
michael@0 225 ok(found.int === expected.int, "instant pref init int" );
michael@0 226 ok(found.bool === expected.bool, "instant pref init bool" );
michael@0 227 ok(found.string === expected.string, "instant pref init string" );
michael@0 228 ok(found.wstring_data === expected.wstring_data, "instant pref init wstring");
michael@0 229 ok(found.unichar_data === expected.unichar_data, "instant pref init unichar");
michael@0 230 todo(found.file_data === expected.file_data, "instant pref init file" );
michael@0 231
michael@0 232 // were all elements correctly initialized? (loose check)
michael@0 233 found = ReadPrefsFromUI(aPrefWindow);
michael@0 234 ok(found.int == expected.int, "instant element init int" );
michael@0 235 ok(found.bool == expected.bool, "instant element init bool" );
michael@0 236 ok(found.string == expected.string, "instant element init string" );
michael@0 237 ok(found.wstring_data == expected.wstring_data, "instant element init wstring");
michael@0 238 ok(found.unichar_data == expected.unichar_data, "instant element init unichar");
michael@0 239 todo(found.file_data == expected.file_data, "instant element init file" );
michael@0 240
michael@0 241 // do some changes in the UI
michael@0 242 expected = kPrefValueSet2;
michael@0 243 WritePrefsToUI(aPrefWindow, expected);
michael@0 244
michael@0 245 // UI changes should get passed to the <preference>s,
michael@0 246 // but currently they aren't if the changes are made programmatically
michael@0 247 // (the handlers preference.change/prefpane.input and prefpane.change
michael@0 248 // are called for manual changes, though).
michael@0 249 found = ReadPrefsFromPreferences(aPrefWindow);
michael@0 250 todo(found.int === expected.int, "instant change pref int" );
michael@0 251 todo(found.bool === expected.bool, "instant change pref bool" );
michael@0 252 todo(found.string === expected.string, "instant change pref string" );
michael@0 253 todo(found.wstring_data === expected.wstring_data, "instant change pref wstring");
michael@0 254 todo(found.unichar_data === expected.unichar_data, "instant change pref unichar");
michael@0 255 todo(found.file_data === expected.file_data, "instant change pref file" );
michael@0 256
michael@0 257 // and these changes should get passed to the system instantly
michael@0 258 // (which obviously can't pass with the above failing)
michael@0 259 found = ReadPrefsFromSystem();
michael@0 260 todo(found.int === expected.int, "instant change element int" );
michael@0 261 todo(found.bool === expected.bool, "instant change element bool" );
michael@0 262 todo(found.string === expected.string, "instant change element string" );
michael@0 263 todo(found.wstring_data === expected.wstring_data, "instant change element wstring");
michael@0 264 todo(found.unichar_data === expected.unichar_data, "instant change element unichar");
michael@0 265 todo(found.file_data === expected.file_data, "instant change element file" );
michael@0 266
michael@0 267 // try resetting the prefs to default values (which should be empty here)
michael@0 268 GetXULElement(aPrefWindow, "tests.static_preference_int" ).reset();
michael@0 269 GetXULElement(aPrefWindow, "tests.static_preference_bool" ).reset();
michael@0 270 GetXULElement(aPrefWindow, "tests.static_preference_string" ).reset();
michael@0 271 GetXULElement(aPrefWindow, "tests.static_preference_wstring").reset();
michael@0 272 GetXULElement(aPrefWindow, "tests.static_preference_unichar").reset();
michael@0 273 GetXULElement(aPrefWindow, "tests.static_preference_file" ).reset();
michael@0 274
michael@0 275 // check system
michael@0 276 expected = CreateEmptyPrefValueSet();
michael@0 277 found = ReadPrefsFromSystem();
michael@0 278 ok(found.int === expected.int, "instant reset system int" );
michael@0 279 ok(found.bool === expected.bool, "instant reset system bool" );
michael@0 280 ok(found.string === expected.string, "instant reset system string" );
michael@0 281 ok(found.wstring_data === expected.wstring_data, "instant reset system wstring");
michael@0 282 ok(found.unichar_data === expected.unichar_data, "instant reset system unichar");
michael@0 283 ok(found.file_data === expected.file_data, "instant reset system file" );
michael@0 284
michael@0 285 // check UI
michael@0 286 expected =
michael@0 287 {
michael@0 288 // alas, we don't have XUL elements with typeof(value) == int :(
michael@0 289 // int: 0,
michael@0 290 int: "",
michael@0 291 bool: false,
michael@0 292 string: "",
michael@0 293 wstring_data: "",
michael@0 294 unichar_data: "",
michael@0 295 file_data: "",
michael@0 296 wstring: {},
michael@0 297 unichar: {},
michael@0 298 file: {}
michael@0 299 };
michael@0 300 found = ReadPrefsFromUI(aPrefWindow);
michael@0 301 ok(found.int === expected.int, "instant reset element int" );
michael@0 302 ok(found.bool === expected.bool, "instant reset element bool" );
michael@0 303 ok(found.string === expected.string, "instant reset element string" );
michael@0 304 ok(found.wstring_data === expected.wstring_data, "instant reset element wstring");
michael@0 305 ok(found.unichar_data === expected.unichar_data, "instant reset element unichar");
michael@0 306 // ok(found.file_data === expected.file_data, "instant reset element file" );
michael@0 307
michael@0 308 // check hasUserValue
michael@0 309 ok(GetXULElement(aPrefWindow, "tests.static_preference_int" ).hasUserValue === false, "instant reset hasUserValue int" );
michael@0 310 ok(GetXULElement(aPrefWindow, "tests.static_preference_bool" ).hasUserValue === false, "instant reset hasUserValue bool" );
michael@0 311 ok(GetXULElement(aPrefWindow, "tests.static_preference_string" ).hasUserValue === false, "instant reset hasUserValue string" );
michael@0 312 ok(GetXULElement(aPrefWindow, "tests.static_preference_wstring").hasUserValue === false, "instant reset hasUserValue wstring");
michael@0 313 ok(GetXULElement(aPrefWindow, "tests.static_preference_unichar").hasUserValue === false, "instant reset hasUserValue unichar");
michael@0 314 ok(GetXULElement(aPrefWindow, "tests.static_preference_file" ).hasUserValue === false, "instant reset hasUserValue file" );
michael@0 315
michael@0 316 // done with instant apply checks
michael@0 317 }
michael@0 318
michael@0 319 function RunNonInstantPrefTestGeneral(aPrefWindow)
michael@0 320 {
michael@0 321 // Non-instant apply tests are harder: not only do we need to check that
michael@0 322 // fiddling with the values does *not* change the system settings, but
michael@0 323 // also that they *are* (not) set after closing (cancelling) the dialog...
michael@0 324
michael@0 325 // remark: there's currently no UI element binding for files
michael@0 326
michael@0 327 // were all <preferences> correctly initialized?
michael@0 328 var expected = kPrefValueSet1;
michael@0 329 var found = ReadPrefsFromPreferences(aPrefWindow);
michael@0 330 ok(found.int === expected.int, "non-instant pref init int" );
michael@0 331 ok(found.bool === expected.bool, "non-instant pref init bool" );
michael@0 332 ok(found.string === expected.string, "non-instant pref init string" );
michael@0 333 ok(found.wstring_data === expected.wstring_data, "non-instant pref init wstring");
michael@0 334 ok(found.unichar_data === expected.unichar_data, "non-instant pref init unichar");
michael@0 335 todo(found.file_data === expected.file_data, "non-instant pref init file" );
michael@0 336
michael@0 337 // were all elements correctly initialized? (loose check)
michael@0 338 found = ReadPrefsFromUI(aPrefWindow);
michael@0 339 ok(found.int == expected.int, "non-instant element init int" );
michael@0 340 ok(found.bool == expected.bool, "non-instant element init bool" );
michael@0 341 ok(found.string == expected.string, "non-instant element init string" );
michael@0 342 ok(found.wstring_data == expected.wstring_data, "non-instant element init wstring");
michael@0 343 ok(found.unichar_data == expected.unichar_data, "non-instant element init unichar");
michael@0 344 todo(found.file_data == expected.file_data, "non-instant element init file" );
michael@0 345
michael@0 346 // do some changes in the UI
michael@0 347 expected = kPrefValueSet2;
michael@0 348 WritePrefsToUI(aPrefWindow, expected);
michael@0 349
michael@0 350 // UI changes should get passed to the <preference>s,
michael@0 351 // but currently they aren't if the changes are made programmatically
michael@0 352 // (the handlers preference.change/prefpane.input and prefpane.change
michael@0 353 // are called for manual changes, though).
michael@0 354 found = ReadPrefsFromPreferences(aPrefWindow);
michael@0 355 todo(found.int === expected.int, "non-instant change pref int" );
michael@0 356 todo(found.bool === expected.bool, "non-instant change pref bool" );
michael@0 357 todo(found.string === expected.string, "non-instant change pref string" );
michael@0 358 todo(found.wstring_data === expected.wstring_data, "non-instant change pref wstring");
michael@0 359 todo(found.unichar_data === expected.unichar_data, "non-instant change pref unichar");
michael@0 360 todo(found.file_data === expected.file_data, "non-instant change pref file" );
michael@0 361
michael@0 362 // and these changes should *NOT* get passed to the system
michael@0 363 // (which obviously always passes with the above failing)
michael@0 364 expected = kPrefValueSet1;
michael@0 365 found = ReadPrefsFromSystem();
michael@0 366 ok(found.int === expected.int, "non-instant change element int" );
michael@0 367 ok(found.bool === expected.bool, "non-instant change element bool" );
michael@0 368 ok(found.string === expected.string, "non-instant change element string" );
michael@0 369 ok(found.wstring_data === expected.wstring_data, "non-instant change element wstring");
michael@0 370 ok(found.unichar_data === expected.unichar_data, "non-instant change element unichar");
michael@0 371 todo(found.file_data === expected.file_data, "non-instant change element file" );
michael@0 372
michael@0 373 // try resetting the prefs to default values (which should be empty here)
michael@0 374 GetXULElement(aPrefWindow, "tests.static_preference_int" ).reset();
michael@0 375 GetXULElement(aPrefWindow, "tests.static_preference_bool" ).reset();
michael@0 376 GetXULElement(aPrefWindow, "tests.static_preference_string" ).reset();
michael@0 377 GetXULElement(aPrefWindow, "tests.static_preference_wstring").reset();
michael@0 378 GetXULElement(aPrefWindow, "tests.static_preference_unichar").reset();
michael@0 379 GetXULElement(aPrefWindow, "tests.static_preference_file" ).reset();
michael@0 380
michael@0 381 // check system: the current values *MUST NOT* change
michael@0 382 expected = kPrefValueSet1;
michael@0 383 found = ReadPrefsFromSystem();
michael@0 384 ok(found.int === expected.int, "non-instant reset system int" );
michael@0 385 ok(found.bool === expected.bool, "non-instant reset system bool" );
michael@0 386 ok(found.string === expected.string, "non-instant reset system string" );
michael@0 387 ok(found.wstring_data === expected.wstring_data, "non-instant reset system wstring");
michael@0 388 ok(found.unichar_data === expected.unichar_data, "non-instant reset system unichar");
michael@0 389 todo(found.file_data === expected.file_data, "non-instant reset system file" );
michael@0 390
michael@0 391 // check UI: these values should be reset
michael@0 392 expected =
michael@0 393 {
michael@0 394 // alas, we don't have XUL elements with typeof(value) == int :(
michael@0 395 // int: 0,
michael@0 396 int: "",
michael@0 397 bool: false,
michael@0 398 string: "",
michael@0 399 wstring_data: "",
michael@0 400 unichar_data: "",
michael@0 401 file_data: "",
michael@0 402 wstring: {},
michael@0 403 unichar: {},
michael@0 404 file: {}
michael@0 405 };
michael@0 406 found = ReadPrefsFromUI(aPrefWindow);
michael@0 407 ok(found.int === expected.int, "non-instant reset element int" );
michael@0 408 ok(found.bool === expected.bool, "non-instant reset element bool" );
michael@0 409 ok(found.string === expected.string, "non-instant reset element string" );
michael@0 410 ok(found.wstring_data === expected.wstring_data, "non-instant reset element wstring");
michael@0 411 ok(found.unichar_data === expected.unichar_data, "non-instant reset element unichar");
michael@0 412 // ok(found.file_data === expected.file_data, "non-instant reset element file" );
michael@0 413
michael@0 414 // check hasUserValue
michael@0 415 ok(GetXULElement(aPrefWindow, "tests.static_preference_int" ).hasUserValue === false, "non-instant reset hasUserValue int" );
michael@0 416 ok(GetXULElement(aPrefWindow, "tests.static_preference_bool" ).hasUserValue === false, "non-instant reset hasUserValue bool" );
michael@0 417 ok(GetXULElement(aPrefWindow, "tests.static_preference_string" ).hasUserValue === false, "non-instant reset hasUserValue string" );
michael@0 418 ok(GetXULElement(aPrefWindow, "tests.static_preference_wstring").hasUserValue === false, "non-instant reset hasUserValue wstring");
michael@0 419 ok(GetXULElement(aPrefWindow, "tests.static_preference_unichar").hasUserValue === false, "non-instant reset hasUserValue unichar");
michael@0 420 ok(GetXULElement(aPrefWindow, "tests.static_preference_file" ).hasUserValue === false, "non-instant reset hasUserValue file" );
michael@0 421 }
michael@0 422
michael@0 423 function RunNonInstantPrefTestClose(aPrefWindow)
michael@0 424 {
michael@0 425 WritePrefsToPreferences(aPrefWindow, kPrefValueSet2);
michael@0 426 }
michael@0 427
michael@0 428 function RunCheckCommandRedirect(aPrefWindow)
michael@0 429 {
michael@0 430 GetXULElement(aPrefWindow, "checkbox").click();
michael@0 431 ok(GetXULElement(aPrefWindow, "tests.static_preference_bool").value, "redirected command bool");
michael@0 432 GetXULElement(aPrefWindow, "checkbox").click();
michael@0 433 ok(!GetXULElement(aPrefWindow, "tests.static_preference_bool").value, "redirected command bool");
michael@0 434 }
michael@0 435
michael@0 436 function RunResetPrefTest(aPrefWindow)
michael@0 437 {
michael@0 438 // try resetting the prefs to default values
michael@0 439 GetXULElement(aPrefWindow, "tests.static_preference_int" ).reset();
michael@0 440 GetXULElement(aPrefWindow, "tests.static_preference_bool" ).reset();
michael@0 441 GetXULElement(aPrefWindow, "tests.static_preference_string" ).reset();
michael@0 442 GetXULElement(aPrefWindow, "tests.static_preference_wstring").reset();
michael@0 443 GetXULElement(aPrefWindow, "tests.static_preference_unichar").reset();
michael@0 444 GetXULElement(aPrefWindow, "tests.static_preference_file" ).reset();
michael@0 445 }
michael@0 446
michael@0 447 function InitTestPrefs(aInstantApply)
michael@0 448 {
michael@0 449 // set instant apply mode and init prefs to set 1
michael@0 450 kPref.setBoolPref("browser.preferences.instantApply", aInstantApply);
michael@0 451 WritePrefsToSystem(kPrefValueSet1);
michael@0 452 }
michael@0 453
michael@0 454 function RunTestInstant()
michael@0 455 {
michael@0 456 // test with instantApply
michael@0 457 InitTestPrefs(true);
michael@0 458 openDialog("window_preferences.xul", "", "modal", RunInstantPrefTest, false);
michael@0 459
michael@0 460 // - test deferred reset in child window
michael@0 461 InitTestPrefs(true);
michael@0 462 openDialog("window_preferences2.xul", "", "modal", RunResetPrefTest, false);
michael@0 463 expected = kPrefValueSet1;
michael@0 464 found = ReadPrefsFromSystem();
michael@0 465 ok(found.int === expected.int, "instant reset deferred int" );
michael@0 466 ok(found.bool === expected.bool, "instant reset deferred bool" );
michael@0 467 ok(found.string === expected.string, "instant reset deferred string" );
michael@0 468 ok(found.wstring_data === expected.wstring_data, "instant reset deferred wstring");
michael@0 469 ok(found.unichar_data === expected.unichar_data, "instant reset deferred unichar");
michael@0 470 todo(found.file_data === expected.file_data, "instant reset deferred file" );
michael@0 471 }
michael@0 472
michael@0 473 function RunTestNonInstant()
michael@0 474 {
michael@0 475 // test without instantApply
michael@0 476 // - general tests, similar to instant apply
michael@0 477 InitTestPrefs(false);
michael@0 478 openDialog("window_preferences.xul", "", "modal", RunNonInstantPrefTestGeneral, false);
michael@0 479
michael@0 480 // - test Cancel
michael@0 481 InitTestPrefs(false);
michael@0 482 openDialog("window_preferences.xul", "", "modal", RunNonInstantPrefTestClose, false);
michael@0 483 var expected = kPrefValueSet1;
michael@0 484 var found = ReadPrefsFromSystem();
michael@0 485 ok(found.int === expected.int, "non-instant cancel system int" );
michael@0 486 ok(found.bool === expected.bool, "non-instant cancel system bool" );
michael@0 487 ok(found.string === expected.string, "non-instant cancel system string" );
michael@0 488 ok(found.wstring_data === expected.wstring_data, "non-instant cancel system wstring");
michael@0 489 ok(found.unichar_data === expected.unichar_data, "non-instant cancel system unichar");
michael@0 490 todo(found.file_data === expected.file_data, "non-instant cancel system file" );
michael@0 491
michael@0 492 // - test Accept
michael@0 493 InitTestPrefs(false);
michael@0 494 openDialog("window_preferences.xul", "", "modal", RunNonInstantPrefTestClose, true);
michael@0 495 expected = kPrefValueSet2;
michael@0 496 found = ReadPrefsFromSystem();
michael@0 497 ok(found.int === expected.int, "non-instant accept system int" );
michael@0 498 ok(found.bool === expected.bool, "non-instant accept system bool" );
michael@0 499 ok(found.string === expected.string, "non-instant accept system string" );
michael@0 500 ok(found.wstring_data === expected.wstring_data, "non-instant accept system wstring");
michael@0 501 ok(found.unichar_data === expected.unichar_data, "non-instant accept system unichar");
michael@0 502 todo(found.file_data === expected.file_data, "non-instant accept system file" );
michael@0 503
michael@0 504 // - test deferred reset in child window
michael@0 505 InitTestPrefs(false);
michael@0 506 openDialog("window_preferences2.xul", "", "modal", RunResetPrefTest, true);
michael@0 507 expected = CreateEmptyPrefValueSet();
michael@0 508 found = ReadPrefsFromSystem();
michael@0 509 ok(found.int === expected.int, "non-instant reset deferred int" );
michael@0 510 ok(found.bool === expected.bool, "non-instant reset deferred bool" );
michael@0 511 ok(found.string === expected.string, "non-instant reset deferred string" );
michael@0 512 ok(found.wstring_data === expected.wstring_data, "non-instant reset deferred wstring");
michael@0 513 ok(found.unichar_data === expected.unichar_data, "non-instant reset deferred unichar");
michael@0 514 ok(found.file_data === expected.file_data, "non-instant reset deferred file" );
michael@0 515 }
michael@0 516
michael@0 517 function RunTestCommandRedirect()
michael@0 518 {
michael@0 519 openDialog("window_preferences_commandretarget.xul", "", "modal", RunCheckCommandRedirect, true);
michael@0 520 }
michael@0 521
michael@0 522 function RunTest()
michael@0 523 {
michael@0 524 RunTestInstant();
michael@0 525 RunTestNonInstant();
michael@0 526 RunTestCommandRedirect();
michael@0 527 SimpleTest.finish();
michael@0 528 }
michael@0 529 ]]>
michael@0 530 </script>
michael@0 531
michael@0 532 <body xmlns="http://www.w3.org/1999/xhtml">
michael@0 533 <p id="display"></p>
michael@0 534 <div id="content" style="display: none"></div>
michael@0 535 <pre id="test"></pre>
michael@0 536 </body>
michael@0 537
michael@0 538 </window>

mercurial