Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1942)

Unified Diff: content/renderer/media/media_stream_dispatcher_unittest.cc

Issue 2763743002: Android: not to pause screen capture when Chrome is put to background (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/renderer/media/media_stream_dispatcher_unittest.cc
diff --git a/content/renderer/media/media_stream_dispatcher_unittest.cc b/content/renderer/media/media_stream_dispatcher_unittest.cc
index 82f609719209be4aa34c40fcef98926247ba5e3b..8ce41a701dc23a1f32c70aa60837a9b19baa37d9 100644
--- a/content/renderer/media/media_stream_dispatcher_unittest.cc
+++ b/content/renderer/media/media_stream_dispatcher_unittest.cc
@@ -26,11 +26,13 @@ namespace {
const int kRouteId = 0;
const int kAudioSessionId = 3;
const int kVideoSessionId = 5;
+const int kScreenSessionId = 7;
const int kRequestId1 = 10;
const int kRequestId2 = 20;
const MediaStreamType kAudioType = MEDIA_DEVICE_AUDIO_CAPTURE;
const MediaStreamType kVideoType = MEDIA_DEVICE_VIDEO_CAPTURE;
+const MediaStreamType kScreenType = MEDIA_DESKTOP_VIDEO_CAPTURE;
class MockMediaStreamDispatcherEventHandler
: public MediaStreamDispatcherEventHandler,
@@ -378,4 +380,72 @@ TEST_F(MediaStreamDispatcherTest, DeviceClosed) {
StreamDeviceInfo::kNoId);
}
+TEST_F(MediaStreamDispatcherTest, GetVideoCaptureDevices) {
+ std::unique_ptr<MediaStreamDispatcher> dispatcher(
+ new MediaStreamDispatcher(NULL));
tommi (sloooow) - chröme 2017/03/21 09:21:17 nullptr
braveyao 2017/03/22 00:45:32 Done.
+ std::unique_ptr<MockMediaStreamDispatcherEventHandler> handler(
+ new MockMediaStreamDispatcherEventHandler);
+ url::Origin security_origin;
+
+ StreamDeviceInfo video_device_info;
+ video_device_info.device.name = "Camera";
+ video_device_info.device.id = "device_path";
+ video_device_info.device.type = kVideoType;
+ video_device_info.session_id = kVideoSessionId;
+
+ StreamDeviceInfo screen_device_info;
+ screen_device_info.device.name = "Screen";
+ screen_device_info.device.id = "screen_capture";
+ screen_device_info.device.type = kScreenType;
+ screen_device_info.session_id = kScreenSessionId;
+
+ EXPECT_EQ(dispatcher->requests_.size(), size_t(0));
tommi (sloooow) - chröme 2017/03/21 09:21:17 EXPECT_TRUE(dispatcher->requests_.empty()); In Ch
braveyao 2017/03/22 00:45:32 Acknowledged. Done.
+ EXPECT_EQ(dispatcher->label_stream_map_.size(), size_t(0));
+
+ int ipc_request_id1 = dispatcher->next_ipc_id_;
+ dispatcher->OpenDevice(kRequestId1, handler.get()->AsWeakPtr(),
+ video_device_info.device.id, kVideoType,
+ security_origin);
+ int ipc_request_id2 = dispatcher->next_ipc_id_;
+ EXPECT_NE(ipc_request_id1, ipc_request_id2);
+ dispatcher->OpenDevice(kRequestId2, handler.get()->AsWeakPtr(),
+ screen_device_info.device.id, kScreenType,
+ security_origin);
+ EXPECT_EQ(dispatcher->requests_.size(), size_t(2));
+
+ // Complete the OpenDevice of request 1.
+ std::string stream_label1 = std::string("stream1");
+ dispatcher->OnMessageReceived(MediaStreamMsg_DeviceOpened(
+ kRouteId, ipc_request_id1, stream_label1, video_device_info));
+ EXPECT_EQ(handler->request_id_, kRequestId1);
+
+ // Complete the OpenDevice of request 2.
+ std::string stream_label2 = std::string("stream2");
+ dispatcher->OnMessageReceived(MediaStreamMsg_DeviceOpened(
+ kRouteId, ipc_request_id2, stream_label2, screen_device_info));
+ EXPECT_EQ(handler->request_id_, kRequestId2);
+
+ EXPECT_EQ(dispatcher->requests_.size(), size_t(0));
+ EXPECT_EQ(dispatcher->label_stream_map_.size(), size_t(2));
+
+ // Only the device with |kVideoType| will be got.
+ StreamDeviceInfoArray video_device_array;
+ dispatcher->GetVideoCaptureDevices(video_device_array);
+ EXPECT_EQ(video_device_array.size(), size_t(1));
+
+ // Close the device from request 2.
+ dispatcher->CloseDevice(stream_label2);
+ EXPECT_EQ(dispatcher->video_session_id(stream_label2, 0),
+ StreamDeviceInfo::kNoId);
+
+ // Close the device from request 1.
+ dispatcher->CloseDevice(stream_label1);
+ EXPECT_EQ(dispatcher->video_session_id(stream_label1, 0),
+ StreamDeviceInfo::kNoId);
+
+ // Verify that the request have been completed.
+ EXPECT_EQ(dispatcher->label_stream_map_.size(), size_t(0));
+ EXPECT_EQ(dispatcher->requests_.size(), size_t(0));
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698