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

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

Issue 2272163003: ResizeObserver: Olipan C++ tests (Closed)
Patch Set: CR fixes 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
« no previous file with comments | « third_party/WebKit/Source/core/observer/ResizeObserverController.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 23 matching lines...) Expand all
43 48
44 } // namespace 49 } // namespace
45 50
46 /* Testing: 51 /* Testing:
47 * getTargetSize 52 * getTargetSize
48 * setTargetSize 53 * setTargetSize
49 * oubservationSizeOutOfSync == false 54 * oubservationSizeOutOfSync == false
50 * modify target size 55 * modify target size
51 * oubservationSizeOutOfSync == true 56 * oubservationSizeOutOfSync == true
52 */ 57 */
53 class ResizeObservationUnitTest : public SimTest { }; 58 class ResizeObserverUnitTest : public SimTest { };
54 59
55 TEST_F(ResizeObservationUnitTest, ObserveSchedulesFrame) 60 TEST_F(ResizeObserverUnitTest, ResizeObservationSize)
56 { 61 {
57 SimRequest mainResource("https://example.com/", "text/html"); 62 SimRequest mainResource("https://example.com/", "text/html");
58 loadURL("https://example.com/"); 63 loadURL("https://example.com/");
59 64
60 mainResource.start(); 65 mainResource.start();
61 mainResource.write( 66 mainResource.write(
62 "<div id='domTarget' style='width:100px;height:100px'>yo</div>" 67 "<div id='domTarget' style='width:100px;height:100px'>yo</div>"
63 "<svg height='200' width='200'>" 68 "<svg height='200' width='200'>"
64 "<circle id='svgTarget' cx='100' cy='100' r='100'/>" 69 "<circle id='svgTarget' cx='100' cy='100' r='100'/>"
65 "</svg>" 70 "</svg>"
(...skipping 22 matching lines...) Expand all
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 TEST_F(ResizeObserverUnitTest, TestMemoryLeaks)
104 {
105
106 ResizeObserverController& controller = document().ensureResizeObserverContro ller();
107 const HeapHashSet<WeakMember<ResizeObserver>>& observers = controller.observ ers();
108 ASSERT_EQ(observers.size(), 0U);
109 v8::HandleScope scope(v8::Isolate::GetCurrent());
110
111 ScriptController& script = document().executingFrame()->script();
112
113 //
114 // Test whether ResizeObserver is kept alive by direct JS reference
115 //
116 script.executeScriptInMainWorldAndReturnValue(
117 ScriptSourceCode("var ro = new ResizeObserver( entries => {});"),
118 ScriptController::ExecuteScriptWhenScriptsDisabled);
119 ASSERT_EQ(observers.size(), 1U);
120 script.executeScriptInMainWorldAndReturnValue(
121 ScriptSourceCode("ro = undefined;"),
122 ScriptController::ExecuteScriptWhenScriptsDisabled);
123 V8GCController::collectAllGarbageForTesting(v8::Isolate::GetCurrent());
124 WebHeap::collectAllGarbageForTesting();
125 ASSERT_EQ(observers.isEmpty(), true);
126
127 //
128 // Test whether ResizeObserver is kept alive by an Element
129 //
130 script.executeScriptInMainWorldAndReturnValue(
131 ScriptSourceCode(
132 "var ro = new ResizeObserver( () => {});"
133 "var el = document.createElement('div');"
134 "ro.observe(el);"
135 "ro = undefined;"
136 ),
137 ScriptController::ExecuteScriptWhenScriptsDisabled);
138 ASSERT_EQ(observers.size(), 1U);
139 V8GCController::collectAllGarbageForTesting(v8::Isolate::GetCurrent());
140 WebHeap::collectAllGarbageForTesting();
141 ASSERT_EQ(observers.size(), 1U);
142 script.executeScriptInMainWorldAndReturnValue(
143 ScriptSourceCode("el = undefined;"),
144 ScriptController::ExecuteScriptWhenScriptsDisabled);
145 V8GCController::collectAllGarbageForTesting(v8::Isolate::GetCurrent());
146 WebHeap::collectAllGarbageForTesting();
147 ASSERT_EQ(observers.isEmpty(), true);
148 }
149
98 } // namespace blink 150 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/observer/ResizeObserverController.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698