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