summaryrefslogtreecommitdiffstats
path: root/dom/media/test/test_playback.html
blob: 2df6df85f17dfebce6a363eb30199c71656ef5ba (plain)
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
121
122
123
<!DOCTYPE HTML>
<html>
<head>
  <title>Test playback of media files that should play OK</title>
  <script type="text/javascript" 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">

// longer timeout for slow platforms
if (isSlowPlatform()) {
  SimpleTest.requestLongerTimeout(3);
  SimpleTest.requestCompleteLog();
}

var manager = new MediaTestManager;

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

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

  v.src = test.name;
  v.name = test.name;

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

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

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

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

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

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

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

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

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

  v.addEventListener("load", noLoad, false);
  v.addEventListener("loadedmetadata", check, false);
  v.addEventListener("timeupdate", timeUpdate, false);

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

  document.body.appendChild(v);
  v.play();

  // Debug timeouts on slow platforms.
  if (isSlowPlatform()) {
    var events = ["suspend", "play", "canplay", "canplaythrough", "loadstart", "loadedmetadata",
                  "loadeddata", "playing", "ended", "error", "stalled", "emptied", "abort",
                  "waiting", "pause"];
    function logEvent(e) {
      var v = e.target;
      Log(e.target.token, "got " + e.type);
    }
    events.forEach(function(e) {
      v.addEventListener(e, logEvent, false);
    });
  }
}

manager.runTests(gPlayTests, startTest);

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