blob: b57ee346b475819af4c0248691e23f57c8645ba0 [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;
var lastErrorFired = false;
function logEvent(evt)
{
consoleWrite("<br>EVENT('" + evt.type + "')");
}
function loadedmetadata(evt)
{
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);
lastErrorFired = true;
checkEndTest();
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 && lastErrorFired)
endTest();
};
findMediaElement();
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>