content/media/test/test_play_twice.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/media/test/test_play_twice.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,79 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <title>Test playback of media files that should play OK</title>
     1.8 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     1.9 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.10 +  <script type="text/javascript" src="manifest.js"></script>
    1.11 +</head>
    1.12 +<body>
    1.13 +<pre id="test">
    1.14 +<script class="testbody" type="text/javascript">
    1.15 +
    1.16 +var manager = new MediaTestManager;
    1.17 +
    1.18 +function startTest(test, token) {
    1.19 +  var v = document.createElement('video');
    1.20 +  v.preload = "metadata";
    1.21 +  v.token = token;
    1.22 +  manager.started(token);
    1.23 +  v.src = test.name;
    1.24 +  v.name = test.name;
    1.25 +  v.playingCount = 0;
    1.26 +  var check = function(test, v) { return function() {
    1.27 +    checkMetadata(test.name, v, test);
    1.28 +  }}(test, v);
    1.29 +  var noLoad = function(test, v) { return function() {
    1.30 +    ok(false, test.name + " should not fire 'load' event");
    1.31 +  }}(test, v);
    1.32 +  var checkEnded = function(test, v) { return function() {
    1.33 +    if (test.duration) {
    1.34 +      ok(Math.abs(v.currentTime - test.duration) < 0.1,
    1.35 +         test.name + " current time at end: " + v.currentTime);
    1.36 +    }
    1.37 +    is(v.readyState, v.HAVE_CURRENT_DATA, test.name + " checking readyState");
    1.38 +    ok(v.readyState != v.NETWORK_LOADED, test.name + " shouldn't report NETWORK_LOADED");
    1.39 +    ok(v.ended, test.name + " checking playback has ended");
    1.40 +    ok(v.playingCount > 0, "Expect at least one playing event");
    1.41 +    v.playingCount = 0;
    1.42 +    if (v._playedOnce && v.seenSuspend) {
    1.43 +      v.parentNode.removeChild(v);
    1.44 +      manager.finished(v.token);
    1.45 +    } else {
    1.46 +      v._playedOnce = true;
    1.47 +      v.play();
    1.48 +    }
    1.49 +  }}(test, v);
    1.50 +  var checkSuspended = function(test, v) { return function() {
    1.51 +    if (v.seenSuspend)
    1.52 +      return;
    1.53 +
    1.54 +    v.seenSuspend = true;
    1.55 +    ok(true, test.name + " got suspend");
    1.56 +    if (v._playedOnce && v.seenSuspend) {
    1.57 +      v.parentNode.removeChild(v);
    1.58 +      manager.finished(v.token);
    1.59 +    }
    1.60 +  }}(test, v);
    1.61 +  var checkPlaying = function(test, v) { return function() {
    1.62 +    is(test.name, v.name, "Should be testing file we think we're testing...");
    1.63 +    v.playingCount++;
    1.64 +  }}(test, v);
    1.65 +  v.addEventListener("load", noLoad, false);
    1.66 +  v.addEventListener("loadedmetadata", check, false);
    1.67 +  v.addEventListener("playing", checkPlaying, false);
    1.68 +
    1.69 +  // We should get "ended" and "suspend" events for every resource
    1.70 +  v.addEventListener("ended", checkEnded, false);
    1.71 +  v.addEventListener("suspend", checkSuspended, false);
    1.72 +  
    1.73 +  document.body.appendChild(v);
    1.74 +  v.play();
    1.75 +}
    1.76 +
    1.77 +manager.runTests(gReplayTests, startTest);
    1.78 +
    1.79 +</script>
    1.80 +</pre>
    1.81 +</body>
    1.82 +</html>

mercurial