Commit 106aa0ab authored by haraken's avatar haraken Committed by Commit bot

MediaStream tests need to call WebHeap::collectGarbage

Now that Blink-side objects about MediaStream are moved to oilpan's heap, we need to call WebHeap::collectGarbage in MediaStream tests to test that a particular object is gone. This CL adds necessary WebHeap::collectGarbage calls to content_unittests about MediaStreams.

Review URL: https://codereview.chromium.org/549153002

Cr-Commit-Position: refs/heads/master@{#294099}
parent b1204ef0
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "media/base/bind_to_current_loop.h" #include "media/base/bind_to_current_loop.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/WebKit/public/web/WebHeap.h"
namespace content { namespace content {
...@@ -41,6 +42,11 @@ class MediaStreamVideoCapturerSourceTest : public testing::Test { ...@@ -41,6 +42,11 @@ class MediaStreamVideoCapturerSourceTest : public testing::Test {
source_stopped_(false) { source_stopped_(false) {
} }
virtual void TearDown() OVERRIDE {
webkit_source_.reset();
blink::WebHeap::collectAllGarbageForTesting();
}
void InitWithDeviceInfo(const StreamDeviceInfo& device_info) { void InitWithDeviceInfo(const StreamDeviceInfo& device_info) {
delegate_ = new MockVideoCapturerDelegate(device_info); delegate_ = new MockVideoCapturerDelegate(device_info);
source_ = new MediaStreamVideoCapturerSource( source_ = new MediaStreamVideoCapturerSource(
...@@ -53,6 +59,7 @@ class MediaStreamVideoCapturerSourceTest : public testing::Test { ...@@ -53,6 +59,7 @@ class MediaStreamVideoCapturerSourceTest : public testing::Test {
blink::WebMediaStreamSource::TypeVideo, blink::WebMediaStreamSource::TypeVideo,
base::UTF8ToUTF16("dummy_source_name")); base::UTF8ToUTF16("dummy_source_name"));
webkit_source_.setExtraData(source_); webkit_source_.setExtraData(source_);
webkit_source_id_ = webkit_source_.id();
} }
blink::WebMediaStreamTrack StartSource() { blink::WebMediaStreamTrack StartSource() {
...@@ -73,7 +80,7 @@ class MediaStreamVideoCapturerSourceTest : public testing::Test { ...@@ -73,7 +80,7 @@ class MediaStreamVideoCapturerSourceTest : public testing::Test {
void OnSourceStopped(const blink::WebMediaStreamSource& source) { void OnSourceStopped(const blink::WebMediaStreamSource& source) {
source_stopped_ = true; source_stopped_ = true;
EXPECT_EQ(source.id(), webkit_source_.id()); EXPECT_EQ(source.id(), webkit_source_id_);
} }
protected: protected:
...@@ -87,6 +94,7 @@ class MediaStreamVideoCapturerSourceTest : public testing::Test { ...@@ -87,6 +94,7 @@ class MediaStreamVideoCapturerSourceTest : public testing::Test {
blink::WebMediaStreamSource webkit_source_; blink::WebMediaStreamSource webkit_source_;
MediaStreamVideoCapturerSource* source_; // owned by webkit_source. MediaStreamVideoCapturerSource* source_; // owned by webkit_source.
scoped_refptr<VideoCapturerDelegate> delegate_; scoped_refptr<VideoCapturerDelegate> delegate_;
blink::WebString webkit_source_id_;
bool source_stopped_; bool source_stopped_;
}; };
...@@ -132,6 +140,7 @@ TEST_F(MediaStreamVideoCapturerSourceTest, Ended) { ...@@ -132,6 +140,7 @@ TEST_F(MediaStreamVideoCapturerSourceTest, Ended) {
blink::WebMediaStreamSource::TypeVideo, blink::WebMediaStreamSource::TypeVideo,
base::UTF8ToUTF16("dummy_source_name")); base::UTF8ToUTF16("dummy_source_name"));
webkit_source_.setExtraData(source_); webkit_source_.setExtraData(source_);
webkit_source_id_ = webkit_source_.id();
blink::WebMediaStreamTrack track = StartSource(); blink::WebMediaStreamTrack track = StartSource();
message_loop_.RunUntilIdle(); message_loop_.RunUntilIdle();
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "content/renderer/media/mock_media_stream_video_source.h" #include "content/renderer/media/mock_media_stream_video_source.h"
#include "media/base/video_frame.h" #include "media/base/video_frame.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/WebKit/public/web/WebHeap.h"
using ::testing::_; using ::testing::_;
using ::testing::DoAll; using ::testing::DoAll;
...@@ -55,6 +56,11 @@ class MediaStreamVideoSourceTest ...@@ -55,6 +56,11 @@ class MediaStreamVideoSourceTest
webkit_source_.setExtraData(mock_source_); webkit_source_.setExtraData(mock_source_);
} }
virtual void TearDown() {
webkit_source_.reset();
blink::WebHeap::collectAllGarbageForTesting();
}
protected: protected:
// Create a track that's associated with |webkit_source_|. // Create a track that's associated with |webkit_source_|.
blink::WebMediaStreamTrack CreateTrack( blink::WebMediaStreamTrack CreateTrack(
......
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include "third_party/WebKit/public/platform/WebRTCStatsRequest.h" #include "third_party/WebKit/public/platform/WebRTCStatsRequest.h"
#include "third_party/WebKit/public/platform/WebRTCVoidRequest.h" #include "third_party/WebKit/public/platform/WebRTCVoidRequest.h"
#include "third_party/WebKit/public/platform/WebURL.h" #include "third_party/WebKit/public/platform/WebURL.h"
#include "third_party/WebKit/public/web/WebHeap.h"
#include "third_party/libjingle/source/talk/app/webrtc/peerconnectioninterface.h" #include "third_party/libjingle/source/talk/app/webrtc/peerconnectioninterface.h"
static const char kDummySdp[] = "dummy sdp"; static const char kDummySdp[] = "dummy sdp";
...@@ -219,6 +220,14 @@ class RTCPeerConnectionHandlerTest : public ::testing::Test { ...@@ -219,6 +220,14 @@ class RTCPeerConnectionHandlerTest : public ::testing::Test {
ASSERT_TRUE(mock_peer_connection_); ASSERT_TRUE(mock_peer_connection_);
} }
virtual void TearDown() {
pc_handler_.reset();
mock_tracker_.reset();
mock_dependency_factory_.reset();
mock_client_.reset();
blink::WebHeap::collectAllGarbageForTesting();
}
// Creates a WebKit local MediaStream. // Creates a WebKit local MediaStream.
blink::WebMediaStream CreateLocalMediaStream( blink::WebMediaStream CreateLocalMediaStream(
const std::string& stream_label) { const std::string& stream_label) {
...@@ -762,6 +771,8 @@ TEST_F(RTCPeerConnectionHandlerTest, RemoveAndAddAudioTrackFromRemoteStream) { ...@@ -762,6 +771,8 @@ TEST_F(RTCPeerConnectionHandlerTest, RemoveAndAddAudioTrackFromRemoteStream) {
EXPECT_EQ(0u, modified_audio_tracks1.size()); EXPECT_EQ(0u, modified_audio_tracks1.size());
} }
blink::WebHeap::collectGarbageForTesting();
// Add the WebRtc audio track again. // Add the WebRtc audio track again.
remote_stream->AddTrack(webrtc_track.get()); remote_stream->AddTrack(webrtc_track.get());
blink::WebVector<blink::WebMediaStreamTrack> modified_audio_tracks2; blink::WebVector<blink::WebMediaStreamTrack> modified_audio_tracks2;
...@@ -798,6 +809,8 @@ TEST_F(RTCPeerConnectionHandlerTest, RemoveAndAddVideoTrackFromRemoteStream) { ...@@ -798,6 +809,8 @@ TEST_F(RTCPeerConnectionHandlerTest, RemoveAndAddVideoTrackFromRemoteStream) {
EXPECT_EQ(0u, modified_video_tracks1.size()); EXPECT_EQ(0u, modified_video_tracks1.size());
} }
blink::WebHeap::collectGarbageForTesting();
// Add the WebRtc video track again. // Add the WebRtc video track again.
remote_stream->AddTrack(webrtc_track.get()); remote_stream->AddTrack(webrtc_track.get());
blink::WebVector<blink::WebMediaStreamTrack> modified_video_tracks2; blink::WebVector<blink::WebMediaStreamTrack> modified_video_tracks2;
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
#include "third_party/WebKit/public/platform/WebString.h" #include "third_party/WebKit/public/platform/WebString.h"
#include "third_party/WebKit/public/platform/WebVector.h" #include "third_party/WebKit/public/platform/WebVector.h"
#include "third_party/WebKit/public/web/WebHeap.h"
namespace content { namespace content {
...@@ -150,6 +151,11 @@ class UserMediaClientImplTest : public ::testing::Test { ...@@ -150,6 +151,11 @@ class UserMediaClientImplTest : public ::testing::Test {
scoped_ptr<MediaStreamDispatcher>(ms_dispatcher_).Pass())); scoped_ptr<MediaStreamDispatcher>(ms_dispatcher_).Pass()));
} }
virtual void TearDown() OVERRIDE {
used_media_impl_.reset();
blink::WebHeap::collectAllGarbageForTesting();
}
blink::WebMediaStream RequestLocalMediaStream() { blink::WebMediaStream RequestLocalMediaStream() {
used_media_impl_->RequestUserMedia(); used_media_impl_->RequestUserMedia();
FakeMediaStreamDispatcherRequestUserMediaComplete(); FakeMediaStreamDispatcherRequestUserMediaComplete();
...@@ -210,10 +216,12 @@ class UserMediaClientImplTest : public ::testing::Test { ...@@ -210,10 +216,12 @@ class UserMediaClientImplTest : public ::testing::Test {
used_media_impl_->last_created_video_source(); used_media_impl_->last_created_video_source();
if (video_source->SourceHasAttemptedToStart()) if (video_source->SourceHasAttemptedToStart())
video_source->FailToStartMockedSource(); video_source->FailToStartMockedSource();
blink::WebHeap::collectGarbageForTesting();
} }
void FailToCreateNextAudioCapturer() { void FailToCreateNextAudioCapturer() {
dependency_factory_->FailToCreateNextAudioCapturer(); dependency_factory_->FailToCreateNextAudioCapturer();
blink::WebHeap::collectGarbageForTesting();
} }
protected: protected:
...@@ -343,6 +351,7 @@ TEST_F(UserMediaClientImplTest, StopSourceWhenMediaStreamGoesOutOfScope) { ...@@ -343,6 +351,7 @@ TEST_F(UserMediaClientImplTest, StopSourceWhenMediaStreamGoesOutOfScope) {
// Makes sure the test itself don't hold a reference to the created // Makes sure the test itself don't hold a reference to the created
// MediaStream. // MediaStream.
used_media_impl_->ClearLastGeneratedStream(); used_media_impl_->ClearLastGeneratedStream();
blink::WebHeap::collectGarbageForTesting();
// Expect the sources to be stopped when the MediaStream goes out of scope. // Expect the sources to be stopped when the MediaStream goes out of scope.
EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter());
...@@ -369,6 +378,7 @@ TEST_F(UserMediaClientImplTest, MediaVideoSourceFailToStart) { ...@@ -369,6 +378,7 @@ TEST_F(UserMediaClientImplTest, MediaVideoSourceFailToStart) {
used_media_impl_->request_state()); used_media_impl_->request_state());
EXPECT_EQ(MEDIA_DEVICE_TRACK_START_FAILURE, EXPECT_EQ(MEDIA_DEVICE_TRACK_START_FAILURE,
used_media_impl_->error_reason()); used_media_impl_->error_reason());
blink::WebHeap::collectGarbageForTesting();
EXPECT_EQ(1, ms_dispatcher_->request_stream_counter()); EXPECT_EQ(1, ms_dispatcher_->request_stream_counter());
EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter());
EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter());
...@@ -384,6 +394,7 @@ TEST_F(UserMediaClientImplTest, MediaAudioSourceFailToInitialize) { ...@@ -384,6 +394,7 @@ TEST_F(UserMediaClientImplTest, MediaAudioSourceFailToInitialize) {
used_media_impl_->request_state()); used_media_impl_->request_state());
EXPECT_EQ(MEDIA_DEVICE_TRACK_START_FAILURE, EXPECT_EQ(MEDIA_DEVICE_TRACK_START_FAILURE,
used_media_impl_->error_reason()); used_media_impl_->error_reason());
blink::WebHeap::collectGarbageForTesting();
EXPECT_EQ(1, ms_dispatcher_->request_stream_counter()); EXPECT_EQ(1, ms_dispatcher_->request_stream_counter());
EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter());
EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter());
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/WebKit/public/platform/WebMediaConstraints.h" #include "third_party/WebKit/public/platform/WebMediaConstraints.h"
#include "third_party/WebKit/public/web/WebHeap.h"
#include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h" #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h"
using ::testing::_; using ::testing::_;
...@@ -190,6 +191,11 @@ class WebRtcLocalAudioTrackTest : public ::testing::Test { ...@@ -190,6 +191,11 @@ class WebRtcLocalAudioTrackTest : public ::testing::Test {
capturer_->SetCapturerSourceForTesting(capturer_source_, params_); capturer_->SetCapturerSourceForTesting(capturer_source_, params_);
} }
virtual void TearDown() OVERRIDE {
blink_source_.reset();
blink::WebHeap::collectAllGarbageForTesting();
}
media::AudioParameters params_; media::AudioParameters params_;
blink::WebMediaStreamSource blink_source_; blink::WebMediaStreamSource blink_source_;
scoped_refptr<MockCapturerSource> capturer_source_; scoped_refptr<MockCapturerSource> capturer_source_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment