| 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 eb46576a320bcd92d1264793ae31d7a64d6e3d2f..d37f1bf2e09066c69a6a20aae490c6522351be7d 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);
|
|
|
| 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
|
| @@ -138,8 +145,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);
|
| @@ -150,8 +157,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,
|
| @@ -166,8 +173,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);
|
| @@ -185,8 +192,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,
|
| @@ -201,8 +208,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));
|
| @@ -221,8 +228,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);
|
|
|
| @@ -236,8 +243,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));
|
| @@ -256,8 +263,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(
|
| @@ -278,8 +285,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));
|
|
|