Bug 1250266 - Always send a TTL in the Push mochitests. r=benbangert
authorKit Cambridge <kcambridge@mozilla.com>
Mon, 22 Feb 2016 11:54:54 -0800
changeset 321539 c2d7c361bc9582ff6443d0c763b1ab37eea76856
parent 321538 9ad211da67cd7aae924db35dc9edf2a56be565bf
child 321540 6839dfd7e63f5c5f7931a9bd8b2d9ccd49be6bea
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbenbangert
bugs1250266
milestone47.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 1250266 - Always send a TTL in the Push mochitests. r=benbangert MozReview-Commit-ID: 4hoBveTY2pE
dom/push/test/push-server.sjs
dom/push/test/test_data.html
dom/push/test/test_register.html
dom/push/test/test_serviceworker_lifetime.html
dom/push/test/webpush.js
--- a/dom/push/test/push-server.sjs
+++ b/dom/push/test/push-server.sjs
@@ -34,19 +34,26 @@ function handleRequest(request, response
   let bodyStream = Cc["@mozilla.org/binaryinputstream;1"].createInstance(Ci.nsIBinaryInputStream);
   bodyStream.setInputStream(request.bodyInputStream);
   let size = 0;
   let data = [];
   for (let available; available = bodyStream.available();) {
     data.push(bodyStream.readByteArray(available));
     size += available;
   }
-  xhr.send(concatUint8Arrays(data, size));
+
+  function reply(statusCode, statusText) {
+    response.setStatusLine(request.httpVersion, statusCode, statusText);
+    response.finish();
+  }
 
   xhr.onload = function(e) {
     debug("xhr : " + this.status);
-  }
+    reply(this.status, this.statusText);
+  };
   xhr.onerror = function(e) {
     debug("xhr error: " + e);
-  }
+    reply(500, "Internal Server Error");
+  };
 
-  response.setStatusLine(request.httpVersion, "200", "OK");
+  response.processAsync();
+  xhr.send(concatUint8Arrays(data, size));
 }
--- a/dom/push/test/test_data.html
+++ b/dom/push/test/test_data.html
@@ -102,17 +102,17 @@ http://creativecommons.org/licenses/publ
       new Uint8Array(data.auth),
       "Mismatched auth secret"
     );
   });
 
   function waitForMessage(pushSubscription, message) {
     return Promise.all([
       controlledFrame.waitOnWorkerMessage("finished"),
-      webpush(pushSubscription, message),
+      webpush(pushSubscription, message, 120),
     ]).then(([message]) => message);
   }
 
   add_task(function* sendPushMessageFromPage() {
     var typedArray = new Uint8Array([226, 130, 40, 240, 40, 140, 188]);
     var json = { hello: "world" };
 
     var message = yield waitForMessage(pushSubscription, "Text message from page");
@@ -162,16 +162,17 @@ http://creativecommons.org/licenses/publ
     // Send a blank message.
     var [message] = yield Promise.all([
       controlledFrame.waitOnWorkerMessage("finished"),
       fetch("http://mochi.test:8888/tests/dom/push/test/push-server.sjs", {
         method: "PUT",
         headers: {
           "X-Push-Method": "POST",
           "X-Push-Server": pushSubscription.endpoint,
+          "TTL": "120",
         },
       }),
     ]);
     ok(!message.data, "Should exclude data for blank messages");
   });
 
   add_task(function* unsubscribe() {
     controlledFrame.remove();
--- a/dom/push/test/test_register.html
+++ b/dom/push/test/test_register.html
@@ -66,16 +66,17 @@ http://creativecommons.org/licenses/publ
   add_task(function* waitForPushNotification() {
     yield Promise.all([
       controlledFrame.waitOnWorkerMessage("finished"),
       fetch("http://mochi.test:8888/tests/dom/push/test/push-server.sjs", {
         method: "PUT",
         headers: {
           "X-Push-Method": "POST",
           "X-Push-Server": pushSubscription.endpoint,
+          "TTL": "120",
         },
       }),
     ]);
   });
 
   add_task(function* unsubscribe() {
     controlledFrame.remove();
     yield pushSubscription.unsubscribe();
--- a/dom/push/test/test_serviceworker_lifetime.html
+++ b/dom/push/test/test_serviceworker_lifetime.html
@@ -70,19 +70,20 @@
     });
     return p;
   }
 
   function sendPushToPushServer(pushEndpoint) {
     // Work around CORS for now.
     var xhr = new XMLHttpRequest();
     xhr.open('GET', "http://mochi.test:8888/tests/dom/push/test/push-server.sjs", true);
-    xhr.setRequestHeader("X-Push-Method", "PUT");
+    xhr.setRequestHeader("X-Push-Method", "POST");
     xhr.setRequestHeader("X-Push-Server", pushEndpoint);
-    xhr.send("version=24601");
+    xhr.setRequestHeader("TTL", "120");
+    xhr.send(null);
   }
 
   function unregisterPushNotification(ctx) {
     return ctx.subscription.unsubscribe().then(function(result) {
       ok(result, "unsubscribe should succeed.");
       ctx.subscription = null;
       return ctx;
     });
--- a/dom/push/test/webpush.js
+++ b/dom/push/test/webpush.js
@@ -164,17 +164,17 @@
   /*
    * Request push for a message.  This returns a promise that resolves when the
    * push has been delivered to the push service.
    *
    * @param subscription A PushSubscription that contains endpoint and p256dh
    *                     parameters.
    * @param data         The message to send.
    */
-  function webpush(subscription, data) {
+  function webpush(subscription, data, ttl) {
     data = ensureView(data);
 
     var salt = g.crypto.getRandomValues(new Uint8Array(16));
     return webCrypto.generateKey(P256DH, false, ['deriveBits'])
       .then(localKey => {
         return Promise.all([
           encrypt(localKey.privateKey, subscription.getKey("p256dh"), salt, data),
           // 1337 p-256 specific haxx to get the raw value out of the spki value
@@ -184,23 +184,24 @@
         var options = {
           method: 'PUT',
           headers: {
             'X-Push-Server': subscription.endpoint,
             // Web Push requires POST requests.
             'X-Push-Method': 'POST',
             'Encryption-Key': 'keyid=p256dh;dh=' + base64url.encode(pubkey),
             Encryption: 'keyid=p256dh;salt=' + base64url.encode(salt),
-            'Content-Encoding': 'aesgcm128'
+            'Content-Encoding': 'aesgcm128',
+            'TTL': ttl,
           },
           body: payload,
         };
         return fetch('http://mochi.test:8888/tests/dom/push/test/push-server.sjs', options);
       }).then(response => {
-        if (response.status / 100 !== 2) {
+        if (Math.floor(response.status / 100) !== 2) {
           throw new Error('Unable to deliver message');
         }
         return response;
       });
   }
 
   g.webpush = webpush;
 }(this));