dom/media/test/test_playback.html
author Sandor Molnar <smolnar@mozilla.com>
Wed, 16 Jul 2025 08:01:46 +0300 (5 hours ago)
changeset 796723 8b0d004a4d3f03394d1e7072f95d95a65415a0dc
parent 697969 7c42528aa6cc2ff958fdf7831f2e219e6217dc80
permissions -rw-r--r--
Revert "Bug 1976137: apply code formatting via Lando" for causing build bustages @ Platform.cpp This reverts commit a2bbd0d672396015e05d323e236619a39b34570a. Revert "Bug 1976137 part 4: Remove DocAccessibleChild overrides of SendCaretMoveEvent and SendFocusEvent. r=eeejay" This reverts commit 102a35ed28b8cc8f3ed069ba46e8e1949a6348bf. Revert "Bug 1976137 part 3: Remove aCaretRect argument from PlatformCaretMoveEvent and PlatformFocusEvent. r=eeejay" This reverts commit b46aa6464fceaab0d48edada247983c6879e0c74. Revert "Bug 1976137 part 2: Move UpdateSystemCaretFor to Platform.cpp. r=eeejay" This reverts commit 21f1cfda868038cb85a01c45512699f4812b9045. Revert "Bug 1976137 part 1: Unify Windows AccessibleWrap::UpdateSystemCaretFor. r=eeejay" This reverts commit 05970d567b067b63a45659f56dd77d9190e5e7f7.
<!DOCTYPE HTML>
<html>
<head>
  <title>Test playback of media files that should play OK</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>
<pre id="test">
<script class="testbody" type="text/javascript">

var manager = new MediaTestManager;

function startTest(test, token) {
  var video = document.createElement('video');
  video.preload = "metadata";
  video.token = token;
  video.prevTime = 0;
  video.seenEnded = false;
  video.seenSuspend = false;

  var handler = {
    "ontimeout": function() {
      Log(token, "timed out: ended=" + video.seenEnded + ", suspend=" + video.seenSuspend);
    }
  };
  manager.started(token, handler);

  video.src = test.name;
  video.name = test.name;

  var check = function(t, v) { return function() {
    is(t.name, v.name, t.name + ": Name should match #1");
    checkMetadata(t.name, v, t);
  }}(test, video);

  var noLoad = function(t) { return function() {
    ok(false, t.name + " should not fire 'load' event");
  }}(test, video);

  var noError = function(t, v) { return function() {
    ok(false, t.name + " should not fire 'error' event " + v.error.message);
  }}(test, video);

  var finish = function() {
    video.finished = true;
    video.removeEventListener("timeupdate", timeUpdate);
    removeNodeAndSource(video);
    manager.finished(video.token);
  }

  // We should get "ended" and "suspend" events to finish the test.
  var mayFinish = function() {
    if (video.seenEnded && video.seenSuspend) {
      finish();
    }
  }

  var checkEnded = function(t, v) { return function() {
    is(t.name, v.name, t.name + ": Name should match #2");
    checkMetadata(t.name, v, test);
    is(v.readyState, v.HAVE_CURRENT_DATA, t.name + " checking readyState");
    ok(v.ended, t.name + " checking playback has ended");
    ok(!v.finished, t.name + " shouldn't be finished");
    ok(!v.seenEnded, t.name + " shouldn't be ended");

    v.seenEnded = true;
    mayFinish();
  }}(test, video);

  var checkSuspended = function(t, v) { return function() {
    if (v.seenSuspend) {
      return;
    }
    is(t.name, v.name, t.name + ": Name should match #3");

    v.seenSuspend = true;
    mayFinish();
  }}(test, video);

  var timeUpdate = function(t, v) { return function() {
    if (v.prevTime > v.currentTime) {
      ok(false, t.name + " time should run forwards: p=" +
                v.prevTime + " c=" + v.currentTime);
    }
    v.prevTime = v.currentTime;
  }}(test, video);

  video.addEventListener("load", noLoad);
  video.addEventListener("error", noError);
  video.addEventListener("loadedmetadata", check);
  video.addEventListener("timeupdate", timeUpdate);

  // We should get "ended" and "suspend" events for every resource
  video.addEventListener("ended", checkEnded);
  video.addEventListener("suspend", checkSuspended);

  document.body.appendChild(video);
  video.play();
}

manager.runTests(gPlayTests, startTest);

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