Commit 02b15d5a authored by haraken's avatar haraken Committed by Commit bot

MediaStream content_unittests need to trigger a GC before tear down

Given that MediaStream objects in the Blink side are allocated on Oilpan's heap, we need to trigger a GC to collect MediaStream objects in the Chromium side that depend on the lifetime of the MediaStream objects in the Blink side.

This CL adds Heap::collectAllGarbage to TearDown methods of MediaStream content_unittests. This guarantees that MediaStream objects used in the content_unittests are collected before the content_unittests finish. Otherwise, the LSan complains that the MediaStream objects leak in the content_unittests.

This is an issue that happens only in testing.

BUG=340522

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

Cr-Commit-Position: refs/heads/master@{#295920}
parent a0aab5b4
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,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"
namespace content { namespace content {
...@@ -40,6 +41,11 @@ class MediaStreamVideoTrackTest : public ::testing::Test { ...@@ -40,6 +41,11 @@ class MediaStreamVideoTrackTest : public ::testing::Test {
virtual ~MediaStreamVideoTrackTest() { virtual ~MediaStreamVideoTrackTest() {
} }
virtual void TearDown() OVERRIDE {
blink_source_.reset();
blink::WebHeap::collectAllGarbageForTesting();
}
void DeliverVideoFrameAndWaitForRenderer(MockMediaStreamVideoSink* sink) { void DeliverVideoFrameAndWaitForRenderer(MockMediaStreamVideoSink* sink) {
base::RunLoop run_loop; base::RunLoop run_loop;
base::Closure quit_closure = run_loop.QuitClosure(); base::Closure quit_closure = run_loop.QuitClosure();
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#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/web/WebHeap.h"
namespace content { namespace content {
...@@ -44,17 +45,22 @@ class VideoSourceHandlerTest : public ::testing::Test { ...@@ -44,17 +45,22 @@ class VideoSourceHandlerTest : public ::testing::Test {
public: public:
VideoSourceHandlerTest() VideoSourceHandlerTest()
: child_process_(new ChildProcess()), : child_process_(new ChildProcess()),
registry_() { registry_(new MockMediaStreamRegistry()) {
handler_.reset(new VideoSourceHandler(&registry_)); handler_.reset(new VideoSourceHandler(registry_.get()));
registry_.Init(kTestStreamUrl); registry_->Init(kTestStreamUrl);
registry_.AddVideoTrack(kTestVideoTrackId); registry_->AddVideoTrack(kTestVideoTrackId);
}
virtual void TearDown() {
registry_.reset();
blink::WebHeap::collectAllGarbageForTesting();
} }
protected: protected:
base::MessageLoop message_loop_; base::MessageLoop message_loop_;
scoped_ptr<ChildProcess> child_process_; scoped_ptr<ChildProcess> child_process_;
scoped_ptr<VideoSourceHandler> handler_; scoped_ptr<VideoSourceHandler> handler_;
MockMediaStreamRegistry registry_; scoped_ptr<MockMediaStreamRegistry> registry_;
}; };
TEST_F(VideoSourceHandlerTest, OpenClose) { TEST_F(VideoSourceHandlerTest, OpenClose) {
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "content/renderer/media/webrtc/mock_peer_connection_dependency_factory.h" #include "content/renderer/media/webrtc/mock_peer_connection_dependency_factory.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"
#include "third_party/libjingle/source/talk/media/webrtc/webrtcvideoframe.h" #include "third_party/libjingle/source/talk/media/webrtc/webrtcvideoframe.h"
namespace content { namespace content {
...@@ -48,6 +49,11 @@ class MediaStreamRemoteVideoSourceTest ...@@ -48,6 +49,11 @@ class MediaStreamRemoteVideoSourceTest
webkit_source_.setExtraData(remote_source_); webkit_source_.setExtraData(remote_source_);
} }
virtual void TearDown() OVERRIDE {
webkit_source_.reset();
blink::WebHeap::collectAllGarbageForTesting();
}
MediaStreamRemoteVideoSourceUnderTest* source() { MediaStreamRemoteVideoSourceUnderTest* source() {
return remote_source_; return remote_source_;
} }
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#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/web/WebHeap.h"
using ::testing::_; using ::testing::_;
...@@ -40,8 +41,9 @@ class VideoDestinationHandlerTest : public PpapiUnittest { ...@@ -40,8 +41,9 @@ class VideoDestinationHandlerTest : public PpapiUnittest {
registry_->Init(kTestStreamUrl); registry_->Init(kTestStreamUrl);
} }
virtual void TearDown() { virtual void TearDown() OVERRIDE {
registry_.reset(); registry_.reset();
blink::WebHeap::collectAllGarbageForTesting();
PpapiUnittest::TearDown(); PpapiUnittest::TearDown();
} }
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "third_party/WebKit/public/platform/WebMediaStreamSource.h" #include "third_party/WebKit/public/platform/WebMediaStreamSource.h"
#include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" #include "third_party/WebKit/public/platform/WebMediaStreamTrack.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 {
...@@ -28,6 +29,11 @@ class WebRtcMediaStreamAdapterTest : public ::testing::Test { ...@@ -28,6 +29,11 @@ class WebRtcMediaStreamAdapterTest : public ::testing::Test {
dependency_factory_.reset(new MockPeerConnectionDependencyFactory()); dependency_factory_.reset(new MockPeerConnectionDependencyFactory());
} }
virtual void TearDown() OVERRIDE {
adapter_.reset();
blink::WebHeap::collectAllGarbageForTesting();
}
blink::WebMediaStream CreateBlinkMediaStream(bool audio, bool video) { blink::WebMediaStream CreateBlinkMediaStream(bool audio, bool video) {
blink::WebVector<blink::WebMediaStreamTrack> audio_track_vector( blink::WebVector<blink::WebMediaStreamTrack> audio_track_vector(
audio ? static_cast<size_t>(1) : 0); audio ? static_cast<size_t>(1) : 0);
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "media/base/audio_bus.h" #include "media/base/audio_bus.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
#include "third_party/WebKit/public/web/WebHeap.h"
namespace content { namespace content {
...@@ -50,6 +51,12 @@ class WebRtcLocalAudioSourceProviderTest : public testing::Test { ...@@ -50,6 +51,12 @@ class WebRtcLocalAudioSourceProviderTest : public testing::Test {
source_provider_->OnSetFormat(source_params_); source_provider_->OnSetFormat(source_params_);
} }
virtual void TearDown() OVERRIDE {
source_provider_.reset();
blink_track_.reset();
blink::WebHeap::collectAllGarbageForTesting();
}
media::AudioParameters source_params_; media::AudioParameters source_params_;
scoped_ptr<int16[]> source_data_; scoped_ptr<int16[]> source_data_;
media::AudioParameters sink_params_; media::AudioParameters sink_params_;
......
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