OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "modules/webaudio/BaseAudioContext.h" | 5 #include "modules/webaudio/BaseAudioContext.h" |
6 | 6 |
7 #include "bindings/core/v8/V8BindingForCore.h" | 7 #include "bindings/core/v8/V8BindingForCore.h" |
8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
9 #include "core/dom/DocumentUserGestureToken.h" | 9 #include "core/dom/DocumentUserGestureToken.h" |
10 #include "core/frame/FrameOwner.h" | 10 #include "core/frame/FrameOwner.h" |
11 #include "core/frame/FrameTypes.h" | 11 #include "core/frame/FrameTypes.h" |
12 #include "core/frame/FrameView.h" | 12 #include "core/frame/FrameView.h" |
13 #include "core/frame/Settings.h" | 13 #include "core/frame/Settings.h" |
14 #include "core/loader/DocumentLoader.h" | 14 #include "core/loader/DocumentLoader.h" |
15 #include "core/loader/EmptyClients.h" | 15 #include "core/loader/EmptyClients.h" |
16 #include "core/testing/DummyPageHolder.h" | 16 #include "core/testing/DummyPageHolder.h" |
17 #include "modules/webaudio/AudioContextOptions.h" | 17 #include "modules/webaudio/AudioContextOptions.h" |
18 #include "platform/UserGestureIndicator.h" | 18 #include "platform/UserGestureIndicator.h" |
19 #include "platform/testing/HistogramTester.h" | 19 #include "platform/testing/HistogramTester.h" |
20 #include "platform/testing/TestingPlatformSupport.h" | 20 #include "platform/testing/TestingPlatformSupport.h" |
21 #include "platform/wtf/PtrUtil.h" | |
22 #include "public/platform/WebAudioDevice.h" | 21 #include "public/platform/WebAudioDevice.h" |
23 #include "public/platform/WebAudioLatencyHint.h" | 22 #include "public/platform/WebAudioLatencyHint.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
25 | 24 |
26 namespace blink { | 25 namespace blink { |
27 | 26 |
28 namespace { | 27 namespace { |
29 | 28 |
30 const char* const kCrossOriginMetric = "WebAudio.Autoplay.CrossOrigin"; | 29 const char* const kCrossOriginMetric = "WebAudio.Autoplay.CrossOrigin"; |
31 | 30 |
(...skipping 28 matching lines...) Expand all Loading... |
60 double SampleRate() override { return sample_rate_; } | 59 double SampleRate() override { return sample_rate_; } |
61 int FramesPerBuffer() override { return frames_per_buffer_; } | 60 int FramesPerBuffer() override { return frames_per_buffer_; } |
62 | 61 |
63 private: | 62 private: |
64 double sample_rate_; | 63 double sample_rate_; |
65 int frames_per_buffer_; | 64 int frames_per_buffer_; |
66 }; | 65 }; |
67 | 66 |
68 class BaseAudioContextTestPlatform : public TestingPlatformSupport { | 67 class BaseAudioContextTestPlatform : public TestingPlatformSupport { |
69 public: | 68 public: |
70 std::unique_ptr<WebAudioDevice> CreateAudioDevice( | 69 WebAudioDevice* CreateAudioDevice(unsigned number_of_input_channels, |
71 unsigned number_of_input_channels, | 70 unsigned number_of_channels, |
72 unsigned number_of_channels, | 71 const WebAudioLatencyHint& latency_hint, |
73 const WebAudioLatencyHint& latency_hint, | 72 WebAudioDevice::RenderCallback*, |
74 WebAudioDevice::RenderCallback*, | 73 const WebString& device_id, |
75 const WebString& device_id, | 74 const WebSecurityOrigin&) override { |
76 const WebSecurityOrigin&) override { | 75 return new MockWebAudioDevice(AudioHardwareSampleRate(), |
77 return WTF::MakeUnique<MockWebAudioDevice>(AudioHardwareSampleRate(), | 76 AudioHardwareBufferSize()); |
78 AudioHardwareBufferSize()); | |
79 } | 77 } |
80 | 78 |
81 double AudioHardwareSampleRate() override { return 44100; } | 79 double AudioHardwareSampleRate() override { return 44100; } |
82 size_t AudioHardwareBufferSize() override { return 128; } | 80 size_t AudioHardwareBufferSize() override { return 128; } |
83 }; | 81 }; |
84 | 82 |
85 } // anonymous namespace | 83 } // anonymous namespace |
86 | 84 |
87 class BaseAudioContextTest : public ::testing::Test { | 85 class BaseAudioContextTest : public ::testing::Test { |
88 protected: | 86 protected: |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 audio_context->resumeContext(GetScriptStateFrom(ChildDocument())); | 284 audio_context->resumeContext(GetScriptStateFrom(ChildDocument())); |
287 RejectPendingResolvers(audio_context); | 285 RejectPendingResolvers(audio_context); |
288 RecordAutoplayStatus(audio_context); | 286 RecordAutoplayStatus(audio_context); |
289 | 287 |
290 histogram_tester.ExpectBucketCount( | 288 histogram_tester.ExpectBucketCount( |
291 kCrossOriginMetric, AutoplayStatus::kAutoplayStatusSucceeded, 1); | 289 kCrossOriginMetric, AutoplayStatus::kAutoplayStatusSucceeded, 1); |
292 histogram_tester.ExpectTotalCount(kCrossOriginMetric, 1); | 290 histogram_tester.ExpectTotalCount(kCrossOriginMetric, 1); |
293 } | 291 } |
294 | 292 |
295 } // namespace blink | 293 } // namespace blink |
OLD | NEW |