<!DOCTYPE html>
<title>Test that an invalid "src" fires an error event and changing "src" to a valid one triggers media load.</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<video></video>
<script>
// 1. Test that an invalid src attribute fires an error when the file fails to load.
// 2. Test that changing src attribute triggers load after a load fails.
// 3. Test that changing src triggers load once a file is known to be valid.
async_test(function(t) {
var mediaFile;
var loadedCount = 0;
var video = document.querySelector("video");
video.onloadedmetadata = t.step_func(function() {
var url = video.currentSrc;
assert_equals(url.substr(url.lastIndexOf("/media/")+7), mediaFile);
assert_false(isNaN(video.duration));
if (++loadedCount == 2) {
t.done();
return;
}
mediaFile = "content/counting.ogv";
video.src = mediaFile;
});
video.onerror = t.step_func(function() {
assert_equals(loadedCount, 0);
var url = video.currentSrc;
assert_equals(url.substr(url.lastIndexOf("/media/")+7), "bogus");
assert_equals(video.networkState, HTMLMediaElement.NETWORK_NO_SOURCE);
assert_equals(video.error.code, MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED);
mediaFile = "content/test.ogv";
video.src = mediaFile;
});
mediaFile = "bogus";
video.src = mediaFile;
});
</script>