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

Unified Diff: third_party/WebKit/Source/modules/webaudio/AudioWorkletTest.cpp

Issue 1960533003: [DO NOT SUBMIT] AudioWorklet FS1: importing scripts (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
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..b5704c68da0d1d728b8c26f27de207098536bd82
--- /dev/null
+++ b/third_party/WebKit/Source/modules/webaudio/AudioWorkletTest.cpp
@@ -0,0 +1,80 @@
+// Copyright 2016 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 "modules/webaudio/AudioWorklet.h"
+
+#include "bindings/core/v8/ScriptSourceCode.h"
+#include "bindings/core/v8/V8GCController.h"
+#include "bindings/core/v8/WorkerOrWorkletScriptController.h"
+#include "core/frame/LocalFrame.h"
+#include "core/testing/DummyPageHolder.h"
+#include "modules/webaudio/AudioWorkletGlobalScope.h"
+#include "modules/webaudio/AudioWorkletProcessorDefinition.h"
+#include "modules/webaudio/WindowAudioWorklet.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "wtf/OwnPtr.h"
+
+namespace blink {
+
+namespace {
+
+ static void clearHandle(const v8::WeakCallbackInfo<ScopedPersistent<v8::Function>>& data)
+ {
+ data.GetParameter()->clear();
+ }
+
+} // namespace
+
+class AudioWorkletTest : public testing::Test {
+public:
+ AudioWorkletTest()
+ : m_page(DummyPageHolder::create())
+ {
+ }
+
+ AudioWorklet* AudioWorklet()
+ {
+ return WindowAudioWorklet::from(*m_page->frame().localDOMWindow()).audioWorklet(&m_page->document());
+ }
+
+protected:
+ OwnPtr<DummyPageHolder> m_page;
+};
+
+TEST_F(AudioWorkletTest, GarbageCollectionOfAudioWorkletProcessorDefinition)
+{
+ AudioWorkletGlobalScope* globalScope = toAudioWorkletGlobalScope(AudioWorklet()->workletGlobalScope());
+ globalScope->scriptController()->evaluate(ScriptSourceCode("registerAudioWorkletProcessor('foo', class { process() { } });"));
+
+ AudioWorkletProcessorDefinition* definition = globalScope->findDefinition("foo");
+ ASSERT(definition);
+
+ v8::Isolate* isolate = globalScope->scriptController()->getScriptState()->isolate();
+ ASSERT(isolate);
+
+ // Set our ScopedPersistent to the paint function, and make weak.
+ ScopedPersistent<v8::Function> handle;
+ {
+ v8::HandleScope handleScope(isolate);
+ handle.set(isolate, definition->processFunctionForTesting(isolate));
+ handle.setWeak(&handle, clearHandle);
+ }
+ ASSERT(!handle.isEmpty());
+ ASSERT(handle.isWeak());
+
+ // Run a GC, persistent shouldn't have been collected yet.
+ ThreadHeap::collectAllGarbage();
+ V8GCController::collectAllGarbageForTesting(isolate);
+ ASSERT(!handle.isEmpty());
+
+ // Delete the page & associated objects.
+ m_page.clear();
+
+ // Run a GC, the persistent should have been collected.
+ ThreadHeap::collectAllGarbage();
+ V8GCController::collectAllGarbageForTesting(isolate);
+ ASSERT(handle.isEmpty());
+}
+
+} // naespace blink

Powered by Google App Engine
This is Rietveld 408576698