Bug 1161433: reject empty gUM contraints with NotSupportedError. r=jib
authorNils Ohlmeier [:drno] <drno@ohlmeier.org>
Fri, 08 May 2015 12:05:48 -0700
changeset 243051 bf588f714b314e5bfe3cff35cb0788a71c3e2250
parent 243050 3d43ed34435515e4fd18937281f882bd8f4a431a
child 243052 8b2364aef0dd5912953cc4bbf43d7eaf2c9fd358
push id59572
push userdrno@ohlmeier.org
push dateFri, 08 May 2015 19:07:16 +0000
treeherdermozilla-inbound@bf588f714b31 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjib
bugs1161433
milestone40.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 1161433: reject empty gUM contraints with NotSupportedError. r=jib
dom/media/MediaManager.cpp
dom/media/MediaStreamError.cpp
dom/media/tests/mochitest/test_getUserMedia_constraints.html
--- a/dom/media/MediaManager.cpp
+++ b/dom/media/MediaManager.cpp
@@ -1348,16 +1348,21 @@ public:
     return NS_OK;
   }
 
   nsresult
   SelectDevice(MediaEngine* backend)
   {
     MOZ_ASSERT(mOnSuccess);
     MOZ_ASSERT(mOnFailure);
+
+    if (!IsOn(mConstraints.mVideo) && !IsOn(mConstraints.mAudio)) {
+      Fail(NS_LITERAL_STRING("NotSupportedError"));
+      return NS_ERROR_FAILURE;
+    }
     if (IsOn(mConstraints.mVideo)) {
       nsTArray<nsRefPtr<VideoDevice>> sources;
       GetSources(backend, GetInvariant(mConstraints.mVideo),
                  &MediaEngine::EnumerateVideoDevices, sources);
       if (!sources.Length()) {
         Fail(NS_LITERAL_STRING("NotFoundError"));
         return NS_ERROR_FAILURE;
       }
@@ -1373,16 +1378,21 @@ public:
         Fail(NS_LITERAL_STRING("NotFoundError"));
         return NS_ERROR_FAILURE;
       }
       // Pick the first available device.
       mAudioDevice = sources[0];
       LOG(("Selected audio device"));
     }
 
+    if (!mAudioDevice && !mVideoDevice) {
+      Fail(NS_LITERAL_STRING("NotFoundError"));
+      return NS_ERROR_FAILURE;
+    }
+
     return NS_OK;
   }
 
   /**
    * Allocates a video or audio device and returns a MediaStream via
    * a GetUserMediaStreamRunnable. Runs off the main thread.
    */
   void
--- a/dom/media/MediaStreamError.cpp
+++ b/dom/media/MediaStreamError.cpp
@@ -22,16 +22,19 @@ BaseMediaMgrError::BaseMediaMgrError(con
       mMessage.AssignLiteral("The object can not be found here.");
     } else if (mName.EqualsLiteral("PermissionDeniedError")) {
       mMessage.AssignLiteral("The user did not grant permission for the operation.");
     } else if (mName.EqualsLiteral("SourceUnavailableError")) {
       mMessage.AssignLiteral("The source of the MediaStream could not be "
           "accessed due to a hardware error (e.g. lock from another process).");
     } else if (mName.EqualsLiteral("InternalError")) {
       mMessage.AssignLiteral("Internal error.");
+    } else if (mName.EqualsLiteral("NotSupportedError")) {
+      mMessage.AssignLiteral("Constraints with no audio or video in it are not "
+          "supported");
     }
   }
 }
 
 
 NS_IMPL_ISUPPORTS0(MediaMgrError)
 
 namespace dom {
--- a/dom/media/tests/mochitest/test_getUserMedia_constraints.html
+++ b/dom/media/tests/mochitest/test_getUserMedia_constraints.html
@@ -45,16 +45,19 @@ var tests = [
     constraints: { video: { mediaSource: 'window' } },
     error: "PermissionDeniedError" },
   { message: "browser screensharing requires permission",
     constraints: { video: { mediaSource: 'browser' } },
     error: "PermissionDeniedError" },
   { message: "unknown mediaSource fails",
     constraints: { video: { mediaSource: 'uncle' } },
     error: "NotFoundError" },
+  { message: "emtpy constraint fails",
+    constraints: { },
+    error: "NotSupportedError" },
   { message: "Success-path: optional video facingMode + audio ignoring facingMode",
     constraints: { fake: true,
                    audio: { mediaSource: 'microphone',
                             facingMode: 'left',
                             foo: 0,
                             advanced: [{ facingMode: 'environment' },
                                        { facingMode: 'user' },
                                        { bar: 0 }] },