Bug 1371166 - Explicitly load videos via video.load to get a cross origin requests to take place. r?jib
Change where load calls are used in media recorder principals test to more
reliably force cross origin requests.
MozReview-Commit-ID: 7La6ZIRmsTQ
--- a/dom/media/test/test_mediarecorder_principals.html
+++ b/dom/media/test/test_mediarecorder_principals.html
@@ -26,37 +26,35 @@ let throwOutside = e => setTimeout(() =>
// Generate a random key. The first load with that key will return
// data, the second and subsequent loads with that key will return a redirect
// to a different origin ('localhost:8888' will be redirected to 'example.org',
// and 'example.org' will be redirected to 'localhost:8888').
// Loading data from two different origins should be detected by the media
// cache and result in a null principal so that the MediaRecorder usages below
// fail.
-// This test relies on that preloading the metadata then loading a sufficiently
-// long video will result in two separate requests to load the resource. This
-// ends up relying on the impl of MediaCache and friends and we should probably
-// replace this test with a more robust gtest or the like.
+// This test relies on that preloading the metadata then forcing another load
+// via video.load() will result in two requests taking place to retreive the
+// resource.
let key = Math.floor(Math.random()*100000000);
let interval;
function testPrincipals(resource) {
if (!resource) {
todo(false, "No types supported");
return;
}
// First test: Load file from same-origin first, then get redirected to
// another origin before attempting to record stream.
let video = document.getElementById("v1");
video.src =
"http://mochi.test:8888/tests/dom/media/test/dynamic_redirect.sjs?key=v1_" +
key + "&res=" + resource.name;
- video.load();
- // To limit readahead, avoid racing with playback and "catching up" mode.
- return new Promise(resolve => video.onloadeddata = resolve).then(() => {
+ return new Promise(resolve => video.onloadedmetadata = resolve).then(() => {
+ video.load();
video.play();
interval = setInterval(() => info("video.currentTime = "+ video.currentTime), 1000);
let msg = "mediaRecorder.start() must throw SecurityError";
return new Promise(resolve => video.onplaying = resolve)
.then(() => waitUntil(() => video.currentTime > resource.duration / 5))
// Test failure of the next step only, so "catch-bypass" any errors above.
.then(() => Promise.resolve()
@@ -66,27 +64,27 @@ function testPrincipals(resource) {
})
.then(() => {
// Second test: Load file from same-origin first, but record ASAP, before
// getting redirected to another origin.
let video = document.getElementById("v2");
video.src =
"http://mochi.test:8888/tests/dom/media/test/dynamic_redirect.sjs?key=v2_" +
key + "&res=" + resource.name;
- video.load();
let rec, hasStopped, hasEnded = new Promise(r => video.onended = r);
let data = [];
let msgNoThrow = "mediaRecorder.start() should not throw here";
let msgSecErr = "mediaRecorder.onerror must fire SecurityError";
let msgOnStop = "mediaRecorder.onstop must also have fired";
- return new Promise(resolve => video.onloadeddata = resolve).then(() => {
+ return new Promise(resolve => video.onloadedmetadata = resolve).then(() => {
rec = new MediaRecorder(video.mozCaptureStreamUntilEnded());
rec.ondataavailable = e => data.push(e.data);
rec.start();
+ video.load();
hasStopped = new Promise(resolve => rec.onstop = resolve);
video.play();
})
.then(() => ok(true, msgNoThrow), e => is(e.name, null, msgNoThrow))
.then(() => Promise.race([
new Promise((_, reject) => rec.onerror = e => reject(new DOMException("", e.name))),
hasEnded
]))