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

Unified Diff: third_party/WebKit/Source/web/tests/ResizeObserverTest.cpp

Issue 2272163003: ResizeObserver: Olipan C++ tests (Closed)
Patch Set: CR fixes Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/observer/ResizeObserverController.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/web/tests/ResizeObserverTest.cpp
diff --git a/third_party/WebKit/Source/web/tests/ResizeObserverTest.cpp b/third_party/WebKit/Source/web/tests/ResizeObserverTest.cpp
index e78a0ebdabefd197f680f3cab007d3ca9501afb1..66da446160c494e7f15833692f92d2b904ade6e5 100644
--- a/third_party/WebKit/Source/web/tests/ResizeObserverTest.cpp
+++ b/third_party/WebKit/Source/web/tests/ResizeObserverTest.cpp
@@ -4,9 +4,14 @@
#include "core/observer/ResizeObserver.h"
+#include "bindings/core/v8/ScriptController.h"
+#include "bindings/core/v8/ScriptSourceCode.h"
+#include "bindings/core/v8/V8GCController.h"
#include "core/observer/ResizeObservation.h"
#include "core/observer/ResizeObserverCallback.h"
+#include "core/observer/ResizeObserverController.h"
#include "platform/testing/UnitTestHelpers.h"
+#include "public/web/WebHeap.h"
#include "web/WebViewImpl.h"
#include "web/tests/sim/SimCompositor.h"
#include "web/tests/sim/SimDisplayItemList.h"
@@ -50,9 +55,9 @@ private:
* modify target size
* oubservationSizeOutOfSync == true
*/
-class ResizeObservationUnitTest : public SimTest { };
+class ResizeObserverUnitTest : public SimTest { };
-TEST_F(ResizeObservationUnitTest, ObserveSchedulesFrame)
+TEST_F(ResizeObserverUnitTest, ResizeObservationSize)
{
SimRequest mainResource("https://example.com/", "text/html");
loadURL("https://example.com/");
@@ -95,4 +100,51 @@ TEST_F(ResizeObservationUnitTest, ObserveSchedulesFrame)
ASSERT_EQ(svgObservation->targetDepth() - domObservation->targetDepth(), (size_t)1);
}
+TEST_F(ResizeObserverUnitTest, TestMemoryLeaks)
+{
+
+ ResizeObserverController& controller = document().ensureResizeObserverController();
+ const HeapHashSet<WeakMember<ResizeObserver>>& observers = controller.observers();
+ ASSERT_EQ(observers.size(), 0U);
+ v8::HandleScope scope(v8::Isolate::GetCurrent());
+
+ ScriptController& script = document().executingFrame()->script();
+
+ //
+ // Test whether ResizeObserver is kept alive by direct JS reference
+ //
+ script.executeScriptInMainWorldAndReturnValue(
+ ScriptSourceCode("var ro = new ResizeObserver( entries => {});"),
+ ScriptController::ExecuteScriptWhenScriptsDisabled);
+ ASSERT_EQ(observers.size(), 1U);
+ script.executeScriptInMainWorldAndReturnValue(
+ ScriptSourceCode("ro = undefined;"),
+ ScriptController::ExecuteScriptWhenScriptsDisabled);
+ V8GCController::collectAllGarbageForTesting(v8::Isolate::GetCurrent());
+ WebHeap::collectAllGarbageForTesting();
+ ASSERT_EQ(observers.isEmpty(), true);
+
+ //
+ // Test whether ResizeObserver is kept alive by an Element
+ //
+ script.executeScriptInMainWorldAndReturnValue(
+ ScriptSourceCode(
+ "var ro = new ResizeObserver( () => {});"
+ "var el = document.createElement('div');"
+ "ro.observe(el);"
+ "ro = undefined;"
+ ),
+ ScriptController::ExecuteScriptWhenScriptsDisabled);
+ ASSERT_EQ(observers.size(), 1U);
+ V8GCController::collectAllGarbageForTesting(v8::Isolate::GetCurrent());
+ WebHeap::collectAllGarbageForTesting();
+ ASSERT_EQ(observers.size(), 1U);
+ script.executeScriptInMainWorldAndReturnValue(
+ ScriptSourceCode("el = undefined;"),
+ ScriptController::ExecuteScriptWhenScriptsDisabled);
+ V8GCController::collectAllGarbageForTesting(v8::Isolate::GetCurrent());
+ WebHeap::collectAllGarbageForTesting();
+ ASSERT_EQ(observers.isEmpty(), true);
+}
+
} // namespace blink
« 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