| Index: third_party/WebKit/Source/modules/csspaint/PaintWorkletTest.cpp
|
| diff --git a/third_party/WebKit/Source/modules/csspaint/PaintWorkletTest.cpp b/third_party/WebKit/Source/modules/csspaint/PaintWorkletTest.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..8a23cae263261d1f4c6729277ee7019290702a5c
|
| --- /dev/null
|
| +++ b/third_party/WebKit/Source/modules/csspaint/PaintWorkletTest.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/csspaint/PaintWorklet.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/csspaint/CSSPaintDefinition.h"
|
| +#include "modules/csspaint/PaintWorkletGlobalScope.h"
|
| +#include "modules/csspaint/WindowPaintWorklet.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 PaintWorkletTest : public testing::Test {
|
| +public:
|
| + PaintWorkletTest()
|
| + : m_page(DummyPageHolder::create())
|
| + {
|
| + }
|
| +
|
| + PaintWorklet* paintWorklet()
|
| + {
|
| + return WindowPaintWorklet::from(*m_page->frame().localDOMWindow()).paintWorklet(&m_page->document());
|
| + }
|
| +
|
| +protected:
|
| + OwnPtr<DummyPageHolder> m_page;
|
| +};
|
| +
|
| +TEST_F(PaintWorkletTest, GarbageCollectionOfCSSPaintDefinition)
|
| +{
|
| + PaintWorkletGlobalScope* globalScope = toPaintWorkletGlobalScope(paintWorklet()->workletGlobalScope());
|
| + globalScope->scriptController()->evaluate(ScriptSourceCode("registerPaint('foo', class { paint() { } });"));
|
| +
|
| + CSSPaintDefinition* 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->paintFunctionForTesting(isolate));
|
| + handle.setWeak(&handle, clearHandle);
|
| + }
|
| + ASSERT(!handle.isEmpty());
|
| + ASSERT(handle.isWeak());
|
| +
|
| + // Run a GC, persistent shouldn't have been collected yet.
|
| + Heap::collectAllGarbage();
|
| + V8GCController::collectAllGarbageForTesting(isolate);
|
| + ASSERT(!handle.isEmpty());
|
| +
|
| + // Delete the page & associated objects.
|
| + m_page.clear();
|
| +
|
| + // Run a GC, the persistent should have been collected.
|
| + Heap::collectAllGarbage();
|
| + V8GCController::collectAllGarbageForTesting(isolate);
|
| + ASSERT(handle.isEmpty());
|
| +}
|
| +
|
| +} // naespace blink
|
|
|