| 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" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 using AutoplayStatus = BaseAudioContext::AutoplayStatus; | 80 using AutoplayStatus = BaseAudioContext::AutoplayStatus; |
| 81 | 81 |
| 82 void SetUp() override { | 82 void SetUp() override { |
| 83 m_dummyPageHolder = DummyPageHolder::create(); | 83 m_dummyPageHolder = DummyPageHolder::create(); |
| 84 m_dummyFrameOwner = DummyFrameOwner::create(); | 84 m_dummyFrameOwner = DummyFrameOwner::create(); |
| 85 document().updateSecurityOrigin( | 85 document().updateSecurityOrigin( |
| 86 SecurityOrigin::create("https", "example.com", 80)); | 86 SecurityOrigin::create("https", "example.com", 80)); |
| 87 } | 87 } |
| 88 | 88 |
| 89 void TearDown() override { | 89 void TearDown() override { |
| 90 if (m_childFrame) { | 90 if (m_childFrame) |
| 91 m_childDocumentLoader->detachFromFrame(); | |
| 92 m_childDocumentLoader.clear(); | |
| 93 m_childFrame->detach(FrameDetachType::Remove); | 91 m_childFrame->detach(FrameDetachType::Remove); |
| 94 } | |
| 95 } | 92 } |
| 96 | 93 |
| 97 void createChildFrame() { | 94 void createChildFrame() { |
| 98 m_childFrame = LocalFrame::create( | 95 m_childFrame = LocalFrame::create( |
| 99 MockCrossOriginFrameLoaderClient::create(document().frame()), | 96 MockCrossOriginFrameLoaderClient::create(document().frame()), |
| 100 document().frame()->host(), m_dummyFrameOwner.get()); | 97 document().frame()->host(), m_dummyFrameOwner.get()); |
| 101 m_childFrame->setView(FrameView::create(*m_childFrame, IntSize(500, 500))); | 98 m_childFrame->setView(FrameView::create(*m_childFrame, IntSize(500, 500))); |
| 102 m_childFrame->init(); | 99 m_childFrame->init(); |
| 103 m_childDocumentLoader = DocumentLoader::create( | |
| 104 m_childFrame.get(), ResourceRequest("https://www.example.com"), | |
| 105 SubstituteData(), ClientRedirectPolicy::NotClientRedirect); | |
| 106 | 100 |
| 107 childDocument().updateSecurityOrigin( | 101 childDocument().updateSecurityOrigin( |
| 108 SecurityOrigin::create("https", "cross-origin.com", 80)); | 102 SecurityOrigin::create("https", "cross-origin.com", 80)); |
| 109 } | 103 } |
| 110 | 104 |
| 111 Document& document() { return m_dummyPageHolder->document(); } | 105 Document& document() { return m_dummyPageHolder->document(); } |
| 112 | 106 |
| 113 Document& childDocument() { return *m_childFrame->document(); } | 107 Document& childDocument() { return *m_childFrame->document(); } |
| 114 | 108 |
| 115 ScriptState* getScriptStateFrom(const Document& document) { | 109 ScriptState* getScriptStateFrom(const Document& document) { |
| 116 return ScriptState::forMainWorld(document.frame()); | 110 return ScriptState::forMainWorld(document.frame()); |
| 117 } | 111 } |
| 118 | 112 |
| 119 void rejectPendingResolvers(BaseAudioContext* audioContext) { | 113 void rejectPendingResolvers(BaseAudioContext* audioContext) { |
| 120 audioContext->rejectPendingResolvers(); | 114 audioContext->rejectPendingResolvers(); |
| 121 } | 115 } |
| 122 | 116 |
| 123 void recordAutoplayStatus(BaseAudioContext* audioContext) { | 117 void recordAutoplayStatus(BaseAudioContext* audioContext) { |
| 124 audioContext->recordAutoplayStatus(); | 118 audioContext->recordAutoplayStatus(); |
| 125 } | 119 } |
| 126 | 120 |
| 127 private: | 121 private: |
| 128 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; | 122 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; |
| 129 Persistent<DummyFrameOwner> m_dummyFrameOwner; | 123 Persistent<DummyFrameOwner> m_dummyFrameOwner; |
| 130 | 124 |
| 131 Persistent<LocalFrame> m_childFrame; | 125 Persistent<LocalFrame> m_childFrame; |
| 132 Persistent<DocumentLoader> m_childDocumentLoader; | |
| 133 | 126 |
| 134 BaseAudioContextTestPlatform m_testPlatform; | 127 BaseAudioContextTestPlatform m_testPlatform; |
| 135 }; | 128 }; |
| 136 | 129 |
| 137 TEST_F(BaseAudioContextTest, AutoplayMetrics_NoRestriction) { | 130 TEST_F(BaseAudioContextTest, AutoplayMetrics_NoRestriction) { |
| 138 HistogramTester histogramTester; | 131 HistogramTester histogramTester; |
| 139 | 132 |
| 140 BaseAudioContext* audioContext = | 133 BaseAudioContext* audioContext = |
| 141 BaseAudioContext::create(document(), ASSERT_NO_EXCEPTION); | 134 BaseAudioContext::create(document(), ASSERT_NO_EXCEPTION); |
| 142 recordAutoplayStatus(audioContext); | 135 recordAutoplayStatus(audioContext); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 audioContext->resumeContext(getScriptStateFrom(childDocument())); | 279 audioContext->resumeContext(getScriptStateFrom(childDocument())); |
| 287 rejectPendingResolvers(audioContext); | 280 rejectPendingResolvers(audioContext); |
| 288 recordAutoplayStatus(audioContext); | 281 recordAutoplayStatus(audioContext); |
| 289 | 282 |
| 290 histogramTester.expectBucketCount(kCrossOriginMetric, | 283 histogramTester.expectBucketCount(kCrossOriginMetric, |
| 291 AutoplayStatus::AutoplayStatusSucceeded, 1); | 284 AutoplayStatus::AutoplayStatusSucceeded, 1); |
| 292 histogramTester.expectTotalCount(kCrossOriginMetric, 1); | 285 histogramTester.expectTotalCount(kCrossOriginMetric, 1); |
| 293 } | 286 } |
| 294 | 287 |
| 295 } // namespace blink | 288 } // namespace blink |
| OLD | NEW |