DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (c68fe15a81fc)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=467972
-->
<head>
  <title>Test for Bug 467972</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  <script type="text/javascript" src="manifest.js"></script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=467972">Mozilla Bug 467972</a>

<p id="display"></p>
<div id="content" style="display: none">
  
</div>
<pre id="test">
<script type="application/javascript">

// Test for Bug 467972. Tests that when we play to end, seek to 0, and play again, that we don't
// send/receive multiple loadeddata and loadedmetadata events.

var manager = new MediaTestManager;

function seekStarted(evt) {
  var v = evt.target;
  v._gotSeekStarted = true;
}

function seekEnded(evt) {
  var v = evt.target;
  v._gotSeekEnded = true;
  v.play();
}

function loadedData(evt) {
  var v = evt.target;
  v._loadedDataCount++;
  ok(v._loadedDataCount <= 1, "No more than 1 onloadeddata event for " + v._name);
}

function loadedMetaData(evt) {
  var v = evt.target;
  v._loadedMetaDataCount++;
  ok(v._loadedMetaDataCount <= 1, "No more than 1 onloadedmetadata event for " + v._name);
  checkMetadata(v._name, v, v._test);
  v.play();
}

function playing(evt) {
  evt.target._playingCount++;
}

function removeNodeAndListener(n) {
  n.removeEventListener("loadedmetadata", loadedMetaData);
  n.removeEventListener("ended", playbackEnded);
  n.removeEventListener("playing", playing);
  n.removeEventListener("loadeddata", loadedData);
  n.removeEventListener("seeking", seekStarted);
  n.removeEventListener("seeked", seekEnded);
  removeNodeAndSource(n);
}

function playbackEnded(evt) {
  var v = evt.target;
  v._endCount++;
  ok(v.currentTime >= v.duration-0.1 && v.currentTime <= v.duration + 0.1,
     "CurrentTime (" + v.currentTime + ") should be around " + v.duration
      + " for " + v._name);
  if (!v._playedOnce) {
    v.currentTime = 0;
    ok(v.seeking, "seeking should be true for " + v._name);
    ok(!v.ended, "ended shouldn't be true once seeking has begun for " + v._name);
    v._playedOnce = true;
  } else {
    ok(v._gotSeekEnded, "Should have received seekended for " + v._name);
    ok(v._gotSeekStarted, "Should have received seekstarted for " + v._name);
    is(v._loadedDataCount, 1, "Should have 1 onloadeddata event for " + v._name);
    is(v._loadedMetaDataCount, 1, "Should have 1 onloadedmetadata event for " + v._name);
    is(v._endCount, 2, "Should have received two ended events for " + v._name);
    ok(v._playingCount > 0, "Should have at least one playing event for " + v._name);
    v._finished = true;
    removeNodeAndListener(v);
    manager.finished(v.token);
  }
}

function startTest(test, token) {
  var v = document.createElement('video');
  v.preload = "auto";
  v.token = token;
  manager.started(token);
  v.src = test.name;
  v._name = test.name;
  v._playedOnce = false;
  v._gotSeekEnded = false;
  v._gotSeekStarted = false;
  v._loadedDataCount = 0;
  v._loadedMetaDataCount = 0;
  v._playingCount = 0;
  v._endCount = 0;
  v._test = test;
  v._finished = false;
  v.addEventListener("loadedmetadata", loadedMetaData);
  v.addEventListener("ended", playbackEnded);
  v.addEventListener("playing", playing);
  v.addEventListener("loadeddata", loadedData);
  v.addEventListener("seeking", seekStarted);
  v.addEventListener("seeked", seekEnded);
  document.body.appendChild(v);
}

manager.runTests(gSmallTests, startTest);

</script>
</pre>
</body>
</html>