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

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

Issue 8480028: support video device enumeration from renderer process. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: code review Created 8 years, 11 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
===================================================================
--- content/renderer/media/media_stream_dispatcher_unittest.cc (revision 118766)
+++ content/renderer/media/media_stream_dispatcher_unittest.cc (working copy)
@@ -19,6 +19,8 @@
const int kVideoSessionId = 5;
const int kRequestId1 = 10;
const int kRequestId2 = 20;
+const int kRequestId3 = 30;
+const int kRequestId4 = 40;
class MockMediaStreamDispatcherEventHandler
: public MediaStreamDispatcherEventHandler {
@@ -32,25 +34,47 @@
int request_id,
const std::string &label,
const media_stream::StreamDeviceInfoArray& audio_device_array,
- const media_stream::StreamDeviceInfoArray& video_device_array) {
+ const media_stream::StreamDeviceInfoArray& video_device_array) OVERRIDE {
request_id_ = request_id;
label_ = label;
}
- virtual void OnStreamGenerationFailed(int request_id) {
+ virtual void OnStreamGenerationFailed(int request_id) OVERRIDE {
request_id_ = request_id;
}
virtual void OnAudioDeviceFailed(const std::string& label,
- int index) {
+ int index) OVERRIDE {
audio_failed = true;
}
virtual void OnVideoDeviceFailed(const std::string& label,
- int index) {
+ int index) OVERRIDE {
video_failed = true;
}
+ virtual void OnDevicesEnumerated(
+ int request_id,
+ const media_stream::StreamDeviceInfoArray& device_array) OVERRIDE {
+ request_id_ = request_id;
+ }
+
+ virtual void OnDevicesEnumerationFailed(int request_id) OVERRIDE {
+ request_id_ = request_id;
+ }
+
+ virtual void OnDeviceOpened(
+ int request_id,
+ const std::string& label,
+ const media_stream::StreamDeviceInfo& video_device) OVERRIDE {
+ request_id_ = request_id;
+ label_ = label;
+ }
+
+ virtual void OnDeviceOpenFailed(int request_id) OVERRIDE {
+ request_id_ = request_id;
+ }
+
int request_id_;
std::string label_;
bool audio_failed;
@@ -61,7 +85,7 @@
} // namespace
-TEST(MediaStreamDispatcherTest, Basic) {
+TEST(MediaStreamDispatcherTest, BasicStream) {
scoped_ptr<MediaStreamDispatcher> dispatcher(new MediaStreamDispatcher(NULL));
scoped_ptr<MockMediaStreamDispatcherEventHandler>
handler(new MockMediaStreamDispatcherEventHandler);
@@ -135,6 +159,88 @@
EXPECT_EQ(dispatcher->requests_.size(), size_t(0));
}
+TEST(MediaStreamDispatcherTest, BasicVideoDevice) {
+ scoped_ptr<MediaStreamDispatcher> dispatcher(new MediaStreamDispatcher(NULL));
+ scoped_ptr<MockMediaStreamDispatcherEventHandler>
+ handler(new MockMediaStreamDispatcherEventHandler);
+ std::string security_origin;
+
+ int ipc_request_id1 = dispatcher->next_ipc_id_;
+ dispatcher->EnumerateDevices(kRequestId1, handler.get(),
+ media_stream::kVideoCapture, security_origin);
+ int ipc_request_id2 = dispatcher->next_ipc_id_;
+ EXPECT_NE(ipc_request_id1, ipc_request_id2);
+ dispatcher->EnumerateDevices(kRequestId2, handler.get(),
+ media_stream::kVideoCapture, security_origin);
+ EXPECT_EQ(dispatcher->requests_.size(), size_t(2));
+
+ media_stream::StreamDeviceInfoArray video_device_array(1);
+ media_stream::StreamDeviceInfo video_device_info;
+ video_device_info.name = "Camera";
+ video_device_info.device_id = "device_path";
+ video_device_info.stream_type = media_stream::kVideoCapture;
+ video_device_info.session_id = kVideoSessionId;
+ video_device_array[0] = video_device_info;
+
+ // Complete the enumeration of request 1.
+ dispatcher->OnMessageReceived(MediaStreamMsg_DevicesEnumerated(
+ kRouteId, ipc_request_id1, video_device_array));
+ EXPECT_EQ(handler->request_id_, kRequestId1);
+
+ // Complete the enumeration of request 2.
+ dispatcher->OnMessageReceived(MediaStreamMsg_DevicesEnumerated(
+ kRouteId, ipc_request_id2, video_device_array));
+ EXPECT_EQ(handler->request_id_, kRequestId2);
+
+ EXPECT_EQ(dispatcher->requests_.size(), size_t(0));
+ EXPECT_EQ(dispatcher->label_stream_map_.size(), size_t(0));
+
+ int ipc_request_id3 = dispatcher->next_ipc_id_;
+ dispatcher->OpenDevice(kRequestId3, handler.get(),
+ video_device_info.device_id,
+ media_stream::kVideoCapture, security_origin);
+ int ipc_request_id4 = dispatcher->next_ipc_id_;
+ EXPECT_NE(ipc_request_id3, ipc_request_id4);
+ dispatcher->OpenDevice(kRequestId4, handler.get(),
+ video_device_info.device_id,
+ media_stream::kVideoCapture, 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_id3, stream_label1, video_device_info));
+ EXPECT_EQ(handler->request_id_, kRequestId3);
+
+ // Complete the OpenDevice of request 2.
+ std::string stream_label2 = std::string("stream2");
+ dispatcher->OnMessageReceived(MediaStreamMsg_DeviceOpened(
+ kRouteId, ipc_request_id4, stream_label2, video_device_info));
+ EXPECT_EQ(handler->request_id_, kRequestId4);
+
+ EXPECT_EQ(dispatcher->requests_.size(), size_t(0));
+ EXPECT_EQ(dispatcher->label_stream_map_.size(), size_t(2));
+
+ // Check the video_session_id.
+ EXPECT_EQ(dispatcher->video_session_id(stream_label1, 0), kVideoSessionId);
+ EXPECT_EQ(dispatcher->video_session_id(stream_label2, 0), kVideoSessionId);
+
+ // Stop stream2.
+ dispatcher->StopStream(stream_label2);
+ EXPECT_EQ(dispatcher->video_session_id(stream_label2, 0),
+ media_stream::StreamDeviceInfo::kNoId);
+
+ // Stop stream1.
+ dispatcher->StopStream(stream_label1);
+ EXPECT_EQ(dispatcher->video_session_id(stream_label1, 0),
+ media_stream::StreamDeviceInfo::kNoId);
+ EXPECT_EQ(dispatcher->label_stream_map_.size(), size_t(0));
+
+ // 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));
+}
+
TEST(MediaStreamDispatcherTest, TestFailure) {
scoped_ptr<MediaStreamDispatcher> dispatcher(new MediaStreamDispatcher(NULL));
scoped_ptr<MockMediaStreamDispatcherEventHandler>
« no previous file with comments | « content/renderer/media/media_stream_dispatcher_eventhandler.h ('k') | content/renderer/media/media_stream_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698