Bug 983301 Add a test for FetchEvent.respondWith(5). r=bz

This commit is contained in:
Ben Kelly 2015-08-06 18:12:14 -07:00
parent 82841444d6
commit ab6a144621
2 changed files with 16 additions and 0 deletions

View File

@ -96,6 +96,11 @@ fetchXHR('nonresponse2.txt', null, function(xhr) {
finish();
});
fetchXHR('nonpromise.txt', null, function(xhr) {
my_ok(xhr.status == 0, "load should not complete");
finish();
});
fetchXHR('headers.txt', function(xhr) {
my_ok(xhr.status == 200, "load should be successful");
my_ok(xhr.responseText == "1", "request header checks should have passed");

View File

@ -76,6 +76,17 @@ onfetch = function(ev) {
ev.respondWith(Promise.resolve({}));
}
else if (ev.request.url.includes("nonpromise.txt")) {
try {
// This should coerce to Promise(5) instead of throwing
ev.respondWith(5);
} catch (e) {
// test is expecting failure, so return a success if we get a thrown
// exception
ev.respondWith(new Response('respondWith(5) threw ' + e));
}
}
else if (ev.request.url.includes("headers.txt")) {
var ok = true;
ok &= ev.request.headers.get("X-Test1") == "header1";