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

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

Issue 2565863002: IntersectionObserver: use post task inside of resume(). (Closed)
Patch Set: Added test Created 4 years 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/IntersectionObserverController.cpp ('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/IntersectionObserverTest.cpp
diff --git a/third_party/WebKit/Source/web/tests/IntersectionObserverTest.cpp b/third_party/WebKit/Source/web/tests/IntersectionObserverTest.cpp
index 3172f7a09840f6e3441f18352effcfe4ba6f8843..825edddae8d8e7ae055f69b6c67a5fb07fc85cc5 100644
--- a/third_party/WebKit/Source/web/tests/IntersectionObserverTest.cpp
+++ b/third_party/WebKit/Source/web/tests/IntersectionObserverTest.cpp
@@ -6,6 +6,7 @@
#include "core/dom/IntersectionObserverCallback.h"
#include "core/dom/IntersectionObserverInit.h"
+#include "core/frame/FrameView.h"
#include "platform/testing/UnitTestHelpers.h"
#include "web/WebViewImpl.h"
#include "web/tests/sim/SimCompositor.h"
@@ -67,4 +68,63 @@ TEST_F(IntersectionObserverTest, ObserveSchedulesFrame) {
EXPECT_TRUE(compositor().needsBeginFrame());
}
+TEST_F(IntersectionObserverTest, ResumePostsTask) {
+ webView().resize(WebSize(800, 600));
+ SimRequest mainResource("https://example.com/", "text/html");
+ loadURL("https://example.com/");
+ mainResource.complete(
+ "<div id='leading-space' style='height: 700px;'></div>"
+ "<div id='target'></div>"
+ "<div id='trailing-space' style='height: 700px;'></div>");
+
+ IntersectionObserverInit observerInit;
+ DummyExceptionStateForTesting exceptionState;
+ TestIntersectionObserverCallback* observerCallback =
+ new TestIntersectionObserverCallback(document());
+ IntersectionObserver* observer = IntersectionObserver::create(
+ observerInit, *observerCallback, exceptionState);
+ ASSERT_FALSE(exceptionState.hadException());
+
+ Element* target = document().getElementById("target");
+ ASSERT_TRUE(target);
+ observer->observe(target, exceptionState);
+
+ compositor().beginFrame();
+ testing::runPendingTasks();
dcheng 2016/12/13 01:35:36 Just to make sure I understand: is this to try to
szager1 2016/12/13 01:40:44 Correct.
+ EXPECT_EQ(observerCallback->callCount(), 0);
+
+ // When document is not suspended, beginFrame() will generate notifications
+ // and post a task to deliver them.
+ document().view()->layoutViewportScrollableArea()->setScrollOffset(
+ ScrollOffset(0, 300), ProgrammaticScroll);
+ compositor().beginFrame();
+ EXPECT_EQ(observerCallback->callCount(), 0);
+ testing::runPendingTasks();
+ EXPECT_EQ(observerCallback->callCount(), 1);
+
+ // When a document is suspended, beginFrame() will generate a notification,
+ // but it will not be delivered. The notification will, however, be
+ // available via takeRecords();
+ document().suspendScheduledTasks();
+ document().view()->layoutViewportScrollableArea()->setScrollOffset(
+ ScrollOffset(0, 0), ProgrammaticScroll);
+ compositor().beginFrame();
+ EXPECT_EQ(observerCallback->callCount(), 1);
+ testing::runPendingTasks();
+ EXPECT_EQ(observerCallback->callCount(), 1);
+ EXPECT_FALSE(observer->takeRecords(exceptionState).isEmpty());
+
+ // Generate a notification while document is suspended; then resume document.
+ // Notification should happen in a post task.
+ document().view()->layoutViewportScrollableArea()->setScrollOffset(
+ ScrollOffset(0, 300), ProgrammaticScroll);
+ compositor().beginFrame();
+ testing::runPendingTasks();
+ EXPECT_EQ(observerCallback->callCount(), 1);
+ document().resumeScheduledTasks();
+ EXPECT_EQ(observerCallback->callCount(), 1);
+ testing::runPendingTasks();
+ EXPECT_EQ(observerCallback->callCount(), 2);
+}
+
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/dom/IntersectionObserverController.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698