Skip to content

Commit

Permalink
Bug 1256088 - Merge mock app-info implementation into AppInfo.jsm. r=gps
Browse files Browse the repository at this point in the history
  • Loading branch information
arai-a committed Mar 16, 2016
1 parent d7aaa4c commit 50608d5
Show file tree
Hide file tree
Showing 34 changed files with 246 additions and 854 deletions.
29 changes: 3 additions & 26 deletions browser/components/places/tests/unit/head_bookmarks.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,36 +29,13 @@ const ORGANIZER_FOLDER_ANNO = "PlacesOrganizer/OrganizerFolder";
const ORGANIZER_QUERY_ANNO = "PlacesOrganizer/OrganizerQuery";

// Needed by some test that relies on having an app registered.
var XULAppInfo = {
vendor: "Mozilla",
Cu.import("resource://testing-common/AppInfo.jsm", this);
updateAppInfo({
name: "PlacesTest",
ID: "{230de50e-4cd1-11dc-8314-0800200c9a66}",
version: "1",
appBuildID: "2007010101",
platformVersion: "",
platformBuildID: "2007010101",
inSafeMode: false,
logConsoleErrors: true,
OS: "XPCShell",
XPCOMABI: "noarch-spidermonkey",

QueryInterface: XPCOMUtils.generateQI([
Ci.nsIXULAppInfo,
Ci.nsIXULRuntime,
])
};

var XULAppInfoFactory = {
createInstance: function (outer, iid) {
if (outer != null)
throw Cr.NS_ERROR_NO_AGGREGATION;
return XULAppInfo.QueryInterface(iid);
}
};
var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
registrar.registerFactory(Components.ID("{fbfae60b-64a4-44ef-a911-08ceb70b9f31}"),
"XULAppInfo", "@mozilla.org/xre/app-info;1",
XULAppInfoFactory);
});

// Smart bookmarks constants.
const SMART_BOOKMARKS_VERSION = 7;
Expand Down
29 changes: 3 additions & 26 deletions browser/components/sessionstore/test/unit/test_backup_once.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,13 @@ var Paths;
var SessionFile;

// We need a XULAppInfo to initialize SessionFile
var XULAppInfo = {
vendor: "Mozilla",
Cu.import("resource://testing-common/AppInfo.jsm", this);
updateAppInfo({
name: "SessionRestoreTest",
ID: "{230de50e-4cd1-11dc-8314-0800200c9a66}",
version: "1",
appBuildID: "2007010101",
platformVersion: "",
platformBuildID: "2007010101",
inSafeMode: false,
logConsoleErrors: true,
OS: "XPCShell",
XPCOMABI: "noarch-spidermonkey",

QueryInterface: XPCOMUtils.generateQI([
Ci.nsIXULAppInfo,
Ci.nsIXULRuntime,
])
};

var XULAppInfoFactory = {
createInstance: function (outer, iid) {
if (outer != null)
throw Cr.NS_ERROR_NO_AGGREGATION;
return XULAppInfo.QueryInterface(iid);
}
};
var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
registrar.registerFactory(Components.ID("{fbfae60b-64a4-44ef-a911-08ceb70b9f31}"),
"XULAppInfo", "@mozilla.org/xre/app-info;1",
XULAppInfoFactory);
});

function run_test() {
run_next_test();
Expand Down
30 changes: 3 additions & 27 deletions browser/components/sessionstore/test/unit/test_shutdown_cleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,13 @@ const MAX_ENTRIES = 9;
const URL = "http://example.com/#";

// We need a XULAppInfo to initialize SessionFile
var XULAppInfo = {
vendor: "Mozilla",
Cu.import("resource://testing-common/AppInfo.jsm", this);
updateAppInfo({
name: "SessionRestoreTest",
ID: "{230de50e-4cd1-11dc-8314-0800200c9a66}",
version: "1",
appBuildID: "2007010101",
platformVersion: "",
platformBuildID: "2007010101",
inSafeMode: false,
logConsoleErrors: true,
OS: "XPCShell",
XPCOMABI: "noarch-spidermonkey",

QueryInterface: XPCOMUtils.generateQI([
Ci.nsIXULAppInfo,
Ci.nsIXULRuntime,
])
};

var XULAppInfoFactory = {
createInstance: function (outer, iid) {
if (outer != null)
throw Cr.NS_ERROR_NO_AGGREGATION;
return XULAppInfo.QueryInterface(iid);
}
};

var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
registrar.registerFactory(Components.ID("{fbfae60b-64a4-44ef-a911-08ceb70b9f31}"),
"XULAppInfo", "@mozilla.org/xre/app-info;1",
XULAppInfoFactory);
});

add_task(function* setup() {
let source = do_get_file("data/sessionstore_valid.js");
Expand Down
68 changes: 9 additions & 59 deletions browser/experiments/test/xpcshell/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ const EXPERIMENT2_XPI_SHA1 = "sha1:" + sha1File(EXPERIMENT2_PATH);
const EXPERIMENT3_ID = "[email protected]";
const EXPERIMENT4_ID = "[email protected]";

const DEFAULT_BUILDID = "2014060601";

const FAKE_EXPERIMENTS_1 = [
{
id: "id1",
Expand Down Expand Up @@ -162,63 +160,15 @@ function getExperimentAddons(previous=false) {
return deferred.promise;
}

function createAppInfo(optionsIn) {
const XULAPPINFO_CONTRACTID = "@mozilla.org/xre/app-info;1";
const XULAPPINFO_CID = Components.ID("{c763b610-9d49-455a-bbd2-ede71682a1ac}");

let options = optionsIn || {};
let id = options.id || "[email protected]";
let name = options.name || "XPCShell";
let version = options.version || "1.0";
let platformVersion = options.platformVersion || "1.0";
let date = options.date || new Date();

let buildID = options.buildID || DEFAULT_BUILDID;

gAppInfo = {
// nsIXULAppInfo
vendor: "Mozilla",
name: name,
ID: id,
version: version,
appBuildID: buildID,
platformVersion: platformVersion ? platformVersion : "1.0",
platformBuildID: buildID,

// nsIXULRuntime
inSafeMode: false,
logConsoleErrors: true,
OS: "XPCShell",
XPCOMABI: "noarch-spidermonkey",
invalidateCachesOnRestart: function invalidateCachesOnRestart() {
// Do nothing
},

// nsICrashReporter
annotations: {},

annotateCrashReport: function(key, data) {
this.annotations[key] = data;
},

QueryInterface: XPCOMUtils.generateQI([Ci.nsIXULAppInfo,
Ci.nsIXULRuntime,
Ci.nsICrashReporter,
Ci.nsISupports])
};

let XULAppInfoFactory = {
createInstance: function (outer, iid) {
if (outer != null) {
throw Cr.NS_ERROR_NO_AGGREGATION;
}
return gAppInfo.QueryInterface(iid);
}
};

let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
registrar.registerFactory(XULAPPINFO_CID, "XULAppInfo",
XULAPPINFO_CONTRACTID, XULAppInfoFactory);
function createAppInfo(ID="[email protected]", name="XPCShell",
version="1.0", platformVersion="1.0") {
let tmp = {};
Cu.import("resource://testing-common/AppInfo.jsm", tmp);
tmp.updateAppInfo({
ID, name, version, platformVersion,
crashReporter: true,
});
gAppInfo = tmp.getAppInfo();
}

/**
Expand Down
39 changes: 33 additions & 6 deletions browser/experiments/test/xpcshell/test_conditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,33 @@ const sanityFilter = function filter(c) {
return true;
}

// Utility function to generate build ID for previous/next date.
function addDate(buildId, diff) {
let m = /^([0-9]{4})([0-9]{2})([0-9]{2})(.*)$/.exec(buildId);
if (!m) {
throw Error("Unsupported build ID: " + buildId);
}
let year = Number.parseInt(m[1], 10);
let month = Number.parseInt(m[2], 10);
let date = Number.parseInt(m[3], 10);
let remainingParts = m[4];

let d = new Date();
d.setUTCFullYear(year, month - 1, date);
d.setTime(d.getTime() + diff * 24 * 60 * 60 * 1000);

let yearStr = String(d.getUTCFullYear());
let monthStr = ("0" + String(d.getUTCMonth() + 1)).slice(-2);
let dateStr = ("0" + String(d.getUTCDate())).slice(-2);
return yearStr + monthStr + dateStr + remainingParts;
}
function prevDate(buildId) {
return addDate(buildId, -1);
}
function nextDate(buildId) {
return addDate(buildId, 1);
}

add_task(function* test_simpleFields() {
let testData = [
// "expected applicable?", failure reason or null, manifest data
Expand Down Expand Up @@ -138,13 +165,13 @@ add_task(function* test_simpleFields() {
[false, ["buildIDs"], {buildIDs: ["not-a-build-id", gAppInfo.platformBuildID + "-invalid"]}],
[true, null, {buildIDs: ["not-a-build-id", gAppInfo.platformBuildID]}],

[true, null, {minBuildID: "2014060501"}],
[true, null, {minBuildID: "2014060601"}],
[false, ["minBuildID"], {minBuildID: "2014060701"}],
[true, null, {minBuildID: prevDate(gAppInfo.platformBuildID)}],
[true, null, {minBuildID: gAppInfo.platformBuildID}],
[false, ["minBuildID"], {minBuildID: nextDate(gAppInfo.platformBuildID)}],

[false, ["maxBuildID"], {maxBuildID: "2014010101"}],
[true, null, {maxBuildID: "2014060601"}],
[true, null, {maxBuildID: "2014060901"}],
[false, ["maxBuildID"], {maxBuildID: prevDate(gAppInfo.platformBuildID)}],
[true, null, {maxBuildID: gAppInfo.platformBuildID}],
[true, null, {maxBuildID: nextDate(gAppInfo.platformBuildID)}],

// sample

Expand Down
54 changes: 8 additions & 46 deletions browser/modules/test/unit/social/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,52 +28,14 @@ const MANIFEST_PREFS = Services.prefs.getBranch("social.manifest.");
// initApp below).
const gProfD = do_get_profile();

const XULAPPINFO_CONTRACTID = "@mozilla.org/xre/app-info;1";
const XULAPPINFO_CID = Components.ID("{c763b610-9d49-455a-bbd2-ede71682a1ac}");

function createAppInfo(id, name, version, platformVersion) {
gAppInfo = {
// nsIXULAppInfo
vendor: "Mozilla",
name: name,
ID: id,
version: version,
appBuildID: "2007010101",
platformVersion: platformVersion ? platformVersion : "1.0",
platformBuildID: "2007010101",

// nsIXULRuntime
inSafeMode: false,
logConsoleErrors: true,
OS: "XPCShell",
XPCOMABI: "noarch-spidermonkey",
invalidateCachesOnRestart: function invalidateCachesOnRestart() {
// Do nothing
},

// nsICrashReporter
annotations: {},

annotateCrashReport: function(key, data) {
this.annotations[key] = data;
},

QueryInterface: XPCOMUtils.generateQI([Ci.nsIXULAppInfo,
Ci.nsIXULRuntime,
Ci.nsICrashReporter,
Ci.nsISupports])
};

var XULAppInfoFactory = {
createInstance: function (outer, iid) {
if (outer != null)
throw Components.results.NS_ERROR_NO_AGGREGATION;
return gAppInfo.QueryInterface(iid);
}
};
var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
registrar.registerFactory(XULAPPINFO_CID, "XULAppInfo",
XULAPPINFO_CONTRACTID, XULAppInfoFactory);
function createAppInfo(ID, name, version, platformVersion="1.0") {
let tmp = {};
Cu.import("resource://testing-common/AppInfo.jsm", tmp);
tmp.updateAppInfo({
ID, name, version, platformVersion,
crashReporter: true,
});
gAppInfo = tmp.getAppInfo();
}

function initApp() {
Expand Down
37 changes: 3 additions & 34 deletions chrome/test/unit/test_abi.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,10 @@
const XULAppInfo = {
vendor: "Mozilla",
Components.utils.import("resource://testing-common/AppInfo.jsm", this);
updateAppInfo({
name: "XPCShell",
ID: "{39885e5f-f6b4-4e2a-87e5-6259ecf79011}",
version: "5",
appBuildID: "2007010101",
platformVersion: "1.9",
platformBuildID: "2007010101",
inSafeMode: false,
logConsoleErrors: true,
OS: "XPCShell",
XPCOMABI: "noarch-spidermonkey",

QueryInterface: function QueryInterface(iid) {
if (iid.equals(Ci.nsIXULAppInfo)
|| iid.equals(Ci.nsIXULRuntime)
|| iid.equals(Ci.nsISupports))
return this;

throw Components.results.NS_ERROR_NO_INTERFACE;
}
};

const XULAppInfoFactory = {
// These two are used when we register all our factories (and unregister)
CID: XULAPPINFO_CID,
scheme: "XULAppInfo",
contractID: XULAPPINFO_CONTRACTID,
createInstance: function (outer, iid) {
if (outer != null)
throw Cr.NS_ERROR_NO_AGGREGATION;
return XULAppInfo.QueryInterface(iid);
}
};

var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
registrar.registerFactory(XULAPPINFO_CID, "XULAppInfo",
XULAPPINFO_CONTRACTID, XULAppInfoFactory);
});

registerManifests([do_get_file("data/test_abi.manifest")]);

Expand Down
Loading

0 comments on commit 50608d5

Please sign in to comment.