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

Unified Diff: third_party/WebKit/LayoutTests/intersection-observer/helper-functions.js

Issue 1983383002: Convert IntersectionObserver tests to use testRunner.runIdleTasks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: 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
Index: third_party/WebKit/LayoutTests/intersection-observer/helper-functions.js
diff --git a/third_party/WebKit/LayoutTests/intersection-observer/helper-functions.js b/third_party/WebKit/LayoutTests/intersection-observer/helper-functions.js
index 7e2612d49f5806c2244c5d96c295b16c54ef6a02..6fd2361eef0914b9ca25690730aef02da71e29ce 100644
--- a/third_party/WebKit/LayoutTests/intersection-observer/helper-functions.js
+++ b/third_party/WebKit/LayoutTests/intersection-observer/helper-functions.js
@@ -8,6 +8,47 @@ function rectArea(rect) {
return (rect.left - rect.right) * (rect.bottom - rect.top);
}
+// waitForNotification is a requestIdleCallback wrapped in a setTimeout wrapped in a
+// requestAnimationFrame. What in the wide, wide world of sports is going on here?
+//
+// Here's the order of events:
+//
+// - firstTestFunction
+// - Change layout to generate new IntersectionObserver notifications.
+// - waitForNotification(secondTestFunction)
+// - requestAnimationFrame
+// - BeginFrame
+// - requestAnimationFrame handler runs.
+// - setTimeout
+// - FrameView::updateAllLifecyclePhases
+// - IntersectionObserver generates notification based on the new layout.
+// - Post idle task to deliver notification.
+// - setTimeout handler runs.
+// - testRunner.runIdleTasks or requestIdleCallback.
+// - Idle tasks run -- more or less immediately if (self.testRunner),
+// possibly delayed if (!self.testRunner).
+// - IntersectionObserver notifications are delivered.
+// - secondTestFunction
+// - Verify notifications generated by firstTestFunction.
+// - Change layout to generate new IntersectionObserver notifications.
+// - waitForNotification(thirdTestFunction)
+//
+// Note that this should work equally well in these operation conditions:
+//
+// - layout test using single-threaded compositing (the default)
+// - layout test using multi-threaded compositing (virtual/threaded/)
+// - Not in a layout test and using multi-threaded compositing (the only configuration we ship)
+function waitForNotification(f) {
+ requestAnimationFrame(() => {
+ setTimeout(() => {
+ if (self.testRunner)
+ testRunner.runIdleTasks(f);
+ else
+ requestIdleCallback(f);
+ })
+ })
+}
+
function rectToString(rect) {
return "[" + rect.left + ", " + rect.right + ", " + rect.top + ", " + rect.bottom + "]";
}

Powered by Google App Engine
This is Rietveld 408576698