[go: up one dir, main page]

Bug 1324548 - Remove dead code and add test to refuse video track. r?padenot draft
authorLéo Paquet
Thu, 02 Nov 2017 17:57:52 +0100
changeset 692158 737fd7ea08139261f917919f1a98eb28f0687278
parent 692157 a94297de3c0f4d4a3fe4c6573994d42b50fde7ef
child 738684 09882eb1df2b22e62c01954c3f83cf4f599118ff
push id87419
push userbmo:leo.paquet@etu.univ-lyon1.fr
push dateThu, 02 Nov 2017 17:01:47 +0000
reviewerspadenot
bugs1324548
milestone58.0a1
Bug 1324548 - Remove dead code and add test to refuse video track. r?padenot MozReview-Commit-ID: 4dGtgzBfN94
dom/media/webaudio/MediaStreamTrackAudioSourceNode.cpp
dom/media/webaudio/MediaStreamTrackAudioSourceNode.h
dom/media/webaudio/test/mochitest.ini
dom/media/webaudio/test/test_mediaStreamTrackAudioSourceNodeVideo.html
--- a/dom/media/webaudio/MediaStreamTrackAudioSourceNode.cpp
+++ b/dom/media/webaudio/MediaStreamTrackAudioSourceNode.cpp
@@ -131,59 +131,16 @@ MediaStreamTrackAudioSourceNode::DetachF
     mInputTrack = nullptr;
   }
   if (mInputPort) {
     mInputPort->Destroy();
     mInputPort = nullptr;
   }
 }
 
-void
-MediaStreamTrackAudioSourceNode::AttachToFirstTrack(const RefPtr<DOMMediaStream>& aMediaStream)
-{
-  nsTArray<RefPtr<AudioStreamTrack>> tracks;
-  aMediaStream->GetAudioTracks(tracks);
-
-  for (const RefPtr<AudioStreamTrack>& track : tracks) {
-    if (track->Ended()) {
-      continue;
-    }
-
-    AttachToTrack(track);
-    MarkActive();
-    return;
-  }
-
-  // There was no track available. We'll allow the node to be garbage collected.
-  MarkInactive();
-}
-
-void
-MediaStreamTrackAudioSourceNode::NotifyTrackAdded(const RefPtr<MediaStreamTrack>& aTrack)
-{
-  if (mInputTrack) {
-    return;
-  }
-
-  if (!aTrack->AsAudioStreamTrack()) {
-    return;
-  }
-
-  AttachToTrack(aTrack);
-}
-
-void
-MediaStreamTrackAudioSourceNode::NotifyTrackRemoved(const RefPtr<MediaStreamTrack>& aTrack)
-{
-  if (aTrack != mInputTrack) {
-    return;
-  }
-
-  DetachFromTrack();
-}
 /**
  * Changes the principal. Note that this will be called on the main thread, but
  * changes will be enacted on the MediaStreamGraph thread. If the principal
  * change results in the document principal losing access to the stream, then
  * there needs to be other measures in place to ensure that any media that is
  * governed by the new stream principal is not available to the MediaStreamGraph
  * before this change completes. Otherwise, a site could get access to
  * media that they are not authorized to receive.
--- a/dom/media/webaudio/MediaStreamTrackAudioSourceNode.h
+++ b/dom/media/webaudio/MediaStreamTrackAudioSourceNode.h
@@ -89,21 +89,16 @@ public:
   size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override;
 
   // Attaches to aTrack so that its audio content will be used as input.
   void AttachToTrack(const RefPtr<MediaStreamTrack>& aTrack);
 
   // Detaches from the currently attached track if there is one.
   void DetachFromTrack();
 
-  // Attaches to the first available audio track in aMediaStream.
-  void AttachToFirstTrack(const RefPtr<DOMMediaStream>& aMediaStream);
-  // From DOMMediaStream::TrackListener.
-  void NotifyTrackAdded(const RefPtr<MediaStreamTrack>& aTrack) override;
-  void NotifyTrackRemoved(const RefPtr<MediaStreamTrack>& aTrack) override;
   // From PrincipalChangeObserver<MediaStreamTrack>.
   void PrincipalChanged(MediaStreamTrack* aMediaStreamTrack) override;
 
 protected:
   explicit MediaStreamTrackAudioSourceNode(AudioContext* aContext);
   void Init(MediaStreamTrack* aMediaStreamTrack, ErrorResult& aRv);
   void Destroy();
   virtual ~MediaStreamTrackAudioSourceNode();
--- a/dom/media/webaudio/test/mochitest.ini
+++ b/dom/media/webaudio/test/mochitest.ini
@@ -167,16 +167,17 @@ skip-if = toolkit == 'android' # bug 114
 [test_mediaStreamAudioSourceNode.html]
 [test_mediaStreamAudioSourceNodeCrossOrigin.html]
 tags=capturestream
 [test_mediaStreamAudioSourceNodeNoGC.html]
 [test_mediaStreamAudioSourceNodePassThrough.html]
 [test_mediaStreamAudioSourceNodeResampling.html]
 tags=capturestream
 [test_mediaStreamTrackAudioSourceNode.html]
+[test_mediaStreamTrackAudioSourceNodeVideo.html]
 [test_mixingRules.html]
 skip-if = toolkit == 'android' # bug 1091965
 [test_nodeToParamConnection.html]
 [test_nodeCreationDocumentGone.html]
 [test_OfflineAudioContext.html]
 [test_offlineDestinationChannelCountLess.html]
 [test_offlineDestinationChannelCountMore.html]
 [test_oscillatorNode.html]
new file mode 100644
--- /dev/null
+++ b/dom/media/webaudio/test/test_mediaStreamTrackAudioSourceNodeVideo.html
@@ -0,0 +1,31 @@
+<!DOCTYPE HTML>
+<html>
+<meta charset="utf-8">
+<head>
+  <title>Test MediaStreamTrackAudioSourceNode throw video track</title>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="/tests/dom/media/webaudio/test/webaudio.js"></script>
+  <script type="text/javascript" src="/tests/dom/media/tests/mochitest/head.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+  createVideoTrack = () => {
+    let c = document.createElement("canvas");
+    c.getContext("2d");
+    return c.captureStream().getTracks()[0];
+  }
+
+  let context = new AudioContext();
+  let track = createVideoTrack();
+
+  expectException(() => {
+    let mediaStreamTrackSource = new MediaStreamTrackAudioSourceNode(
+      context,
+      { mediaStreamTrack: track });
+  }, DOMException.INVALID_STATE_ERR);
+</script>
+</pre>
+</body>
+</html>