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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Some of the js-test.js boilerplate will add stuff to the top of the document early 1 // Some of the js-test.js boilerplate will add stuff to the top of the document early
2 // enough to screw with frame offsets that are measured by the test. Delay all that 2 // enough to screw with frame offsets that are measured by the test. Delay all that
3 // jazz until the actual test code is finished. 3 // jazz until the actual test code is finished.
4 setPrintTestResultsLazily(); 4 setPrintTestResultsLazily();
5 self.jsTestIsAsync = true; 5 self.jsTestIsAsync = true;
6 6
7 function rectArea(rect) { 7 function rectArea(rect) {
8 return (rect.left - rect.right) * (rect.bottom - rect.top); 8 return (rect.left - rect.right) * (rect.bottom - rect.top);
9 } 9 }
10 10
11 // waitForNotification is a requestIdleCallback wrapped in a setTimeout wrapped in a
12 // requestAnimationFrame. What in the wide, wide world of sports is going on he re?
13 //
14 // Here's the order of events:
15 //
16 // - firstTestFunction
17 // - Change layout to generate new IntersectionObserver notifications.
18 // - waitForNotification(secondTestFunction)
19 // - requestAnimationFrame
20 // - BeginFrame
21 // - requestAnimationFrame handler runs.
22 // - setTimeout
23 // - FrameView::updateAllLifecyclePhases
24 // - IntersectionObserver generates notification based on the new layout.
25 // - Post idle task to deliver notification.
26 // - setTimeout handler runs.
27 // - testRunner.runIdleTasks or requestIdleCallback.
28 // - Idle tasks run -- more or less immediately if (self.testRunner),
29 // possibly delayed if (!self.testRunner).
30 // - IntersectionObserver notifications are delivered.
31 // - secondTestFunction
32 // - Verify notifications generated by firstTestFunction.
33 // - Change layout to generate new IntersectionObserver notifications.
34 // - waitForNotification(thirdTestFunction)
35 //
36 // Note that this should work equally well in these operation conditions:
37 //
38 // - layout test using single-threaded compositing (the default)
39 // - layout test using multi-threaded compositing (virtual/threaded/)
40 // - Not in a layout test and using multi-threaded compositing (the only confi guration we ship)
41 function waitForNotification(f) {
42 requestAnimationFrame(() => {
43 setTimeout(() => {
44 if (self.testRunner)
45 testRunner.runIdleTasks(f);
46 else
47 requestIdleCallback(f);
48 })
49 })
50 }
51
11 function rectToString(rect) { 52 function rectToString(rect) {
12 return "[" + rect.left + ", " + rect.right + ", " + rect.top + ", " + rect.bot tom + "]"; 53 return "[" + rect.left + ", " + rect.right + ", " + rect.top + ", " + rect.bot tom + "]";
13 } 54 }
14 55
15 function entryToString(entry) { 56 function entryToString(entry) {
16 var ratio = ((entry.intersectionRect.width * entry.intersectionRect.height) / 57 var ratio = ((entry.intersectionRect.width * entry.intersectionRect.height) /
17 (entry.boundingClientRect.width * entry.boundingClientRect.height )); 58 (entry.boundingClientRect.width * entry.boundingClientRect.height ));
18 return ( 59 return (
19 "boundingClientRect=" + rectToString(entry.boundingClientRect) + "\n" + 60 "boundingClientRect=" + rectToString(entry.boundingClientRect) + "\n" +
20 "intersectionRect=" + rectToString(entry.intersectionRect) + "\n" + 61 "intersectionRect=" + rectToString(entry.intersectionRect) + "\n" +
21 "visibleRatio=" + ratio + "\n" + 62 "visibleRatio=" + ratio + "\n" +
22 "rootBounds=" + rectToString(entry.rootBounds) + "\n" + 63 "rootBounds=" + rectToString(entry.rootBounds) + "\n" +
23 "target=" + entry.target + "\n" + 64 "target=" + entry.target + "\n" +
24 "time=" + entry.time); 65 "time=" + entry.time);
25 } 66 }
26 67
27 function intersectionRatio(entry) { 68 function intersectionRatio(entry) {
28 var targetArea = rectArea(entry.boundingClientRect); 69 var targetArea = rectArea(entry.boundingClientRect);
29 if (!targetArea) 70 if (!targetArea)
30 return 0; 71 return 0;
31 return rectArea(entry.intersectionRect) / targetArea; 72 return rectArea(entry.intersectionRect) / targetArea;
32 } 73 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698