toolkit/content/tests/chrome/test_preferences.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/content/tests/chrome/test_preferences.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,538 @@
     1.4 +<?xml version="1.0"?>
     1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     1.6 +<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
     1.7 +
     1.8 +<window title="Preferences Window Tests"
     1.9 +        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
    1.10 +        onload="RunTest();">
    1.11 +
    1.12 +  <script type="application/javascript"
    1.13 +          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
    1.14 +
    1.15 +  <script type="application/javascript">
    1.16 +  <![CDATA[
    1.17 +    if (navigator.platform.startsWith("Mac")) {
    1.18 +      SimpleTest.expectAssertions(4);
    1.19 +    } else {
    1.20 +      SimpleTest.expectAssertions(0,1);
    1.21 +    }
    1.22 +    SimpleTest.waitForExplicitFinish();
    1.23 +
    1.24 +    const kPref = Components.classes["@mozilla.org/preferences-service;1"]
    1.25 +                            .getService(Components.interfaces.nsIPrefBranch);
    1.26 +
    1.27 +    // preference values, set 1
    1.28 +    const kPrefValueSet1 =
    1.29 +    {
    1.30 +        int:          23,
    1.31 +        bool:         true,
    1.32 +        string:       "rheeet!",
    1.33 +        wstring_data: "日本語",
    1.34 +        unichar_data: "äöüßÄÖÜ",
    1.35 +        file_data:    "/",
    1.36 +
    1.37 +        wstring: Components.classes["@mozilla.org/pref-localizedstring;1"]
    1.38 +                           .createInstance(Components.interfaces.nsIPrefLocalizedString),
    1.39 +        unichar: Components.classes["@mozilla.org/supports-string;1"]
    1.40 +                           .createInstance(Components.interfaces.nsISupportsString),
    1.41 +        file:    Components.classes["@mozilla.org/file/local;1"]
    1.42 +                           .createInstance(Components.interfaces.nsILocalFile)
    1.43 +    };
    1.44 +    kPrefValueSet1.wstring.data = kPrefValueSet1.wstring_data;
    1.45 +    kPrefValueSet1.unichar.data = kPrefValueSet1.unichar_data;
    1.46 +    SafeFileInit(kPrefValueSet1.file, kPrefValueSet1.file_data);
    1.47 +
    1.48 +    // preference values, set 2
    1.49 +    const kPrefValueSet2 =
    1.50 +    {
    1.51 +        int:          42,
    1.52 +        bool:         false,
    1.53 +        string:       "Mozilla",
    1.54 +        wstring_data: "헤드라인A",
    1.55 +        unichar_data: "áôùšŽ",
    1.56 +        file_data:    "/home",
    1.57 +
    1.58 +        wstring: Components.classes["@mozilla.org/pref-localizedstring;1"]
    1.59 +                           .createInstance(Components.interfaces.nsIPrefLocalizedString),
    1.60 +        unichar: Components.classes["@mozilla.org/supports-string;1"]
    1.61 +                           .createInstance(Components.interfaces.nsISupportsString),
    1.62 +        file:    Components.classes["@mozilla.org/file/local;1"]
    1.63 +                           .createInstance(Components.interfaces.nsILocalFile)
    1.64 +    };
    1.65 +    kPrefValueSet2.wstring.data = kPrefValueSet2.wstring_data;
    1.66 +    kPrefValueSet2.unichar.data = kPrefValueSet2.unichar_data;
    1.67 +    SafeFileInit(kPrefValueSet2.file, kPrefValueSet2.file_data);
    1.68 +
    1.69 +
    1.70 +    function SafeFileInit(aFile, aPath)
    1.71 +    {
    1.72 +      // set file path without dying for exceptions
    1.73 +      try
    1.74 +      {
    1.75 +        aFile.initWithPath(aPath);
    1.76 +      }
    1.77 +      catch (ignored) {}
    1.78 +    }
    1.79 +
    1.80 +    function CreateEmptyPrefValueSet()
    1.81 +    {
    1.82 +      var result =
    1.83 +      {
    1.84 +        int:          undefined,
    1.85 +        bool:         undefined,
    1.86 +        string:       undefined,
    1.87 +        wstring_data: undefined,
    1.88 +        unichar_data: undefined,
    1.89 +        file_data:    undefined,
    1.90 +        wstring:      undefined,
    1.91 +        unichar:      undefined,
    1.92 +        file:         undefined
    1.93 +      };
    1.94 +      return result;
    1.95 +    }
    1.96 +
    1.97 +    function WritePrefsToSystem(aPrefValueSet)
    1.98 +    {
    1.99 +      // write preference data via XPCOM
   1.100 +      kPref.setIntPref ("tests.static_preference_int",    aPrefValueSet.int);
   1.101 +      kPref.setBoolPref("tests.static_preference_bool",   aPrefValueSet.bool);
   1.102 +      kPref.setCharPref("tests.static_preference_string", aPrefValueSet.string);
   1.103 +      kPref.setComplexValue("tests.static_preference_wstring",
   1.104 +                            Components.interfaces.nsIPrefLocalizedString,
   1.105 +                            aPrefValueSet.wstring);
   1.106 +      kPref.setComplexValue("tests.static_preference_unichar",
   1.107 +                            Components.interfaces.nsISupportsString,
   1.108 +                            aPrefValueSet.unichar);
   1.109 +      kPref.setComplexValue("tests.static_preference_file",
   1.110 +                            Components.interfaces.nsILocalFile,
   1.111 +                            aPrefValueSet.file);
   1.112 +    }
   1.113 +
   1.114 +    function ReadPrefsFromSystem()
   1.115 +    {
   1.116 +      // read preference data via XPCOM
   1.117 +      var result = CreateEmptyPrefValueSet();
   1.118 +      try {result.int    = kPref.getIntPref ("tests.static_preference_int")   } catch (ignored) {};
   1.119 +      try {result.bool   = kPref.getBoolPref("tests.static_preference_bool")  } catch (ignored) {};
   1.120 +      try {result.string = kPref.getCharPref("tests.static_preference_string")} catch (ignored) {};
   1.121 +      try
   1.122 +      {
   1.123 +        result.wstring = kPref.getComplexValue("tests.static_preference_wstring",
   1.124 +                                               Components.interfaces.nsIPrefLocalizedString);
   1.125 +        result.wstring_data = result.wstring.data;
   1.126 +      }
   1.127 +      catch (ignored) {};
   1.128 +      try
   1.129 +      {
   1.130 +        result.unichar = kPref.getComplexValue("tests.static_preference_unichar",
   1.131 +                                               Components.interfaces.nsISupportsString);
   1.132 +        result.unichar_data = result.unichar.data;
   1.133 +      }
   1.134 +      catch (ignored) {};
   1.135 +      try
   1.136 +      {
   1.137 +        result.file = kPref.getComplexValue("tests.static_preference_file",
   1.138 +                                            Components.interfaces.nsILocalFile);
   1.139 +        result.file_data    = result.file.data;
   1.140 +      }
   1.141 +      catch (ignored) {};
   1.142 +      return result;
   1.143 +    }
   1.144 +
   1.145 +    function GetXULElement(aPrefWindow, aID)
   1.146 +    {
   1.147 +      return aPrefWindow.document.getElementById(aID);
   1.148 +    }
   1.149 +
   1.150 +    function WritePrefsToPreferences(aPrefWindow, aPrefValueSet)
   1.151 +    {
   1.152 +      // write preference data into <preference>s
   1.153 +      GetXULElement(aPrefWindow, "tests.static_preference_int"    ).value = aPrefValueSet.int;
   1.154 +      GetXULElement(aPrefWindow, "tests.static_preference_bool"   ).value = aPrefValueSet.bool;
   1.155 +      GetXULElement(aPrefWindow, "tests.static_preference_string" ).value = aPrefValueSet.string;
   1.156 +      GetXULElement(aPrefWindow, "tests.static_preference_wstring").value = aPrefValueSet.wstring_data;
   1.157 +      GetXULElement(aPrefWindow, "tests.static_preference_unichar").value = aPrefValueSet.unichar_data;
   1.158 +      GetXULElement(aPrefWindow, "tests.static_preference_file"   ).value = aPrefValueSet.file_data;
   1.159 +    }
   1.160 +
   1.161 +    function ReadPrefsFromPreferences(aPrefWindow)
   1.162 +    {
   1.163 +      // read preference data from <preference>s
   1.164 +      var result =
   1.165 +      {
   1.166 +        int:          GetXULElement(aPrefWindow, "tests.static_preference_int"    ).value,
   1.167 +        bool:         GetXULElement(aPrefWindow, "tests.static_preference_bool"   ).value,
   1.168 +        string:       GetXULElement(aPrefWindow, "tests.static_preference_string" ).value,
   1.169 +        wstring_data: GetXULElement(aPrefWindow, "tests.static_preference_wstring").value,
   1.170 +        unichar_data: GetXULElement(aPrefWindow, "tests.static_preference_unichar").value,
   1.171 +        file_data:    GetXULElement(aPrefWindow, "tests.static_preference_file"   ).value,
   1.172 +        wstring: Components.classes["@mozilla.org/pref-localizedstring;1"]
   1.173 +                           .createInstance(Components.interfaces.nsIPrefLocalizedString),
   1.174 +        unichar: Components.classes["@mozilla.org/supports-string;1"]
   1.175 +                           .createInstance(Components.interfaces.nsISupportsString),
   1.176 +        file:    Components.classes["@mozilla.org/file/local;1"]
   1.177 +                           .createInstance(Components.interfaces.nsILocalFile)
   1.178 +      }
   1.179 +      result.wstring.data = result.wstring_data;
   1.180 +      result.unichar.data = result.unichar_data;
   1.181 +      SafeFileInit(result.file, result.file_data);
   1.182 +      return result;
   1.183 +    }
   1.184 +
   1.185 +    function WritePrefsToUI(aPrefWindow, aPrefValueSet)
   1.186 +    {
   1.187 +      // write preference data into UI elements
   1.188 +      GetXULElement(aPrefWindow, "static_element_int"    ).value   = aPrefValueSet.int;
   1.189 +      GetXULElement(aPrefWindow, "static_element_bool"   ).checked = aPrefValueSet.bool;
   1.190 +      GetXULElement(aPrefWindow, "static_element_string" ).value   = aPrefValueSet.string;
   1.191 +      GetXULElement(aPrefWindow, "static_element_wstring").value   = aPrefValueSet.wstring_data;
   1.192 +      GetXULElement(aPrefWindow, "static_element_unichar").value   = aPrefValueSet.unichar_data;
   1.193 +      GetXULElement(aPrefWindow, "static_element_file"   ).value   = aPrefValueSet.file_data;
   1.194 +    }
   1.195 +
   1.196 +    function ReadPrefsFromUI(aPrefWindow)
   1.197 +    {
   1.198 +      // read preference data from <preference>s
   1.199 +      var result =
   1.200 +      {
   1.201 +        int:          GetXULElement(aPrefWindow, "static_element_int"    ).value,
   1.202 +        bool:         GetXULElement(aPrefWindow, "static_element_bool"   ).checked,
   1.203 +        string:       GetXULElement(aPrefWindow, "static_element_string" ).value,
   1.204 +        wstring_data: GetXULElement(aPrefWindow, "static_element_wstring").value,
   1.205 +        unichar_data: GetXULElement(aPrefWindow, "static_element_unichar").value,
   1.206 +        file_data:    GetXULElement(aPrefWindow, "static_element_file"   ).value,
   1.207 +        wstring: Components.classes["@mozilla.org/pref-localizedstring;1"]
   1.208 +                           .createInstance(Components.interfaces.nsIPrefLocalizedString),
   1.209 +        unichar: Components.classes["@mozilla.org/supports-string;1"]
   1.210 +                           .createInstance(Components.interfaces.nsISupportsString),
   1.211 +        file:    Components.classes["@mozilla.org/file/local;1"]
   1.212 +                           .createInstance(Components.interfaces.nsILocalFile)
   1.213 +      }
   1.214 +      result.wstring.data = result.wstring_data;
   1.215 +      result.unichar.data = result.unichar_data;
   1.216 +      SafeFileInit(result.file, result.file_data);
   1.217 +      return result;
   1.218 +    }
   1.219 +
   1.220 +
   1.221 +    function RunInstantPrefTest(aPrefWindow)
   1.222 +    {
   1.223 +      // remark: there's currently no UI element binding for files
   1.224 +
   1.225 +      // were all <preferences> correctly initialized?
   1.226 +      var expected = kPrefValueSet1;
   1.227 +      var found    = ReadPrefsFromPreferences(aPrefWindow);
   1.228 +      ok(found.int          === expected.int,          "instant pref init int"    );
   1.229 +      ok(found.bool         === expected.bool,         "instant pref init bool"   );
   1.230 +      ok(found.string       === expected.string,       "instant pref init string" );
   1.231 +      ok(found.wstring_data === expected.wstring_data, "instant pref init wstring");
   1.232 +      ok(found.unichar_data === expected.unichar_data, "instant pref init unichar");
   1.233 +      todo(found.file_data  === expected.file_data,    "instant pref init file"   );
   1.234 +
   1.235 +      // were all elements correctly initialized? (loose check)
   1.236 +      found = ReadPrefsFromUI(aPrefWindow);
   1.237 +      ok(found.int          == expected.int,          "instant element init int"    );
   1.238 +      ok(found.bool         == expected.bool,         "instant element init bool"   );
   1.239 +      ok(found.string       == expected.string,       "instant element init string" );
   1.240 +      ok(found.wstring_data == expected.wstring_data, "instant element init wstring");
   1.241 +      ok(found.unichar_data == expected.unichar_data, "instant element init unichar");
   1.242 +      todo(found.file_data  == expected.file_data,    "instant element init file"   );
   1.243 +
   1.244 +      // do some changes in the UI
   1.245 +      expected = kPrefValueSet2;
   1.246 +      WritePrefsToUI(aPrefWindow, expected);
   1.247 +
   1.248 +      // UI changes should get passed to the <preference>s,
   1.249 +      // but currently they aren't if the changes are made programmatically
   1.250 +      // (the handlers preference.change/prefpane.input and prefpane.change
   1.251 +      //  are called for manual changes, though).
   1.252 +      found = ReadPrefsFromPreferences(aPrefWindow);
   1.253 +      todo(found.int          === expected.int,          "instant change pref int"    );
   1.254 +      todo(found.bool         === expected.bool,         "instant change pref bool"   );
   1.255 +      todo(found.string       === expected.string,       "instant change pref string" );
   1.256 +      todo(found.wstring_data === expected.wstring_data, "instant change pref wstring");
   1.257 +      todo(found.unichar_data === expected.unichar_data, "instant change pref unichar");
   1.258 +      todo(found.file_data    === expected.file_data,    "instant change pref file"   );
   1.259 +
   1.260 +      // and these changes should get passed to the system instantly
   1.261 +      // (which obviously can't pass with the above failing)
   1.262 +      found = ReadPrefsFromSystem();
   1.263 +      todo(found.int          === expected.int,          "instant change element int"    );
   1.264 +      todo(found.bool         === expected.bool,         "instant change element bool"   );
   1.265 +      todo(found.string       === expected.string,       "instant change element string" );
   1.266 +      todo(found.wstring_data === expected.wstring_data, "instant change element wstring");
   1.267 +      todo(found.unichar_data === expected.unichar_data, "instant change element unichar");
   1.268 +      todo(found.file_data    === expected.file_data,    "instant change element file"   );
   1.269 +
   1.270 +      // try resetting the prefs to default values (which should be empty here)
   1.271 +      GetXULElement(aPrefWindow, "tests.static_preference_int"    ).reset();
   1.272 +      GetXULElement(aPrefWindow, "tests.static_preference_bool"   ).reset();
   1.273 +      GetXULElement(aPrefWindow, "tests.static_preference_string" ).reset();
   1.274 +      GetXULElement(aPrefWindow, "tests.static_preference_wstring").reset();
   1.275 +      GetXULElement(aPrefWindow, "tests.static_preference_unichar").reset();
   1.276 +      GetXULElement(aPrefWindow, "tests.static_preference_file"   ).reset();
   1.277 +
   1.278 +      // check system
   1.279 +      expected = CreateEmptyPrefValueSet();
   1.280 +      found    = ReadPrefsFromSystem();
   1.281 +      ok(found.int          === expected.int,          "instant reset system int"    );
   1.282 +      ok(found.bool         === expected.bool,         "instant reset system bool"   );
   1.283 +      ok(found.string       === expected.string,       "instant reset system string" );
   1.284 +      ok(found.wstring_data === expected.wstring_data, "instant reset system wstring");
   1.285 +      ok(found.unichar_data === expected.unichar_data, "instant reset system unichar");
   1.286 +      ok(found.file_data    === expected.file_data,    "instant reset system file"   );
   1.287 +
   1.288 +      // check UI
   1.289 +      expected =
   1.290 +      {
   1.291 +        // alas, we don't have XUL elements with typeof(value) == int :(
   1.292 +        // int:         0,
   1.293 +        int:          "",
   1.294 +        bool:         false,
   1.295 +        string:       "",
   1.296 +        wstring_data: "",
   1.297 +        unichar_data: "",
   1.298 +        file_data:    "",
   1.299 +        wstring:      {},
   1.300 +        unichar:      {},
   1.301 +        file:         {}
   1.302 +      };
   1.303 +      found = ReadPrefsFromUI(aPrefWindow);
   1.304 +      ok(found.int          === expected.int,          "instant reset element int"    );
   1.305 +      ok(found.bool         === expected.bool,         "instant reset element bool"   );
   1.306 +      ok(found.string       === expected.string,       "instant reset element string" );
   1.307 +      ok(found.wstring_data === expected.wstring_data, "instant reset element wstring");
   1.308 +      ok(found.unichar_data === expected.unichar_data, "instant reset element unichar");
   1.309 +//      ok(found.file_data    === expected.file_data,    "instant reset element file"   );
   1.310 +
   1.311 +      // check hasUserValue
   1.312 +      ok(GetXULElement(aPrefWindow, "tests.static_preference_int"    ).hasUserValue === false, "instant reset hasUserValue int"    );
   1.313 +      ok(GetXULElement(aPrefWindow, "tests.static_preference_bool"   ).hasUserValue === false, "instant reset hasUserValue bool"   );
   1.314 +      ok(GetXULElement(aPrefWindow, "tests.static_preference_string" ).hasUserValue === false, "instant reset hasUserValue string" );
   1.315 +      ok(GetXULElement(aPrefWindow, "tests.static_preference_wstring").hasUserValue === false, "instant reset hasUserValue wstring");
   1.316 +      ok(GetXULElement(aPrefWindow, "tests.static_preference_unichar").hasUserValue === false, "instant reset hasUserValue unichar");
   1.317 +      ok(GetXULElement(aPrefWindow, "tests.static_preference_file"   ).hasUserValue === false, "instant reset hasUserValue file"   );
   1.318 +
   1.319 +      // done with instant apply checks
   1.320 +    }
   1.321 +
   1.322 +    function RunNonInstantPrefTestGeneral(aPrefWindow)
   1.323 +    {
   1.324 +      // Non-instant apply tests are harder: not only do we need to check that
   1.325 +      // fiddling with the values does *not* change the system settings, but
   1.326 +      // also that they *are* (not) set after closing (cancelling) the dialog...
   1.327 +
   1.328 +      // remark: there's currently no UI element binding for files
   1.329 +
   1.330 +      // were all <preferences> correctly initialized?
   1.331 +      var expected = kPrefValueSet1;
   1.332 +      var found    = ReadPrefsFromPreferences(aPrefWindow);
   1.333 +      ok(found.int          === expected.int,          "non-instant pref init int"    );
   1.334 +      ok(found.bool         === expected.bool,         "non-instant pref init bool"   );
   1.335 +      ok(found.string       === expected.string,       "non-instant pref init string" );
   1.336 +      ok(found.wstring_data === expected.wstring_data, "non-instant pref init wstring");
   1.337 +      ok(found.unichar_data === expected.unichar_data, "non-instant pref init unichar");
   1.338 +      todo(found.file_data  === expected.file_data,    "non-instant pref init file"   );
   1.339 +
   1.340 +      // were all elements correctly initialized? (loose check)
   1.341 +      found = ReadPrefsFromUI(aPrefWindow);
   1.342 +      ok(found.int          == expected.int,          "non-instant element init int"    );
   1.343 +      ok(found.bool         == expected.bool,         "non-instant element init bool"   );
   1.344 +      ok(found.string       == expected.string,       "non-instant element init string" );
   1.345 +      ok(found.wstring_data == expected.wstring_data, "non-instant element init wstring");
   1.346 +      ok(found.unichar_data == expected.unichar_data, "non-instant element init unichar");
   1.347 +      todo(found.file_data  == expected.file_data,    "non-instant element init file"   );
   1.348 +
   1.349 +      // do some changes in the UI
   1.350 +      expected = kPrefValueSet2;
   1.351 +      WritePrefsToUI(aPrefWindow, expected);
   1.352 +
   1.353 +      // UI changes should get passed to the <preference>s,
   1.354 +      // but currently they aren't if the changes are made programmatically
   1.355 +      // (the handlers preference.change/prefpane.input and prefpane.change
   1.356 +      //  are called for manual changes, though).
   1.357 +      found = ReadPrefsFromPreferences(aPrefWindow);
   1.358 +      todo(found.int          === expected.int,          "non-instant change pref int"    );
   1.359 +      todo(found.bool         === expected.bool,         "non-instant change pref bool"   );
   1.360 +      todo(found.string       === expected.string,       "non-instant change pref string" );
   1.361 +      todo(found.wstring_data === expected.wstring_data, "non-instant change pref wstring");
   1.362 +      todo(found.unichar_data === expected.unichar_data, "non-instant change pref unichar");
   1.363 +      todo(found.file_data    === expected.file_data,    "non-instant change pref file"   );
   1.364 +
   1.365 +      // and these changes should *NOT* get passed to the system
   1.366 +      // (which obviously always passes with the above failing)
   1.367 +      expected = kPrefValueSet1;
   1.368 +      found    = ReadPrefsFromSystem();
   1.369 +      ok(found.int          === expected.int,          "non-instant change element int"    );
   1.370 +      ok(found.bool         === expected.bool,         "non-instant change element bool"   );
   1.371 +      ok(found.string       === expected.string,       "non-instant change element string" );
   1.372 +      ok(found.wstring_data === expected.wstring_data, "non-instant change element wstring");
   1.373 +      ok(found.unichar_data === expected.unichar_data, "non-instant change element unichar");
   1.374 +      todo(found.file_data  === expected.file_data,    "non-instant change element file"   );
   1.375 +
   1.376 +      // try resetting the prefs to default values (which should be empty here)
   1.377 +      GetXULElement(aPrefWindow, "tests.static_preference_int"    ).reset();
   1.378 +      GetXULElement(aPrefWindow, "tests.static_preference_bool"   ).reset();
   1.379 +      GetXULElement(aPrefWindow, "tests.static_preference_string" ).reset();
   1.380 +      GetXULElement(aPrefWindow, "tests.static_preference_wstring").reset();
   1.381 +      GetXULElement(aPrefWindow, "tests.static_preference_unichar").reset();
   1.382 +      GetXULElement(aPrefWindow, "tests.static_preference_file"   ).reset();
   1.383 +
   1.384 +      // check system: the current values *MUST NOT* change
   1.385 +      expected = kPrefValueSet1;
   1.386 +      found    = ReadPrefsFromSystem();
   1.387 +      ok(found.int          === expected.int,          "non-instant reset system int"    );
   1.388 +      ok(found.bool         === expected.bool,         "non-instant reset system bool"   );
   1.389 +      ok(found.string       === expected.string,       "non-instant reset system string" );
   1.390 +      ok(found.wstring_data === expected.wstring_data, "non-instant reset system wstring");
   1.391 +      ok(found.unichar_data === expected.unichar_data, "non-instant reset system unichar");
   1.392 +      todo(found.file_data  === expected.file_data,    "non-instant reset system file"   );
   1.393 +
   1.394 +      // check UI: these values should be reset
   1.395 +      expected =
   1.396 +      {
   1.397 +        // alas, we don't have XUL elements with typeof(value) == int :(
   1.398 +        // int:         0,
   1.399 +        int:          "",
   1.400 +        bool:         false,
   1.401 +        string:       "",
   1.402 +        wstring_data: "",
   1.403 +        unichar_data: "",
   1.404 +        file_data:    "",
   1.405 +        wstring:      {},
   1.406 +        unichar:      {},
   1.407 +        file:         {}
   1.408 +      };
   1.409 +      found = ReadPrefsFromUI(aPrefWindow);
   1.410 +      ok(found.int          === expected.int,          "non-instant reset element int"    );
   1.411 +      ok(found.bool         === expected.bool,         "non-instant reset element bool"   );
   1.412 +      ok(found.string       === expected.string,       "non-instant reset element string" );
   1.413 +      ok(found.wstring_data === expected.wstring_data, "non-instant reset element wstring");
   1.414 +      ok(found.unichar_data === expected.unichar_data, "non-instant reset element unichar");
   1.415 +//      ok(found.file_data    === expected.file_data,    "non-instant reset element file"   );
   1.416 +
   1.417 +      // check hasUserValue
   1.418 +      ok(GetXULElement(aPrefWindow, "tests.static_preference_int"    ).hasUserValue === false, "non-instant reset hasUserValue int"    );
   1.419 +      ok(GetXULElement(aPrefWindow, "tests.static_preference_bool"   ).hasUserValue === false, "non-instant reset hasUserValue bool"   );
   1.420 +      ok(GetXULElement(aPrefWindow, "tests.static_preference_string" ).hasUserValue === false, "non-instant reset hasUserValue string" );
   1.421 +      ok(GetXULElement(aPrefWindow, "tests.static_preference_wstring").hasUserValue === false, "non-instant reset hasUserValue wstring");
   1.422 +      ok(GetXULElement(aPrefWindow, "tests.static_preference_unichar").hasUserValue === false, "non-instant reset hasUserValue unichar");
   1.423 +      ok(GetXULElement(aPrefWindow, "tests.static_preference_file"   ).hasUserValue === false, "non-instant reset hasUserValue file"   );
   1.424 +    }
   1.425 +
   1.426 +    function RunNonInstantPrefTestClose(aPrefWindow)
   1.427 +    {
   1.428 +      WritePrefsToPreferences(aPrefWindow, kPrefValueSet2);
   1.429 +    }
   1.430 +
   1.431 +    function RunCheckCommandRedirect(aPrefWindow)
   1.432 +    {
   1.433 +      GetXULElement(aPrefWindow, "checkbox").click();
   1.434 +      ok(GetXULElement(aPrefWindow, "tests.static_preference_bool").value, "redirected command bool");
   1.435 +      GetXULElement(aPrefWindow, "checkbox").click();
   1.436 +      ok(!GetXULElement(aPrefWindow, "tests.static_preference_bool").value, "redirected command bool");
   1.437 +    }
   1.438 +
   1.439 +    function RunResetPrefTest(aPrefWindow)
   1.440 +    {
   1.441 +      // try resetting the prefs to default values
   1.442 +      GetXULElement(aPrefWindow, "tests.static_preference_int"    ).reset();
   1.443 +      GetXULElement(aPrefWindow, "tests.static_preference_bool"   ).reset();
   1.444 +      GetXULElement(aPrefWindow, "tests.static_preference_string" ).reset();
   1.445 +      GetXULElement(aPrefWindow, "tests.static_preference_wstring").reset();
   1.446 +      GetXULElement(aPrefWindow, "tests.static_preference_unichar").reset();
   1.447 +      GetXULElement(aPrefWindow, "tests.static_preference_file"   ).reset();
   1.448 +    }
   1.449 +
   1.450 +    function InitTestPrefs(aInstantApply)
   1.451 +    {
   1.452 +      // set instant apply mode and init prefs to set 1
   1.453 +      kPref.setBoolPref("browser.preferences.instantApply", aInstantApply);
   1.454 +      WritePrefsToSystem(kPrefValueSet1);
   1.455 +    }
   1.456 +
   1.457 +    function RunTestInstant()
   1.458 +    {
   1.459 +      // test with instantApply
   1.460 +      InitTestPrefs(true);
   1.461 +      openDialog("window_preferences.xul", "", "modal", RunInstantPrefTest, false);
   1.462 +
   1.463 +      // - test deferred reset in child window
   1.464 +      InitTestPrefs(true);
   1.465 +      openDialog("window_preferences2.xul", "", "modal", RunResetPrefTest, false);
   1.466 +      expected = kPrefValueSet1;
   1.467 +      found    = ReadPrefsFromSystem();
   1.468 +      ok(found.int          === expected.int,          "instant reset deferred int"    );
   1.469 +      ok(found.bool         === expected.bool,         "instant reset deferred bool"   );
   1.470 +      ok(found.string       === expected.string,       "instant reset deferred string" );
   1.471 +      ok(found.wstring_data === expected.wstring_data, "instant reset deferred wstring");
   1.472 +      ok(found.unichar_data === expected.unichar_data, "instant reset deferred unichar");
   1.473 +      todo(found.file_data  === expected.file_data,    "instant reset deferred file"   );
   1.474 +    }
   1.475 +
   1.476 +    function RunTestNonInstant()
   1.477 +    {
   1.478 +      // test without instantApply
   1.479 +      // - general tests, similar to instant apply
   1.480 +      InitTestPrefs(false);
   1.481 +      openDialog("window_preferences.xul", "", "modal", RunNonInstantPrefTestGeneral, false);
   1.482 +
   1.483 +      // - test Cancel
   1.484 +      InitTestPrefs(false);
   1.485 +      openDialog("window_preferences.xul", "", "modal", RunNonInstantPrefTestClose, false);
   1.486 +      var expected = kPrefValueSet1;
   1.487 +      var found    = ReadPrefsFromSystem();
   1.488 +      ok(found.int          === expected.int,          "non-instant cancel system int"    );
   1.489 +      ok(found.bool         === expected.bool,         "non-instant cancel system bool"   );
   1.490 +      ok(found.string       === expected.string,       "non-instant cancel system string" );
   1.491 +      ok(found.wstring_data === expected.wstring_data, "non-instant cancel system wstring");
   1.492 +      ok(found.unichar_data === expected.unichar_data, "non-instant cancel system unichar");
   1.493 +      todo(found.file_data  === expected.file_data,    "non-instant cancel system file"   );
   1.494 +      
   1.495 +      // - test Accept
   1.496 +      InitTestPrefs(false);
   1.497 +      openDialog("window_preferences.xul", "", "modal", RunNonInstantPrefTestClose, true);
   1.498 +      expected = kPrefValueSet2;
   1.499 +      found    = ReadPrefsFromSystem();
   1.500 +      ok(found.int          === expected.int,          "non-instant accept system int"    );
   1.501 +      ok(found.bool         === expected.bool,         "non-instant accept system bool"   );
   1.502 +      ok(found.string       === expected.string,       "non-instant accept system string" );
   1.503 +      ok(found.wstring_data === expected.wstring_data, "non-instant accept system wstring");
   1.504 +      ok(found.unichar_data === expected.unichar_data, "non-instant accept system unichar");
   1.505 +      todo(found.file_data  === expected.file_data,    "non-instant accept system file"   );
   1.506 +
   1.507 +      // - test deferred reset in child window
   1.508 +      InitTestPrefs(false);
   1.509 +      openDialog("window_preferences2.xul", "", "modal", RunResetPrefTest, true);
   1.510 +      expected = CreateEmptyPrefValueSet();
   1.511 +      found    = ReadPrefsFromSystem();
   1.512 +      ok(found.int          === expected.int,          "non-instant reset deferred int"    );
   1.513 +      ok(found.bool         === expected.bool,         "non-instant reset deferred bool"   );
   1.514 +      ok(found.string       === expected.string,       "non-instant reset deferred string" );
   1.515 +      ok(found.wstring_data === expected.wstring_data, "non-instant reset deferred wstring");
   1.516 +      ok(found.unichar_data === expected.unichar_data, "non-instant reset deferred unichar");
   1.517 +      ok(found.file_data    === expected.file_data,    "non-instant reset deferred file"   );
   1.518 +    }
   1.519 +
   1.520 +    function RunTestCommandRedirect()
   1.521 +    {
   1.522 +      openDialog("window_preferences_commandretarget.xul", "", "modal", RunCheckCommandRedirect, true);
   1.523 +    }
   1.524 +
   1.525 +    function RunTest()
   1.526 +    {
   1.527 +      RunTestInstant();
   1.528 +      RunTestNonInstant();
   1.529 +      RunTestCommandRedirect();
   1.530 +      SimpleTest.finish();
   1.531 +    }
   1.532 +  ]]>
   1.533 +  </script>
   1.534 +
   1.535 +  <body xmlns="http://www.w3.org/1999/xhtml">
   1.536 +    <p id="display"></p>
   1.537 +    <div id="content" style="display: none"></div>
   1.538 +    <pre id="test"></pre>
   1.539 +  </body>
   1.540 +
   1.541 +</window>

mercurial