Commit a731c68f authored by danakj's avatar danakj Committed by Commit Bot

Use ScopedTestingPlatformSupport to set the Platform in WebRTC unittest

Without using this, the Platform object is not replaced when the test
class shuts down. This makes the next test to run have a Platform
pointer to a deleted object, and causes a crash if any future tests
in the shard will try to use the Platform.

R=avi@chromium.org, pdr@chromium.org

Bug: 419087, 745091
Change-Id: I09145e6a6a8ad1b0b1f9d0d77f04dc147a90972a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1726730Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Commit-Queue: danakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#682445}
parent 941e5ca2
......@@ -45,5 +45,6 @@ specific_include_rules = {
],
".*_(unit|pixel|perf)test.*\.cc": [
"+components/viz/test",
"+third_party/blink/renderer/platform/testing",
],
}
......@@ -28,6 +28,7 @@
#include "third_party/blink/public/platform/web_string.h"
#include "third_party/blink/public/web/web_heap.h"
#include "third_party/blink/public/web/web_local_frame.h"
#include "third_party/blink/renderer/platform/testing/testing_platform_support.h"
#include "third_party/webrtc/api/media_stream_interface.h"
using testing::Return;
......@@ -100,9 +101,6 @@ class WebRtcAudioRendererTest : public testing::Test,
protected:
WebRtcAudioRendererTest() : source_(new MockAudioRendererSource()) {
blink::Platform::SetCurrentPlatformForTesting(
&audio_device_factory_platform_);
blink::WebVector<blink::WebMediaStreamTrack> dummy_tracks;
stream_.Initialize(blink::WebString::FromUTF8("new stream"), dummy_tracks,
dummy_tracks);
......@@ -116,7 +114,7 @@ class WebRtcAudioRendererTest : public testing::Test,
nullptr, base::UnguessableToken::Create(), device_id);
EXPECT_CALL(
audio_device_factory_platform_,
*audio_device_factory_platform_,
MockNewAudioRendererSink(_, nullptr /*blink::WebLocalFrame*/, _))
.Times(testing::AtLeast(1));
EXPECT_CALL(*this, MockCreateAudioRendererSink(
......@@ -182,7 +180,8 @@ class WebRtcAudioRendererTest : public testing::Test,
blink::WebHeap::CollectAllGarbageForTesting();
}
AudioDeviceFactoryTestingPlatformSupport audio_device_factory_platform_;
blink::ScopedTestingPlatformSupport<AudioDeviceFactoryTestingPlatformSupport>
audio_device_factory_platform_;
const base::Optional<base::UnguessableToken> kAudioProcessingId =
base::UnguessableToken::Create();
base::test::ScopedTaskEnvironment task_environment_{
......
......@@ -162,6 +162,10 @@ class BLINK_PLATFORM_EXPORT Platform {
// Used to switch the current platform only for testing.
// You should not pass in a Platform object that is not fully instantiated.
//
// NOTE: Instead of calling this directly, us a ScopedTestingPlatformSupport
// which will restore the previous platform on exit, preventing tests from
// clobbering each other.
static void SetCurrentPlatformForTesting(Platform*);
// This sets up a minimally viable implementation of blink::Thread without
......
......@@ -144,6 +144,9 @@ class ScopedTestingPlatformSupport final {
const T* operator->() const { return testing_platform_support_.get(); }
T* operator->() { return testing_platform_support_.get(); }
const T& operator*() const { return *testing_platform_support_; }
T& operator*() { return *testing_platform_support_; }
T* GetTestingPlatformSupport() { return testing_platform_support_.get(); }
private:
......
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