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

Side by Side Diff: third_party/WebKit/Source/modules/webaudio/AudioWorkletThreadTest.cpp

Issue 2539443004: Worker: Move ParentFrameTaskRunners from WorkerReportingProxy to ObjectProxy (Closed)
Patch Set: rebase Created 3 years, 11 months 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
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/AudioWorkletThread.h" 5 #include "modules/webaudio/AudioWorkletThread.h"
6 6
7 #include "bindings/core/v8/ScriptSourceCode.h" 7 #include "bindings/core/v8/ScriptSourceCode.h"
8 #include "bindings/core/v8/SourceLocation.h" 8 #include "bindings/core/v8/SourceLocation.h"
9 #include "bindings/core/v8/V8GCController.h" 9 #include "bindings/core/v8/V8GCController.h"
10 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" 10 #include "bindings/core/v8/WorkerOrWorkletScriptController.h"
11 #include "core/inspector/ConsoleMessage.h" 11 #include "core/inspector/ConsoleMessage.h"
12 #include "core/workers/ParentFrameTaskRunners.h"
13 #include "core/workers/WorkerBackingThread.h" 12 #include "core/workers/WorkerBackingThread.h"
14 #include "core/workers/WorkerLoaderProxy.h" 13 #include "core/workers/WorkerLoaderProxy.h"
15 #include "core/workers/WorkerOrWorkletGlobalScope.h" 14 #include "core/workers/WorkerOrWorkletGlobalScope.h"
16 #include "core/workers/WorkerReportingProxy.h" 15 #include "core/workers/WorkerReportingProxy.h"
17 #include "core/workers/WorkerThreadStartupData.h" 16 #include "core/workers/WorkerThreadStartupData.h"
18 #include "platform/CrossThreadFunctional.h" 17 #include "platform/CrossThreadFunctional.h"
19 #include "platform/WaitableEvent.h" 18 #include "platform/WaitableEvent.h"
20 #include "platform/WebThreadSupportingGC.h" 19 #include "platform/WebThreadSupportingGC.h"
21 #include "platform/heap/Handle.h" 20 #include "platform/heap/Handle.h"
22 #include "platform/testing/TestingPlatformSupport.h" 21 #include "platform/testing/TestingPlatformSupport.h"
(...skipping 19 matching lines...) Expand all
42 void countFeature(UseCounter::Feature) override {} 41 void countFeature(UseCounter::Feature) override {}
43 void countDeprecation(UseCounter::Feature) override {} 42 void countDeprecation(UseCounter::Feature) override {}
44 void reportException(const String& errorMessage, 43 void reportException(const String& errorMessage,
45 std::unique_ptr<SourceLocation>, 44 std::unique_ptr<SourceLocation>,
46 int exceptionId) override {} 45 int exceptionId) override {}
47 void reportConsoleMessage(MessageSource, 46 void reportConsoleMessage(MessageSource,
48 MessageLevel, 47 MessageLevel,
49 const String& message, 48 const String& message,
50 SourceLocation*) override {} 49 SourceLocation*) override {}
51 void postMessageToPageInspector(const String&) override {} 50 void postMessageToPageInspector(const String&) override {}
52 ParentFrameTaskRunners* getParentFrameTaskRunners() override {
53 return m_parentFrameTaskRunners.get();
54 }
55
56 void didEvaluateWorkerScript(bool success) override {} 51 void didEvaluateWorkerScript(bool success) override {}
57 void didCloseWorkerGlobalScope() override {} 52 void didCloseWorkerGlobalScope() override {}
58 void willDestroyWorkerGlobalScope() override {} 53 void willDestroyWorkerGlobalScope() override {}
59 void didTerminateWorkerThread() override {} 54 void didTerminateWorkerThread() override {}
60 55
61 private: 56 private:
62 TestAudioWorkletReportingProxy() 57 TestAudioWorkletReportingProxy() {}
63 : m_parentFrameTaskRunners(ParentFrameTaskRunners::create(nullptr)) {}
64
65 Persistent<ParentFrameTaskRunners> m_parentFrameTaskRunners;
66 }; 58 };
67 59
68 } // namespace 60 } // namespace
69 61
70 class AudioWorkletThreadTest : public ::testing::Test { 62 class AudioWorkletThreadTest : public ::testing::Test {
71 public: 63 public:
72 void SetUp() override { 64 void SetUp() override {
73 AudioWorkletThread::createSharedBackingThreadForTest(); 65 AudioWorkletThread::createSharedBackingThreadForTest();
66 m_parentFrameTaskRunners = ParentFrameTaskRunners::create(nullptr);
74 m_reportingProxy = TestAudioWorkletReportingProxy::create(); 67 m_reportingProxy = TestAudioWorkletReportingProxy::create();
75 m_securityOrigin = 68 m_securityOrigin =
76 SecurityOrigin::create(KURL(ParsedURLString, "http://fake.url/")); 69 SecurityOrigin::create(KURL(ParsedURLString, "http://fake.url/"));
77 } 70 }
78 71
79 void TearDown() override { AudioWorkletThread::clearSharedBackingThread(); } 72 void TearDown() override { AudioWorkletThread::clearSharedBackingThread(); }
80 73
81 std::unique_ptr<AudioWorkletThread> createAudioWorkletThread() { 74 std::unique_ptr<AudioWorkletThread> createAudioWorkletThread() {
82 std::unique_ptr<AudioWorkletThread> thread = 75 std::unique_ptr<AudioWorkletThread> thread = AudioWorkletThread::create(
83 AudioWorkletThread::create(nullptr, *m_reportingProxy); 76 nullptr, *m_reportingProxy, m_parentFrameTaskRunners.get());
84 thread->start(WorkerThreadStartupData::create( 77 thread->start(WorkerThreadStartupData::create(
85 KURL(ParsedURLString, "http://fake.url/"), "fake user agent", "", 78 KURL(ParsedURLString, "http://fake.url/"), "fake user agent", "",
86 nullptr, DontPauseWorkerGlobalScopeOnStart, nullptr, "", 79 nullptr, DontPauseWorkerGlobalScopeOnStart, nullptr, "",
87 m_securityOrigin.get(), nullptr, WebAddressSpaceLocal, nullptr, nullptr, 80 m_securityOrigin.get(), nullptr, WebAddressSpaceLocal, nullptr, nullptr,
88 WorkerV8Settings::Default(), false /* inspectorNetworkCapability */)); 81 WorkerV8Settings::Default(), false /* inspectorNetworkCapability */));
89 return thread; 82 return thread;
90 } 83 }
91 84
92 // Attempts to run some simple script for |thread|. 85 // Attempts to run some simple script for |thread|.
93 void checkWorkletCanExecuteScript(WorkerThread* thread) { 86 void checkWorkletCanExecuteScript(WorkerThread* thread) {
(...skipping 10 matching lines...) Expand all
104 private: 97 private:
105 void executeScriptInWorklet(WorkerThread* thread, WaitableEvent* waitEvent) { 98 void executeScriptInWorklet(WorkerThread* thread, WaitableEvent* waitEvent) {
106 WorkerOrWorkletScriptController* scriptController = 99 WorkerOrWorkletScriptController* scriptController =
107 thread->globalScope()->scriptController(); 100 thread->globalScope()->scriptController();
108 scriptController->evaluate(ScriptSourceCode("var counter = 0; ++counter;")); 101 scriptController->evaluate(ScriptSourceCode("var counter = 0; ++counter;"));
109 waitEvent->signal(); 102 waitEvent->signal();
110 } 103 }
111 104
112 RefPtr<SecurityOrigin> m_securityOrigin; 105 RefPtr<SecurityOrigin> m_securityOrigin;
113 std::unique_ptr<WorkerReportingProxy> m_reportingProxy; 106 std::unique_ptr<WorkerReportingProxy> m_reportingProxy;
107 Persistent<ParentFrameTaskRunners> m_parentFrameTaskRunners;
114 }; 108 };
115 109
116 TEST_F(AudioWorkletThreadTest, Basic) { 110 TEST_F(AudioWorkletThreadTest, Basic) {
117 std::unique_ptr<AudioWorkletThread> worklet = createAudioWorkletThread(); 111 std::unique_ptr<AudioWorkletThread> worklet = createAudioWorkletThread();
118 checkWorkletCanExecuteScript(worklet.get()); 112 checkWorkletCanExecuteScript(worklet.get());
119 worklet->terminateAndWait(); 113 worklet->terminateAndWait();
120 } 114 }
121 115
122 // Tests that the same WebThread is used for new worklets if the WebThread is 116 // Tests that the same WebThread is used for new worklets if the WebThread is
123 // still alive. 117 // still alive.
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 ASSERT_TRUE(secondIsolate); 190 ASSERT_TRUE(secondIsolate);
197 EXPECT_EQ(firstIsolate, secondIsolate); 191 EXPECT_EQ(firstIsolate, secondIsolate);
198 192
199 // Verify that the isolate can run some scripts correctly in the second 193 // Verify that the isolate can run some scripts correctly in the second
200 // worklet. 194 // worklet.
201 checkWorkletCanExecuteScript(secondWorklet.get()); 195 checkWorkletCanExecuteScript(secondWorklet.get());
202 secondWorklet->terminateAndWait(); 196 secondWorklet->terminateAndWait();
203 } 197 }
204 198
205 } // namespace blink 199 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698