зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1471573 - Make SpecialPowers RequestDumpCoverageCounters and RequestResetCoverageCounters async messages that wait on the dumping/resetting to actually happen. r=jmaher
--HG-- extra : rebase_source : 5e7814abb8761cbf5ab44b4c9d2f1c456b2ed912 extra : intermediate-source : e7272b60f48f1e97d557c490eed44404daba4e85 extra : source : eb34fd6b8ce3b9e9fdf8d4610530b7d6ec693765
This commit is contained in:
Родитель
fbfb9237c9
Коммит
49c0576523
|
@ -11,6 +11,7 @@ XPCOMUtils.defineLazyModuleGetters(this, {
|
|||
ExtensionTestCommon: "resource://testing-common/ExtensionTestCommon.jsm",
|
||||
NetUtil: "resource://gre/modules/NetUtil.jsm",
|
||||
Services: "resource://gre/modules/Services.jsm",
|
||||
PerTestCoverageUtils: "resource://testing-common/PerTestCoverageUtils.jsm",
|
||||
});
|
||||
|
||||
this.SpecialPowersError = function(aMsg) {
|
||||
|
@ -554,16 +555,16 @@ SpecialPowersObserverAPI.prototype = {
|
|||
}
|
||||
|
||||
case "SPRequestDumpCoverageCounters": {
|
||||
let codeCoverage = Cc["@mozilla.org/tools/code-coverage;1"].
|
||||
getService(Ci.nsICodeCoverage);
|
||||
codeCoverage.dumpCounters();
|
||||
PerTestCoverageUtils.afterTest().then(() =>
|
||||
this._sendReply(aMessage, "SPRequestDumpCoverageCounters", {})
|
||||
);
|
||||
return undefined; // See comment at the beginning of this function.
|
||||
}
|
||||
|
||||
case "SPRequestResetCoverageCounters": {
|
||||
let codeCoverage = Cc["@mozilla.org/tools/code-coverage;1"].
|
||||
getService(Ci.nsICodeCoverage);
|
||||
codeCoverage.resetCounters();
|
||||
PerTestCoverageUtils.beforeTest().then(() =>
|
||||
this._sendReply(aMessage, "SPRequestResetCoverageCounters", {})
|
||||
);
|
||||
return undefined; // See comment at the beginning of this function.
|
||||
}
|
||||
|
||||
|
|
|
@ -35,9 +35,7 @@ function SpecialPowers(window) {
|
|||
"SPPrefService",
|
||||
"SPProcessCrashService",
|
||||
"SPSetTestPluginEnabledState",
|
||||
"SPCleanUpSTSData",
|
||||
"SPRequestDumpCoverageCounters",
|
||||
"SPRequestResetCoverageCounters"];
|
||||
"SPCleanUpSTSData"];
|
||||
|
||||
this.SP_ASYNC_MESSAGES = ["SpecialPowers.Focus",
|
||||
"SpecialPowers.Quit",
|
||||
|
@ -48,7 +46,9 @@ function SpecialPowers(window) {
|
|||
"SPProcessCrashManagerWait",
|
||||
"SPStartupExtension",
|
||||
"SPUnloadExtension",
|
||||
"SPExtensionMessage"];
|
||||
"SPExtensionMessage",
|
||||
"SPRequestDumpCoverageCounters",
|
||||
"SPRequestResetCoverageCounters"];
|
||||
addMessageListener("SPPingService", this._messageListener);
|
||||
addMessageListener("SpecialPowers.FilesCreated", this._messageListener);
|
||||
addMessageListener("SpecialPowers.FilesError", this._messageListener);
|
||||
|
|
|
@ -22,6 +22,9 @@ ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
|
|||
ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
|
||||
ChromeUtils.import("resource://gre/modules/ServiceWorkerCleanUp.jsm");
|
||||
|
||||
ChromeUtils.defineModuleGetter(this, "PerTestCoverageUtils",
|
||||
"resource://testing-common/PerTestCoverageUtils.jsm");
|
||||
|
||||
// We're loaded with "this" not set to the global in some cases, so we
|
||||
// have to play some games to get at the global object here. Normally
|
||||
// we'd try "this" from a function called with undefined this value,
|
||||
|
@ -1982,12 +1985,38 @@ SpecialPowersAPI.prototype = {
|
|||
return this._sendSyncMessage("SPCleanUpSTSData", {origin, flags: flags || 0});
|
||||
},
|
||||
|
||||
requestDumpCoverageCounters() {
|
||||
this._sendSyncMessage("SPRequestDumpCoverageCounters", {});
|
||||
requestDumpCoverageCounters(cb) {
|
||||
// We want to avoid a roundtrip between child and parent.
|
||||
if (!PerTestCoverageUtils.enabled) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
return new Promise(resolve => {
|
||||
let messageListener = _ => {
|
||||
this._removeMessageListener("SPRequestDumpCoverageCounters", messageListener);
|
||||
resolve();
|
||||
};
|
||||
|
||||
this._addMessageListener("SPRequestDumpCoverageCounters", messageListener);
|
||||
this._sendAsyncMessage("SPRequestDumpCoverageCounters", {});
|
||||
});
|
||||
},
|
||||
|
||||
requestResetCoverageCounters() {
|
||||
this._sendSyncMessage("SPRequestResetCoverageCounters", {});
|
||||
requestResetCoverageCounters(cb) {
|
||||
// We want to avoid a roundtrip between child and parent.
|
||||
if (!PerTestCoverageUtils.enabled) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
return new Promise(resolve => {
|
||||
let messageListener = _ => {
|
||||
this._removeMessageListener("SPRequestResetCoverageCounters", messageListener);
|
||||
resolve();
|
||||
};
|
||||
|
||||
this._addMessageListener("SPRequestResetCoverageCounters", messageListener);
|
||||
this._sendAsyncMessage("SPRequestResetCoverageCounters", {});
|
||||
});
|
||||
},
|
||||
|
||||
_nextExtensionID: 0,
|
||||
|
|
|
@ -26,8 +26,6 @@ if (gcovResultsPath) {
|
|||
gcovResultsDir.initWithPath(gcovResultsPath);
|
||||
}
|
||||
|
||||
const enabled = !!gcovResultsPath;
|
||||
|
||||
function awaitPromise(promise) {
|
||||
let ret;
|
||||
let complete = false;
|
||||
|
@ -60,7 +58,7 @@ function moveDirectoryContents(src, dst) {
|
|||
var PerTestCoverageUtils = class PerTestCoverageUtilsClass {
|
||||
// Resets the counters to 0.
|
||||
static async beforeTest() {
|
||||
if (!enabled) {
|
||||
if (!PerTestCoverageUtils.enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -81,7 +79,7 @@ var PerTestCoverageUtils = class PerTestCoverageUtilsClass {
|
|||
|
||||
// Dumps counters and moves the gcda files in the directory expected by codecoverage.py.
|
||||
static async afterTest() {
|
||||
if (!enabled) {
|
||||
if (!PerTestCoverageUtils.enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -97,3 +95,5 @@ var PerTestCoverageUtils = class PerTestCoverageUtilsClass {
|
|||
awaitPromise(this.afterTest());
|
||||
}
|
||||
};
|
||||
|
||||
PerTestCoverageUtils.enabled = !!gcovResultsPath;
|
||||
|
|
|
@ -14,13 +14,15 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1380659
|
|||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
SpecialPowers.requestDumpCoverageCounters();
|
||||
SimpleTest.ok(true, "Counters dumped.");
|
||||
(async function() {
|
||||
await SpecialPowers.requestDumpCoverageCounters();
|
||||
SimpleTest.ok(true, "Counters dumped.");
|
||||
|
||||
SpecialPowers.requestResetCoverageCounters();
|
||||
SimpleTest.ok(true, "Counters reset.");
|
||||
await SpecialPowers.requestResetCoverageCounters();
|
||||
SimpleTest.ok(true, "Counters reset.");
|
||||
|
||||
SimpleTest.finish();
|
||||
SimpleTest.finish();
|
||||
})();
|
||||
|
||||
</script>
|
||||
</head>
|
||||
|
|
Загрузка…
Ссылка в новой задаче