OLD | NEW |
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 GetGlobalScopeManager().AddGlobalScope( |
| 27 GetPaintWorklet()->CreateGlobalScope()); |
| 28 } |
| 29 |
24 PaintWorklet* GetPaintWorklet() { | 30 PaintWorklet* GetPaintWorklet() { |
25 return WindowPaintWorklet::From(*page_->GetFrame().DomWindow()) | 31 return WindowPaintWorklet::From(*page_->GetFrame().DomWindow()) |
26 .paintWorklet(); | 32 .paintWorklet(); |
27 } | 33 } |
28 | 34 |
| 35 WorkletGlobalScopeManager& GetGlobalScopeManager() { |
| 36 return GetPaintWorklet()->GetGlobalScopeManager(); |
| 37 } |
| 38 |
29 protected: | 39 protected: |
30 std::unique_ptr<DummyPageHolder> page_; | 40 std::unique_ptr<DummyPageHolder> page_; |
31 }; | 41 }; |
32 | 42 |
33 TEST_F(PaintWorkletTest, GarbageCollectionOfCSSPaintDefinition) { | 43 TEST_F(PaintWorkletTest, GarbageCollectionOfCSSPaintDefinition) { |
34 PaintWorkletGlobalScopeProxy* proxy = PaintWorkletGlobalScopeProxy::From( | 44 auto proxy = PaintWorkletGlobalScopeProxy::From( |
35 GetPaintWorklet()->GetWorkletGlobalScopeProxy()); | 45 GetGlobalScopeManager().FindAvailableGlobalScope()); |
36 PaintWorkletGlobalScope* global_scope = proxy->global_scope(); | 46 PaintWorkletGlobalScope* global_scope = proxy->global_scope(); |
37 global_scope->ScriptController()->Evaluate( | 47 global_scope->ScriptController()->Evaluate( |
38 ScriptSourceCode("registerPaint('foo', class { paint() { } });")); | 48 ScriptSourceCode("registerPaint('foo', class { paint() { } });")); |
39 | 49 |
40 CSSPaintDefinition* definition = global_scope->FindDefinition("foo"); | 50 CSSPaintDefinition* definition = global_scope->FindDefinition("foo"); |
41 DCHECK(definition); | 51 DCHECK(definition); |
42 | 52 |
43 v8::Isolate* isolate = | 53 v8::Isolate* isolate = |
44 global_scope->ScriptController()->GetScriptState()->GetIsolate(); | 54 global_scope->ScriptController()->GetScriptState()->GetIsolate(); |
45 DCHECK(isolate); | 55 DCHECK(isolate); |
(...skipping 16 matching lines...) Expand all Loading... |
62 // Delete the page & associated objects. | 72 // Delete the page & associated objects. |
63 page_.reset(); | 73 page_.reset(); |
64 | 74 |
65 // Run a GC, the persistent should have been collected. | 75 // Run a GC, the persistent should have been collected. |
66 ThreadState::Current()->CollectAllGarbage(); | 76 ThreadState::Current()->CollectAllGarbage(); |
67 V8GCController::CollectAllGarbageForTesting(isolate); | 77 V8GCController::CollectAllGarbageForTesting(isolate); |
68 DCHECK(handle.IsEmpty()); | 78 DCHECK(handle.IsEmpty()); |
69 } | 79 } |
70 | 80 |
71 } // namespace blink | 81 } // namespace blink |
OLD | NEW |