summaryrefslogtreecommitdiffstats
path: root/dom/media/test/test_reset_src.html
blob: 0b05eba49aa661d3521fa25b5d8f05aef26f4edd (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
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=804875
-->

<head>
  <title>Test for bug 804875</title>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript" src="manifest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank"
href="https://bugzilla.mozilla.org/show_bug.cgi?id=804875">Mozilla Bug 804875</a>

<canvas></canvas>

<pre id="test">
<script class="testbody" type="text/javascript">

var manager = new MediaTestManager;

function finish(v) {
  removeNodeAndSource(v);
  manager.finished(v.token);
}

function onLoadedData_Audio(e) {
  var t = e.target;
  is(t.videoHeight, 0, t.name + ": videoHeight should be zero when there is no video.");
  is(t.videoWidth, 0, t.name + ": videoWidth should be zero when there is no video.");
  is(t.mozPaintedFrames, 0, t.name + ": mozPaintedFrames should be zero when there is no video.");
  is(t.mozFrameDelay, 0, t.name + ": mozFrameDelay should be zero when there is no video.");
  var c = document.getElementsByTagName("canvas")[0].getContext("2d");
  try {
    c.drawImage(t, 0, 0, t.videoHeight, t.videoWidth);
  } catch (e) {
    ok(true, t.name + ": Trying to draw to a canvas should throw, since we don't have a frame anymore");
    finish(t);
    return;
  }
  ok(false, t.name + ": We should not succeed to draw a video frame on the canvas.");
  finish(t);
}

function onTimeUpdate_Video(e) {
  var t = e.target;
  if (t.currentTime < t.duration / 4) {
    return;
  }
  t.removeEventListener("timeupdate", onTimeUpdate_Video);
  // There's no guarantee that a video frame composite notification reaches
  // us before timeupdate fires.
  ok(t.mozPaintedFrames >= 0, t.name + ": mozPaintedFrames should be positive or zero, is " + t.mozPaintedFrames + ".");
  ok(t.mozFrameDelay >= 0, t.name + ": mozFrameDelay should be positive or zero, is " + t.mozFrameDelay + ".");

  if (t._firstTime) {
    t.src = t.src;
    t._firstTime = false;
  } else {
    var source = getPlayableAudio(gPlayTests);
    if (!source) {
      todo("No audio file available.")
      finish(t);
    } else {
      t.removeEventListener("loadeddata", onLoadedData_Video);
      t.addEventListener("loadeddata", onLoadedData_Audio);
      t.src = source.name;
    }
  }
}

function onLoadedData_Video(e) {
  var t = e.target;
  isnot(t.videoHeight, 0, t.name + ": We should have a videoHeight.");
  isnot(t.videoWidth, 0, t.name + ": We should have a videoWidth.");
  t.addEventListener("timeupdate", onTimeUpdate_Video);
  t.play();
}

function startTest(test, token) {
  var v = document.createElement('video');
  document.body.appendChild(v);
  v._firstTime = true;
  v.addEventListener("loadeddata", onLoadedData_Video);
  v.src = test.name;
  v.token = token;
  v.name = test.name;
  v.play();
  manager.started(token);
}

manager.runTests(getPlayableVideos(gSmallTests.concat(gSeekTests)), startTest);
</script>
</pre>
</body>
</html>