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

Side by Side Diff: content/renderer/media/media_stream_video_capture_source_unittest.cc

Issue 295483002: Make sure ReadyStateEnded is fired when video stream stops (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | content/renderer/media/media_stream_video_capturer_source.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/message_loop/message_loop.h"
6 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
7 #include "content/child/child_process.h" 8 #include "content/child/child_process.h"
8 #include "content/renderer/media/media_stream_video_capturer_source.h" 9 #include "content/renderer/media/media_stream_video_capturer_source.h"
9 #include "content/renderer/media/media_stream_video_track.h" 10 #include "content/renderer/media/media_stream_video_track.h"
10 #include "content/renderer/media/mock_media_constraint_factory.h" 11 #include "content/renderer/media/mock_media_constraint_factory.h"
11 #include "testing/gmock/include/gmock/gmock.h" 12 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 14
14 namespace content { 15 namespace content {
15 16
16 class MockVideoCapturerDelegate : public VideoCapturerDelegate { 17 class MockVideoCapturerDelegate : public VideoCapturerDelegate {
17 public: 18 public:
18 explicit MockVideoCapturerDelegate(const StreamDeviceInfo& device_info) 19 explicit MockVideoCapturerDelegate(const StreamDeviceInfo& device_info)
19 : VideoCapturerDelegate(device_info) {} 20 : VideoCapturerDelegate(device_info) {}
20 21
21 MOCK_METHOD3(StartCapture, 22 MOCK_METHOD3(StartCapture,
22 void(const media::VideoCaptureParams& params, 23 void(const media::VideoCaptureParams& params,
23 const VideoCaptureDeliverFrameCB& new_frame_callback, 24 const VideoCaptureDeliverFrameCB& new_frame_callback,
24 const StartedCallback& started_callback)); 25 const RunningCallback& running_callback));
25 MOCK_METHOD0(StopCapture,void()); 26 MOCK_METHOD0(StopCapture, void());
26 27
27 private: 28 private:
28 virtual ~MockVideoCapturerDelegate() {} 29 virtual ~MockVideoCapturerDelegate() {}
29 }; 30 };
30 31
31 class MediaStreamVideoCapturerSourceTest : public testing::Test { 32 class MediaStreamVideoCapturerSourceTest : public testing::Test {
32 public: 33 public:
33 MediaStreamVideoCapturerSourceTest() 34 MediaStreamVideoCapturerSourceTest()
34 : child_process_(new ChildProcess()), 35 : child_process_(new ChildProcess()),
35 source_(NULL) { 36 source_(NULL) {
(...skipping 17 matching lines...) Expand all
53 bool enabled = true; 54 bool enabled = true;
54 // CreateVideoTrack will trigger OnConstraintsApplied. 55 // CreateVideoTrack will trigger OnConstraintsApplied.
55 return MediaStreamVideoTrack::CreateVideoTrack( 56 return MediaStreamVideoTrack::CreateVideoTrack(
56 source_, factory.CreateWebMediaConstraints(), 57 source_, factory.CreateWebMediaConstraints(),
57 base::Bind( 58 base::Bind(
58 &MediaStreamVideoCapturerSourceTest::OnConstraintsApplied, 59 &MediaStreamVideoCapturerSourceTest::OnConstraintsApplied,
59 base::Unretained(this)), 60 base::Unretained(this)),
60 enabled); 61 enabled);
61 } 62 }
62 63
64 MockVideoCapturerDelegate& mock_delegate() {
65 return *static_cast<MockVideoCapturerDelegate*>(delegate_.get());
66 }
67
63 protected: 68 protected:
64 void OnConstraintsApplied(MediaStreamSource* source, bool success) { 69 void OnConstraintsApplied(MediaStreamSource* source, bool success) {
65 } 70 }
66 71
72 base::MessageLoop message_loop_;
67 scoped_ptr<ChildProcess> child_process_; 73 scoped_ptr<ChildProcess> child_process_;
68 blink::WebMediaStreamSource webkit_source_; 74 blink::WebMediaStreamSource webkit_source_;
69 MediaStreamVideoCapturerSource* source_; // owned by webkit_source. 75 MediaStreamVideoCapturerSource* source_; // owned by webkit_source.
70 scoped_refptr<MockVideoCapturerDelegate> delegate_; 76 scoped_refptr<VideoCapturerDelegate> delegate_;
71 }; 77 };
72 78
73 TEST_F(MediaStreamVideoCapturerSourceTest, TabCaptureAllowResolutionChange) { 79 TEST_F(MediaStreamVideoCapturerSourceTest, TabCaptureAllowResolutionChange) {
74 StreamDeviceInfo device_info; 80 StreamDeviceInfo device_info;
75 device_info.device.type = MEDIA_TAB_VIDEO_CAPTURE; 81 device_info.device.type = MEDIA_TAB_VIDEO_CAPTURE;
76 InitWithDeviceInfo(device_info); 82 InitWithDeviceInfo(device_info);
77 83
78 EXPECT_CALL(*delegate_, StartCapture( 84 EXPECT_CALL(mock_delegate(), StartCapture(
79 testing::Field(&media::VideoCaptureParams::allow_resolution_change, true), 85 testing::Field(&media::VideoCaptureParams::allow_resolution_change, true),
80 testing::_, 86 testing::_,
81 testing::_)).Times(1); 87 testing::_)).Times(1);
82 blink::WebMediaStreamTrack track = StartSource(); 88 blink::WebMediaStreamTrack track = StartSource();
83 // When the track goes out of scope, the source will be stopped. 89 // When the track goes out of scope, the source will be stopped.
84 EXPECT_CALL(*delegate_, StopCapture()); 90 EXPECT_CALL(mock_delegate(), StopCapture());
85 } 91 }
86 92
87 TEST_F(MediaStreamVideoCapturerSourceTest, 93 TEST_F(MediaStreamVideoCapturerSourceTest,
88 DesktopCaptureAllowResolutionChange) { 94 DesktopCaptureAllowResolutionChange) {
89 StreamDeviceInfo device_info; 95 StreamDeviceInfo device_info;
90 device_info.device.type = MEDIA_DESKTOP_VIDEO_CAPTURE; 96 device_info.device.type = MEDIA_DESKTOP_VIDEO_CAPTURE;
91 InitWithDeviceInfo(device_info); 97 InitWithDeviceInfo(device_info);
92 98
93 EXPECT_CALL(*delegate_, StartCapture( 99 EXPECT_CALL(mock_delegate(), StartCapture(
94 testing::Field(&media::VideoCaptureParams::allow_resolution_change, true), 100 testing::Field(&media::VideoCaptureParams::allow_resolution_change, true),
95 testing::_, 101 testing::_,
96 testing::_)).Times(1); 102 testing::_)).Times(1);
97 blink::WebMediaStreamTrack track = StartSource(); 103 blink::WebMediaStreamTrack track = StartSource();
98 // When the track goes out of scope, the source will be stopped. 104 // When the track goes out of scope, the source will be stopped.
99 EXPECT_CALL(*delegate_, StopCapture()); 105 EXPECT_CALL(mock_delegate(), StopCapture());
106 }
107
108 TEST_F(MediaStreamVideoCapturerSourceTest, Ended) {
109 StreamDeviceInfo device_info;
110 device_info.device.type = MEDIA_DESKTOP_VIDEO_CAPTURE;
111 delegate_ = new VideoCapturerDelegate(device_info);
112 source_ = new MediaStreamVideoCapturerSource(
113 device_info,
114 MediaStreamSource::SourceStoppedCallback(),
115 delegate_);
116 webkit_source_.initialize(base::UTF8ToUTF16("dummy_source_id"),
117 blink::WebMediaStreamSource::TypeVideo,
118 base::UTF8ToUTF16("dummy_source_name"));
119 webkit_source_.setExtraData(source_);
120 blink::WebMediaStreamTrack track = StartSource();
121 message_loop_.RunUntilIdle();
122
123 delegate_->OnStateUpdateOnRenderThread(VIDEO_CAPTURE_STATE_STARTED);
124 message_loop_.RunUntilIdle();
125 EXPECT_EQ(blink::WebMediaStreamSource::ReadyStateLive,
126 webkit_source_.readyState());
127
128 delegate_->OnStateUpdateOnRenderThread(VIDEO_CAPTURE_STATE_ERROR);
129 message_loop_.RunUntilIdle();
130 EXPECT_EQ(blink::WebMediaStreamSource::ReadyStateEnded,
131 webkit_source_.readyState());
100 } 132 }
101 133
102 } // namespace content 134 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/renderer/media/media_stream_video_capturer_source.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698