| 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 <style> |
| 5 <iframe id="target-iframe" src="../resources/intersection-observer-subframe.html
" style="height: 100px; overflow-y: scroll"></iframe> | 5 #root { |
| 6 <div style="width:100%; height:700px;"></div> | 6 width: 200px; |
| 7 height: 200px; |
| 8 overflow-y: scroll; |
| 9 } |
| 10 #target { |
| 11 width: 100px; |
| 12 height: 100px; |
| 13 background-color: green; |
| 14 position: absolute; |
| 15 } |
| 16 </style> |
| 17 <div id="root" style="position: absolute"> |
| 18 <div id="target" style="left: 50px; top: 250px"></div> |
| 19 </div> |
| 7 | 20 |
| 8 <script> | 21 <script> |
| 9 description("Simple intersection observer test with no explicit root and target
in an iframe."); | 22 description("Test that no notifications are generated when root is not in the
containing block chain of target."); |
| 10 var entries = []; | 23 var root = document.getElementById("root"); |
| 11 var targetIframe = document.getElementById("target-iframe"); | 24 var target = document.getElementById("target"); |
| 25 var entries = []; |
| 12 | 26 |
| 13 targetIframe.onload = function() { | 27 function observer_callback(changes) { |
| 14 var target = targetIframe.contentDocument.getElementById("target"); | 28 changes.forEach(function(e) { entries.push(e) }); |
| 15 var iframeScroller = targetIframe.contentDocument.scrollingElement; | 29 } |
| 16 | 30 new IntersectionObserver(observer_callback, {root: root}).observe(target); |
| 17 observer_callback = function(changes) { | |
| 18 for (var i in changes) | |
| 19 entries.push(changes[i]); | |
| 20 }; | |
| 21 var observer = new IntersectionObserver(observer_callback, {}); | |
| 22 observer.observe(target); | |
| 23 | 31 |
| 24 function step0() { | 32 function step0() { |
| 25 setTimeout(function() { | 33 setTimeout(function() { |
| 26 shouldBeEqualToNumber("entries.length", 0); | 34 shouldBeEqualToNumber("entries.length", 0); |
| 27 document.scrollingElement.scrollTop = 200; | 35 target.style.top = "10px"; |
| 28 requestAnimationFrame(step1); | 36 requestAnimationFrame(step1); |
| 29 }); | 37 }); |
| 30 } | 38 } |
| 31 | 39 |
| 32 function step1() { | 40 function step1() { |
| 33 setTimeout(function() { | 41 setTimeout(function() { |
| 34 shouldBeEqualToNumber("entries.length", 0); | 42 shouldBeEqualToNumber("entries.length", 1); |
| 35 iframeScroller.scrollTop = 250; | 43 shouldBeEqualToNumber("entries[0].boundingClientRect.left", 58); |
| 44 shouldBeEqualToNumber("entries[0].boundingClientRect.right", 158); |
| 45 shouldBeEqualToNumber("entries[0].boundingClientRect.top", 18); |
| 46 shouldBeEqualToNumber("entries[0].boundingClientRect.bottom", 118); |
| 47 shouldBeEqualToNumber("entries[0].intersectionRect.left", 58); |
| 48 shouldBeEqualToNumber("entries[0].intersectionRect.right", 158); |
| 49 shouldBeEqualToNumber("entries[0].intersectionRect.top", 18); |
| 50 shouldBeEqualToNumber("entries[0].intersectionRect.bottom", 118); |
| 51 shouldBeEqualToNumber("entries[0].rootBounds.left", 8); |
| 52 shouldBeEqualToNumber("entries[0].rootBounds.right", 193); |
| 53 shouldBeEqualToNumber("entries[0].rootBounds.top", 8); |
| 54 shouldBeEqualToNumber("entries[0].rootBounds.bottom", 208); |
| 55 shouldEvaluateToSameObject("entries[0].target", target); |
| 56 target.style.top = "250px"; |
| 36 requestAnimationFrame(step2); | 57 requestAnimationFrame(step2); |
| 37 }); | 58 }); |
| 38 } | 59 } |
| 39 | 60 |
| 40 function step2() { | 61 function step2() { |
| 41 setTimeout(function() { | 62 setTimeout(function() { |
| 42 shouldBeEqualToNumber("entries.length", 1); | 63 shouldBeEqualToNumber("entries.length", 2); |
| 43 shouldBeEqualToNumber("entries[0].boundingClientRect.left", 18); | 64 shouldBeEqualToNumber("entries[1].boundingClientRect.left", 58); |
| 44 shouldBeEqualToNumber("entries[0].boundingClientRect.right", 118); | 65 shouldBeEqualToNumber("entries[1].boundingClientRect.right", 158); |
| 45 shouldBeEqualToNumber("entries[0].boundingClientRect.top", 468); | 66 shouldBeEqualToNumber("entries[1].boundingClientRect.top", 258); |
| 46 shouldBeEqualToNumber("entries[0].boundingClientRect.bottom", 568); | 67 shouldBeEqualToNumber("entries[1].boundingClientRect.bottom", 358); |
| 47 shouldBeEqualToNumber("entries[0].intersectionRect.left", 18); | 68 shouldBeEqualToNumber("entries[1].intersectionRect.left", 0); |
| 48 shouldBeEqualToNumber("entries[0].intersectionRect.right", 118); | 69 shouldBeEqualToNumber("entries[1].intersectionRect.right", 0); |
| 49 shouldBeEqualToNumber("entries[0].intersectionRect.top", 510); | 70 shouldBeEqualToNumber("entries[1].intersectionRect.top", 0); |
| 50 shouldBeEqualToNumber("entries[0].intersectionRect.bottom", 568); | 71 shouldBeEqualToNumber("entries[1].intersectionRect.bottom", 0); |
| 51 shouldBeEqualToNumber("entries[0].rootBounds.left", 0); | 72 shouldBeEqualToNumber("entries[1].rootBounds.left", 8); |
| 52 shouldBeEqualToNumber("entries[0].rootBounds.right", 785); | 73 shouldBeEqualToNumber("entries[1].rootBounds.right", 193); |
| 53 shouldBeEqualToNumber("entries[0].rootBounds.top", 0); | 74 shouldBeEqualToNumber("entries[1].rootBounds.top", 8); |
| 54 shouldBeEqualToNumber("entries[0].rootBounds.bottom", 600); | 75 shouldBeEqualToNumber("entries[1].rootBounds.bottom", 208); |
| 55 shouldEvaluateToSameObject("entries[0].target", target); | 76 shouldEvaluateToSameObject("entries[1].target", target); |
| 56 document.scrollingElement.scrollTop = 100; | 77 root.style.position = "static"; |
| 78 target.style.top = "10px"; |
| 57 requestAnimationFrame(step3); | 79 requestAnimationFrame(step3); |
| 58 }); | 80 }); |
| 59 } | 81 } |
| 60 | 82 |
| 61 function step3() { | 83 function step3() { |
| 62 setTimeout(function() { | 84 setTimeout(function() { |
| 63 shouldBeEqualToNumber("entries.length", 2); | 85 shouldBeEqualToNumber("entries.length", 2); |
| 64 shouldBeEqualToNumber("entries[1].boundingClientRect.left", 18); | 86 target.style.top = "250px"; |
| 65 shouldBeEqualToNumber("entries[1].boundingClientRect.right", 118); | 87 requestAnimationFrame(step4); |
| 66 shouldBeEqualToNumber("entries[1].boundingClientRect.top", 568); | 88 }); |
| 67 shouldBeEqualToNumber("entries[1].boundingClientRect.bottom", 668); | 89 } |
| 68 shouldBeEqualToNumber("entries[1].intersectionRect.left", 0); | 90 |
| 69 shouldBeEqualToNumber("entries[1].intersectionRect.right", 0); | 91 function step4() { |
| 70 shouldBeEqualToNumber("entries[1].intersectionRect.top", 0); | 92 setTimeout(function() { |
| 71 shouldBeEqualToNumber("entries[1].intersectionRect.bottom", 0); | 93 shouldBeEqualToNumber("entries.length", 2); |
| 72 shouldBeEqualToNumber("entries[1].rootBounds.left", 0); | |
| 73 shouldBeEqualToNumber("entries[1].rootBounds.right", 785); | |
| 74 shouldBeEqualToNumber("entries[1].rootBounds.top", 0); | |
| 75 shouldBeEqualToNumber("entries[1].rootBounds.bottom", 600); | |
| 76 shouldEvaluateToSameObject("entries[1].target", target); | |
| 77 finishJSTest(); | 94 finishJSTest(); |
| 78 document.scrollingElement.scrollTop = 0; | |
| 79 }); | 95 }); |
| 80 } | 96 } |
| 81 | 97 |
| 82 step0(); | 98 step0(); |
| 83 } | |
| 84 </script> | 99 </script> |
| OLD | NEW |