<!doctype html>
<html>
<head>
<title>video.networkState - NETWORK_LOADING</title>
<script src="../../w3cwrapper.js"></script>
</head>
<body>
<p><a href="http://dev.w3.org/html5/spec/Overview.html#dom-media-networkstate">spec reference</a></p>
<video id="v" autoplay controls>
</video>
<div id="log"></div>
<script>
var t = async_test("videoElement.networkState should be NETWORK_LOADING during progress event", {timeout:30000});
var v = document.getElementById("v")
v.addEventListener("progress", function() {
// Allow for both NETWORK_LOADING and NETWORK_IDLE. NETWORK_IDLE can occur
// when the resource has loaded before the first `progress` event fired.
// In that case, we fire a `progress` event and a `suspend` event, but the
// networkState will already be set to NETWORK_IDLE.
// This is technically not spec compliant, but has been the behavior for years
// now.
let valid_network_state = v.networkState == v.NETWORK_LOADING ||
v.networkState == v.NETWORK_IDLE;
t.step(function() {
assert_true(valid_network_state,
"networkState should be NETWORK_LOADING during `progress` event, \
or NETWORK_IDLE if the `suspend` event is queued")
})
if (v.networkState == v.NETWORK_LOADING) {
// The test passed as expected.
t.done();
}
// If the networkState is NETWORK_IDLE, the test will complete in the
// `suspend` event handler.
v.pause();
});
v.addEventListener("suspend", function() {
if (v.networkState != v.NETWORK_IDLE) {
t.step(function() {
// Only log this on failure, to simplify the expectations file.
assert_true(
v.networkState,
v.NETWORK_IDLE,
"networkState should be NETWORK_IDLE when the `suspend` event is fired");
})
}
// Stop the test.
t.done();
v.pause();
});
v.src = getVideoURI("http://media.w3.org/2010/05/video/movie_300") + "?" + new Date() + Math.random();
</script>
</body>
</html>