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

Side by Side Diff: third_party/WebKit/Source/modules/csspaint/PaintWorkletTest.cpp

Issue 1839913002: Implement PaintWorkletGlobalScope#registerPaint() for the CSS Paint API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase + remove WillBe types. Created 4 years, 8 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "modules/csspaint/PaintWorklet.h"
6
7 #include "bindings/core/v8/ScriptSourceCode.h"
8 #include "bindings/core/v8/V8GCController.h"
9 #include "bindings/core/v8/WorkerOrWorkletScriptController.h"
10 #include "core/frame/LocalFrame.h"
11 #include "core/testing/DummyPageHolder.h"
12 #include "modules/csspaint/CSSPaintDefinition.h"
13 #include "modules/csspaint/PaintWorkletGlobalScope.h"
14 #include "modules/csspaint/WindowPaintWorklet.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "wtf/OwnPtr.h"
17
18 namespace blink {
19
20 namespace {
21
22 static void clearHandle(const v8::WeakCallbackInfo<ScopedPersistent<v8::Function >>& data)
23 {
24 data.GetParameter()->clear();
25 }
26
27 } // namespace
28
29 class PaintWorkletTest : public testing::Test {
30 public:
31 PaintWorkletTest()
32 : m_page(DummyPageHolder::create())
33 {
34 }
35
36 PaintWorklet* paintWorklet()
37 {
38 return WindowPaintWorklet::from(*m_page->frame().localDOMWindow()).paint Worklet(&m_page->document());
39 }
40
41 protected:
42 OwnPtr<DummyPageHolder> m_page;
43 };
44
45 TEST_F(PaintWorkletTest, GarbageCollectionOfCSSPaintDefinition)
46 {
47 PaintWorkletGlobalScope* globalScope = toPaintWorkletGlobalScope(paintWorkle t()->workletGlobalScope());
48 globalScope->scriptController()->evaluate(ScriptSourceCode("registerPaint('f oo', class { paint() { } });"));
49
50 CSSPaintDefinition* definition = globalScope->findDefinition("foo");
51 ASSERT(definition);
52
53 v8::Isolate* isolate = globalScope->scriptController()->getScriptState()->is olate();
54 ASSERT(isolate);
55
56 // Set our ScopedPersistent to the paint function, and make weak.
57 ScopedPersistent<v8::Function> handle;
58 {
59 v8::HandleScope handleScope(isolate);
60 handle.set(isolate, definition->paintFunctionForTesting(isolate));
61 handle.setWeak(&handle, clearHandle);
62 }
63 ASSERT(!handle.isEmpty());
64 ASSERT(handle.isWeak());
65
66 // Run a GC, persistent shouldn't have been collected yet.
67 Heap::collectAllGarbage();
68 V8GCController::collectAllGarbageForTesting(isolate);
69 ASSERT(!handle.isEmpty());
70
71 // Delete the page & associated objects.
72 m_page.clear();
73
74 // Run a GC, the persistent should have been collected.
75 Heap::collectAllGarbage();
76 V8GCController::collectAllGarbageForTesting(isolate);
77 ASSERT(handle.isEmpty());
78 }
79
80 } // naespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698