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

Side by Side Diff: third_party/WebKit/LayoutTests/resources/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: rebase 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
« no previous file with comments | « third_party/WebKit/LayoutTests/intersection-observer/unclipped-root.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // jazz until the actual test code is finished.
4 if (self.isJsTest) {
5 setPrintTestResultsLazily();
6 self.jsTestIsAsync = true;
7 }
8
9 // waitForNotification is a requestIdleCallback wrapped in a setTimeout wrapped in a
10 // requestAnimationFrame. What in the wide, wide world of sports is going on he re?
11 //
12 // Here's the order of events:
13 //
14 // - firstTestFunction
15 // - Change layout to generate new IntersectionObserver notifications.
16 // - waitForNotification(secondTestFunction)
17 // - requestAnimationFrame
18 // - BeginFrame
19 // - requestAnimationFrame handler runs.
20 // - setTimeout
21 // - FrameView::updateAllLifecyclePhases
22 // - IntersectionObserver generates notification based on the new layout.
23 // - Post idle task to deliver notification.
24 // - setTimeout handler runs.
25 // - testRunner.runIdleTasks or requestIdleCallback.
26 // - Idle tasks run -- more or less immediately if (self.testRunner),
27 // possibly delayed if (!self.testRunner).
28 // - IntersectionObserver notifications are delivered.
29 // - secondTestFunction
30 // - Verify notifications generated by firstTestFunction.
31 // - Change layout to generate new IntersectionObserver notifications.
32 // - waitForNotification(thirdTestFunction)
33 //
34 // Note that this should work equally well in these operation conditions:
35 //
36 // - layout test using single-threaded compositing (the default)
37 // - layout test using multi-threaded compositing (virtual/threaded/)
38 // - Not in a layout test and using multi-threaded compositing (the only confi guration we ship)
39 function waitForNotification(f) {
40 requestAnimationFrame(() => {
41 setTimeout(() => {
42 if (self.testRunner)
43 testRunner.runIdleTasks(f);
44 else
45 requestIdleCallback(f);
46 });
47 });
48 }
49
50 function rectToString(rect) {
51 return "[" + rect.left + ", " + rect.right + ", " + rect.top + ", " + rect.bot tom + "]";
52 }
53
54 function entryToString(entry) {
55 var ratio = ((entry.intersectionRect.width * entry.intersectionRect.height) /
56 (entry.boundingClientRect.width * entry.boundingClientRect.height ));
57 return (
58 "boundingClientRect=" + rectToString(entry.boundingClientRect) + "\n" +
59 "intersectionRect=" + rectToString(entry.intersectionRect) + "\n" +
60 "visibleRatio=" + ratio + "\n" +
61 "rootBounds=" + rectToString(entry.rootBounds) + "\n" +
62 "target=" + entry.target + "\n" +
63 "time=" + entry.time);
64 }
65
66 function rectArea(rect) {
67 return (rect.left - rect.right) * (rect.bottom - rect.top);
68 }
69
70 function intersectionRatio(entry) {
71 var targetArea = rectArea(entry.boundingClientRect);
72 if (!targetArea)
73 return 0;
74 return rectArea(entry.intersectionRect) / targetArea;
75 }
76
77 function clientRectToJson(rect) {
78 if (!rect)
79 return null;
80 return {
81 top: rect.top,
82 right: rect.right,
83 bottom: rect.bottom,
84 left: rect.left,
85 width: rect.width,
86 height: rect.height
87 };
88 }
89
90 function coordinatesToClientRectJson(top, right, bottom, left) {
91 return {
92 top: top,
93 right: right,
94 bottom: bottom,
95 left: left,
96 width: right - left,
97 height: bottom - top
98 };
99 }
100
101 function entryToJson(entry) {
102 return {
103 boundingClientRect: clientRectToJson(entry.boundingClientRect),
104 intersectionRect: clientRectToJson(entry.intersectionRect),
105 rootBounds: clientRectToJson(entry.rootBounds),
106 time: entry.time,
107 target: entry.target.id
108 };
109 }
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/intersection-observer/unclipped-root.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698