Bug 1443942 - Fix dom/media/test/midflight-redirect.sjs. r?jya
Problems here:
* The variable `to` is undefined for byte range requests to the end of
the resource, making the math fail. Firefox normally makes ranges requests like
this.
* The bytes.length/4 calculation may not be a whole number, so can
result in a byte range header part of the way between two bytes. We need to
round the length off.
* The contentLength calculation is off-by-one, so use the size of the
actual byte substring being returned, rather than trying to (re-)calculate the
length being returned.
* test_midflight_redirect_blocked needs the redirect to happen
before metadata has completed loading, but other tests require the redirect to
happen *after* metadata is loaded. So add a redirectAt query parameter for the
requester to control when to redirect.
MozReview-Commit-ID: I6n1NqK0Uze
--- a/dom/media/test/midflight-redirect.sjs
+++ b/dom/media/test/midflight-redirect.sjs
@@ -43,26 +43,31 @@ function handleRequest(request, response
response.setStatusLine(request.httpVersion, 303, "See Other");
let url = "http://" + origin +
"/tests/dom/media/test/midflight-redirect.sjs?redirected&" + query;
response.setHeader("Location", url);
response.setHeader("Content-Type", "text/html");
return;
}
- if (from == 0 && !redirected) {
- to = Math.min(bytes.length / 4, 200);
- } else {
- to = to || Math.max(from, bytes.length - 1);
+ if (isNaN(to)) {
+ to = bytes.length - 1;
}
+ if (from == 0 && !redirected) {
+ to = parseInt(parseQuery(query, "redirectAt")) || Math.floor(bytes.length / 4);
+ }
+ to = Math.min(to, bytes.length - 1);
+
+ // Note: 'to' is the first index *excluded*, so we need (to + 1)
+ // in the substring end here.
byterange = bytes.substring(from, to + 1);
- let contentRange = "bytes "+ from +"-"+ to +"/"+ bytes.length;
- let contentLength = (to - from + 1).toString();
+ let contentRange = "bytes " + from + "-" + to + "/" + bytes.length;
+ let contentLength = byterange.length.toString();
response.setStatusLine(request.httpVersion, 206, "Partial Content");
response.setHeader("Content-Range", contentRange);
response.setHeader("Content-Length", contentLength, false);
response.setHeader("Content-Type", type, false);
response.setHeader("Accept-Ranges", "bytes", false);
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
if (redirected && useCors) {
--- a/dom/media/test/test_midflight_redirect_blocked.html
+++ b/dom/media/test/test_midflight_redirect_blocked.html
@@ -37,20 +37,23 @@
}, false);
element.addEventListener("error", ()=>{
resolve(false);
removeNodeAndSource(element);
}, false);
var noise = Math.floor(Math.random() * 100000000);
+ // Note: request redirect before the end of metadata, otherwise we won't
+ // error before metadata has loaded if mixed origins are allowed.
element.src = "midflight-redirect.sjs?resource=" + test.name
+ (useCors ? "&cors" : "")
+ "&type=" + test.type
- + "&noise=" + noise;
+ + "&noise=" + noise
+ + "&redirectAt=200";
element.preload = "metadata";
document.body.appendChild(element);
element.load()
});
}
let v = document.createElement("video");
const testCases = gSmallTests.filter(t => v.canPlayType(t.type));