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:100px; height:100px"></di
v> | 5 <div id="target" style="background-color: green; width:100px; height:100px"></di
v> |
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 one d
ocument."); | 9 description("Simple intersection observer test with no explicit root and one d
ocument."); |
10 var target = document.getElementById("target"); | 10 var target = document.getElementById("target"); |
11 var entries = []; | 11 var entries = []; |
12 | |
13 observer_callback = function(changes) { | 12 observer_callback = function(changes) { |
14 for (var i in changes) | 13 for (var i in changes) |
15 entries.push(changes[i]); | 14 entries.push(changes[i]); |
16 }; | 15 }; |
17 var observer = new IntersectionObserver(observer_callback, {}); | 16 var observer = new IntersectionObserver(observer_callback, {}); |
18 observer.observe(target); | 17 observer.observe(target); |
19 | 18 |
20 // TODO(szager): It shouldn't be necessary to RAF after the call to observer() | 19 onload = function() { |
21 // and before changing the scroll position, but it is. | 20 shouldBeEqualToNumber("entries.length", 0); |
22 | 21 document.scrollingElement.scrollTop = 300; |
23 function step0() { | 22 requestAnimationFrame(step1); |
24 setTimeout(function() { | 23 }; |
25 shouldBeEqualToNumber("entries.length", 0); | |
26 document.scrollingElement.scrollTop = 300; | |
27 requestAnimationFrame(step1); | |
28 }); | |
29 } | |
30 | 24 |
31 function step1() { | 25 function step1() { |
32 setTimeout(function() { | 26 setTimeout(function() { |
33 shouldBeEqualToNumber("entries.length", 1); | 27 shouldBeEqualToNumber("entries.length", 1); |
34 shouldBeEqualToNumber("entries[0].boundingClientRect.left", 8); | 28 shouldBeEqualToNumber("entries[0].boundingClientRect.left", 8); |
35 shouldBeEqualToNumber("entries[0].boundingClientRect.right", 108); | 29 shouldBeEqualToNumber("entries[0].boundingClientRect.right", 108); |
36 shouldBeEqualToNumber("entries[0].boundingClientRect.top", 408); | 30 shouldBeEqualToNumber("entries[0].boundingClientRect.top", 408); |
37 shouldBeEqualToNumber("entries[0].boundingClientRect.bottom", 508); | 31 shouldBeEqualToNumber("entries[0].boundingClientRect.bottom", 508); |
38 shouldBeEqualToNumber("entries[0].intersectionRect.left", 8); | 32 shouldBeEqualToNumber("entries[0].intersectionRect.left", 8); |
39 shouldBeEqualToNumber("entries[0].intersectionRect.right", 108); | 33 shouldBeEqualToNumber("entries[0].intersectionRect.right", 108); |
(...skipping 29 matching lines...) Expand all Loading... |
69 shouldBeEqualToNumber("entries[1].rootBounds.left", 0); | 63 shouldBeEqualToNumber("entries[1].rootBounds.left", 0); |
70 shouldBeEqualToNumber("entries[1].rootBounds.right", 785); | 64 shouldBeEqualToNumber("entries[1].rootBounds.right", 785); |
71 shouldBeEqualToNumber("entries[1].rootBounds.top", 0); | 65 shouldBeEqualToNumber("entries[1].rootBounds.top", 0); |
72 shouldBeEqualToNumber("entries[1].rootBounds.bottom", 600); | 66 shouldBeEqualToNumber("entries[1].rootBounds.bottom", 600); |
73 shouldEvaluateToSameObject("entries[1].target", target); | 67 shouldEvaluateToSameObject("entries[1].target", target); |
74 finishTest(); | 68 finishTest(); |
75 document.scrollingElement.scrollTop = 0; | 69 document.scrollingElement.scrollTop = 0; |
76 }); | 70 }); |
77 } | 71 } |
78 | 72 |
79 requestAnimationFrame(step0); | |
80 </script> | 73 </script> |
OLD | NEW |