1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/media/test/test_preload_suspend.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,90 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=479863 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 479863</title> 1.11 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.12 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.13 +</head> 1.14 +<body> 1.15 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=479863">Mozilla Bug 479863</a> 1.16 +<p id="display"></p> 1.17 +<div id="content" style="display: none"> 1.18 + 1.19 +</div> 1.20 + 1.21 +<video id='v1'></video> 1.22 +<video id='v2' preload="auto"></video> 1.23 +<video id='v3' autoplay></video> 1.24 +<video id='v4'></video> 1.25 +<video id='v5'></video> 1.26 +<video id='v6'></video> 1.27 + 1.28 +<pre id="test"> 1.29 +<script type="application/javascript"> 1.30 +function is() {} 1.31 + 1.32 +var suspendCount = {}; 1.33 +var expectedSuspendCount = {v1:2, v2:1, v3:1, v4:2, v5:2, v6:2}; 1.34 +var totalSuspendCount = 0; 1.35 +for (var i = 0; i < expectedSuspendCount.length; ++i) { 1.36 + totalSuspendCount += expectedSuspendCount[i]; 1.37 +} 1.38 + 1.39 +function suspended(event) { 1.40 + // If the element suspends the download, it should not then be able to 1.41 + // complete it, so we should be stuck in NETWORK_IDLE even though this 1.42 + // event handler could run a long time after the actual suspend. 1.43 + var expectedState = event.type == "load" ? event.target.NETWORK_LOADED 1.44 + : event.target.NETWORK_IDLE; 1.45 + 1.46 + is(event.target.networkState, expectedState, 1.47 + event.target.id + " suspended networkState"); 1.48 + suspendCount[event.target.id]++; 1.49 + 1.50 + --totalSuspendCount; 1.51 + if (totalSuspendCount == 0) { 1.52 + // We're done. 1.53 + for (var i = 1; i <= 6; ++i) { 1.54 + var id = "v" + i; 1.55 + is(suspendCount[id], expectedSuspendCount[id], "Suspend count for " + id); 1.56 + } 1.57 + SimpleTest.finish(); 1.58 + } 1.59 + 1.60 + if (suspendCount[event.target.id] > 1) 1.61 + return; 1.62 + 1.63 + if (event.target.id == "v1") { 1.64 + event.target.preload = "auto"; 1.65 + } else if (event.target.id == "v4") { 1.66 + event.target.play(); 1.67 + } else if (event.target.id == "v5") { 1.68 + event.target.currentTime = 0.1; 1.69 + } else if (event.target.id == "v6") { 1.70 + event.target.autoplay = true; 1.71 + } 1.72 +} 1.73 + 1.74 +var key = Math.random(); 1.75 + 1.76 +SimpleTest.waitForExplicitFinish(); 1.77 +SpecialPowers.pushPrefEnv({"set": [["media.cache_size", 40000]]}, beginTest); 1.78 +function beginTest() { 1.79 + for (var i = 1; i <= 6; ++i) { 1.80 + var id = "v" + i; 1.81 + var v = document.getElementById(id); 1.82 + suspendCount[id] = 0; 1.83 + v.addEventListener("suspend", suspended, false); 1.84 + // Treat "load" as "suspend" for now, it means the same thing: we 1.85 + // stopped the download. 1.86 + v.addEventListener("load", suspended, false); 1.87 + v.src = "seek.ogv?key=" + key + "&id=" + id; 1.88 + } 1.89 +} 1.90 +</script> 1.91 +</pre> 1.92 +</body> 1.93 +</html>