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 <iframe id="target-iframe" src="../resources/intersection-observer-subframe.html
" style="height: 100px; overflow-y: scroll"></iframe> | 5 <iframe id="target-iframe" src="../resources/intersection-observer-subframe.html
" style="height: 100px; overflow-y: scroll"></iframe> |
6 <div style="width:100%; height:700px;"></div> | 6 <div style="width:100%; height:700px;"></div> |
7 | 7 |
8 <script> | 8 <script> |
9 description("Simple intersection observer test with no explicit root and target
in an iframe."); | 9 description("Simple intersection observer test with no explicit root and target
in an iframe."); |
10 var entries = []; | 10 var entries = []; |
11 var targetIframe = document.getElementById("target-iframe"); | 11 var targetIframe = document.getElementById("target-iframe"); |
12 | 12 |
13 targetIframe.onload = function() { | 13 targetIframe.onload = function() { |
14 var target = targetIframe.contentDocument.getElementById("target"); | 14 var target = targetIframe.contentDocument.getElementById("target"); |
15 var iframeScroller = targetIframe.contentDocument.scrollingElement; | 15 var iframeScroller = targetIframe.contentDocument.scrollingElement; |
16 | 16 |
17 observer_callback = function(changes) { | 17 observer_callback = function(changes) { |
18 for (var i in changes) | 18 for (var i in changes) |
19 entries.push(changes[i]); | 19 entries.push(changes[i]); |
20 }; | 20 }; |
21 var observer = new IntersectionObserver(observer_callback, {}); | 21 var observer = new IntersectionObserver(observer_callback, {}); |
22 observer.observe(target); | 22 observer.observe(target); |
23 | 23 |
24 // TODO(szager): It shouldn't be necessary to RAF after the call to observer() | |
25 // and before changing the scroll position, but it is. | |
26 | |
27 function step0() { | 24 function step0() { |
28 setTimeout(function() { | 25 setTimeout(function() { |
29 shouldBeEqualToNumber("entries.length", 0); | 26 shouldBeEqualToNumber("entries.length", 0); |
30 document.scrollingElement.scrollTop = 200; | 27 document.scrollingElement.scrollTop = 200; |
31 requestAnimationFrame(step1); | 28 requestAnimationFrame(step1); |
32 }); | 29 }); |
33 } | 30 } |
34 | 31 |
35 function step1() { | 32 function step1() { |
36 setTimeout(function() { | 33 setTimeout(function() { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 shouldBeEqualToNumber("entries[1].rootBounds.left", 0); | 72 shouldBeEqualToNumber("entries[1].rootBounds.left", 0); |
76 shouldBeEqualToNumber("entries[1].rootBounds.right", 785); | 73 shouldBeEqualToNumber("entries[1].rootBounds.right", 785); |
77 shouldBeEqualToNumber("entries[1].rootBounds.top", 0); | 74 shouldBeEqualToNumber("entries[1].rootBounds.top", 0); |
78 shouldBeEqualToNumber("entries[1].rootBounds.bottom", 600); | 75 shouldBeEqualToNumber("entries[1].rootBounds.bottom", 600); |
79 shouldEvaluateToSameObject("entries[1].target", target); | 76 shouldEvaluateToSameObject("entries[1].target", target); |
80 finishTest(); | 77 finishTest(); |
81 document.scrollingElement.scrollTop = 0; | 78 document.scrollingElement.scrollTop = 0; |
82 }); | 79 }); |
83 } | 80 } |
84 | 81 |
85 requestAnimationFrame(step0); | 82 step0(); |
86 } | 83 } |
87 </script> | 84 </script> |
OLD | NEW |