diff --git a/toolkit/components/telemetry/TelemetryPing.jsm b/toolkit/components/telemetry/TelemetryPing.jsm index 2389d77e6cfb..b2bf12467be0 100644 --- a/toolkit/components/telemetry/TelemetryPing.jsm +++ b/toolkit/components/telemetry/TelemetryPing.jsm @@ -554,7 +554,9 @@ let Impl = { doPing: function doPing(ping, isPersisted) { this._log.trace("doPing - Server " + this._server + ", Persisted " + isPersisted); let deferred = Promise.defer(); - let url = this._server + this.submissionPath(ping); + let isNewPing = isNewPingFormat(ping); + let version = isNewPing ? PING_FORMAT_VERSION : 1; + let url = this._server + this.submissionPath(ping) + "?v=" + version; let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"] .createInstance(Ci.nsIXMLHttpRequest); request.mozBackgroundRequest = true; @@ -587,7 +589,7 @@ let Impl = { request.addEventListener("load", handler(true).bind(this), false); // If that's a legacy ping format, just send its payload. - let networkPayload = isNewPingFormat(ping) ? ping : ping.payload; + let networkPayload = isNewPing ? ping : ping.payload; request.setRequestHeader("Content-Encoding", "gzip"); let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"] .createInstance(Ci.nsIScriptableUnicodeConverter); diff --git a/toolkit/components/telemetry/tests/unit/test_TelemetryPing.js b/toolkit/components/telemetry/tests/unit/test_TelemetryPing.js index 1b5fac2f06bb..27648c3769f3 100644 --- a/toolkit/components/telemetry/tests/unit/test_TelemetryPing.js +++ b/toolkit/components/telemetry/tests/unit/test_TelemetryPing.js @@ -220,6 +220,14 @@ add_task(function* test_simplePing() { yield sendPing(false, false); let request = yield gRequestIterator.next(); + + // Check that we have a version query parameter in the URL. + Assert.notEqual(request.queryString, ""); + + // Make sure the version in the query string matches the new ping format version. + let params = request.queryString.split("&"); + Assert.ok(params.find(p => p == ("v=" + PING_FORMAT_VERSION))); + let ping = decodeRequestPayload(request); checkPingFormat(ping, TEST_PING_TYPE, false, false); }); diff --git a/toolkit/components/telemetry/tests/unit/test_TelemetrySendOldPings.js b/toolkit/components/telemetry/tests/unit/test_TelemetrySendOldPings.js index 854483b6945a..fb5452766fd0 100644 --- a/toolkit/components/telemetry/tests/unit/test_TelemetrySendOldPings.js +++ b/toolkit/components/telemetry/tests/unit/test_TelemetrySendOldPings.js @@ -356,6 +356,55 @@ add_task(function* test_overdue_pings_trigger_send() { yield resetTelemetry(); }); +/** + * Create a ping in the old format, send it, and make sure the request URL contains + * the correct version query parameter. + */ +add_task(function* test_overdue_old_format() { + // A test ping in the old, standard format. + const PING_OLD_FORMAT = { + slug: "1234567abcd", + reason: "test-ping", + payload: { + info: { + reason: "test-ping", + OS: "XPCShell", + appID: "SomeId", + appVersion: "1.0", + appName: "XPCShell", + appBuildID: "123456789", + appUpdateChannel: "Test", + platformBuildID: "987654321", + }, + }, + }; + + const filePath = + Path.join(Constants.Path.profileDir, PING_SAVE_FOLDER, PING_OLD_FORMAT.slug); + + // Write the ping to file and make it overdue. + yield TelemetryFile.savePing(PING_OLD_FORMAT, true); + yield File.setDates(filePath, null, Date.now() - OVERDUE_PING_FILE_AGE); + + let receivedPings = 0; + // Register a new prefix handler to validate the URL. + gHttpServer.registerPrefixHandler("/submit/telemetry/", request => { + // Check that we have a version query parameter in the URL. + Assert.notEqual(request.queryString, ""); + + // Make sure the version in the query string matches the old ping format version. + let params = request.queryString.split("&"); + Assert.ok(params.find(p => p == "v=1")); + + receivedPings++; + }); + + yield startTelemetry(); + Assert.equal(receivedPings, 1, "We must receive a ping in the old format."); + + yield resetTelemetry(); +}); + add_task(function* teardown() { yield stopHttpServer(); });