Bug 1144778 - Send an HTTP Date request header with telemetry pings. r=dexter, a=sylvestre
authorGeorg Fritzsche <georg.fritzsche@googlemail.com>
Fri, 29 Apr 2016 15:16:22 +0200
changeset 333149 e21705062473b3f4fa076ef8e5c9e5b624e33a50
parent 333148 9cc06cd6038eed9f12df93428b8f02fb6478f3ef
child 333150 8fb7bca6de0512920752d72455d2a353ed2847f2
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdexter, sylvestre
bugs1144778
milestone48.0a2
Bug 1144778 - Send an HTTP Date request header with telemetry pings. r=dexter, a=sylvestre
toolkit/components/telemetry/TelemetrySend.jsm
toolkit/components/telemetry/tests/unit/test_TelemetrySend.js
--- a/toolkit/components/telemetry/TelemetrySend.jsm
+++ b/toolkit/components/telemetry/TelemetrySend.jsm
@@ -906,16 +906,17 @@ var TelemetrySendImpl = {
     let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
                   .createInstance(Ci.nsIXMLHttpRequest);
     request.mozBackgroundRequest = true;
     request.timeout = PING_SUBMIT_TIMEOUT_MS;
 
     request.open("POST", url, true);
     request.overrideMimeType("text/plain");
     request.setRequestHeader("Content-Type", "application/json; charset=UTF-8");
+    request.setRequestHeader("Date", Policy.now().toUTCString());
 
     this._pendingPingRequests.set(id, request);
 
     let startTime = new Date();
     let deferred = PromiseUtils.defer();
 
     let onRequestFinished = (success, event) => {
       let onCompletion = () => {
--- a/toolkit/components/telemetry/tests/unit/test_TelemetrySend.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetrySend.js
@@ -165,16 +165,31 @@ add_task(function* test_sendPendingPings
   now = fakeNow(futureDate(now, pingSendTimeout));
   yield pingSendTimerCallback();
 
   pings = yield PingServer.promiseNextPings(5);
   PingServer.registerPingHandler(() => Assert.ok(false, "Should not have received any pings now"));
   countByType = countPingTypes(pings);
 
   Assert.equal(countByType.get(TEST_TYPE_A), 5, "Should have received the correct amount of type A pings");
+
+  yield TelemetrySend.testWaitOnOutgoingPings();
+  PingServer.resetPingHandler();
+});
+
+add_task(function* test_sendDateHeader() {
+  let now = fakeNow(new Date(Date.UTC(2011, 1, 1, 11, 0, 0)));
+  yield TelemetrySend.reset();
+
+  let pingId = yield TelemetryController.submitExternalPing("test-send-date-header", {});
+  let req = yield PingServer.promiseNextRequest();
+  let ping = decodeRequestPayload(req);
+  Assert.equal(req.getHeader("Date"), "Tue, 01 Feb 2011 11:00:00 GMT",
+               "Telemetry should send the correct Date header with requests.");
+  Assert.equal(ping.id, pingId, "Should have received the correct ping id.");
 });
 
 // Test the backoff timeout behavior after send failures.
 add_task(function* test_backoffTimeout() {
   const TYPE_PREFIX = "test-backoffTimeout-";
   const TEST_TYPE_C = TYPE_PREFIX + "C";
   const TEST_TYPE_D = TYPE_PREFIX + "D";
   const TEST_TYPE_E = TYPE_PREFIX + "E";