Bug 1208316 - Test that a MediaStream becoming active triggers autoplay. r?jib draft bug_1208316
authorAndreas Pehrson <pehrsons@gmail.com>
Wed, 14 Sep 2016 10:11:46 +0200
changeset 432211 1d634c25a135d37654184fada31440bdfac6def0
parent 432210 ab298de858ac460986717d88485189283a441720
child 432213 c06a7195850d88d7fb6fea00134388f4cafc515e
push id34233
push userbmo:pehrson@telenordigital.com
push dateTue, 01 Nov 2016 13:21:40 +0000
reviewersjib
bugs1208316
milestone52.0a1
Bug 1208316 - Test that a MediaStream becoming active triggers autoplay. r?jib MozReview-Commit-ID: 9F3MXiLGrvA
dom/media/tests/mochitest/mochitest.ini
dom/media/tests/mochitest/test_getUserMedia_active_autoplay.html
--- a/dom/media/tests/mochitest/mochitest.ini
+++ b/dom/media/tests/mochitest/mochitest.ini
@@ -36,16 +36,17 @@ skip-if = android_version == '18' # andr
 [test_dataChannel_basicVideo.html]
 skip-if = android_version == '18' # android(Bug 1189784, timeouts on 4.3 emulator)
 [test_dataChannel_bug1013809.html]
 skip-if = android_version == '18' # android(Bug 1189784, timeouts on 4.3 emulator)
 [test_dataChannel_noOffer.html]
 [test_enumerateDevices.html]
 [test_ondevicechange.html]
 skip-if = os == 'android'
+[test_getUserMedia_active_autoplay.html]
 [test_getUserMedia_audioCapture.html]
 skip-if = android_version == '18' # android(Bug 1189784, timeouts on 4.3 emulator)
 [test_getUserMedia_addTrackRemoveTrack.html]
 [test_getUserMedia_addtrack_removetrack_events.html]
 [test_getUserMedia_basicAudio.html]
 [test_getUserMedia_basicVideo.html]
 [test_getUserMedia_basicVideo_playAfterLoadedmetadata.html]
 [test_getUserMedia_basicScreenshare.html]
new file mode 100644
--- /dev/null
+++ b/dom/media/tests/mochitest/test_getUserMedia_active_autoplay.html
@@ -0,0 +1,61 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <script type="application/javascript" src="mediaStreamPlayback.js"></script>
+</head>
+<body>
+<pre id="test">
+<video id="testAutoplay" autoplay></video>
+<script type="application/javascript">
+"use strict";
+
+const video = document.getElementById("testAutoplay");
+var stream;
+var otherVideoTrack;
+var otherAudioTrack;
+
+createHTML({
+  title: "MediaStream can be autoplayed in media element after going inactive and then active",
+  bug: "1208316"
+});
+
+runTest(() => getUserMedia({audio: true, video: true}).then(s => {
+  stream = s;
+  otherVideoTrack = stream.getVideoTracks()[0].clone();
+  otherAudioTrack = stream.getAudioTracks()[0].clone();
+
+  video.srcObject = stream;
+  return haveEvent(video, "playing", wait(5000, new Error("Timeout")));
+})
+.then(() => {
+  ok(!video.ended, "Video element should be playing after adding a gUM stream");
+  stream.getTracks().forEach(t => t.stop());
+  return haveEvent(video, "ended", wait(5000, new Error("Timeout")));
+})
+.then(() => {
+  ok(video.ended, "Video element should be ended");
+  stream.addTrack(otherVideoTrack);
+  return haveEvent(video, "playing", wait(5000, new Error("Timeout")));
+})
+.then(() => {
+  ok(!video.ended, "Video element should be playing after adding a video track");
+  stream.getTracks().forEach(t => t.stop());
+  return haveEvent(video, "ended", wait(5000, new Error("Timeout")));
+})
+.then(() => {
+  ok(video.ended, "Video element should be ended");
+  stream.addTrack(otherAudioTrack);
+  return haveEvent(video, "playing", wait(5000, new Error("Timeout")));
+})
+.then(() => {
+  ok(!video.ended, "Video element should be playing after adding a audio track");
+  stream.getTracks().forEach(t => t.stop());
+  return haveEvent(video, "ended", wait(5000, new Error("Timeout")));
+})
+.then(() => {
+  ok(video.ended, "Video element should be ended");
+}));
+</script>
+</pre>
+</body>
+</html>