Bug 1436341 - Fix assertion for when a device operation fails. r?jib draft
authorAndreas Pehrson <pehrsons@gmail.com>
Wed, 07 Mar 2018 12:42:58 +0100
changeset 764303 7ce006e2c57848b5fda7c422dd77c26308bcdd78
parent 764220 f3bd629bbf7352f8a2e960ff3616b633a3025eb0
push id101727
push userbmo:apehrson@mozilla.com
push dateWed, 07 Mar 2018 16:29:27 +0000
reviewersjib
bugs1436341, 1299515
milestone60.0a1
Bug 1436341 - Fix assertion for when a device operation fails. r?jib The previous assertion was from an earlier developer stage which changed during development of bug 1299515. It assumed that mDeviceEnabled was updated only after passing the assert. In the final version of bug 1299515 that is no longer true, and both the failed and the successful device operation asserts can now be unified to one. MozReview-Commit-ID: KMdnIs0UgPr
dom/media/MediaManager.cpp
--- a/dom/media/MediaManager.cpp
+++ b/dom/media/MediaManager.cpp
@@ -4096,16 +4096,18 @@ SourceListener::SetEnabledFor(TrackID aT
           (MozPromiseHolder<DeviceOperationPromise>& h) {
             h.Resolve(aEnable ? device->Start() : device->Stop(), __func__);
           });
     }, []() {
       // Timer was canceled by us. We signal this with NS_ERROR_ABORT.
       return DeviceOperationPromise::CreateAndResolve(NS_ERROR_ABORT, __func__);
     })->Then(GetMainThreadSerialEventTarget(), __func__,
     [self, this, &state, aTrackID, aEnable](nsresult aResult) mutable {
+      MOZ_ASSERT_IF(aResult != NS_ERROR_ABORT,
+                    state.mDeviceEnabled == aEnable);
       MOZ_ASSERT(state.mOperationInProgress);
       state.mOperationInProgress = false;
 
       if (state.mStopped) {
         // Device was stopped on main thread during the operation. Nothing to do.
         return;
       }
 
@@ -4115,19 +4117,16 @@ SourceListener::SetEnabledFor(TrackID aT
            aTrackID == kAudioTrack ? "audio" : "video",
            aTrackID,
            NS_SUCCEEDED(aResult) ? "succeeded" : "failed"));
 
       if (NS_FAILED(aResult) && aResult != NS_ERROR_ABORT) {
         // This path handles errors from starting or stopping the device.
         // NS_ERROR_ABORT are for cases where *we* aborted. They need graceful
         // handling.
-        MOZ_ASSERT(state.mDeviceEnabled != aEnable,
-                   "If operating the device failed, the device's `enabled` "
-                   "state must remain at its old value");
         if (aEnable) {
           // Starting the device failed. Stopping the track here will make the
           // MediaStreamTrack end after a pass through the MediaStreamGraph.
           StopTrack(aTrackID);
         } else {
           // Stopping the device failed. This is odd, but not fatal.
           MOZ_ASSERT_UNREACHABLE("The device should be stoppable");
 
@@ -4137,17 +4136,16 @@ SourceListener::SetEnabledFor(TrackID aT
         }
         return;
       }
 
       // This path is for a device operation aResult that was success or
       // NS_ERROR_ABORT (*we* canceled the operation).
       // At this point we have to follow up on the intended state, i.e., update
       // the device state if the track state changed in the meantime.
-      MOZ_ASSERT_IF(NS_SUCCEEDED(aResult), state.mDeviceEnabled == aEnable);
 
       if (state.mTrackEnabled == state.mDeviceEnabled) {
         // Intended state is same as device's current state.
         // Nothing more to do.
         return;
       }
 
       // Track state changed during this operation. We'll start over.