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="root" style="display: inline-block; overflow-y: scroll; height: 200px;"
> | 5 <div id="root" style="display: inline-block; overflow-y: scroll; height: 200px;"
> |
6 <div id="target" style="width:100px; height:300px"></div> | 6 <div id="target" style="width:100px; height:300px"></div> |
7 <iframe id="target-iframe" src="../resources/intersection-observer-subframe.ht
ml" style="width: 300px; height: 100px; overflow-y: scroll"></iframe> | 7 <iframe id="target-iframe" src="../resources/intersection-observer-subframe.ht
ml" style="width: 300px; height: 100px; overflow-y: scroll"></iframe> |
8 </div> | 8 </div> |
9 <div style="width:100%; height:700px;"></div> | 9 <div style="width:100%; height:700px;"></div> |
10 | 10 |
11 <script> | 11 <script> |
12 description("Simple intersection observer test with no explicit root and target
in an iframe."); | 12 description("Simple intersection observer test with no explicit root and target
in an iframe."); |
13 var entries = []; | 13 var entries = []; |
14 var root = document.getElementById("root"); | 14 var root = document.getElementById("root"); |
15 var targetIframe = document.getElementById("target-iframe"); | 15 var targetIframe = document.getElementById("target-iframe"); |
16 | 16 |
17 targetIframe.onload = function() { | 17 targetIframe.onload = function() { |
18 var target = targetIframe.contentDocument.getElementById("target"); | 18 var target = targetIframe.contentDocument.getElementById("target"); |
19 var iframeScroller = targetIframe.contentDocument.scrollingElement; | 19 var iframeScroller = targetIframe.contentDocument.scrollingElement; |
20 | 20 |
21 observer_callback = function(changes) { | 21 observer_callback = function(changes) { |
22 for (var i in changes) | 22 for (var i in changes) |
23 entries.push(changes[i]); | 23 entries.push(changes[i]); |
24 }; | 24 }; |
25 var observer = new IntersectionObserver(observer_callback, {"root": document.g
etElementById("root")}); | 25 var observer = new IntersectionObserver(observer_callback, {"root": document.g
etElementById("root")}); |
26 observer.observe(target); | 26 observer.observe(target); |
27 | 27 |
28 // TODO(szager): It shouldn't be necessary to RAF after the call to observer() | |
29 // and before changing the scroll position, but it is. | |
30 | |
31 function step0() { | 28 function step0() { |
32 setTimeout(function() { | 29 setTimeout(function() { |
33 shouldBeEqualToNumber("entries.length", 0); | 30 shouldBeEqualToNumber("entries.length", 0); |
34 document.scrollingElement.scrollTop = 250; | 31 document.scrollingElement.scrollTop = 250; |
35 requestAnimationFrame(step1); | 32 requestAnimationFrame(step1); |
36 }); | 33 }); |
37 } | 34 } |
38 | 35 |
39 function step1() { | 36 function step1() { |
40 setTimeout(function() { | 37 setTimeout(function() { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 shouldBeEqualToNumber("entries[1].rootBounds.left", 8); | 92 shouldBeEqualToNumber("entries[1].rootBounds.left", 8); |
96 shouldBeEqualToNumber("entries[1].rootBounds.right", 312); | 93 shouldBeEqualToNumber("entries[1].rootBounds.right", 312); |
97 shouldBeEqualToNumber("entries[1].rootBounds.top", 608); | 94 shouldBeEqualToNumber("entries[1].rootBounds.top", 608); |
98 shouldBeEqualToNumber("entries[1].rootBounds.bottom", 808); | 95 shouldBeEqualToNumber("entries[1].rootBounds.bottom", 808); |
99 shouldEvaluateToSameObject("entries[1].target", target); | 96 shouldEvaluateToSameObject("entries[1].target", target); |
100 finishTest(); | 97 finishTest(); |
101 document.scrollingElement.scrollTop = 0; | 98 document.scrollingElement.scrollTop = 0; |
102 }); | 99 }); |
103 } | 100 } |
104 | 101 |
105 requestAnimationFrame(step0); | 102 step0(); |
106 } | 103 } |
107 </script> | 104 </script> |
OLD | NEW |