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

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

Issue 1988633002: Schedule a frame from IntersectionObserver::observe. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Oilpan doesn't like stack-allocated callback Created 4 years, 7 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/dom/IntersectionObserver.cpp ('k') | third_party/WebKit/Source/web/web.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/web/tests/IntersectionObserverTest.cpp
diff --git a/third_party/WebKit/Source/web/tests/IntersectionObserverTest.cpp b/third_party/WebKit/Source/web/tests/IntersectionObserverTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..b9bff2fab2dca4159fd2c522c7c7b6c6c8835da1
--- /dev/null
+++ b/third_party/WebKit/Source/web/tests/IntersectionObserverTest.cpp
@@ -0,0 +1,65 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/dom/IntersectionObserver.h"
+
+#include "core/dom/IntersectionObserverCallback.h"
+#include "core/dom/IntersectionObserverInit.h"
+#include "platform/testing/UnitTestHelpers.h"
+#include "web/WebViewImpl.h"
+#include "web/tests/sim/SimCompositor.h"
+#include "web/tests/sim/SimDisplayItemList.h"
+#include "web/tests/sim/SimRequest.h"
+#include "web/tests/sim/SimTest.h"
+#include "wtf/CurrentTime.h"
+
+namespace blink {
+
+namespace {
+
+class TestIntersectionObserverCallback : public IntersectionObserverCallback {
+public:
+ TestIntersectionObserverCallback(Document& document) : m_document(document), m_callCount(0) { }
+ void handleEvent(const HeapVector<Member<IntersectionObserverEntry>>&, IntersectionObserver&) override { m_callCount++; }
+ ExecutionContext* getExecutionContext() const override { return m_document; }
+ int callCount() const { return m_callCount; }
+
+ DEFINE_INLINE_TRACE() {
+ IntersectionObserverCallback::trace(visitor);
+ visitor->trace(m_document);
+ }
+
+private:
+ Member<Document> m_document;
+ int m_callCount;
+};
+
+} // namespace
+
+class IntersectionObserverTest : public SimTest { };
+
+TEST_F(IntersectionObserverTest, ObserveSchedulesFrame)
+{
+ SimRequest mainResource("https://example.com/", "text/html");
+ loadURL("https://example.com/");
+ mainResource.complete("<div id='target'></div>");
+
+ IntersectionObserverInit observerInit;
+ TrackExceptionState exceptionState;
+ TestIntersectionObserverCallback* observerCallback = new TestIntersectionObserverCallback(document());
+ IntersectionObserver* observer = IntersectionObserver::create(observerInit, *observerCallback, exceptionState);
+ ASSERT_FALSE(exceptionState.hadException());
+
+ compositor().beginFrame();
+ ASSERT_FALSE(compositor().needsAnimate());
+ EXPECT_TRUE(observer->takeRecords().isEmpty());
+ EXPECT_EQ(observerCallback->callCount(), 0);
+
+ Element* target = document().getElementById("target");
+ ASSERT_TRUE(target);
+ observer->observe(target);
+ EXPECT_TRUE(compositor().needsAnimate());
+}
+
+} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/dom/IntersectionObserver.cpp ('k') | third_party/WebKit/Source/web/web.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698