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 |
| 21 using GlobalScopeProxies = |
| 22 WTF::HashSet<std::unique_ptr<WorkletGlobalScopeProxy>>; |
| 23 |
20 class PaintWorkletTest : public testing::Test { | 24 class PaintWorkletTest : public testing::Test { |
21 public: | 25 public: |
22 PaintWorkletTest() : page_(DummyPageHolder::Create()) {} | 26 PaintWorkletTest() : page_(DummyPageHolder::Create()) {} |
23 | 27 |
| 28 void SetUp() override { GetPaintWorklet()->AddWorkletGlobalScopesIfNeeded(); } |
| 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 GlobalScopeProxies& GetGlobalScopeProxies() { |
| 36 return GetPaintWorklet()->global_scope_proxies_; |
| 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 GlobalScopeProxies& proxies = GetGlobalScopeProxies(); |
35 GetPaintWorklet()->GetWorkletGlobalScopeProxy()); | 45 EXPECT_EQ(1u, proxies.size()); |
| 46 PaintWorkletGlobalScopeProxy* proxy = |
| 47 PaintWorkletGlobalScopeProxy::From(proxies.begin()->get()); |
36 PaintWorkletGlobalScope* global_scope = proxy->global_scope(); | 48 PaintWorkletGlobalScope* global_scope = proxy->global_scope(); |
37 global_scope->ScriptController()->Evaluate( | 49 global_scope->ScriptController()->Evaluate( |
38 ScriptSourceCode("registerPaint('foo', class { paint() { } });")); | 50 ScriptSourceCode("registerPaint('foo', class { paint() { } });")); |
39 | 51 |
40 CSSPaintDefinition* definition = global_scope->FindDefinition("foo"); | 52 CSSPaintDefinition* definition = global_scope->FindDefinition("foo"); |
41 ASSERT(definition); | 53 ASSERT(definition); |
42 | 54 |
43 v8::Isolate* isolate = | 55 v8::Isolate* isolate = |
44 global_scope->ScriptController()->GetScriptState()->GetIsolate(); | 56 global_scope->ScriptController()->GetScriptState()->GetIsolate(); |
45 ASSERT(isolate); | 57 ASSERT(isolate); |
(...skipping 16 matching lines...) Expand all Loading... |
62 // Delete the page & associated objects. | 74 // Delete the page & associated objects. |
63 page_.reset(); | 75 page_.reset(); |
64 | 76 |
65 // Run a GC, the persistent should have been collected. | 77 // Run a GC, the persistent should have been collected. |
66 ThreadState::Current()->CollectAllGarbage(); | 78 ThreadState::Current()->CollectAllGarbage(); |
67 V8GCController::CollectAllGarbageForTesting(isolate); | 79 V8GCController::CollectAllGarbageForTesting(isolate); |
68 ASSERT(handle.IsEmpty()); | 80 ASSERT(handle.IsEmpty()); |
69 } | 81 } |
70 | 82 |
71 } // namespace blink | 83 } // namespace blink |
OLD | NEW |