OLD | NEW |
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) { |
| 8 return (rect.left - rect.right) * (rect.bottom - rect.top); |
| 9 } |
| 10 |
7 function rectToString(rect) { | 11 function rectToString(rect) { |
8 return "[" + rect.left + ", " + rect.right + ", " + rect.top + ", " + rect.bot
tom + "]"; | 12 return "[" + rect.left + ", " + rect.right + ", " + rect.top + ", " + rect.bot
tom + "]"; |
9 } | 13 } |
10 | 14 |
11 function entryToString(entry) { | 15 function entryToString(entry) { |
12 var ratio = ((entry.intersectionRect.width * entry.intersectionRect.height) / | 16 var ratio = ((entry.intersectionRect.width * entry.intersectionRect.height) / |
13 (entry.boundingClientRect.width * entry.boundingClientRect.height
)); | 17 (entry.boundingClientRect.width * entry.boundingClientRect.height
)); |
14 return ( | 18 return ( |
15 "boundingClientRect=" + rectToString(entry.boundingClientRect) + "\n" + | 19 "boundingClientRect=" + rectToString(entry.boundingClientRect) + "\n" + |
16 "intersectionRect=" + rectToString(entry.intersectionRect) + "\n" + | 20 "intersectionRect=" + rectToString(entry.intersectionRect) + "\n" + |
17 "visibleRatio=" + ratio + "\n" + | 21 "visibleRatio=" + ratio + "\n" + |
18 "rootBounds=" + rectToString(entry.rootBounds) + "\n" + | 22 "rootBounds=" + rectToString(entry.rootBounds) + "\n" + |
19 "target=" + entry.target + "\n" + | 23 "target=" + entry.target + "\n" + |
20 "time=" + entry.time); | 24 "time=" + entry.time); |
21 } | 25 } |
| 26 |
| 27 function intersectionRatio(entry) { |
| 28 var targetArea = rectArea(entry.boundingClientRect); |
| 29 if (!targetArea) |
| 30 return 0; |
| 31 return rectArea(entry.intersectionRect) / targetArea; |
| 32 } |
OLD | NEW |