modules/libpref/test/unit/head_libPrefs.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/modules/libpref/test/unit/head_libPrefs.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,45 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +const NS_APP_USER_PROFILE_50_DIR = "ProfD";
     1.9 +
    1.10 +const Ci = Components.interfaces;
    1.11 +const Cc = Components.classes;
    1.12 +const Cr = Components.results;
    1.13 +const Cu = Components.utils;
    1.14 +
    1.15 +function do_check_throws(f, result, stack)
    1.16 +{
    1.17 +  if (!stack)
    1.18 +    stack = Components.stack.caller;
    1.19 +
    1.20 +  try {
    1.21 +    f();
    1.22 +  } catch (exc) {
    1.23 +    if (exc.result == result)
    1.24 +      return;
    1.25 +    do_throw("expected result " + result + ", caught " + exc, stack);
    1.26 +  }
    1.27 +  do_throw("expected result " + result + ", none thrown", stack);
    1.28 +}
    1.29 +
    1.30 +var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
    1.31 +
    1.32 +// Register current test directory as provider for the profile directory.
    1.33 +var provider = {
    1.34 +  getFile: function(prop, persistent) {
    1.35 +    persistent.value = true;
    1.36 +    if (prop == NS_APP_USER_PROFILE_50_DIR)
    1.37 +      return dirSvc.get("CurProcD", Ci.nsIFile);
    1.38 +    throw Cr.NS_ERROR_FAILURE;
    1.39 +  },
    1.40 +  QueryInterface: function(iid) {
    1.41 +    if (iid.equals(Ci.nsIDirectoryServiceProvider) ||
    1.42 +        iid.equals(Ci.nsISupports)) {
    1.43 +      return this;
    1.44 +    }
    1.45 +    throw Cr.NS_ERROR_NO_INTERFACE;
    1.46 +  }
    1.47 +};
    1.48 +dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);

mercurial