Bug 1495935 [wpt PR 13321] - Include ended tracks when cloning MediaStreams., a=testonly
authorGuido Urdaneta <guidou@chromium.org>
Tue, 09 Oct 2018 04:13:43 +0000
changeset 495945 32e2bba388814b034c661c290e561e51efc31f5a
parent 495944 bb8a619658078f2cdc43c964d4779b5b5b6aeb33
child 495946 fedfac60200e8e25d08f1bec463b62589d8d4d53
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1495935, 13321, 770908, 1256796, 596247
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1495935 [wpt PR 13321] - Include ended tracks when cloning MediaStreams., a=testonly Automatic update from web-platform-testsInclude ended tracks when cloning MediaStreams. This CL also covers the MediaStream constructor. In addition, tests are moved to WPT. Bug: 770908 Change-Id: I6db9a86e9ee839efc2b04b00ae8fc57f07d852c3 Reviewed-on: https://chromium-review.googlesource.com/c/1256796 Commit-Queue: Guido Urdaneta <guidou@chromium.org> Reviewed-by: Harald Alvestrand <hta@chromium.org> Cr-Commit-Position: refs/heads/master@{#596247} -- wpt-commits: 425430423cbe2cc78a34b2e4732a0d4361052219 wpt-pr: 13321
testing/web-platform/tests/mediacapture-streams/MediaStream-clone.https.html
testing/web-platform/tests/mediacapture-streams/MediaStream-idl.https.html
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/mediacapture-streams/MediaStream-clone.https.html
@@ -0,0 +1,94 @@
+<!doctype html>
+<html>
+<head>
+<title>MediaStream and MediaStreamTrack clone()</title>
+<link rel="help" href="https://w3c.github.io/mediacapture-main/#dom-mediastream-clone">
+<link rel="help" href="https://w3c.github.io/mediacapture-main/#dom-mediastreamtrack-clone">
+</head>
+<body>
+<p class="instructions">When prompted, accept to give permission to use your audio and video devices.</p>
+<h1 class="instructions">Description</h1>
+<p class="instructions">This test checks that cloning MediaStreams and MediaStreamTracks works as expected.</p>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<script>
+
+promise_test(async t => {
+  const stream = await navigator.mediaDevices.getUserMedia({video: true, audio: true});
+  assert_equals(stream.getAudioTracks().length, 1);
+  assert_equals(stream.getVideoTracks().length, 1);
+
+  const clone1 = stream.clone();
+  assert_equals(clone1.getAudioTracks().length, 1);
+  assert_equals(clone1.getVideoTracks().length, 1);
+  assert_not_equals(stream.getAudioTracks()[0].id, clone1.getAudioTracks()[0].id);
+  assert_not_equals(stream.getVideoTracks()[0].id, clone1.getVideoTracks()[0].id);
+
+  stream.getTracks().forEach(track => track.stop());
+  assert_false(stream.active);
+  assert_equals(stream.getAudioTracks()[0].readyState, "ended");
+  assert_equals(stream.getVideoTracks()[0].readyState, "ended");
+  assert_true(clone1.active);
+  assert_equals(clone1.getAudioTracks()[0].readyState, "live");
+  assert_equals(clone1.getVideoTracks()[0].readyState, "live");
+
+  clone1.getAudioTracks()[0].stop();
+  assert_true(clone1.active);
+  assert_equals(clone1.getAudioTracks()[0].readyState, "ended");
+  assert_equals(clone1.getVideoTracks()[0].readyState, "live");
+
+  const clone2 = clone1.clone();
+  assert_true(clone2.active);
+  assert_equals(clone2.getAudioTracks()[0].readyState, "ended");
+  assert_equals(clone2.getVideoTracks()[0].readyState, "live");
+
+  clone1.getVideoTracks()[0].stop();
+  clone2.getVideoTracks()[0].stop();
+
+  const clone3 = clone2.clone();
+  assert_false(clone3.active);
+  assert_equals(clone3.getAudioTracks()[0].readyState, "ended");
+  assert_equals(clone3.getVideoTracks()[0].readyState, "ended");
+  assert_not_equals(clone1.getAudioTracks()[0].id, clone2.getAudioTracks()[0].id);
+  assert_not_equals(clone1.getVideoTracks()[0].id, clone2.getVideoTracks()[0].id);
+  assert_not_equals(clone2.getAudioTracks()[0].id, clone3.getAudioTracks()[0].id);
+  assert_not_equals(clone2.getVideoTracks()[0].id, clone3.getVideoTracks()[0].id);
+  assert_not_equals(clone1.getAudioTracks()[0].id, clone3.getAudioTracks()[0].id);
+  assert_not_equals(clone1.getVideoTracks()[0].id, clone3.getVideoTracks()[0].id);
+}, "Tests that cloning MediaStream objects works as expected");
+
+promise_test(async t => {
+  const stream = await navigator.mediaDevices.getUserMedia({video: true, audio: true});
+  assert_equals(stream.getAudioTracks().length, 1);
+  assert_equals(stream.getVideoTracks().length, 1);
+  assert_equals(stream.getAudioTracks()[0].readyState, "live");
+  assert_equals(stream.getVideoTracks()[0].readyState, "live");
+  assert_true(stream.active);
+
+  const audio_clone = stream.getAudioTracks()[0].clone();
+  const video_clone = stream.getVideoTracks()[0].clone();
+  assert_equals(audio_clone.readyState, "live");
+  assert_equals(video_clone.readyState, "live");
+  assert_not_equals(stream.getAudioTracks()[0].id, audio_clone.id);
+  assert_not_equals(stream.getVideoTracks()[0].id, video_clone.id);
+
+  stream.getTracks().forEach(track => track.stop());
+  assert_false(stream.active);
+  assert_equals(stream.getAudioTracks()[0].readyState, "ended");
+  assert_equals(stream.getVideoTracks()[0].readyState, "ended");
+  assert_equals(audio_clone.readyState, "live");
+  assert_equals(video_clone.readyState, "live");
+
+  stream.addTrack(audio_clone);
+  stream.addTrack(video_clone);
+  assert_true(stream.active);
+
+  stream.getTracks().forEach(track => track.stop());
+  assert_false(stream.active);
+  assert_equals(audio_clone.readyState, "ended");
+  assert_equals(video_clone.readyState, "ended");
+}, "Tests that cloning MediaStreamTrack objects works as expected");
+
+</script>
+</body>
+</html>
--- a/testing/web-platform/tests/mediacapture-streams/MediaStream-idl.https.html
+++ b/testing/web-platform/tests/mediacapture-streams/MediaStream-idl.https.html
@@ -15,44 +15,53 @@
 <h1 class="instructions">Description</h1>
 <p class="instructions">This test checks that the MediaStream constructor
 follows the algorithm set in the spec.</p>
 
 <div id='log'></div>
 <script src=/resources/testharness.js></script>
 <script src=/resources/testharnessreport.js></script>
 <script>
-var t = async_test("Tests that a MediaStream constructor follows the algorithm set in the spec", {timeout: 10000});
-t.step(function() {
+let t = async_test("Tests that a MediaStream constructor follows the algorithm set in the spec", {timeout: 10000});
+t.step(() => {
   navigator.mediaDevices.getUserMedia({video: true, audio:true})
-    .then(t.step_func(function (stream) {
-      var stream1 = new MediaStream();
+    .then(t.step_func(stream => {
+      let stream1 = new MediaStream();
       assert_not_equals(stream.id, stream1.id, "Two different MediaStreams have different ids");
-      var stream2 = new MediaStream(stream);
-      assert_not_equals(stream.id, stream2.id, "A MediaStream constructed from another have different ids");
-      var audioTrack1 = stream.getAudioTracks()[0];
-      var videoTrack = stream.getVideoTracks()[0];
-      assert_equals(audioTrack1, stream2.getAudioTracks()[0], "A MediaStream constructed from another share the same audio track");
-      assert_equals(videoTrack, stream2.getVideoTracks()[0], "A MediaStream constructed from another share the same video track");
-      var stream4 = new MediaStream([audioTrack1]);
+      let stream2 = new MediaStream(stream);
+      assert_not_equals(stream.id, stream2.id, "A MediaStream constructed from another has a different id");
+      let audioTrack1 = stream.getAudioTracks()[0];
+      let videoTrack = stream.getVideoTracks()[0];
+      assert_equals(audioTrack1, stream2.getAudioTracks()[0], "A MediaStream constructed from another shares the same audio track");
+      assert_equals(videoTrack, stream2.getVideoTracks()[0], "A MediaStream constructed from another shares the same video track");
+      let stream4 = new MediaStream([audioTrack1]);
       assert_equals(stream4.getTrackById(audioTrack1.id), audioTrack1, "a non-ended track gets added via the MediaStream constructor");
 
-      var audioTrack2 = audioTrack1.clone();
+      let audioTrack2 = audioTrack1.clone();
       audioTrack2.addEventListener("ended", t.unreached_func("ended event should not be fired by MediaStreamTrack.stop()."));
       audioTrack2.stop();
       assert_equals(audioTrack2.readyState, "ended", "a stopped track is marked ended synchronously");
 
-      var stream3 = new MediaStream([audioTrack2, videoTrack]);
+      let stream3 = new MediaStream([audioTrack2, videoTrack]);
       assert_equals(stream3.getTrackById(audioTrack2.id), audioTrack2, "an ended track gets added via the MediaStream constructor");
       assert_equals(stream3.getTrackById(videoTrack.id), videoTrack, "a non-ended track gets added via the MediaStream constructor even if the previous track was ended");
 
-      var stream5 = new MediaStream([audioTrack2]);
+      let stream5 = new MediaStream([audioTrack2]);
       assert_equals(stream5.getTrackById(audioTrack2.id), audioTrack2, "an ended track gets added via the MediaStream constructor");
       assert_false(stream5.active, "a MediaStream created using the MediaStream() constructor whose arguments are lists of MediaStreamTrack objects that are all ended, the MediaStream object MUST be created with its active attribute set to false");
 
-      // Use a timeout to detect a misfire of the ended event.
-      t.step_timeout(t.step_func_done());
+      stream.oninactive = t.step_func(() => {
+        assert_false(stream.active);
+        stream.getTracks().forEach(track => {
+          assert_equals(track.readyState, "ended");
+        });
+        // Use a timeout to detect a misfire of the ended event.
+        t.step_timeout(t.step_func_done());
+      });
+
+      audioTrack1.stop();
+      videoTrack.stop();
     })
   );
 });
 </script>
 </body>
 </html>