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

Unified Diff: third_party/WebKit/Source/platform/audio/PushPullFIFOTest.cpp

Issue 2777903005: Add WebThread in AudioDestination to support AudioWorkletThread (Closed)
Patch Set: Refactoring AudioDestination for thread safety Created 3 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/audio/PushPullFIFOTest.cpp
diff --git a/third_party/WebKit/Source/platform/audio/PushPullFIFOTest.cpp b/third_party/WebKit/Source/platform/audio/PushPullFIFOTest.cpp
index 9351b4281d13b47fbf34e13dc8b9ae9643a9dabb..ef837b941d061d46f917790fd99428134c504c8c 100644
--- a/third_party/WebKit/Source/platform/audio/PushPullFIFOTest.cpp
+++ b/third_party/WebKit/Source/platform/audio/PushPullFIFOTest.cpp
@@ -8,6 +8,8 @@
#include <vector>
#include "platform/audio/AudioUtilities.h"
#include "platform/testing/TestingPlatformSupport.h"
+#include "platform/wtf/Functional.h"
+#include "platform/heap/Persistent.h"
#include "platform/wtf/PtrUtil.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -15,6 +17,13 @@ namespace blink {
namespace {
+class MockAudioDestination {
+ public:
+ MockAudioDestination() {}
+ ~MockAudioDestination() {}
+ void RequestRender (size_t frames_requested, size_t frames_to_render) {}
+};
+
// Check the basic contract of FIFO.
TEST(PushPullFIFOBasicTest, BasicTests) {
// This suppresses the multi-thread warning for GTest. Potently it increases
@@ -25,27 +34,35 @@ TEST(PushPullFIFOBasicTest, BasicTests) {
// i.e.) m_fifoLength <= kMaxFIFOLength
EXPECT_DEATH(new PushPullFIFO(2, PushPullFIFO::kMaxFIFOLength + 1), "");
+ MockAudioDestination* test_destination = new MockAudioDestination();
+
std::unique_ptr<PushPullFIFO> test_fifo =
WTF::WrapUnique(new PushPullFIFO(2, 1024));
// The input bus length must be |AudioUtilities::kRenderQuantumFrames|.
// i.e.) inputBus->length() == kRenderQuantumFrames
- RefPtr<AudioBus> input_bus_of129_frames =
+ RefPtr<AudioBus> input_bus_129_frames =
AudioBus::Create(2, AudioUtilities::kRenderQuantumFrames + 1);
- EXPECT_DEATH(test_fifo->Push(input_bus_of129_frames.Get()), "");
- RefPtr<AudioBus> input_bus_of127_frames =
+ EXPECT_DEATH(test_fifo->Push(input_bus_129_frames.Get()), "");
+ RefPtr<AudioBus> input_bus_127_frames =
AudioBus::Create(2, AudioUtilities::kRenderQuantumFrames - 1);
- EXPECT_DEATH(test_fifo->Push(input_bus_of127_frames.Get()), "");
+ EXPECT_DEATH(test_fifo->Push(input_bus_127_frames.Get()), "");
// Pull request frames cannot exceed the length of output bus.
// i.e.) framesRequested <= outputBus->length()
- RefPtr<AudioBus> output_bus_of512_frames = AudioBus::Create(2, 512);
- EXPECT_DEATH(test_fifo->Pull(output_bus_of512_frames.Get(), 513), "");
+ RefPtr<AudioBus> output_bus_512_frames = AudioBus::Create(2, 512);
+ EXPECT_DEATH(test_fifo->Pull(output_bus_512_frames.Get(), 513,
+ WTF::Bind(&MockAudioDestination::RequestRender,
+ WTF::Unretained(test_destination))),
+ "");
// Pull request frames cannot exceed the length of FIFO.
// i.e.) framesRequested <= m_fifoLength
- RefPtr<AudioBus> output_bus_of1025_frames = AudioBus::Create(2, 1025);
- EXPECT_DEATH(test_fifo->Pull(output_bus_of1025_frames.Get(), 1025), "");
+ RefPtr<AudioBus> output_bus_1025_frames = AudioBus::Create(2, 1025);
+ EXPECT_DEATH(test_fifo->Pull(output_bus_1025_frames.Get(), 1025,
+ WTF::Bind(&MockAudioDestination::RequestRender,
+ WTF::Unretained(test_destination))),
+ "");
}
// Fills each AudioChannel in an AudioBus with a series of linearly increasing
@@ -134,6 +151,8 @@ TEST_P(PushPullFIFOFeatureTest, FeatureTests) {
const FIFOTestSetup setup = GetParam().setup;
const FIFOTestExpectedState expected_state = GetParam().expected_state;
+ MockAudioDestination* test_destination = new MockAudioDestination();
+
// Create a FIFO with a specified configuration.
std::unique_ptr<PushPullFIFO> fifo = WTF::WrapUnique(
new PushPullFIFO(setup.number_of_channels, setup.fifo_length));
@@ -153,7 +172,9 @@ TEST_P(PushPullFIFOFeatureTest, FeatureTests) {
} else {
output_bus =
AudioBus::Create(setup.number_of_channels, action.number_of_frames);
- fifo->Pull(output_bus.Get(), action.number_of_frames);
+ fifo->Pull(output_bus.Get(), action.number_of_frames,
+ WTF::Bind(&MockAudioDestination::RequestRender,
+ WTF::Unretained(test_destination)));
LOG(INFO) << "PULL " << action.number_of_frames << " frames";
}
}
@@ -169,7 +190,8 @@ TEST_P(PushPullFIFOFeatureTest, FeatureTests) {
// Verify in-FIFO samples.
for (const auto& sample : expected_state.fifo_samples) {
- EXPECT_TRUE(VerifyBusValueAtIndex(fifo->Bus(), sample.index, sample.value));
+ EXPECT_TRUE(VerifyBusValueAtIndex(fifo->GetFIFOBusForTest(),
+ sample.index, sample.value));
}
// Verify samples from the most recent output bus.

Powered by Google App Engine
This is Rietveld 408576698