Bug 1471573 - Make SpecialPowers RequestDumpCoverageCounters and RequestResetCoverageCounters async messages that wait on the dumping/resetting to actually happen. r=jmaher
☠☠ backed out by 7a80adc796d7 ☠ ☠
authorMarco Castelluccio <mcastelluccio@mozilla.com>
Thu, 28 Jun 2018 09:40:32 +0100
changeset 425026 eb34fd6b8ce3b9e9fdf8d4610530b7d6ec693765
parent 425025 b1fcf4dda09949b96a82474f0606fac85ab45974
child 425027 0903f7dc6c7f3d7f10fec403d2ebee470e887876
push id34232
push userrgurzau@mozilla.com
push dateWed, 04 Jul 2018 16:30:38 +0000
treeherdermozilla-central@6c0fa9a675c9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmaher
bugs1471573
milestone63.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
Bug 1471573 - Make SpecialPowers RequestDumpCoverageCounters and RequestResetCoverageCounters async messages that wait on the dumping/resetting to actually happen. r=jmaher
testing/specialpowers/content/SpecialPowersObserverAPI.js
testing/specialpowers/content/specialpowers.js
testing/specialpowers/content/specialpowersAPI.js
tools/code-coverage/tests/mochitest/test_coverage_specialpowers.html
--- a/testing/specialpowers/content/SpecialPowersObserverAPI.js
+++ b/testing/specialpowers/content/SpecialPowersObserverAPI.js
@@ -6,16 +6,17 @@
 
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 
 XPCOMUtils.defineLazyModuleGetters(this, {
   ExtensionData: "resource://gre/modules/Extension.jsm",
   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) {
   Error.call(this);
   // let {stack} = new Error();
   this.message = aMsg;
   this.name = "SpecialPowersError";
 };
@@ -549,26 +550,26 @@ SpecialPowersObserverAPI.prototype = {
         let uri = Services.io.newURI(origin);
         let sss = Cc["@mozilla.org/ssservice;1"].
                   getService(Ci.nsISiteSecurityService);
         sss.removeState(Ci.nsISiteSecurityService.HEADER_HSTS, uri, flags);
         return undefined;
       }
 
       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.
       }
 
       case "SPLoadExtension": {
         let id = aMessage.data.id;
         let ext = aMessage.data.ext;
         let extension = ExtensionTestCommon.generate(ext);
 
--- a/testing/specialpowers/content/specialpowers.js
+++ b/testing/specialpowers/content/specialpowers.js
@@ -30,30 +30,30 @@ function SpecialPowers(window) {
   this.SP_SYNC_MESSAGES = ["SPChromeScriptMessage",
                            "SPLoadChromeScript",
                            "SPImportInMainProcess",
                            "SPObserverService",
                            "SPPermissionManager",
                            "SPPrefService",
                            "SPProcessCrashService",
                            "SPSetTestPluginEnabledState",
-                           "SPCleanUpSTSData",
-                           "SPRequestDumpCoverageCounters",
-                           "SPRequestResetCoverageCounters"];
+                           "SPCleanUpSTSData"];
 
   this.SP_ASYNC_MESSAGES = ["SpecialPowers.Focus",
                             "SpecialPowers.Quit",
                             "SpecialPowers.CreateFiles",
                             "SpecialPowers.RemoveFiles",
                             "SPPingService",
                             "SPLoadExtension",
                             "SPProcessCrashManagerWait",
                             "SPStartupExtension",
                             "SPUnloadExtension",
-                            "SPExtensionMessage"];
+                            "SPExtensionMessage",
+                            "SPRequestDumpCoverageCounters",
+                            "SPRequestResetCoverageCounters"];
   addMessageListener("SPPingService", this._messageListener);
   addMessageListener("SpecialPowers.FilesCreated", this._messageListener);
   addMessageListener("SpecialPowers.FilesError", this._messageListener);
   let self = this;
   Services.obs.addObserver(function onInnerWindowDestroyed(subject, topic, data) {
     var id = subject.QueryInterface(Ci.nsISupportsPRUint64).data;
     if (self._windowID === id) {
       Services.obs.removeObserver(onInnerWindowDestroyed, "inner-window-destroyed");
--- a/testing/specialpowers/content/specialpowersAPI.js
+++ b/testing/specialpowers/content/specialpowersAPI.js
@@ -1977,22 +1977,34 @@ SpecialPowersAPI.prototype = {
   removeServiceWorkerDataForExampleDomain() {
     return wrapIfUnwrapped(ServiceWorkerCleanUp.removeFromHost("example.com"));
   },
 
   cleanUpSTSData(origin, flags) {
     return this._sendSyncMessage("SPCleanUpSTSData", {origin, flags: flags || 0});
   },
 
-  requestDumpCoverageCounters() {
-    this._sendSyncMessage("SPRequestDumpCoverageCounters", {});
+  requestDumpCoverageCounters(cb) {
+    let messageListener = _ => {
+      this._removeMessageListener("SPRequestDumpCoverageCounters", messageListener);
+      cb();
+    };
+
+    this._addMessageListener("SPRequestDumpCoverageCounters", messageListener);
+    this._sendAsyncMessage("SPRequestDumpCoverageCounters", {});
   },
 
-  requestResetCoverageCounters() {
-    this._sendSyncMessage("SPRequestResetCoverageCounters", {});
+  requestResetCoverageCounters(cb) {
+    let messageListener = _ => {
+      this._removeMessageListener("SPRequestResetCoverageCounters", messageListener);
+      cb();
+    };
+
+    this._addMessageListener("SPRequestResetCoverageCounters", messageListener);
+    this._sendAsyncMessage("SPRequestResetCoverageCounters", {});
   },
 
   _nextExtensionID: 0,
   _extensionListeners: null,
 
   loadExtension(ext, handler) {
     if (this._extensionListeners == null) {
       this._extensionListeners = new Set();
--- a/tools/code-coverage/tests/mochitest/test_coverage_specialpowers.html
+++ b/tools/code-coverage/tests/mochitest/test_coverage_specialpowers.html
@@ -9,23 +9,25 @@ https://bugzilla.mozilla.org/show_bug.cg
   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
   <script type="application/javascript">
 
   /** Test for Bug 1380659 **/
 
   SimpleTest.waitForExplicitFinish();
 
-  SpecialPowers.requestDumpCoverageCounters();
-  SimpleTest.ok(true, "Counters dumped.");
+  (async function() {
+    await new Promise(resolve => SpecialPowers.requestDumpCoverageCounters(resolve));
+    SimpleTest.ok(true, "Counters dumped.");
 
-  SpecialPowers.requestResetCoverageCounters();
-  SimpleTest.ok(true, "Counters reset.");
+    await new Promise(resolve => SpecialPowers.requestResetCoverageCounters(resolve));
+    SimpleTest.ok(true, "Counters reset.");
 
-  SimpleTest.finish();
+    SimpleTest.finish();
+  })();
 
   </script>
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1380659">Mozilla Bug 1380659</a>
 <p id="display"></p>
 <div id="content" style="display: none">