| Index: third_party/WebKit/Source/modules/webaudio/AudioWorkletTest.cpp
|
| diff --git a/third_party/WebKit/Source/modules/webaudio/AudioWorkletTest.cpp b/third_party/WebKit/Source/modules/webaudio/AudioWorkletTest.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..1e2624225121ef4cf7b06d283f4f0f989aac5272
|
| --- /dev/null
|
| +++ b/third_party/WebKit/Source/modules/webaudio/AudioWorkletTest.cpp
|
| @@ -0,0 +1,147 @@
|
| +// Copyright 2017 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "core/testing/DummyPageHolder.h"
|
| +#include "core/workers/ThreadedWorkletMessagingProxy.h"
|
| +#include "core/workers/ThreadedWorkletObjectProxy.h"
|
| +#include "core/workers/WorkerInspectorProxy.h"
|
| +#include "core/workers/WorkerThread.h"
|
| +#include "core/workers/WorkerThreadStartupData.h"
|
| +#include "core/workers/WorkerThreadTestHelper.h"
|
| +#include "core/workers/WorkletThreadHolder.h"
|
| +#include "modules/webaudio/AudioWorkletGlobalScope.h"
|
| +#include "platform/weborigin/SecurityOrigin.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +namespace blink {
|
| +
|
| +class AudioWorkletThreadForTest : public WorkerThread {
|
| + public:
|
| + AudioWorkletThreadForTest(
|
| + WorkerLoaderProxyProvider* workerLoaderProxyProvider,
|
| + WorkerReportingProxy& workerReportingProxy)
|
| + : WorkerThread(WorkerLoaderProxy::create(workerLoaderProxyProvider),
|
| + workerReportingProxy) {}
|
| + ~AudioWorkletThreadForTest() override{};
|
| +
|
| + WorkerBackingThread& workerBackingThread() override {
|
| + return *WorkletThreadHolder<AudioWorkletThreadForTest>::getInstance()
|
| + ->thread();
|
| + }
|
| +
|
| + void clearWorkerBackingThread() override {}
|
| +
|
| + WorkerOrWorkletGlobalScope* createWorkerGlobalScope(
|
| + std::unique_ptr<WorkerThreadStartupData> startupData) final {
|
| + RefPtr<SecurityOrigin> securityOrigin =
|
| + SecurityOrigin::create(startupData->m_scriptURL);
|
| + return AudioWorkletGlobalScope::create(
|
| + startupData->m_scriptURL, startupData->m_userAgent,
|
| + securityOrigin.release(), this->isolate(), this);
|
| + }
|
| +
|
| + bool isOwningBackingThread() const final { return false; }
|
| +
|
| + static void ensureSharedBackingThread() {
|
| + DCHECK(isMainThread());
|
| + WorkletThreadHolder<AudioWorkletThreadForTest>::createForTest(
|
| + "AudioWorkletThreadForTest");
|
| + }
|
| +
|
| + static void clearSharedBackingThread() {
|
| + DCHECK(isMainThread());
|
| + WorkletThreadHolder<AudioWorkletThreadForTest>::clearInstance();
|
| + }
|
| +};
|
| +
|
| +class AudioWorkletMessagingProxyForTest : public ThreadedWorkletMessagingProxy {
|
| + public:
|
| + AudioWorkletMessagingProxyForTest(ExecutionContext* executionContext)
|
| + : ThreadedWorkletMessagingProxy(executionContext) {
|
| + m_mockWorkerLoaderProxyProvider =
|
| + WTF::makeUnique<MockWorkerLoaderProxyProvider>();
|
| + setWorkerThreadForTest(WTF::makeUnique<AudioWorkletThreadForTest>(
|
| + m_mockWorkerLoaderProxyProvider.get(), workletObjectProxy()));
|
| + AudioWorkletThreadForTest::ensureSharedBackingThread();
|
| + }
|
| +
|
| + ~AudioWorkletMessagingProxyForTest() override {
|
| + workerThread()->workerLoaderProxy()->detachProvider(
|
| + m_mockWorkerLoaderProxyProvider.get());
|
| + workerThread()->terminateAndWait();
|
| + AudioWorkletThreadForTest::clearSharedBackingThread();
|
| + };
|
| +
|
| + void start() {
|
| + KURL scriptURL(ParsedURLString, "http://fake.url/");
|
| + std::unique_ptr<Vector<char>> cachedMetaData = nullptr;
|
| + Vector<CSPHeaderAndType> contentSecurityPolicyHeaders;
|
| + String referrerPolicy = "";
|
| + m_securityOrigin = SecurityOrigin::create(scriptURL);
|
| + WorkerClients* workerClients = nullptr;
|
| + Vector<String> originTrialTokens;
|
| + std::unique_ptr<WorkerSettings> workerSettings = nullptr;
|
| + workerThread()->start(
|
| + WorkerThreadStartupData::create(
|
| + scriptURL, "fake user agent", "// fake source code",
|
| + std::move(cachedMetaData), DontPauseWorkerGlobalScopeOnStart,
|
| + &contentSecurityPolicyHeaders, referrerPolicy,
|
| + m_securityOrigin.get(), workerClients, WebAddressSpaceLocal,
|
| + &originTrialTokens, std::move(workerSettings),
|
| + WorkerV8Settings::Default()),
|
| + getParentFrameTaskRunners());
|
| + workerInspectorProxy()->workerThreadCreated(
|
| + toDocument(getExecutionContext()), workerThread(), scriptURL);
|
| + }
|
| +
|
| + protected:
|
| + std::unique_ptr<WorkerThread> createWorkerThread(double originTime) final {
|
| + NOTREACHED();
|
| + return nullptr;
|
| + }
|
| +
|
| + private:
|
| + friend class AudioWorkletTest;
|
| +
|
| + std::unique_ptr<MockWorkerLoaderProxyProvider>
|
| + m_mockWorkerLoaderProxyProvider;
|
| + RefPtr<SecurityOrigin> m_securityOrigin;
|
| +};
|
| +
|
| +class AudioWorkletTest : public ::testing::Test {
|
| + public:
|
| + void SetUp() override {
|
| + m_page = DummyPageHolder::create();
|
| + m_messagingProxy =
|
| + WTF::makeUnique<AudioWorkletMessagingProxyForTest>(&m_page->document());
|
| + }
|
| +
|
| + AudioWorkletMessagingProxyForTest* messagingProxy() {
|
| + return m_messagingProxy.get();
|
| + }
|
| +
|
| + AudioWorkletThreadForTest* workerThread() {
|
| + return static_cast<AudioWorkletThreadForTest*>(
|
| + m_messagingProxy->workerThread());
|
| + }
|
| +
|
| + Document& document() { return m_page->document(); }
|
| +
|
| + private:
|
| + std::unique_ptr<DummyPageHolder> m_page;
|
| + std::unique_ptr<AudioWorkletMessagingProxyForTest> m_messagingProxy;
|
| +};
|
| +
|
| +TEST_F(AudioWorkletTest, Basic) {
|
| + messagingProxy()->start();
|
| + EXPECT_TRUE(workerThread());
|
| +
|
| + // TODO(hongchan):
|
| + // 1. Test instantiation of AudioWorkletThread
|
| + // 2. Test instantiation of AudioWorkletGlobalScope
|
| + // 3. Test registration of AudioWorkletProcessor
|
| + // 4. Test instantiation of AudioWorkletProcessor
|
| +}
|
| +
|
| +} // namespace blink
|
|
|