content/media/test/test_wav_ended2.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/media/test/test_wav_ended2.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,62 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <title>Wave Media test: ended and replaying</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 +</head>
    1.11 +<body>
    1.12 +<!-- try with autoplay and no v.play in starttest, also with both -->
    1.13 +<pre id="test">
    1.14 +<script class="testbody" type="text/javascript">
    1.15 +// Test if audio can be replayed after ended.
    1.16 +var completed = false;
    1.17 +var playingCount = 0;
    1.18 +var endCount = 0;
    1.19 +
    1.20 +function startTest() {
    1.21 +  if (completed)
    1.22 +    return;
    1.23 +
    1.24 +  var v = document.getElementById('v');
    1.25 +  v.play();
    1.26 +}
    1.27 +
    1.28 +function playbackStarted() {
    1.29 +  if (completed)
    1.30 +    return;
    1.31 +
    1.32 +  playingCount++;
    1.33 +}
    1.34 +
    1.35 +function playbackEnded() {
    1.36 +  if (completed)
    1.37 +    return;
    1.38 +
    1.39 +  endCount++;
    1.40 +  var v = document.getElementById('v');
    1.41 +  ok(v.currentTime >= 0.9 && v.currentTime <= 1.1,
    1.42 +     "Checking currentTime at end: " + v.currentTime);
    1.43 +  ok(v.ended, "Checking playback has ended");
    1.44 +  ok(playingCount > 0, "Expect at least one playing event");
    1.45 +  playingCount = 0;
    1.46 +  if (endCount < 2) {
    1.47 +    v.play();
    1.48 +  } else {
    1.49 +    ok(endCount == 2, "Check playback after ended event");
    1.50 +    completed = true;
    1.51 +    SimpleTest.finish();
    1.52 +  }
    1.53 +}
    1.54 +
    1.55 +SimpleTest.waitForExplicitFinish();
    1.56 +</script>
    1.57 +</pre>
    1.58 +<audio id='v'
    1.59 +       onloadedmetadata='return startTest();'
    1.60 +       onplaying='return playbackStarted();'
    1.61 +       onended='return playbackEnded();'>
    1.62 +  <source type='audio/x-wav' src='r11025_s16_c1.wav'>
    1.63 +</audio>
    1.64 +</body>
    1.65 +</html>

mercurial