summaryrefslogtreecommitdiffstats
path: root/dom/media/test/test_bug879717.html
blob: 37c9a402ad73286041b3890663bfe2a8b5b4522b (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
124
125
126
127
128
129
130
131
132
133
134
<!DOCTYPE HTML>
<html>
<head>
  <title>Test for bug 879717, check that a video element can be drawn into a canvas at various states of playback</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(1.5);
}

var manager = new MediaTestManager;

var canvas = document.createElement('canvas');
document.body.appendChild(canvas);

var checkDrawImage = function(eventName, videoElement) {
  var exception = null;
  var exceptionName = "nothing";
  try {
    var ctx = canvas.getContext('2d');
    ctx.drawImage(videoElement, 0, 0, canvas.width, canvas.height);
  } catch (e) {
    exception = e;
    exceptionName = e.name;
  }
  ok(exception === null,
    "drawImage shouldn't throw an exception on " + eventName +
    " of " + videoElement.testName + ", got " + exceptionName);
};

var checkDrawImageEventHandler = function(ev) {
  checkDrawImage(ev.type, ev.target);
};
var startTest = function(media, token) {
  manager.started(token);

  // File playback
  var v1 = document.createElement("video");
  v1.autoplay = true;

  // Captured file playback
  var v2 = document.createElement("video");

  // Stream playback
  var v3 = document.createElement("video");
  v3.autoplay = true;

  v1.gotLoadeddata = false;
  v2.gotLoadeddata = false;
  v3.gotLoadeddata = false;

  v1.testName = "v1 (" + media.name + ")";
  v2.testName = "v2 (Captured " + media.name + ")";
  v3.testName = "v3 (Stream of " + media.name + ")";

  checkDrawImage("beforeplay", v1);
  checkDrawImage("beforeplay", v2);
  checkDrawImage("beforeplay", v3);

  v1.onloadedmetadata = checkDrawImageEventHandler;
  v2.onloadedmetadata = checkDrawImageEventHandler;
  v3.onloadedmetadata = checkDrawImageEventHandler;

  v1.onplay = checkDrawImageEventHandler;
  v2.onplay = checkDrawImageEventHandler;
  v3.onplay = checkDrawImageEventHandler;

  function onplaying(ev) {
    if (!ev.target.gotPlaying) {
      ev.target.gotPlaying = true;
      checkDrawImageEventHandler(ev);
    }
  }
  v1.onplaying = onplaying;
  v2.onplaying = onplaying;
  v3.onplaying = onplaying;

  var onloadeddata = function(ev) {
    ev.target.gotLoadeddata = true;
    checkDrawImageEventHandler(ev);
  };

  v1.onloadeddata = onloadeddata;
  v2.onloadeddata = onloadeddata;
  v3.onloadeddata = onloadeddata;

  var checkFinished = function() {
    if (!v1.testFinished || !v2.testFinished || !v3.testFinished) {
      return;
    }

    ok(v1.gotLoadeddata, v1.testName + " should have gotten the 'loadeddata' event callback");
    ok(v2.gotLoadeddata, v2.testName + " should have gotten the 'loadeddata' event callback");
    ok(v3.gotLoadeddata, v3.testName + " should have gotten the 'loadeddata' event callback");

    manager.finished(token);
  };

  var onended = function(ev) {
    checkDrawImageEventHandler(ev);
    removeNodeAndSource(ev.target);
    ev.target.testFinished = true;
    checkFinished();
  };

  v1.onended = onended;
  v2.onended = onended;
  v3.onended = onended;

  document.body.appendChild(v1);
  document.body.appendChild(v2);
  document.body.appendChild(v3);

  v1.src = media.name;
  v2.src = media.name;
  v2.preload = 'metadata';

  v2.addEventListener('loadedmetadata', function () {
    v3.srcObject = v2.mozCaptureStreamUntilEnded();
    v2.play();
  });
}

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