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

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

Issue 2871513002: Worklet: Lazily create PaintWorkletGlobalScopes (Closed)
Patch Set: add class-level comments Created 3 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 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/csspaint/PaintWorklet.h" 5 #include "modules/csspaint/PaintWorklet.h"
6 6
7 #include <memory>
7 #include "bindings/core/v8/ScriptSourceCode.h" 8 #include "bindings/core/v8/ScriptSourceCode.h"
8 #include "bindings/core/v8/V8GCController.h" 9 #include "bindings/core/v8/V8GCController.h"
9 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" 10 #include "bindings/core/v8/WorkerOrWorkletScriptController.h"
10 #include "core/frame/LocalFrame.h" 11 #include "core/frame/LocalFrame.h"
11 #include "core/testing/DummyPageHolder.h" 12 #include "core/testing/DummyPageHolder.h"
12 #include "modules/csspaint/CSSPaintDefinition.h" 13 #include "modules/csspaint/CSSPaintDefinition.h"
13 #include "modules/csspaint/PaintWorkletGlobalScope.h" 14 #include "modules/csspaint/PaintWorkletGlobalScope.h"
15 #include "modules/csspaint/PaintWorkletGlobalScopeProxy.h"
14 #include "modules/csspaint/WindowPaintWorklet.h" 16 #include "modules/csspaint/WindowPaintWorklet.h"
15 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
16 #include <memory>
17 18
18 namespace blink { 19 namespace blink {
19 20
20 class PaintWorkletTest : public testing::Test { 21 class PaintWorkletTest : public testing::Test {
21 public: 22 public:
22 PaintWorkletTest() : page_(DummyPageHolder::Create()) {} 23 PaintWorkletTest() : page_(DummyPageHolder::Create()) {}
23 24
25 void SetUp() override {
26 GetProxies().insert(GetPaintWorklet()->CreateGlobalScope());
27 }
28
24 PaintWorklet* GetPaintWorklet() { 29 PaintWorklet* GetPaintWorklet() {
25 return WindowPaintWorklet::From(*page_->GetFrame().DomWindow()) 30 return WindowPaintWorklet::From(*page_->GetFrame().DomWindow())
26 .paintWorklet(); 31 .paintWorklet();
27 } 32 }
28 33
34 WTF::HashSet<std::unique_ptr<WorkletGlobalScopeProxy>>& GetProxies() {
35 return GetPaintWorklet()->GetProxies();
36 }
37
29 protected: 38 protected:
30 std::unique_ptr<DummyPageHolder> page_; 39 std::unique_ptr<DummyPageHolder> page_;
31 }; 40 };
32 41
33 TEST_F(PaintWorkletTest, GarbageCollectionOfCSSPaintDefinition) { 42 TEST_F(PaintWorkletTest, GarbageCollectionOfCSSPaintDefinition) {
34 PaintWorkletGlobalScopeProxy* proxy = PaintWorkletGlobalScopeProxy::From( 43 PaintWorkletGlobalScopeProxy* proxy =
35 GetPaintWorklet()->GetWorkletGlobalScopeProxy()); 44 PaintWorkletGlobalScopeProxy::From(GetProxies().begin()->get());
36 PaintWorkletGlobalScope* global_scope = proxy->global_scope(); 45 PaintWorkletGlobalScope* global_scope = proxy->global_scope();
37 global_scope->ScriptController()->Evaluate( 46 global_scope->ScriptController()->Evaluate(
38 ScriptSourceCode("registerPaint('foo', class { paint() { } });")); 47 ScriptSourceCode("registerPaint('foo', class { paint() { } });"));
39 48
40 CSSPaintDefinition* definition = global_scope->FindDefinition("foo"); 49 CSSPaintDefinition* definition = global_scope->FindDefinition("foo");
41 DCHECK(definition); 50 DCHECK(definition);
42 51
43 v8::Isolate* isolate = 52 v8::Isolate* isolate =
44 global_scope->ScriptController()->GetScriptState()->GetIsolate(); 53 global_scope->ScriptController()->GetScriptState()->GetIsolate();
45 DCHECK(isolate); 54 DCHECK(isolate);
(...skipping 16 matching lines...) Expand all
62 // Delete the page & associated objects. 71 // Delete the page & associated objects.
63 page_.reset(); 72 page_.reset();
64 73
65 // Run a GC, the persistent should have been collected. 74 // Run a GC, the persistent should have been collected.
66 ThreadState::Current()->CollectAllGarbage(); 75 ThreadState::Current()->CollectAllGarbage();
67 V8GCController::CollectAllGarbageForTesting(isolate); 76 V8GCController::CollectAllGarbageForTesting(isolate);
68 DCHECK(handle.IsEmpty()); 77 DCHECK(handle.IsEmpty());
69 } 78 }
70 79
71 } // namespace blink 80 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698