blob: 8f2f0fc5c10d9464dbeed499eb3d31f5ca6920b3 [file] [log] [blame]
<!doctype html>
<html>
<head>
<style>
video { background-color: yellow; width: 320px; height: 240px;}
</style>
<script src=media-file.js></script>
<script src=video-test.js></script>
</head>
<body>
<video controls ></video>
<p>Test to ensure that a media file blocked by a beforeload handler generates an error
and does not block the document's 'load' event.</p>
<script>
if (window.testRunner)
testRunner.dumpAsText();
var blockedURL;
var allowedURL;
var test;
var loadedmetadataFired = false;
var loadedFired = false;
function logEvent(evt)
{
consoleWrite("<br>EVENT('" + evt.type + "')");
}
function loadedmetadata(evt)
{
logEvent(evt);
consoleWrite("");
loadedmetadataFired = true;
checkEndTest();
}
function setupSourceTest()
{
consoleWrite("<br>*** Test using the &lt;source&gt; element ***");
blockedURL = relativeURL(video.src);
allowedURL = findMediaFile("audio", "content/test");
// Remove 'src' attribute so <source> will be used when we force a reload
video.removeAttribute('src');
var blockedSource = document.createElement('source');
blockedSource.src = blockedURL;
blockedSource.type = mimeTypeForExtension(blockedSource.src.split('.').pop());
video.appendChild(blockedSource);
var allowedSource = document.createElement('source');
allowedSource.src = allowedURL;
allowedSource.type = mimeTypeForExtension(allowedSource.src.split('.').pop());
video.appendChild(allowedSource);
test = 2;
video.load();
};
function error(evt)
{
logEvent(evt);
switch (test)
{
case 1:
testExpected("event.target.tagName", "VIDEO");
testExpected("video.error", null, "!=");
testExpected("video.error.code", MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED);
testExpected("video.networkState", HTMLMediaElement.NETWORK_NO_SOURCE);
setupSourceTest();
break;
case 2:
// The error should have been fired at the <source> and the media element should
// not be in an error state.
testExpected("event.target.tagName", "SOURCE");
testExpected("video.error", null);
break;
case 3:
failTest("Unexpected 'error' event fired!");
break;
}
}
function beforeload(evt)
{
logEvent(evt);
testExpected("event.target.tagName", "VIDEO");
switch (test)
{
case 1:
consoleWrite("blocking load of 'src'");
evt.preventDefault();
break;
case 2:
if (relativeURL(evt.url) == blockedURL) {
consoleWrite("blocking load of first &lt;source&gt; element");
evt.preventDefault();
} else {
consoleWrite("allowing load of second &lt;source&gt; element");
}
break;
}
}
function loaded(evt)
{
loadedFired = true;
checkEndTest();
};
function checkEndTest()
{
if (loadedmetadataFired && loadedFired)
endTest();
};
findMediaElement();
video.addEventListener('loadstart', logEvent, true);
video.addEventListener('loadedmetadata', loadedmetadata, true);
video.addEventListener('beforeload', beforeload, true);
video.addEventListener('error', error, true);
window.addEventListener('load', loaded, true);
consoleWrite("*** Test initial state ***");
testExpected("video.networkState", HTMLMediaElement.NETWORK_EMPTY);
testExpected("video.error", null);
consoleWrite("<br>*** Test blocking the 'src' attribute ***");
test = 1;
var mediaFile = findMediaFile("video", "content/test");
video.src = mediaFile;
</script>
</body>
</html>