author | Gregory Szorc <gps@mozilla.com> |
Sat, 05 Jan 2013 16:10:38 -0800 | |
changeset 117879 | 4ac2babbafecf33fc72228cd5d343c3ab1211841 |
parent 117878 | 712bd4b20e475f4ed26a3bcdac55eb6439f02574 |
child 117880 | dccd490f15326234dd40d487928b3379dacb86ce |
push id | 20731 |
push user | emorley@mozilla.com |
push date | Mon, 07 Jan 2013 12:05:24 +0000 |
treeherder | mozilla-inbound@2889e68bf6ca [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | rnewman |
bugs | 812608 |
milestone | 20.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
--- a/services/healthreport/Makefile.in +++ b/services/healthreport/Makefile.in @@ -13,16 +13,17 @@ modules := \ healthreporter.jsm \ policy.jsm \ profile.jsm \ providers.jsm \ $(NULL) testing_modules := \ mocks.jsm \ + utils.jsm \ $(NULL) TEST_DIRS += tests MODULES_FILES := $(modules) MODULES_DEST = $(FINAL_TARGET)/modules/services/healthreport INSTALL_TARGETS += MODULES
new file mode 100644 --- /dev/null +++ b/services/healthreport/modules-testing/utils.jsm @@ -0,0 +1,73 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +this.EXPORTED_SYMBOLS = [ + "getAppInfo", + "updateAppInfo", +]; + + +const {interfaces: Ci, results: Cr, utils: Cu} = Components; + +Cu.import("resource://gre/modules/XPCOMUtils.jsm"); + +let APP_INFO = { + vendor: "Mozilla", + name: "xpcshell", + ID: "xpcshell@tests.mozilla.org", + version: "1", + appBuildID: "20121107", + platformVersion: "p-ver", + platformBuildID: "20121106", + inSafeMode: false, + logConsoleErrors: true, + OS: "XPCShell", + XPCOMABI: "noarch-spidermonkey", + QueryInterface: XPCOMUtils.generateQI([Ci.nsIXULAppInfo, Ci.nsIXULRuntime]), + invalidateCachesOnRestart: function() {}, +}; + + +/** + * Obtain a reference to the current object used to define XULAppInfo. + */ +this.getAppInfo = function () { return APP_INFO; } + +/** + * Update the current application info. + * + * If the argument is defined, it will be the object used. Else, APP_INFO is + * used. + * + * To change the current XULAppInfo, simply call this function. If there was + * a previously registered app info object, it will be unloaded and replaced. + */ +this.updateAppInfo = function (obj) { + obj = obj || APP_INFO; + APP_INFO = obj; + + let id = Components.ID("{fbfae60b-64a4-44ef-a911-08ceb70b9f31}"); + let cid = "@mozilla.org/xre/app-info;1"; + let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); + + // Unregister an existing factory if one exists. + try { + let existing = Components.manager.getClassObjectByContractID(cid, Ci.nsIFactory); + registrar.unregisterFactory(id, existing); + } catch (ex) {} + + let factory = { + createInstance: function (outer, iid) { + if (outer != null) { + throw Cr.NS_ERROR_NO_AGGREGATION; + } + + return obj.QueryInterface(iid); + }, + }; + + registrar.registerFactory(id, "XULAppInfo", cid, factory); +};
--- a/services/healthreport/tests/xpcshell/head.js +++ b/services/healthreport/tests/xpcshell/head.js @@ -9,8 +9,14 @@ do_get_profile(); (function initMetricsTestingInfrastructure() { let ns = {}; Components.utils.import("resource://testing-common/services-common/logging.js", ns); ns.initTestLogging(); }).call(this); +(function createAppInfo() { + let ns = {}; + Components.utils.import("resource://testing-common/services/healthreport/utils.jsm", ns); + ns.updateAppInfo(); +}).call(this); +
--- a/services/healthreport/tests/xpcshell/test_provider_appinfo.js +++ b/services/healthreport/tests/xpcshell/test_provider_appinfo.js @@ -5,47 +5,16 @@ const {interfaces: Ci, results: Cr, utils: Cu} = Components; Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://gre/modules/services/healthreport/providers.jsm"); Cu.import("resource://gre/modules/services/metrics/dataprovider.jsm"); function run_test() { - let appInfo = { - vendor: "Mozilla", - name: "xpcshell", - ID: "xpcshell@tests.mozilla.org", - version: "1", - appBuildID: "20121107", - platformVersion: "p-ver", - platformBuildID: "20121106", - inSafeMode: false, - logConsoleErrors: true, - OS: "XPCShell", - XPCOMABI: "noarch-spidermonkey", - QueryInterface: XPCOMUtils.generateQI([Ci.nsIXULAppInfo, Ci.nsIXULRuntime]), - invalidateCachesOnRestart: function() {}, - }; - - let factory = { - createInstance: function createInstance(outer, iid) { - if (outer != null) { - throw Cr.NS_ERROR_NO_AGGREGATION; - } - - return appInfo.QueryInterface(iid); - }, - }; - - let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); - registrar.registerFactory(Components.ID("{fbfae60b-64a4-44ef-a911-08ceb70b9f31}"), - "XULAppInfo", "@mozilla.org/xre/app-info;1", - factory); - run_next_test(); } add_test(function test_constructor() { let provider = new AppInfoProvider(); run_next_test(); });