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

Side by Side Diff: third_party/WebKit/Source/web/tests/ResizeObserverTest.cpp

Issue 2272163003: ResizeObserver: Olipan C++ tests (Closed)
Patch Set: Olipan C++ tests Created 4 years, 3 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 "core/observer/ResizeObserver.h" 5 #include "core/observer/ResizeObserver.h"
6 6
7 #include "bindings/core/v8/ScriptController.h"
8 #include "bindings/core/v8/ScriptSourceCode.h"
9 #include "bindings/core/v8/V8GCController.h"
7 #include "core/observer/ResizeObservation.h" 10 #include "core/observer/ResizeObservation.h"
8 #include "core/observer/ResizeObserverCallback.h" 11 #include "core/observer/ResizeObserverCallback.h"
12 #include "core/observer/ResizeObserverController.h"
9 #include "platform/testing/UnitTestHelpers.h" 13 #include "platform/testing/UnitTestHelpers.h"
14 #include "public/web/WebHeap.h"
10 #include "web/WebViewImpl.h" 15 #include "web/WebViewImpl.h"
11 #include "web/tests/sim/SimCompositor.h" 16 #include "web/tests/sim/SimCompositor.h"
12 #include "web/tests/sim/SimDisplayItemList.h" 17 #include "web/tests/sim/SimDisplayItemList.h"
13 #include "web/tests/sim/SimRequest.h" 18 #include "web/tests/sim/SimRequest.h"
14 #include "web/tests/sim/SimTest.h" 19 #include "web/tests/sim/SimTest.h"
15 #include "wtf/CurrentTime.h" 20 #include "wtf/CurrentTime.h"
16 21
17 namespace blink { 22 namespace blink {
18 23
19 namespace { 24 namespace {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 ASSERT_EQ(size.height(), 200); 93 ASSERT_EQ(size.height(), 200);
89 svgObservation->setObservationSize(size); 94 svgObservation->setObservationSize(size);
90 95
91 // Target size is in sync 96 // Target size is in sync
92 ASSERT_FALSE(domObservation->observationSizeOutOfSync()); 97 ASSERT_FALSE(domObservation->observationSizeOutOfSync());
93 98
94 // Target depths 99 // Target depths
95 ASSERT_EQ(svgObservation->targetDepth() - domObservation->targetDepth(), (si ze_t)1); 100 ASSERT_EQ(svgObservation->targetDepth() - domObservation->targetDepth(), (si ze_t)1);
96 } 101 }
97 102
103 class ResizeObserverMemoryTest : public SimTest {};
esprehn 2016/08/30 21:25:23 You don't need a new SimTest class for each one. N
atotic1 2016/08/31 19:05:15 Done.
104 TEST_F(ResizeObserverMemoryTest, TestMemoryLeaks)
105 {
106
107 ResizeObserverController& controller = document().ensureResizeObserverContro ller();
108 HeapHashSet<WeakMember<ResizeObserver>>& observers = controller.observers();
109 ASSERT_EQ(observers.size(), 0U);
110 v8::HandleScope scope(v8::Isolate::GetCurrent());
111
112 ScriptController& script = document().executingFrame()->script();
113
114 //
115 // Test whether ResizeObserver is kept alive by direct JS reference
116 //
117 script.executeScriptInMainWorldAndReturnValue(
118 ScriptSourceCode("var ro = new ResizeObserver( entries => {});"),
119 ScriptController::ExecuteScriptWhenScriptsDisabled);
120 ASSERT_EQ(observers.size(), 1U);
121 script.executeScriptInMainWorldAndReturnValue(
122 ScriptSourceCode("ro = undefined;"),
123 ScriptController::ExecuteScriptWhenScriptsDisabled);
124 V8GCController::collectAllGarbageForTesting(v8::Isolate::GetCurrent());
125 WebHeap::collectAllGarbageForTesting();
126 ASSERT_EQ(observers.isEmpty(), true);
127
128 //
129 // Test whether ResizeObserver is kept alive by an Element
130 //
131 script.executeScriptInMainWorldAndReturnValue(
132 ScriptSourceCode(
133 "var ro = new ResizeObserver( () => {});"
134 "var el = document.createElement('div');"
135 "ro.observe(el);"
136 "ro = undefined;"
137 ),
138 ScriptController::ExecuteScriptWhenScriptsDisabled);
139 ASSERT_EQ(observers.size(), 1U);
140 V8GCController::collectAllGarbageForTesting(v8::Isolate::GetCurrent());
141 WebHeap::collectAllGarbageForTesting();
142 ASSERT_EQ(observers.size(), 1U);
143 script.executeScriptInMainWorldAndReturnValue(
144 ScriptSourceCode("el = undefined;"),
145 ScriptController::ExecuteScriptWhenScriptsDisabled);
146 V8GCController::collectAllGarbageForTesting(v8::Isolate::GetCurrent());
147 WebHeap::collectAllGarbageForTesting();
148 ASSERT_EQ(observers.isEmpty(), true);
149 }
150
98 } // namespace blink 151 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698