diff --git a/toolkit/components/telemetry/TelemetryPing.js b/toolkit/components/telemetry/TelemetryPing.js index e7483619539..39cdc01ab7c 100644 --- a/toolkit/components/telemetry/TelemetryPing.js +++ b/toolkit/components/telemetry/TelemetryPing.js @@ -964,13 +964,26 @@ TelemetryPing.prototype = { this._addons = aAddOns; }, + sendIdlePing: function sendIdlePing(aTest, aServer) { + if (this._isIdleObserver) { + idleService.removeIdleObserver(this, IDLE_TIMEOUT_SECONDS); + this._isIdleObserver = false; + } + if (aTest) { + this.send("test-ping", aServer); + } else if (Telemetry.canSend) { + this.send("idle-daily", aServer); + } + }, + + testPing: function testPing(server) { + this.sendIdlePing(true, server); + }, + /** * This observer drives telemetry. */ observe: function (aSubject, aTopic, aData) { - // Allows to change the server for testing - var server = this._server; - switch (aTopic) { case "profile-after-change": this.setup(); @@ -1027,20 +1040,8 @@ TelemetryPing.prototype = { this._pingLoadsCompleted = 0; this.loadHistograms(aSubject.QueryInterface(Ci.nsIFile), aData != "async"); break; - case "test-ping": - server = aData; - // fall through case "idle": - if (this._isIdleObserver) { - idleService.removeIdleObserver(this, IDLE_TIMEOUT_SECONDS); - this._isIdleObserver = false; - } - if (aTopic == "test-ping") { - this.send("test-ping", server); - } - else if (Telemetry.canSend && aTopic == "idle") { - this.send("idle-daily", server); - } + this.sendIdlePing(false, this._server); break; case "quit-application-granted": if (Telemetry.canSend) { diff --git a/toolkit/components/telemetry/nsITelemetryPing.idl b/toolkit/components/telemetry/nsITelemetryPing.idl index c1e3b4fe1e6..065319a90b6 100644 --- a/toolkit/components/telemetry/nsITelemetryPing.idl +++ b/toolkit/components/telemetry/nsITelemetryPing.idl @@ -14,4 +14,5 @@ interface nsITelemetryPing : nsIObserver { void gatherStartup(); void enableLoadSaveNotifications(); /* Used only for testing. */ void setAddOns(in AString aAddOns); + void testPing(in AString aServer); }; diff --git a/toolkit/components/telemetry/tests/unit/test_TelemetryPing.js b/toolkit/components/telemetry/tests/unit/test_TelemetryPing.js index ecf517cac63..3e62b3b27a2 100644 --- a/toolkit/components/telemetry/tests/unit/test_TelemetryPing.js +++ b/toolkit/components/telemetry/tests/unit/test_TelemetryPing.js @@ -47,7 +47,7 @@ function telemetry_ping () { const TelemetryPing = Cc["@mozilla.org/base/telemetry-ping;1"].getService(Ci.nsITelemetryPing); TelemetryPing.gatherStartup(); TelemetryPing.enableLoadSaveNotifications(); - TelemetryPing.observe(null, "test-ping", SERVER); + TelemetryPing.testPing(SERVER); } // Mostly useful so that you can dump payloads from decodeRequestPayload.