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

Unified Diff: third_party/WebKit/Source/modules/webaudio/BaseAudioContextTest.cpp

Issue 2501863003: Support for AudioContextOptions latencyHint. (Closed)
Patch Set: Updates based on reviewer comments. Created 4 years 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/modules/webaudio/BaseAudioContextTest.cpp
diff --git a/third_party/WebKit/Source/modules/webaudio/BaseAudioContextTest.cpp b/third_party/WebKit/Source/modules/webaudio/BaseAudioContextTest.cpp
index cf60f794230812462c0af56b947fc3e7bb982446..f49da4b53d2a8b10e04f97414895c47558733288 100644
--- a/third_party/WebKit/Source/modules/webaudio/BaseAudioContextTest.cpp
+++ b/third_party/WebKit/Source/modules/webaudio/BaseAudioContextTest.cpp
@@ -17,6 +17,7 @@
#include "platform/testing/HistogramTester.h"
#include "platform/testing/TestingPlatformSupport.h"
#include "public/platform/WebAudioDevice.h"
+#include "public/platform/WebAudioLatencyHint.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace blink {
@@ -24,6 +25,8 @@ namespace blink {
namespace {
const char* const kCrossOriginMetric = "WebAudio.Autoplay.CrossOrigin";
+const WebAudioLatencyHint kLatencyHintInteractive(
+ WebAudioLatencyHint::CategoryInteractive);
hongchan 2016/12/02 17:40:12 Can't this be a part of WebAudioLatencyHint?
Andrew MacPherson 2016/12/05 14:12:53 I have refactored this now to pass an AudioContext
class MockCrossOriginFrameLoaderClient final : public EmptyFrameLoaderClient {
public:
@@ -47,30 +50,34 @@ class MockCrossOriginFrameLoaderClient final : public EmptyFrameLoaderClient {
class MockWebAudioDevice : public WebAudioDevice {
public:
- explicit MockWebAudioDevice(double sampleRate) : m_sampleRate(sampleRate) {}
+ explicit MockWebAudioDevice(double sampleRate, int framesPerBuffer)
+ : m_sampleRate(sampleRate), m_framesPerBuffer(framesPerBuffer) {}
~MockWebAudioDevice() override = default;
void start() override {}
void stop() override {}
double sampleRate() override { return m_sampleRate; }
+ int framesPerBuffer() override { return m_framesPerBuffer; }
private:
double m_sampleRate;
+ int m_framesPerBuffer;
};
class BaseAudioContextTestPlatform : public TestingPlatformSupport {
public:
- WebAudioDevice* createAudioDevice(size_t bufferSize,
- unsigned numberOfInputChannels,
+ WebAudioDevice* createAudioDevice(unsigned numberOfInputChannels,
unsigned numberOfChannels,
- double sampleRate,
+ const WebAudioLatencyHint& latencyHint,
WebAudioDevice::RenderCallback*,
const WebString& deviceId,
const WebSecurityOrigin&) override {
- return new MockWebAudioDevice(sampleRate);
+ return new MockWebAudioDevice(audioHardwareSampleRate(),
+ audioHardwareBufferSize());
}
double audioHardwareSampleRate() override { return 44100; }
+ size_t audioHardwareBufferSize() override { return 128; }
};
} // anonymous namespace
@@ -137,8 +144,8 @@ class BaseAudioContextTest : public ::testing::Test {
TEST_F(BaseAudioContextTest, AutoplayMetrics_NoRestriction) {
HistogramTester histogramTester;
- BaseAudioContext* audioContext =
- BaseAudioContext::create(document(), ASSERT_NO_EXCEPTION);
+ BaseAudioContext* audioContext = BaseAudioContext::create(
+ document(), kLatencyHintInteractive, ASSERT_NO_EXCEPTION);
recordAutoplayStatus(audioContext);
histogramTester.expectTotalCount(kCrossOriginMetric, 0);
@@ -149,8 +156,8 @@ TEST_F(BaseAudioContextTest, AutoplayMetrics_CreateNoGesture) {
createChildFrame();
childDocument().settings()->setMediaPlaybackRequiresUserGesture(true);
- BaseAudioContext* audioContext =
- BaseAudioContext::create(childDocument(), ASSERT_NO_EXCEPTION);
+ BaseAudioContext* audioContext = BaseAudioContext::create(
+ childDocument(), kLatencyHintInteractive, ASSERT_NO_EXCEPTION);
recordAutoplayStatus(audioContext);
histogramTester.expectBucketCount(kCrossOriginMetric,
@@ -165,8 +172,8 @@ TEST_F(BaseAudioContextTest, AutoplayMetrics_CallResumeNoGesture) {
ScriptState::Scope scope(getScriptStateFrom(childDocument()));
- BaseAudioContext* audioContext =
- BaseAudioContext::create(childDocument(), ASSERT_NO_EXCEPTION);
+ BaseAudioContext* audioContext = BaseAudioContext::create(
+ childDocument(), kLatencyHintInteractive, ASSERT_NO_EXCEPTION);
audioContext->resumeContext(getScriptStateFrom(childDocument()));
rejectPendingResolvers(audioContext);
recordAutoplayStatus(audioContext);
@@ -184,8 +191,8 @@ TEST_F(BaseAudioContextTest, AutoplayMetrics_CreateGesture) {
UserGestureIndicator userGestureScope(DocumentUserGestureToken::create(
&childDocument(), UserGestureToken::NewGesture));
- BaseAudioContext* audioContext =
- BaseAudioContext::create(childDocument(), ASSERT_NO_EXCEPTION);
+ BaseAudioContext* audioContext = BaseAudioContext::create(
+ childDocument(), kLatencyHintInteractive, ASSERT_NO_EXCEPTION);
recordAutoplayStatus(audioContext);
histogramTester.expectBucketCount(kCrossOriginMetric,
@@ -200,8 +207,8 @@ TEST_F(BaseAudioContextTest, AutoplayMetrics_CallResumeGesture) {
ScriptState::Scope scope(getScriptStateFrom(childDocument()));
- BaseAudioContext* audioContext =
- BaseAudioContext::create(childDocument(), ASSERT_NO_EXCEPTION);
+ BaseAudioContext* audioContext = BaseAudioContext::create(
+ childDocument(), kLatencyHintInteractive, ASSERT_NO_EXCEPTION);
UserGestureIndicator userGestureScope(DocumentUserGestureToken::create(
&childDocument(), UserGestureToken::NewGesture));
@@ -220,8 +227,8 @@ TEST_F(BaseAudioContextTest, AutoplayMetrics_NodeStartNoGesture) {
createChildFrame();
childDocument().settings()->setMediaPlaybackRequiresUserGesture(true);
- BaseAudioContext* audioContext =
- BaseAudioContext::create(childDocument(), ASSERT_NO_EXCEPTION);
+ BaseAudioContext* audioContext = BaseAudioContext::create(
+ childDocument(), kLatencyHintInteractive, ASSERT_NO_EXCEPTION);
audioContext->maybeRecordStartAttempt();
recordAutoplayStatus(audioContext);
@@ -235,8 +242,8 @@ TEST_F(BaseAudioContextTest, AutoplayMetrics_NodeStartGesture) {
createChildFrame();
childDocument().settings()->setMediaPlaybackRequiresUserGesture(true);
- BaseAudioContext* audioContext =
- BaseAudioContext::create(childDocument(), ASSERT_NO_EXCEPTION);
+ BaseAudioContext* audioContext = BaseAudioContext::create(
+ childDocument(), kLatencyHintInteractive, ASSERT_NO_EXCEPTION);
UserGestureIndicator userGestureScope(DocumentUserGestureToken::create(
&childDocument(), UserGestureToken::NewGesture));
@@ -255,8 +262,8 @@ TEST_F(BaseAudioContextTest, AutoplayMetrics_NodeStartNoGestureThenSuccess) {
ScriptState::Scope scope(getScriptStateFrom(childDocument()));
- BaseAudioContext* audioContext =
- BaseAudioContext::create(childDocument(), ASSERT_NO_EXCEPTION);
+ BaseAudioContext* audioContext = BaseAudioContext::create(
+ childDocument(), kLatencyHintInteractive, ASSERT_NO_EXCEPTION);
audioContext->maybeRecordStartAttempt();
UserGestureIndicator userGestureScope(DocumentUserGestureToken::create(
@@ -277,8 +284,8 @@ TEST_F(BaseAudioContextTest, AutoplayMetrics_NodeStartGestureThenSucces) {
ScriptState::Scope scope(getScriptStateFrom(childDocument()));
- BaseAudioContext* audioContext =
- BaseAudioContext::create(childDocument(), ASSERT_NO_EXCEPTION);
+ BaseAudioContext* audioContext = BaseAudioContext::create(
+ childDocument(), kLatencyHintInteractive, ASSERT_NO_EXCEPTION);
UserGestureIndicator userGestureScope(DocumentUserGestureToken::create(
&childDocument(), UserGestureToken::NewGesture));

Powered by Google App Engine
This is Rietveld 408576698