OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <div style="width:100%;height:700px;"></div> |
| 3 <iframe id="target-iframe" src="subframe.html" style="height: 100px; overflow-y:
scroll" onload="runtests()"></iframe> |
| 4 <div style="width:100%; height:700px;"></div> |
| 5 |
| 6 <script src="../resources/js-test.js"></script> |
| 7 <script src="helper-functions.js"></script> |
| 8 <script> |
| 9 description("Simple intersection observer test with no explicit root and target
in an iframe."); |
| 10 var entries = []; |
| 11 |
| 12 function runtests() { |
| 13 var targetIframe = document.getElementById("target-iframe"); |
| 14 var target = targetIframe.contentDocument.getElementById("target"); |
| 15 var iframeScroller = targetIframe.contentDocument.scrollingElement; |
| 16 |
| 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 |
| 24 // TODO: It shouldn't be necessary to RAF after the call to observer() |
| 25 // and before changing the scroll position, but it is. |
| 26 |
| 27 var expected0 = []; |
| 28 function step0() { |
| 29 setTimeout(function() { |
| 30 checkResults(expected0, "entries"); |
| 31 document.scrollingElement.scrollTop = 200; |
| 32 requestAnimationFrame(step1); |
| 33 }); |
| 34 } |
| 35 |
| 36 var expected1 = []; |
| 37 function step1() { |
| 38 setTimeout(function() { |
| 39 checkResults(expected1, "entries"); |
| 40 iframeScroller.scrollTop = 250; |
| 41 requestAnimationFrame(step2); |
| 42 }); |
| 43 } |
| 44 |
| 45 var expected2 = [ |
| 46 { |
| 47 'boundingClientRect': [ 18, 118, 468, 568 ], |
| 48 'intersectionRect': [ 18, 118, 510, 568], |
| 49 'rootBounds' : [ 0, 785, 0, 600 ], |
| 50 'target': target |
| 51 } |
| 52 ]; |
| 53 function step2() { |
| 54 setTimeout(function() { |
| 55 checkResults(expected2, "entries"); |
| 56 document.scrollingElement.scrollTop = 100; |
| 57 requestAnimationFrame(step3); |
| 58 }); |
| 59 } |
| 60 |
| 61 var expected3 = expected2.concat([ |
| 62 { |
| 63 'boundingClientRect': [ 18, 118, 568, 668 ], |
| 64 'intersectionRect': [ 0, 0, 0, 0 ], |
| 65 'rootBounds' : [ 0, 785, 0, 600 ], |
| 66 'target': target |
| 67 } |
| 68 ]); |
| 69 function step3() { |
| 70 setTimeout(function() { |
| 71 checkResults(expected3, "entries", 1); |
| 72 finishTest(); |
| 73 document.scrollingElement.scrollTop = 0; |
| 74 }); |
| 75 } |
| 76 |
| 77 requestAnimationFrame(step0); |
| 78 } |
| 79 </script> |
OLD | NEW |