| 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 "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
| 8 #include "core/dom/DocumentUserGestureToken.h" | 8 #include "core/dom/DocumentUserGestureToken.h" |
| 9 #include "core/frame/FrameOwner.h" | 9 #include "core/frame/FrameOwner.h" |
| 10 #include "core/frame/FrameTypes.h" | 10 #include "core/frame/FrameTypes.h" |
| 11 #include "core/frame/FrameView.h" | 11 #include "core/frame/FrameView.h" |
| 12 #include "core/frame/Settings.h" | 12 #include "core/frame/Settings.h" |
| 13 #include "core/loader/DocumentLoader.h" | 13 #include "core/loader/DocumentLoader.h" |
| 14 #include "core/loader/EmptyClients.h" | 14 #include "core/loader/EmptyClients.h" |
| 15 #include "core/testing/DummyPageHolder.h" | 15 #include "core/testing/DummyPageHolder.h" |
| 16 #include "platform/UserGestureIndicator.h" | 16 #include "platform/UserGestureIndicator.h" |
| 17 #include "platform/testing/HistogramTester.h" | 17 #include "platform/testing/HistogramTester.h" |
| 18 #include "platform/testing/TestingPlatformSupport.h" | 18 #include "platform/testing/TestingPlatformSupport.h" |
| 19 #include "public/platform/WebAudioDevice.h" | 19 #include "public/platform/WebAudioDevice.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "wtf/PtrUtil.h" |
| 21 | 22 |
| 22 namespace blink { | 23 namespace blink { |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| 26 const char* const kCrossOriginMetric = "WebAudio.Autoplay.CrossOrigin"; | 27 const char* const kCrossOriginMetric = "WebAudio.Autoplay.CrossOrigin"; |
| 27 | 28 |
| 28 class MockCrossOriginFrameLoaderClient final : public EmptyFrameLoaderClient { | 29 class MockCrossOriginFrameLoaderClient final : public EmptyFrameLoaderClient { |
| 29 public: | 30 public: |
| 30 static MockCrossOriginFrameLoaderClient* create(Frame* parent) { | 31 static MockCrossOriginFrameLoaderClient* create(Frame* parent) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 double audioHardwareSampleRate() override { return 44100; } | 74 double audioHardwareSampleRate() override { return 44100; } |
| 74 }; | 75 }; |
| 75 | 76 |
| 76 } // anonymous namespace | 77 } // anonymous namespace |
| 77 | 78 |
| 78 class BaseAudioContextTest : public ::testing::Test { | 79 class BaseAudioContextTest : public ::testing::Test { |
| 79 protected: | 80 protected: |
| 80 using AutoplayStatus = BaseAudioContext::AutoplayStatus; | 81 using AutoplayStatus = BaseAudioContext::AutoplayStatus; |
| 81 | 82 |
| 82 void SetUp() override { | 83 void SetUp() override { |
| 84 m_testPlatform.reset(WTF::makeUnique<BaseAudioContextTestPlatform>()); |
| 83 m_dummyPageHolder = DummyPageHolder::create(); | 85 m_dummyPageHolder = DummyPageHolder::create(); |
| 84 m_dummyFrameOwner = DummyFrameOwner::create(); | 86 m_dummyFrameOwner = DummyFrameOwner::create(); |
| 85 document().updateSecurityOrigin( | 87 document().updateSecurityOrigin( |
| 86 SecurityOrigin::create("https", "example.com", 80)); | 88 SecurityOrigin::create("https", "example.com", 80)); |
| 87 } | 89 } |
| 88 | 90 |
| 89 void TearDown() override { | 91 void TearDown() override { |
| 90 if (m_childFrame) | 92 if (m_childFrame) |
| 91 m_childFrame->detach(FrameDetachType::Remove); | 93 m_childFrame->detach(FrameDetachType::Remove); |
| 92 } | 94 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 117 void recordAutoplayStatus(BaseAudioContext* audioContext) { | 119 void recordAutoplayStatus(BaseAudioContext* audioContext) { |
| 118 audioContext->recordAutoplayStatus(); | 120 audioContext->recordAutoplayStatus(); |
| 119 } | 121 } |
| 120 | 122 |
| 121 private: | 123 private: |
| 122 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; | 124 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; |
| 123 Persistent<DummyFrameOwner> m_dummyFrameOwner; | 125 Persistent<DummyFrameOwner> m_dummyFrameOwner; |
| 124 | 126 |
| 125 Persistent<LocalFrame> m_childFrame; | 127 Persistent<LocalFrame> m_childFrame; |
| 126 | 128 |
| 127 BaseAudioContextTestPlatform m_testPlatform; | 129 ScopedTestingPlatformSupport<BaseAudioContextTestPlatform> m_testPlatform; |
| 128 }; | 130 }; |
| 129 | 131 |
| 130 TEST_F(BaseAudioContextTest, AutoplayMetrics_NoRestriction) { | 132 TEST_F(BaseAudioContextTest, AutoplayMetrics_NoRestriction) { |
| 131 HistogramTester histogramTester; | 133 HistogramTester histogramTester; |
| 132 | 134 |
| 133 BaseAudioContext* audioContext = | 135 BaseAudioContext* audioContext = |
| 134 BaseAudioContext::create(document(), ASSERT_NO_EXCEPTION); | 136 BaseAudioContext::create(document(), ASSERT_NO_EXCEPTION); |
| 135 recordAutoplayStatus(audioContext); | 137 recordAutoplayStatus(audioContext); |
| 136 | 138 |
| 137 histogramTester.expectTotalCount(kCrossOriginMetric, 0); | 139 histogramTester.expectTotalCount(kCrossOriginMetric, 0); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 audioContext->resumeContext(getScriptStateFrom(childDocument())); | 281 audioContext->resumeContext(getScriptStateFrom(childDocument())); |
| 280 rejectPendingResolvers(audioContext); | 282 rejectPendingResolvers(audioContext); |
| 281 recordAutoplayStatus(audioContext); | 283 recordAutoplayStatus(audioContext); |
| 282 | 284 |
| 283 histogramTester.expectBucketCount(kCrossOriginMetric, | 285 histogramTester.expectBucketCount(kCrossOriginMetric, |
| 284 AutoplayStatus::AutoplayStatusSucceeded, 1); | 286 AutoplayStatus::AutoplayStatusSucceeded, 1); |
| 285 histogramTester.expectTotalCount(kCrossOriginMetric, 1); | 287 histogramTester.expectTotalCount(kCrossOriginMetric, 1); |
| 286 } | 288 } |
| 287 | 289 |
| 288 } // namespace blink | 290 } // namespace blink |
| OLD | NEW |