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

Side by Side Diff: third_party/WebKit/Source/modules/webaudio/AudioContextTest.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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "modules/webaudio/AudioContext.h"
6
7 #include "core/dom/Document.h"
8 #include "core/testing/DummyPageHolder.h"
9 #include "platform/testing/TestingPlatformSupport.h"
10 #include "public/platform/WebAudioDevice.h"
11 #include "public/platform/WebAudioLatencyHint.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 namespace blink {
15
16 namespace {
17
18 class MockWebAudioDevice : public WebAudioDevice {
19 public:
20 explicit MockWebAudioDevice(double sampleRate, int framesPerBuffer)
21 : m_sampleRate(sampleRate), m_framesPerBuffer(framesPerBuffer) {}
22 ~MockWebAudioDevice() override = default;
23
24 void start() override {}
25 void stop() override {}
26 double sampleRate() override { return m_sampleRate; }
27 int framesPerBuffer() override { return m_framesPerBuffer; }
28
29 private:
30 double m_sampleRate;
31 int m_framesPerBuffer;
32 };
33
34 class AudioContextTestPlatform : public TestingPlatformSupport {
35 public:
36 WebAudioDevice* createAudioDevice(unsigned numberOfInputChannels,
37 unsigned numberOfChannels,
38 const WebAudioLatencyHint& latencyHint,
39 WebAudioDevice::RenderCallback*,
40 const WebString& deviceId,
41 const WebSecurityOrigin&) override {
42 double bufferSize = 0;
43 switch (latencyHint.category()) {
44 case WebAudioLatencyHint::CategoryInteractive:
45 bufferSize = audioHardwareBufferSize();
46 break;
47 case WebAudioLatencyHint::CategoryBalanced:
48 bufferSize = audioHardwareBufferSize() * 2;
49 break;
50 case WebAudioLatencyHint::CategoryPlayback:
51 bufferSize = audioHardwareBufferSize() * 4;
52 break;
53 default:
54 NOTREACHED();
55 break;
56 }
57
58 return new MockWebAudioDevice(audioHardwareSampleRate(), bufferSize);
59 }
60
61 double audioHardwareSampleRate() override { return 44100; }
62 size_t audioHardwareBufferSize() override { return 128; }
63 };
64
65 } // anonymous namespace
66
67 class AudioContextTest : public ::testing::Test {
68 protected:
69 void SetUp() override { m_dummyPageHolder = DummyPageHolder::create(); }
70
71 void TearDown() override {}
72
73 Document& document() { return m_dummyPageHolder->document(); }
74
75 private:
76 std::unique_ptr<DummyPageHolder> m_dummyPageHolder;
77 AudioContextTestPlatform m_testPlatform;
78 };
79
80 TEST_F(AudioContextTest, AudioContextOptions_WebAudioLatencyHint) {
81 AudioContext* interactiveContext = AudioContext::create(
82 document(), WebAudioLatencyHint(WebAudioLatencyHint::CategoryInteractive),
83 ASSERT_NO_EXCEPTION);
84
85 AudioContext* balancedContext = AudioContext::create(
86 document(), WebAudioLatencyHint(WebAudioLatencyHint::CategoryBalanced),
87 ASSERT_NO_EXCEPTION);
88 EXPECT_GT(balancedContext->baseLatency(), interactiveContext->baseLatency());
89
90 AudioContext* playbackContext = AudioContext::create(
91 document(), WebAudioLatencyHint(WebAudioLatencyHint::CategoryPlayback),
92 ASSERT_NO_EXCEPTION);
93 EXPECT_GT(playbackContext->baseLatency(), balancedContext->baseLatency());
94 }
95
96 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698