testing/modules/AppInfo.jsm

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/testing/modules/AppInfo.jsm	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,74 @@
     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 +"use strict";
     1.9 +
    1.10 +this.EXPORTED_SYMBOLS = [
    1.11 +  "getAppInfo",
    1.12 +  "updateAppInfo",
    1.13 +];
    1.14 +
    1.15 +
    1.16 +const {interfaces: Ci, results: Cr, utils: Cu} = Components;
    1.17 +
    1.18 +Cu.import("resource://gre/modules/XPCOMUtils.jsm");
    1.19 +
    1.20 +let APP_INFO = {
    1.21 +  vendor: "Mozilla",
    1.22 +  name: "xpcshell",
    1.23 +  ID: "xpcshell@tests.mozilla.org",
    1.24 +  version: "1",
    1.25 +  appBuildID: "20121107",
    1.26 +  platformVersion: "p-ver",
    1.27 +  platformBuildID: "20121106",
    1.28 +  inSafeMode: false,
    1.29 +  logConsoleErrors: true,
    1.30 +  OS: "XPCShell",
    1.31 +  XPCOMABI: "noarch-spidermonkey",
    1.32 +  QueryInterface: XPCOMUtils.generateQI([Ci.nsIXULAppInfo, Ci.nsIXULRuntime]),
    1.33 +  invalidateCachesOnRestart: function() {},
    1.34 +};
    1.35 +
    1.36 +
    1.37 +/**
    1.38 + * Obtain a reference to the current object used to define XULAppInfo.
    1.39 + */
    1.40 +this.getAppInfo = function () { return APP_INFO; }
    1.41 +
    1.42 +/**
    1.43 + * Update the current application info.
    1.44 + *
    1.45 + * If the argument is defined, it will be the object used. Else, APP_INFO is
    1.46 + * used.
    1.47 + *
    1.48 + * To change the current XULAppInfo, simply call this function. If there was
    1.49 + * a previously registered app info object, it will be unloaded and replaced.
    1.50 + */
    1.51 +this.updateAppInfo = function (obj) {
    1.52 +  obj = obj || APP_INFO;
    1.53 +  APP_INFO = obj;
    1.54 +
    1.55 +  let id = Components.ID("{fbfae60b-64a4-44ef-a911-08ceb70b9f31}");
    1.56 +  let cid = "@mozilla.org/xre/app-info;1";
    1.57 +  let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
    1.58 +
    1.59 +  // Unregister an existing factory if one exists.
    1.60 +  try {
    1.61 +    let existing = Components.manager.getClassObjectByContractID(cid, Ci.nsIFactory);
    1.62 +    registrar.unregisterFactory(id, existing);
    1.63 +  } catch (ex) {}
    1.64 +
    1.65 +  let factory = {
    1.66 +    createInstance: function (outer, iid) {
    1.67 +      if (outer != null) {
    1.68 +        throw Cr.NS_ERROR_NO_AGGREGATION;
    1.69 +      }
    1.70 +
    1.71 +      return obj.QueryInterface(iid);
    1.72 +    },
    1.73 +  };
    1.74 +
    1.75 +  registrar.registerFactory(id, "XULAppInfo", cid, factory);
    1.76 +};
    1.77 +

mercurial