| OLD | NEW |
| (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 setTimeout 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 // - queue first setTimeout | |
| 21 // - FrameView::updateAllLifecyclePhases | |
| 22 // - IntersectionObserver generates notification based on the new layout. | |
| 23 // - Post task to deliver notification. | |
| 24 // - first setTimeout runs. | |
| 25 // - queue second setTimeout | |
| 26 // - Posted task runs. | |
| 27 // - IntersectionObserver notifications are delivered. | |
| 28 // - second setTimeout runs secondTestFunction | |
| 29 // - Verify notifications generated by firstTestFunction. | |
| 30 // - Change layout to generate new IntersectionObserver notifications. | |
| 31 // - waitForNotification(thirdTestFunction) | |
| 32 function waitForNotification(f) { | |
| 33 requestAnimationFrame(() => { | |
| 34 setTimeout(() => { | |
| 35 setTimeout(f); | |
| 36 }); | |
| 37 }); | |
| 38 } | |
| 39 | |
| 40 function rectToString(rect) { | |
| 41 return "[" + rect.left + ", " + rect.right + ", " + rect.top + ", " + rect.bot
tom + "]"; | |
| 42 } | |
| 43 | |
| 44 function entryToString(entry) { | |
| 45 var ratio = ((entry.intersectionRect.width * entry.intersectionRect.height) / | |
| 46 (entry.boundingClientRect.width * entry.boundingClientRect.height
)); | |
| 47 return ( | |
| 48 "boundingClientRect=" + rectToString(entry.boundingClientRect) + "\n" + | |
| 49 "intersectionRect=" + rectToString(entry.intersectionRect) + "\n" + | |
| 50 "visibleRatio=" + ratio + "\n" + | |
| 51 "rootBounds=" + rectToString(entry.rootBounds) + "\n" + | |
| 52 "target=" + entry.target + "\n" + | |
| 53 "time=" + entry.time); | |
| 54 } | |
| 55 | |
| 56 function rectArea(rect) { | |
| 57 return (rect.left - rect.right) * (rect.bottom - rect.top); | |
| 58 } | |
| 59 | |
| 60 function intersectionRatio(entry) { | |
| 61 var targetArea = rectArea(entry.boundingClientRect); | |
| 62 if (!targetArea) | |
| 63 return 0; | |
| 64 return rectArea(entry.intersectionRect) / targetArea; | |
| 65 } | |
| 66 | |
| 67 function clientRectToJson(rect) { | |
| 68 if (!rect) | |
| 69 return null; | |
| 70 return { | |
| 71 top: rect.top, | |
| 72 right: rect.right, | |
| 73 bottom: rect.bottom, | |
| 74 left: rect.left, | |
| 75 width: rect.width, | |
| 76 height: rect.height | |
| 77 }; | |
| 78 } | |
| 79 | |
| 80 function coordinatesToClientRectJson(top, right, bottom, left) { | |
| 81 return { | |
| 82 top: top, | |
| 83 right: right, | |
| 84 bottom: bottom, | |
| 85 left: left, | |
| 86 width: right - left, | |
| 87 height: bottom - top | |
| 88 }; | |
| 89 } | |
| 90 | |
| 91 function entryToJson(entry) { | |
| 92 return { | |
| 93 boundingClientRect: clientRectToJson(entry.boundingClientRect), | |
| 94 intersectionRect: clientRectToJson(entry.intersectionRect), | |
| 95 rootBounds: clientRectToJson(entry.rootBounds), | |
| 96 time: entry.time, | |
| 97 target: entry.target.id | |
| 98 }; | |
| 99 } | |
| OLD | NEW |