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.
* Instead of re-calculating the contentLength, we can just use the length of
the actual byterange substring being returned. That's clearer.
* 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

--HG--
extra : rebase_source : a6bd68fe75cfd4c46f63ca815c5a4e9390bd671a
This commit is contained in:
Chris Pearce 2018-04-04 14:30:15 +12:00
Родитель 9f21b62342
Коммит fbd7f61c3c
3 изменённых файлов: 16 добавлений и 11 удалений

Просмотреть файл

@ -48,16 +48,21 @@ function handleRequest(request, response)
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);

Просмотреть файл

@ -42,10 +42,12 @@
}, 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;
+ "&redirectAt=200";
element.preload = "metadata";
document.body.appendChild(element);
element.load()

Просмотреть файл

@ -43,13 +43,11 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=489415
return new Promise(function (resolve, reject) {
// Load will redirect mid-flight, which will be detected and should error,
// and we should no longer be able to readback.
var noise = Math.floor(Math.random() * 100000000);
var video = document.createElement("video");
video.preload = "metadata";
video.controls = true;
var url = "http://" + origin + "/tests/dom/media/test/midflight-redirect.sjs?key="
+ noise + "&resource=pixel_aspect_ratio.mp4"
+ "&type=video/mp4";
var url = "http://" + origin + "/tests/dom/media/test/midflight-redirect.sjs"
+ "?resource=pixel_aspect_ratio.mp4&type=video/mp4";
SimpleTest.info("Loading from " + url);
video.src = url;
document.body.appendChild(video);