OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <string> | 5 #include <string> |
6 | 6 |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "content/common/media/media_stream_messages.h" | 10 #include "content/common/media/media_stream_messages.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 const content::MediaStreamDeviceType kVideoType = | 30 const content::MediaStreamDeviceType kVideoType = |
31 content::MEDIA_DEVICE_VIDEO_CAPTURE; | 31 content::MEDIA_DEVICE_VIDEO_CAPTURE; |
32 const content::MediaStreamDeviceType kNoAudioType = | 32 const content::MediaStreamDeviceType kNoAudioType = |
33 content::MEDIA_NO_SERVICE; | 33 content::MEDIA_NO_SERVICE; |
34 | 34 |
35 class MockMediaStreamDispatcherEventHandler | 35 class MockMediaStreamDispatcherEventHandler |
36 : public MediaStreamDispatcherEventHandler, | 36 : public MediaStreamDispatcherEventHandler, |
37 public base::SupportsWeakPtr<MockMediaStreamDispatcherEventHandler> { | 37 public base::SupportsWeakPtr<MockMediaStreamDispatcherEventHandler> { |
38 public: | 38 public: |
39 MockMediaStreamDispatcherEventHandler() | 39 MockMediaStreamDispatcherEventHandler() |
40 : request_id_(-1), | 40 : request_id_(-1) {} |
41 audio_failed(false), | |
42 video_failed(false) {} | |
43 | 41 |
44 virtual void OnStreamGenerated( | 42 virtual void OnStreamGenerated( |
45 int request_id, | 43 int request_id, |
46 const std::string &label, | 44 const std::string &label, |
47 const media_stream::StreamDeviceInfoArray& audio_device_array, | 45 const media_stream::StreamDeviceInfoArray& audio_device_array, |
48 const media_stream::StreamDeviceInfoArray& video_device_array) OVERRIDE { | 46 const media_stream::StreamDeviceInfoArray& video_device_array) OVERRIDE { |
49 request_id_ = request_id; | 47 request_id_ = request_id; |
50 label_ = label; | 48 label_ = label; |
51 } | 49 } |
52 | 50 |
53 virtual void OnStreamGenerationFailed(int request_id) OVERRIDE { | 51 virtual void OnStreamGenerationFailed(int request_id) OVERRIDE { |
54 request_id_ = request_id; | 52 request_id_ = request_id; |
55 } | 53 } |
56 | 54 |
57 virtual void OnAudioDeviceFailed(const std::string& label, | |
58 int index) OVERRIDE { | |
59 audio_failed = true; | |
60 } | |
61 | |
62 virtual void OnVideoDeviceFailed(const std::string& label, | |
63 int index) OVERRIDE { | |
64 video_failed = true; | |
65 } | |
66 | |
67 virtual void OnDevicesEnumerated( | 55 virtual void OnDevicesEnumerated( |
68 int request_id, | 56 int request_id, |
69 const media_stream::StreamDeviceInfoArray& device_array) OVERRIDE { | 57 const media_stream::StreamDeviceInfoArray& device_array) OVERRIDE { |
70 request_id_ = request_id; | 58 request_id_ = request_id; |
71 } | 59 } |
72 | 60 |
73 virtual void OnDevicesEnumerationFailed(int request_id) OVERRIDE { | 61 virtual void OnDevicesEnumerationFailed(int request_id) OVERRIDE { |
74 request_id_ = request_id; | 62 request_id_ = request_id; |
75 } | 63 } |
76 | 64 |
77 virtual void OnDeviceOpened( | 65 virtual void OnDeviceOpened( |
78 int request_id, | 66 int request_id, |
79 const std::string& label, | 67 const std::string& label, |
80 const media_stream::StreamDeviceInfo& video_device) OVERRIDE { | 68 const media_stream::StreamDeviceInfo& video_device) OVERRIDE { |
81 request_id_ = request_id; | 69 request_id_ = request_id; |
82 label_ = label; | 70 label_ = label; |
83 } | 71 } |
84 | 72 |
85 virtual void OnDeviceOpenFailed(int request_id) OVERRIDE { | 73 virtual void OnDeviceOpenFailed(int request_id) OVERRIDE { |
86 request_id_ = request_id; | 74 request_id_ = request_id; |
87 } | 75 } |
88 | 76 |
89 int request_id_; | 77 int request_id_; |
90 std::string label_; | 78 std::string label_; |
91 bool audio_failed; | |
92 bool video_failed; | |
93 | 79 |
94 DISALLOW_COPY_AND_ASSIGN(MockMediaStreamDispatcherEventHandler); | 80 DISALLOW_COPY_AND_ASSIGN(MockMediaStreamDispatcherEventHandler); |
95 }; | 81 }; |
96 | 82 |
97 } // namespace | 83 } // namespace |
98 | 84 |
99 TEST(MediaStreamDispatcherTest, BasicStream) { | 85 TEST(MediaStreamDispatcherTest, BasicStream) { |
100 scoped_ptr<MessageLoop> message_loop(new MessageLoop()); | 86 scoped_ptr<MessageLoop> message_loop(new MessageLoop()); |
101 scoped_ptr<MediaStreamDispatcher> dispatcher(new MediaStreamDispatcher(NULL)); | 87 scoped_ptr<MediaStreamDispatcher> dispatcher(new MediaStreamDispatcher(NULL)); |
102 scoped_ptr<MockMediaStreamDispatcherEventHandler> | 88 scoped_ptr<MockMediaStreamDispatcherEventHandler> |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 | 354 |
369 // Complete the creation of stream1. | 355 // Complete the creation of stream1. |
370 std::string stream_label1 = std::string("stream1"); | 356 std::string stream_label1 = std::string("stream1"); |
371 dispatcher->OnMessageReceived(MediaStreamMsg_StreamGenerated( | 357 dispatcher->OnMessageReceived(MediaStreamMsg_StreamGenerated( |
372 kRouteId, ipc_request_id1, stream_label1, | 358 kRouteId, ipc_request_id1, stream_label1, |
373 audio_device_array, video_device_array)); | 359 audio_device_array, video_device_array)); |
374 EXPECT_EQ(handler->request_id_, kRequestId1); | 360 EXPECT_EQ(handler->request_id_, kRequestId1); |
375 EXPECT_EQ(handler->label_, stream_label1); | 361 EXPECT_EQ(handler->label_, stream_label1); |
376 EXPECT_EQ(dispatcher->video_session_id(stream_label1, 0), kVideoSessionId); | 362 EXPECT_EQ(dispatcher->video_session_id(stream_label1, 0), kVideoSessionId); |
377 | 363 |
378 // Test failure of the video device. | |
379 dispatcher->OnMessageReceived( | |
380 MediaStreamHostMsg_VideoDeviceFailed(kRouteId, stream_label1, 0)); | |
381 EXPECT_EQ(handler->video_failed, true); | |
382 EXPECT_EQ(handler->audio_failed, false); | |
383 // Make sure the audio device still exist but not the video device. | |
384 EXPECT_EQ(dispatcher->audio_session_id(stream_label1, 0), kAudioSessionId); | |
385 | |
386 // Test failure of the audio device. | |
387 dispatcher->OnMessageReceived( | |
388 MediaStreamHostMsg_AudioDeviceFailed(kRouteId, stream_label1, 0)); | |
389 EXPECT_EQ(handler->audio_failed, true); | |
390 | |
391 // Stop stream1. | 364 // Stop stream1. |
392 dispatcher->StopStream(stream_label1); | 365 dispatcher->StopStream(stream_label1); |
393 EXPECT_EQ(dispatcher->label_stream_map_.size(), size_t(0)); | 366 EXPECT_EQ(dispatcher->label_stream_map_.size(), size_t(0)); |
394 } | 367 } |
395 | 368 |
396 TEST(MediaStreamDispatcherTest, CancelGenerateStream) { | 369 TEST(MediaStreamDispatcherTest, CancelGenerateStream) { |
397 scoped_ptr<MessageLoop> message_loop(new MessageLoop()); | 370 scoped_ptr<MessageLoop> message_loop(new MessageLoop()); |
398 scoped_ptr<MediaStreamDispatcher> dispatcher(new MediaStreamDispatcher(NULL)); | 371 scoped_ptr<MediaStreamDispatcher> dispatcher(new MediaStreamDispatcher(NULL)); |
399 scoped_ptr<MockMediaStreamDispatcherEventHandler> | 372 scoped_ptr<MockMediaStreamDispatcherEventHandler> |
400 handler(new MockMediaStreamDispatcherEventHandler); | 373 handler(new MockMediaStreamDispatcherEventHandler); |
(...skipping 25 matching lines...) Expand all Loading... |
426 video_device_array[0] = video_device_info; | 399 video_device_array[0] = video_device_info; |
427 | 400 |
428 std::string stream_label1 = "stream1"; | 401 std::string stream_label1 = "stream1"; |
429 dispatcher->OnMessageReceived(MediaStreamMsg_StreamGenerated( | 402 dispatcher->OnMessageReceived(MediaStreamMsg_StreamGenerated( |
430 kRouteId, ipc_request_id1, stream_label1, | 403 kRouteId, ipc_request_id1, stream_label1, |
431 audio_device_array, video_device_array)); | 404 audio_device_array, video_device_array)); |
432 EXPECT_EQ(handler->request_id_, kRequestId1); | 405 EXPECT_EQ(handler->request_id_, kRequestId1); |
433 EXPECT_EQ(handler->label_, stream_label1); | 406 EXPECT_EQ(handler->label_, stream_label1); |
434 EXPECT_EQ(0u, dispatcher->requests_.size()); | 407 EXPECT_EQ(0u, dispatcher->requests_.size()); |
435 } | 408 } |
OLD | NEW |