Bug 1208328 - Test that "addtrack" and "removetrack" events don't occur on manual operations. r=jib
authorAndreas Pehrson <pehrsons@gmail.com>
Fri, 27 May 2016 18:01:14 +0200
changeset 303630 628f41d0df69133c1f2bde028ed711bf605691a4
parent 303629 0e39947767d4ff214bfd95d8efba78426c3133b1
child 303631 5d8ba0b71eb0f27c2c07ad4ea2d3bcbe7683d1b5
push id79133
push userpehrsons@gmail.com
push dateTue, 05 Jul 2016 09:26:07 +0000
treeherdermozilla-inbound@750df2678990 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjib
bugs1208328
milestone50.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 1208328 - Test that "addtrack" and "removetrack" events don't occur on manual operations. r=jib MozReview-Commit-ID: F3T9upYPlnU
dom/media/tests/mochitest/mochitest.ini
dom/media/tests/mochitest/test_getUserMedia_addtrack_removetrack_events.html
--- a/dom/media/tests/mochitest/mochitest.ini
+++ b/dom/media/tests/mochitest/mochitest.ini
@@ -39,16 +39,17 @@ skip-if = toolkit == 'gonk' || buildapp 
 skip-if = toolkit == 'gonk' || buildapp == 'mulet' # b2g emulator seems to be too slow (Bug 1016498 and 1008080)
 [test_dataChannel_noOffer.html]
 [test_enumerateDevices.html]
 skip-if = buildapp == 'mulet'
 [test_getUserMedia_audioCapture.html]
 skip-if = toolkit == 'gonk' || buildapp == 'mulet' || android_version == '18' # b2g emulator seems to be too slow (Bug 1016498 and 1008080), android(Bug 1189784, timeouts on 4.3 emulator)
 [test_getUserMedia_addTrackRemoveTrack.html]
 skip-if = (toolkit == 'gonk' || buildapp == 'mulet' && debug) # debug-only failure
+[test_getUserMedia_addtrack_removetrack_events.html]
 [test_getUserMedia_basicAudio.html]
 skip-if = (toolkit == 'gonk' || buildapp == 'mulet' && debug) # debug-only failure
 [test_getUserMedia_basicVideo.html]
 skip-if = (toolkit == 'gonk' || buildapp == 'mulet' && debug) # debug-only failure
 [test_getUserMedia_basicVideo_playAfterLoadedmetadata.html]
 skip-if = (toolkit == 'gonk' || buildapp == 'mulet' && debug) # debug-only failure
 [test_getUserMedia_basicScreenshare.html]
 skip-if = buildapp == 'b2g' || toolkit == 'android' # no screenshare on b2g/android # Bug 1141029 Mulet parity with B2G Desktop for TC
new file mode 100644
--- /dev/null
+++ b/dom/media/tests/mochitest/test_getUserMedia_addtrack_removetrack_events.html
@@ -0,0 +1,104 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <script type="application/javascript" src="mediaStreamPlayback.js"></script>
+</head>
+<body>
+<pre id="test">
+<script type="application/javascript">
+"use strict";
+
+createHTML({
+  title: "MediaStream's 'addtrack' and 'removetrack' events shouldn't fire on manual operations",
+  bug: "1208328"
+});
+
+var spinEventLoop = () => new Promise(r => setTimeout(r, 0));
+
+var stream;
+var clone;
+var newStream;
+
+var addTrack = track => {
+  info("Adding track " + track.id);
+  stream.addTrack(track);
+};
+var removeTrack = track => {
+  info("Removing track " + track.id);
+  stream.removeTrack(track);
+};
+var stopTrack = track => {
+  if (track.readyState == "live") {
+    info("Stopping track " + track.id);
+  }
+  track.stop();
+};
+
+runTest(() => getUserMedia({audio: true, video: true})
+  .then(s => {
+    stream = s;
+    clone = s.clone();
+    stream.addEventListener("addtrack", function onAddtrack(event) {
+      ok(false, "addtrack fired unexpectedly for track " + event.track.id);
+    });
+    stream.addEventListener("removetrack", function onRemovetrack(event) {
+      ok(false, "removetrack fired unexpectedly for track " + event.track.id);
+    });
+
+    return getUserMedia({audio: true, video: true});
+  })
+  .then(s => {
+    newStream = s;
+
+    info("Stopping an original track");
+    stopTrack(stream.getTracks()[0]);
+
+    return spinEventLoop();
+  })
+  .then(() => {
+    info("Removing original tracks");
+    stream.getTracks().forEach(t => stream.removeTrack(t));
+
+    return spinEventLoop();
+  })
+  .then(() => {
+    info("Adding other gUM tracks");
+    newStream.getTracks().forEach(t => addTrack(t))
+
+    return spinEventLoop();
+  })
+  .then(() => {
+    info("Adding cloned tracks");
+    let clone = stream.clone();
+    clone.getTracks().forEach(t => addTrack(t));
+
+    return spinEventLoop();
+  })
+  .then(() => {
+    info("Removing a clone");
+    removeTrack(clone.getTracks()[0]);
+
+    return spinEventLoop();
+  })
+  .then(() => {
+    info("Stopping clones");
+    clone.getTracks().forEach(t => stopTrack(t));
+
+    return spinEventLoop();
+  })
+  .then(() => {
+    info("Stopping originals");
+    stream.getTracks().forEach(t => stopTrack(t));
+
+    return spinEventLoop();
+  })
+  .then(() => {
+    info("Removing remaining tracks");
+    stream.getTracks().forEach(t => removeTrack(t));
+
+    return spinEventLoop();
+  }));
+</script>
+</pre>
+</body>
+</html>