Commit b679ffdc authored by Marina Ciocea's avatar Marina Ciocea Committed by Commit Bot

[MediaStreamDeviceObserver] Reset the receiver before Bind().

Reset the receiver before Bind(), in case it was already bound, to avoid
running into Bind()'s internal DCHECK that expects the receiver to not
be bound.

Also add a test verifying that OnDeviceChanged() behaves as expected
after rebind.

Bug: 1093728
Change-Id: Ic964902d3f3af3e3c6963633c13b069ecb344d96
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2250040Reviewed-by: default avatarGuido Urdaneta <guidou@chromium.org>
Commit-Queue: Marina Ciocea <marinaciocea@chromium.org>
Cr-Commit-Position: refs/heads/master@{#779731}
parent 6f1093f9
......@@ -132,6 +132,7 @@ void MediaStreamDeviceObserver::OnDeviceChanged(
void MediaStreamDeviceObserver::BindMediaStreamDeviceObserverReceiver(
mojo::PendingReceiver<mojom::blink::MediaStreamDeviceObserver> receiver) {
receiver_.reset();
receiver_.Bind(std::move(receiver));
}
......
......@@ -64,6 +64,8 @@ class MODULES_EXPORT MediaStreamDeviceObserver
GetNonScreenCaptureDevices);
FRIEND_TEST_ALL_PREFIXES(MediaStreamDeviceObserverTest, OnDeviceStopped);
FRIEND_TEST_ALL_PREFIXES(MediaStreamDeviceObserverTest, OnDeviceChanged);
FRIEND_TEST_ALL_PREFIXES(MediaStreamDeviceObserverTest,
OnDeviceChangedChangesDeviceAfterRebind);
// Private class for keeping track of opened devices and who have
// opened it.
......
......@@ -11,8 +11,10 @@
#include "base/bind.h"
#include "base/run_loop.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/mediastream/media_stream_request.h"
#include "third_party/blink/public/mojom/mediastream/media_stream.mojom-blink.h"
#include "third_party/blink/renderer/modules/mediastream/mock_mojo_media_stream_dispatcher_host.h"
namespace blink {
......@@ -157,4 +159,49 @@ TEST_F(MediaStreamDeviceObserverTest, OnDeviceChanged) {
EXPECT_EQ(observer_->label_stream_map_.size(), 0u);
}
TEST_F(MediaStreamDeviceObserverTest, OnDeviceChangedChangesDeviceAfterRebind) {
const String kStreamLabel = "stream_label";
const std::string kDeviceName = "Video Device";
const blink::mojom::MediaStreamType kDeviceType =
blink::mojom::MediaStreamType::DEVICE_VIDEO_CAPTURE;
// Add a device to the |observer_|, to be changed using OnChangedDevice().
blink::MediaStreamDevice initial_device(kDeviceType, "initial_device",
kDeviceName);
observer_->AddStream(kStreamLabel, initial_device);
// Call the |observer_|'s bind callback and check that its internal
// |receiver_| is bound.
mojo::Remote<mojom::blink::MediaStreamDeviceObserver> remote_observer;
EXPECT_FALSE(observer_->receiver_.is_bound());
observer_->BindMediaStreamDeviceObserverReceiver(
remote_observer.BindNewPipeAndPassReceiver());
EXPECT_TRUE(observer_->receiver_.is_bound());
// Send an OnDeviceChanged() message using the remote mojo pipe, and verify
// that the device is changed.
blink::MediaStreamDevice changed_device =
blink::MediaStreamDevice(kDeviceType, "video_device-123", kDeviceName);
remote_observer->OnDeviceChanged(kStreamLabel, initial_device,
changed_device);
base::RunLoop().RunUntilIdle();
blink::MediaStreamDevices video_devices =
observer_->GetNonScreenCaptureDevices();
ASSERT_EQ(video_devices.size(), 1u);
EXPECT_EQ(video_devices[0].id, "video_device-123");
// Reset the remote end of the mojo pipe, then rebind it, and verify that
// OnDeviceChanged() changes the device after rebind.
remote_observer.reset();
observer_->BindMediaStreamDeviceObserverReceiver(
remote_observer.BindNewPipeAndPassReceiver());
remote_observer->OnDeviceChanged(
kStreamLabel, changed_device,
blink::MediaStreamDevice(kDeviceType, "video_device-456", kDeviceName));
base::RunLoop().RunUntilIdle();
video_devices = observer_->GetNonScreenCaptureDevices();
ASSERT_EQ(video_devices.size(), 1u);
EXPECT_EQ(video_devices[0].id, "video_device-456");
}
} // namespace blink
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment