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

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

Issue 218763007: Update MediaStreamTrack::Stop to latest draft. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments. Created 6 years, 8 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
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/strings/utf_string_conversions.h" 5 #include "base/strings/utf_string_conversions.h"
6 #include "content/renderer/media/media_stream_video_capturer_source.h" 6 #include "content/renderer/media/media_stream_video_capturer_source.h"
7 #include "content/renderer/media/media_stream_video_track.h" 7 #include "content/renderer/media/media_stream_video_track.h"
8 #include "content/renderer/media/mock_media_constraint_factory.h" 8 #include "content/renderer/media/mock_media_constraint_factory.h"
9 #include "content/renderer/media/mock_media_stream_dependency_factory.h" 9 #include "content/renderer/media/mock_media_stream_dependency_factory.h"
10 #include "testing/gmock/include/gmock/gmock.h" 10 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 12
13 namespace content { 13 namespace content {
14 14
15 class MockVideoCapturerDelegate : public VideoCapturerDelegate { 15 class MockVideoCapturerDelegate : public VideoCapturerDelegate {
16 public: 16 public:
17 explicit MockVideoCapturerDelegate(const StreamDeviceInfo& device_info) 17 explicit MockVideoCapturerDelegate(const StreamDeviceInfo& device_info)
18 : VideoCapturerDelegate(device_info) {} 18 : VideoCapturerDelegate(device_info) {}
19 19
20 MOCK_METHOD3(StartDeliver, 20 MOCK_METHOD3(StartDeliver,
21 void(const media::VideoCaptureParams& params, 21 void(const media::VideoCaptureParams& params,
22 const NewFrameCallback& new_frame_callback, 22 const NewFrameCallback& new_frame_callback,
23 const StartedCallback& started_callback)); 23 const StartedCallback& started_callback));
24 MOCK_METHOD0(StopDeliver,void());
24 25
25 private: 26 private:
26 virtual ~MockVideoCapturerDelegate() {} 27 virtual ~MockVideoCapturerDelegate() {}
27 }; 28 };
28 29
29 class MediaStreamVideoCapturerSourceTest : public testing::Test { 30 class MediaStreamVideoCapturerSourceTest : public testing::Test {
30 public: 31 public:
31 void InitWithDeviceInfo(const StreamDeviceInfo& device_info) { 32 void InitWithDeviceInfo(const StreamDeviceInfo& device_info) {
32 delegate_ = new MockVideoCapturerDelegate(device_info); 33 delegate_ = new MockVideoCapturerDelegate(device_info);
33 source_ = new MediaStreamVideoCapturerSource( 34 source_ = new MediaStreamVideoCapturerSource(
34 device_info, 35 device_info,
35 MediaStreamSource::SourceStoppedCallback(), 36 MediaStreamSource::SourceStoppedCallback(),
36 delegate_, 37 delegate_,
37 &factory_); 38 &factory_);
38 39
39 webkit_source_.initialize(base::UTF8ToUTF16("dummy_source_id"), 40 webkit_source_.initialize(base::UTF8ToUTF16("dummy_source_id"),
40 blink::WebMediaStreamSource::TypeVideo, 41 blink::WebMediaStreamSource::TypeVideo,
41 base::UTF8ToUTF16("dummy_source_name")); 42 base::UTF8ToUTF16("dummy_source_name"));
42 webkit_source_.setExtraData(source_); 43 webkit_source_.setExtraData(source_);
43 } 44 }
44 45
45 void StartSource() { 46 blink::WebMediaStreamTrack StartSource() {
46 MockMediaConstraintFactory factory; 47 MockMediaConstraintFactory factory;
47 bool enabled = true; 48 bool enabled = true;
48 MediaStreamDependencyFactory* dependency_factory = NULL; 49 MediaStreamDependencyFactory* dependency_factory = NULL;
49 // CreateVideoTrack will trigger OnSupportedFormats. 50 // CreateVideoTrack will trigger OnConstraintsApplied.
50 MediaStreamVideoTrack::CreateVideoTrack( 51 return MediaStreamVideoTrack::CreateVideoTrack(
51 source_, factory.CreateWebMediaConstraints(), 52 source_, factory.CreateWebMediaConstraints(),
52 base::Bind( 53 base::Bind(
53 &MediaStreamVideoCapturerSourceTest::OnConstraintsApplied, 54 &MediaStreamVideoCapturerSourceTest::OnConstraintsApplied,
54 base::Unretained(this)), 55 base::Unretained(this)),
55 enabled, dependency_factory); 56 enabled, dependency_factory);
56 } 57 }
57 58
58 protected: 59 protected:
59 void OnConstraintsApplied(MediaStreamSource* source, bool success) { 60 void OnConstraintsApplied(MediaStreamSource* source, bool success) {
60 } 61 }
61 62
62 MockMediaStreamDependencyFactory factory_; 63 MockMediaStreamDependencyFactory factory_;
63 blink::WebMediaStreamSource webkit_source_; 64 blink::WebMediaStreamSource webkit_source_;
64 MediaStreamVideoCapturerSource* source_; // owned by webkit_source. 65 MediaStreamVideoCapturerSource* source_; // owned by webkit_source.
65 scoped_refptr<MockVideoCapturerDelegate> delegate_; 66 scoped_refptr<MockVideoCapturerDelegate> delegate_;
66 }; 67 };
67 68
68 TEST_F(MediaStreamVideoCapturerSourceTest, TabCaptureAllowResolutionChange) { 69 TEST_F(MediaStreamVideoCapturerSourceTest, TabCaptureAllowResolutionChange) {
69 StreamDeviceInfo device_info; 70 StreamDeviceInfo device_info;
70 device_info.device.type = MEDIA_TAB_VIDEO_CAPTURE; 71 device_info.device.type = MEDIA_TAB_VIDEO_CAPTURE;
71 InitWithDeviceInfo(device_info); 72 InitWithDeviceInfo(device_info);
72 73
73 EXPECT_CALL(*delegate_, StartDeliver( 74 EXPECT_CALL(*delegate_, StartDeliver(
74 testing::Field(&media::VideoCaptureParams::allow_resolution_change, true), 75 testing::Field(&media::VideoCaptureParams::allow_resolution_change, true),
75 testing::_, 76 testing::_,
76 testing::_)).Times(1); 77 testing::_)).Times(1);
77 StartSource(); 78 blink::WebMediaStreamTrack track = StartSource();
79 // When the track goes out of scope, the source will be stopped.
80 EXPECT_CALL(*delegate_, StopDeliver());
78 } 81 }
79 82
80 TEST_F(MediaStreamVideoCapturerSourceTest, 83 TEST_F(MediaStreamVideoCapturerSourceTest,
81 DesktopCaptureAllowResolutionChange) { 84 DesktopCaptureAllowResolutionChange) {
82 StreamDeviceInfo device_info; 85 StreamDeviceInfo device_info;
83 device_info.device.type = MEDIA_DESKTOP_VIDEO_CAPTURE; 86 device_info.device.type = MEDIA_DESKTOP_VIDEO_CAPTURE;
84 InitWithDeviceInfo(device_info); 87 InitWithDeviceInfo(device_info);
85 88
86 EXPECT_CALL(*delegate_, StartDeliver( 89 EXPECT_CALL(*delegate_, StartDeliver(
87 testing::Field(&media::VideoCaptureParams::allow_resolution_change, true), 90 testing::Field(&media::VideoCaptureParams::allow_resolution_change, true),
88 testing::_, 91 testing::_,
89 testing::_)).Times(1); 92 testing::_)).Times(1);
90 StartSource(); 93 blink::WebMediaStreamTrack track = StartSource();
94 // When the track goes out of scope, the source will be stopped.
95 EXPECT_CALL(*delegate_, StopDeliver());
91 } 96 }
92 97
93 } // namespace content 98 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/media_stream_track.cc ('k') | content/renderer/media/media_stream_video_capturer_source.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698