Chromium Code Reviews| 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..75dc44b2049fc255eee03d52f940c2e2798ed2f7 |
| --- /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::collectGarbage(BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithSweep, BlinkGC::ForcedGC); |
|
haraken
2016/04/01 00:16:06
Use Heap::collectAllGarbage.
ikilpatrick
2016/04/01 03:08:43
Done.
|
| + V8GCController::collectAllGarbageForTesting(isolate); |
| + ASSERT(!handle.isEmpty()); |
| + |
| + // Delete the page & associated objects. |
| + m_page.clear(); |
| + |
| + // Run a GC, the persistent should have been collected. |
| + Heap::collectGarbage(BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithSweep, BlinkGC::ForcedGC); |
| + V8GCController::collectAllGarbageForTesting(isolate); |
|
ikilpatrick
2016/03/31 21:59:05
Is assuming this OK?
At the moment in PaintWorkle
haraken
2016/04/01 00:16:06
Looks good.
|
| + ASSERT(handle.isEmpty()); |
| +} |
| + |
| +} // naespace blink |