blob: cd07bf717fa7668bff2636b4b68b8973f701dc8d [file] [log] [blame]
<!DOCTYPE html>
<title>Check that crossorigin media requests don't reveal information about non-media files.</title>
<script src="/w3c/resources/testharness.js"></script>
<script src="/w3c/resources/testharnessreport.js"></script>
<script src="/media-resources/media-file.js"></script>
<video></video>
<script>
promise_test(async function() {
function get_all_events(url) {
return new Promise(function(resolve, reject) {
let events = [];
let current_state = -1;
let current_buffered_string = "";
const video = document.querySelector("video");
function pollTagState(prefix) {
const state = video.networkState;
if (state != current_state) {
current_state = state
events.push(prefix + "NetworkState=" + state);
}
const buffered = video.buffered;
let buffered_string = "";
for (let i = 0; i < buffered.length; i++) {
buffered_string += "(" + buffered.start(i) + "-" + buffered.end(i) + ")";
}
if (buffered_string != current_buffered_string) {
current_buffered_string = buffered_string;
events.push(prefix + "Buffered=" + buffered_string);
}
}
for (var prop in video) {
if (prop.slice(0,2) == "on") {
video[prop] = function(e) {
events.push(e.type);
pollTagState("+")
}
}
}
pollTagState("");
const interval = setInterval(function() { pollTagState("") }, 1);
video.onerror = function(e) {
events.push("Error("+video.error.message+")");
pollTagState("+")
// Wait for network state to stabilize.
setTimeout(function() {
clearInterval(interval);
resolve(events);
}, 100);
};
video.src = url;
video.play().catch(e=>0);
});
}
const nonexistant_remote = "http://localhost:8000/media/nonexistant.cgi";
const existant_remote = "http://localhost:8000/media/video-throttled-load.cgi?name=resources/test.txt&throttle=200&type=text/plain";
// First do a warmup run. Switching between sources adds some events, so
// the first run will be slightly different.
await get_all_events(nonexistant_remote);
// Get events for a nonexistant remote resource.
const nonexisting_events = await get_all_events(nonexistant_remote);
// Get events for a existant remote resource.
const existing_events = await get_all_events(existant_remote);
console.log(existing_events.join(","));
console.log(nonexisting_events.join(","));
assert_equals(existing_events.join(","), nonexisting_events.join(","));
});
</script>