Bug 1281866 - Test gUM's NotReadableError. r=padenot
authorJan-Ivar Bruaroey <jib@mozilla.com>
Mon, 27 Jun 2016 10:59:37 -0400
changeset 302740 3f8b0c4ea602904ba3eb7593aa34f9f795b28a4a
parent 302739 e5a344d0bcd8dffee9254cff438681688bae69e8
child 302741 53a8197a49ebde73d7898717a8dd272196791b77
push id78852
push userjbruaroey@mozilla.com
push dateMon, 27 Jun 2016 18:31:29 +0000
treeherdermozilla-inbound@3f8b0c4ea602 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot
bugs1281866
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 1281866 - Test gUM's NotReadableError. r=padenot MozReview-Commit-ID: UrMmhTFvrc
dom/media/tests/mochitest/test_getUserMedia_constraints.html
dom/media/webrtc/MediaEngineDefault.cpp
--- a/dom/media/tests/mochitest/test_getUserMedia_constraints.html
+++ b/dom/media/tests/mochitest/test_getUserMedia_constraints.html
@@ -42,16 +42,22 @@ var tests = [
     constraint: "mediaSource" },
   { message: "unknown mediaSource in audio fails",
     constraints: { audio: { mediaSource: 'uncle' } },
     error: "OverconstrainedError",
     constraint: "mediaSource" },
   { message: "emtpy constraint fails",
     constraints: { },
     error: "NotSupportedError" },
+  { message: "Triggering mock failure in default video device fails",
+    constraints: { video: { deviceId: 'bad device' }, fake: true },
+    error: "NotReadableError" },
+  { message: "Triggering mock failure in default audio device fails",
+    constraints: { audio: { deviceId: 'bad device' }, fake: true },
+    error: "NotReadableError" },
   { message: "Success-path: optional video facingMode + audio ignoring facingMode",
     constraints: { audio: { mediaSource: 'microphone',
                             facingMode: 'left',
                             foo: 0,
                             advanced: [{ facingMode: 'environment' },
                                        { facingMode: 'user' },
                                        { bar: 0 }] },
                    video: { mediaSource: 'camera',
--- a/dom/media/webrtc/MediaEngineDefault.cpp
+++ b/dom/media/webrtc/MediaEngineDefault.cpp
@@ -90,16 +90,22 @@ MediaEngineDefaultVideoSource::Allocate(
                                         const MediaEnginePrefs &aPrefs,
                                         const nsString& aDeviceId,
                                         const nsACString& aOrigin)
 {
   if (mState != kReleased) {
     return NS_ERROR_FAILURE;
   }
 
+  // Mock failure for automated tests.
+  if (aConstraints.mDeviceId.IsString() &&
+      aConstraints.mDeviceId.GetAsString().EqualsASCII("bad device")) {
+    return NS_ERROR_FAILURE;
+  }
+
   mOpts = aPrefs;
   mOpts.mWidth = mOpts.mWidth ? mOpts.mWidth : MediaEngine::DEFAULT_43_VIDEO_WIDTH;
   mOpts.mHeight = mOpts.mHeight ? mOpts.mHeight : MediaEngine::DEFAULT_43_VIDEO_HEIGHT;
   mState = kAllocated;
   return NS_OK;
 }
 
 nsresult
@@ -403,16 +409,22 @@ MediaEngineDefaultAudioSource::Allocate(
                                         const MediaEnginePrefs &aPrefs,
                                         const nsString& aDeviceId,
                                         const nsACString& aOrigin)
 {
   if (mState != kReleased) {
     return NS_ERROR_FAILURE;
   }
 
+  // Mock failure for automated tests.
+  if (aConstraints.mDeviceId.IsString() &&
+      aConstraints.mDeviceId.GetAsString().EqualsASCII("bad device")) {
+    return NS_ERROR_FAILURE;
+  }
+
   mState = kAllocated;
   // generate sine wave (default 1KHz)
   mSineGenerator = new SineWaveGenerator(AUDIO_RATE,
                                          static_cast<uint32_t>(aPrefs.mFreq ? aPrefs.mFreq : 1000));
   return NS_OK;
 }
 
 nsresult