Bug 1250266 - Always send a TTL in the Push mochitests. r=benbangert

MozReview-Commit-ID: 4hoBveTY2pE
This commit is contained in:
Kit Cambridge 2016-02-22 11:54:54 -08:00
parent 1b3b1cb7d0
commit 95ab483d20
5 changed files with 21 additions and 10 deletions

View File

@ -39,14 +39,21 @@ function handleRequest(request, response)
data.push(bodyStream.readByteArray(available)); data.push(bodyStream.readByteArray(available));
size += available; size += available;
} }
xhr.send(concatUint8Arrays(data, size));
function reply(statusCode, statusText) {
response.setStatusLine(request.httpVersion, statusCode, statusText);
response.finish();
}
xhr.onload = function(e) { xhr.onload = function(e) {
debug("xhr : " + this.status); debug("xhr : " + this.status);
} reply(this.status, this.statusText);
};
xhr.onerror = function(e) { xhr.onerror = function(e) {
debug("xhr error: " + e); debug("xhr error: " + e);
} reply(500, "Internal Server Error");
};
response.setStatusLine(request.httpVersion, "200", "OK"); response.processAsync();
xhr.send(concatUint8Arrays(data, size));
} }

View File

@ -107,7 +107,7 @@ http://creativecommons.org/licenses/publicdomain/
function waitForMessage(pushSubscription, message) { function waitForMessage(pushSubscription, message) {
return Promise.all([ return Promise.all([
controlledFrame.waitOnWorkerMessage("finished"), controlledFrame.waitOnWorkerMessage("finished"),
webpush(pushSubscription, message), webpush(pushSubscription, message, 120),
]).then(([message]) => message); ]).then(([message]) => message);
} }
@ -167,6 +167,7 @@ http://creativecommons.org/licenses/publicdomain/
headers: { headers: {
"X-Push-Method": "POST", "X-Push-Method": "POST",
"X-Push-Server": pushSubscription.endpoint, "X-Push-Server": pushSubscription.endpoint,
"TTL": "120",
}, },
}), }),
]); ]);

View File

@ -71,6 +71,7 @@ http://creativecommons.org/licenses/publicdomain/
headers: { headers: {
"X-Push-Method": "POST", "X-Push-Method": "POST",
"X-Push-Server": pushSubscription.endpoint, "X-Push-Server": pushSubscription.endpoint,
"TTL": "120",
}, },
}), }),
]); ]);

View File

@ -75,9 +75,10 @@
// Work around CORS for now. // Work around CORS for now.
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.open('GET', "http://mochi.test:8888/tests/dom/push/test/push-server.sjs", true); 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.setRequestHeader("X-Push-Server", pushEndpoint);
xhr.send("version=24601"); xhr.setRequestHeader("TTL", "120");
xhr.send(null);
} }
function unregisterPushNotification(ctx) { function unregisterPushNotification(ctx) {

View File

@ -169,7 +169,7 @@
* parameters. * parameters.
* @param data The message to send. * @param data The message to send.
*/ */
function webpush(subscription, data) { function webpush(subscription, data, ttl) {
data = ensureView(data); data = ensureView(data);
var salt = g.crypto.getRandomValues(new Uint8Array(16)); var salt = g.crypto.getRandomValues(new Uint8Array(16));
@ -189,13 +189,14 @@
'X-Push-Method': 'POST', 'X-Push-Method': 'POST',
'Encryption-Key': 'keyid=p256dh;dh=' + base64url.encode(pubkey), 'Encryption-Key': 'keyid=p256dh;dh=' + base64url.encode(pubkey),
Encryption: 'keyid=p256dh;salt=' + base64url.encode(salt), Encryption: 'keyid=p256dh;salt=' + base64url.encode(salt),
'Content-Encoding': 'aesgcm128' 'Content-Encoding': 'aesgcm128',
'TTL': ttl,
}, },
body: payload, body: payload,
}; };
return fetch('http://mochi.test:8888/tests/dom/push/test/push-server.sjs', options); return fetch('http://mochi.test:8888/tests/dom/push/test/push-server.sjs', options);
}).then(response => { }).then(response => {
if (response.status / 100 !== 2) { if (Math.floor(response.status / 100) !== 2) {
throw new Error('Unable to deliver message'); throw new Error('Unable to deliver message');
} }
return response; return response;