| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <script src="../resources/js-test.js"></script> | 2 <script src="../resources/js-test.js"></script> |
| 3 <script src="helper-functions.js"></script> | 3 <script src="helper-functions.js"></script> |
| 4 <div style="width:100%; height:700px;"></div> | 4 <div style="width:100%; height:700px;"></div> |
| 5 <div id="target" style="background-color: green; width:0px; height:0px"></div> | 5 <div id="target" style="background-color: green; width:0px; height:0px"></div> |
| 6 <div style="width:100%; height:700px;"></div> | 6 <div style="width:100%; height:700px;"></div> |
| 7 | 7 |
| 8 <script> | 8 <script> |
| 9 description("Iintersection observer test with zero-size target element."); | 9 description("Iintersection observer test with zero-size target element."); |
| 10 var target = document.getElementById("target"); | 10 var target = document.getElementById("target"); |
| 11 var entries = []; | 11 var entries = []; |
| 12 var observer = new IntersectionObserver(changes => { entries = entries.concat(ch
anges) }, {}); | 12 observer_callback = function(changes) { |
| 13 for (var i in changes) |
| 14 entries.push(changes[i]); |
| 15 }; |
| 16 var observer = new IntersectionObserver(observer_callback, {}); |
| 17 observer.observe(target); |
| 13 | 18 |
| 14 onload = function() { | 19 onload = function() { |
| 15 observer.observe(target); | 20 shouldBeEqualToNumber("entries.length", 0); |
| 16 entries = entries.concat(observer.takeRecords()); | 21 document.scrollingElement.scrollTop = 300; |
| 17 shouldBeEqualToNumber("entries.length", 0); | 22 requestAnimationFrame(step1); |
| 18 document.scrollingElement.scrollTop = 300; | 23 }; |
| 19 // See README for explanation of double RAF. | |
| 20 requestAnimationFrame(() => { requestAnimationFrame(step1) }); | |
| 21 }; | |
| 22 | 24 |
| 23 function step1() { | 25 function step1() { |
| 24 entries = entries.concat(observer.takeRecords()); | 26 setTimeout(function() { |
| 25 shouldBeEqualToNumber("entries.length", 1); | 27 shouldBeEqualToNumber("entries.length", 1); |
| 26 if (entries.length > 0) { | 28 shouldBeEqualToNumber("entries[0].boundingClientRect.left", 8); |
| 27 shouldBeEqualToNumber("entries[0].boundingClientRect.left", 8); | 29 shouldBeEqualToNumber("entries[0].boundingClientRect.right", 9); |
| 28 shouldBeEqualToNumber("entries[0].boundingClientRect.right", 9); | 30 shouldBeEqualToNumber("entries[0].boundingClientRect.top", 408); |
| 29 shouldBeEqualToNumber("entries[0].boundingClientRect.top", 408); | 31 shouldBeEqualToNumber("entries[0].boundingClientRect.bottom", 409); |
| 30 shouldBeEqualToNumber("entries[0].boundingClientRect.bottom", 409); | 32 shouldBeEqualToNumber("entries[0].intersectionRect.left", 8); |
| 31 shouldBeEqualToNumber("entries[0].intersectionRect.left", 8); | 33 shouldBeEqualToNumber("entries[0].intersectionRect.right", 9); |
| 32 shouldBeEqualToNumber("entries[0].intersectionRect.right", 9); | 34 shouldBeEqualToNumber("entries[0].intersectionRect.top", 408); |
| 33 shouldBeEqualToNumber("entries[0].intersectionRect.top", 408); | 35 shouldBeEqualToNumber("entries[0].intersectionRect.bottom", 409); |
| 34 shouldBeEqualToNumber("entries[0].intersectionRect.bottom", 409); | 36 shouldBeEqualToNumber("entries[0].rootBounds.left", 0); |
| 35 shouldBeEqualToNumber("entries[0].rootBounds.left", 0); | 37 shouldBeEqualToNumber("entries[0].rootBounds.right", 785); |
| 36 shouldBeEqualToNumber("entries[0].rootBounds.right", 785); | 38 shouldBeEqualToNumber("entries[0].rootBounds.top", 0); |
| 37 shouldBeEqualToNumber("entries[0].rootBounds.top", 0); | 39 shouldBeEqualToNumber("entries[0].rootBounds.bottom", 600); |
| 38 shouldBeEqualToNumber("entries[0].rootBounds.bottom", 600); | 40 shouldEvaluateToSameObject("entries[0].target", target); |
| 39 shouldEvaluateToSameObject("entries[0].target", target); | |
| 40 | 41 |
| 41 // ClientRect members of IntersectionObserverEntry should be stable. | 42 // ClientRect members of IntersectionObserverEntry should be stable. |
| 42 shouldEvaluateToSameObject("entries[0].boundingClientRect", entries[0].bound
ingClientRect); | 43 shouldEvaluateToSameObject("entries[0].boundingClientRect", entries[0].bou
ndingClientRect); |
| 43 shouldEvaluateToSameObject("entries[0].intersectionRect", entries[0].interse
ctionRect); | 44 shouldEvaluateToSameObject("entries[0].intersectionRect", entries[0].inter
sectionRect); |
| 44 shouldEvaluateToSameObject("entries[0].rootBounds", entries[0].rootBounds); | 45 shouldEvaluateToSameObject("entries[0].rootBounds", entries[0].rootBounds)
; |
| 46 |
| 47 document.scrollingElement.scrollTop = 100; |
| 48 requestAnimationFrame(step2); |
| 49 }); |
| 45 } | 50 } |
| 46 document.scrollingElement.scrollTop = 100; | |
| 47 requestAnimationFrame(step2); | |
| 48 } | |
| 49 | 51 |
| 50 function step2() { | 52 function step2() { |
| 51 entries = entries.concat(observer.takeRecords()); | 53 setTimeout(function() { |
| 52 shouldBeEqualToNumber("entries.length", 2); | 54 shouldBeEqualToNumber("entries.length", 2); |
| 53 if (entries.length > 1) { | 55 shouldBeEqualToNumber("entries[1].boundingClientRect.left", 8); |
| 54 shouldBeEqualToNumber("entries[1].boundingClientRect.left", 8); | 56 shouldBeEqualToNumber("entries[1].boundingClientRect.right", 9); |
| 55 shouldBeEqualToNumber("entries[1].boundingClientRect.right", 9); | 57 shouldBeEqualToNumber("entries[1].boundingClientRect.top", 608); |
| 56 shouldBeEqualToNumber("entries[1].boundingClientRect.top", 608); | 58 shouldBeEqualToNumber("entries[1].boundingClientRect.bottom", 609); |
| 57 shouldBeEqualToNumber("entries[1].boundingClientRect.bottom", 609); | 59 shouldBeEqualToNumber("entries[1].intersectionRect.left", 0); |
| 58 shouldBeEqualToNumber("entries[1].intersectionRect.left", 0); | 60 shouldBeEqualToNumber("entries[1].intersectionRect.right", 0); |
| 59 shouldBeEqualToNumber("entries[1].intersectionRect.right", 0); | 61 shouldBeEqualToNumber("entries[1].intersectionRect.top", 0); |
| 60 shouldBeEqualToNumber("entries[1].intersectionRect.top", 0); | 62 shouldBeEqualToNumber("entries[1].intersectionRect.bottom", 0); |
| 61 shouldBeEqualToNumber("entries[1].intersectionRect.bottom", 0); | 63 shouldBeEqualToNumber("entries[1].rootBounds.left", 0); |
| 62 shouldBeEqualToNumber("entries[1].rootBounds.left", 0); | 64 shouldBeEqualToNumber("entries[1].rootBounds.right", 785); |
| 63 shouldBeEqualToNumber("entries[1].rootBounds.right", 785); | 65 shouldBeEqualToNumber("entries[1].rootBounds.top", 0); |
| 64 shouldBeEqualToNumber("entries[1].rootBounds.top", 0); | 66 shouldBeEqualToNumber("entries[1].rootBounds.bottom", 600); |
| 65 shouldBeEqualToNumber("entries[1].rootBounds.bottom", 600); | 67 shouldEvaluateToSameObject("entries[1].target", target); |
| 66 shouldEvaluateToSameObject("entries[1].target", target); | 68 finishJSTest(); |
| 69 document.scrollingElement.scrollTop = 0; |
| 70 }); |
| 67 } | 71 } |
| 68 finishJSTest(); | 72 |
| 69 document.scrollingElement.scrollTop = 0; | |
| 70 } | |
| 71 </script> | 73 </script> |
| OLD | NEW |