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 observer = new IntersectionObserver(changes => { entries = entries.concat(ch
anges) }, {}); |
11 var targetIframe = document.getElementById("target-iframe"); | 12 var targetIframe = document.getElementById("target-iframe"); |
| 13 var target; |
| 14 var iframeScroller; |
12 | 15 |
13 targetIframe.onload = function() { | 16 targetIframe.onload = function() { |
14 var target = targetIframe.contentDocument.getElementById("target"); | 17 target = targetIframe.contentDocument.getElementById("target"); |
15 var iframeScroller = targetIframe.contentDocument.scrollingElement; | 18 iframeScroller = targetIframe.contentDocument.scrollingElement; |
| 19 observer.observe(target); |
| 20 entries = entries.concat(observer.takeRecords()); |
| 21 shouldBeEqualToNumber("entries.length", 0); |
| 22 // See README for explanation of double RAF. |
| 23 requestAnimationFrame(() => { requestAnimationFrame(step0) }); |
| 24 } |
16 | 25 |
17 observer_callback = function(changes) { | 26 function step0() { |
18 for (var i in changes) | 27 entries = entries.concat(observer.takeRecords()); |
19 entries.push(changes[i]); | 28 shouldBeEqualToNumber("entries.length", 0); |
20 }; | 29 document.scrollingElement.scrollTop = 200; |
21 var observer = new IntersectionObserver(observer_callback, {}); | 30 requestAnimationFrame(step1); |
22 observer.observe(target); | 31 } |
23 | 32 |
24 function step0() { | 33 function step1() { |
25 setTimeout(function() { | 34 entries = entries.concat(observer.takeRecords()); |
26 shouldBeEqualToNumber("entries.length", 0); | 35 shouldBeEqualToNumber("entries.length", 0); |
27 document.scrollingElement.scrollTop = 200; | 36 iframeScroller.scrollTop = 250; |
28 requestAnimationFrame(step1); | 37 requestAnimationFrame(step2); |
29 }); | 38 } |
| 39 |
| 40 function step2() { |
| 41 entries = entries.concat(observer.takeRecords()); |
| 42 shouldBeEqualToNumber("entries.length", 1); |
| 43 if (entries.length > 0) { |
| 44 shouldBeEqualToNumber("entries[0].boundingClientRect.left", 8); |
| 45 shouldBeEqualToNumber("entries[0].boundingClientRect.right", 108); |
| 46 shouldBeEqualToNumber("entries[0].boundingClientRect.top", -42); |
| 47 shouldBeEqualToNumber("entries[0].boundingClientRect.bottom", 58); |
| 48 shouldBeEqualToNumber("entries[0].intersectionRect.left", 8); |
| 49 shouldBeEqualToNumber("entries[0].intersectionRect.right", 108); |
| 50 shouldBeEqualToNumber("entries[0].intersectionRect.top", 0); |
| 51 shouldBeEqualToNumber("entries[0].intersectionRect.bottom", 58); |
| 52 shouldBeEqualToNumber("entries[0].rootBounds.left", 0); |
| 53 shouldBeEqualToNumber("entries[0].rootBounds.right", 785); |
| 54 shouldBeEqualToNumber("entries[0].rootBounds.top", 0); |
| 55 shouldBeEqualToNumber("entries[0].rootBounds.bottom", 600); |
| 56 shouldEvaluateToSameObject("entries[0].target", target); |
30 } | 57 } |
| 58 document.scrollingElement.scrollTop = 100; |
| 59 requestAnimationFrame(step3); |
| 60 } |
31 | 61 |
32 function step1() { | 62 function step3() { |
33 setTimeout(function() { | 63 entries = entries.concat(observer.takeRecords()); |
34 shouldBeEqualToNumber("entries.length", 0); | 64 shouldBeEqualToNumber("entries.length", 2); |
35 iframeScroller.scrollTop = 250; | 65 if (entries.length > 1) { |
36 requestAnimationFrame(step2); | 66 shouldBeEqualToNumber("entries[1].boundingClientRect.left", 8); |
37 }); | 67 shouldBeEqualToNumber("entries[1].boundingClientRect.right", 108); |
| 68 shouldBeEqualToNumber("entries[1].boundingClientRect.top", -42); |
| 69 shouldBeEqualToNumber("entries[1].boundingClientRect.bottom", 58); |
| 70 shouldBeEqualToNumber("entries[1].intersectionRect.left", 0); |
| 71 shouldBeEqualToNumber("entries[1].intersectionRect.right", 0); |
| 72 shouldBeEqualToNumber("entries[1].intersectionRect.top", 0); |
| 73 shouldBeEqualToNumber("entries[1].intersectionRect.bottom", 0); |
| 74 shouldBeEqualToNumber("entries[1].rootBounds.left", 0); |
| 75 shouldBeEqualToNumber("entries[1].rootBounds.right", 785); |
| 76 shouldBeEqualToNumber("entries[1].rootBounds.top", 0); |
| 77 shouldBeEqualToNumber("entries[1].rootBounds.bottom", 600); |
| 78 shouldEvaluateToSameObject("entries[1].target", target); |
38 } | 79 } |
39 | 80 finishJSTest(); |
40 function step2() { | 81 document.scrollingElement.scrollTop = 0; |
41 setTimeout(function() { | |
42 shouldBeEqualToNumber("entries.length", 1); | |
43 if (entries.length > 0) { | |
44 shouldBeEqualToNumber("entries[0].boundingClientRect.left", 8); | |
45 shouldBeEqualToNumber("entries[0].boundingClientRect.right", 108); | |
46 shouldBeEqualToNumber("entries[0].boundingClientRect.top", -42); | |
47 shouldBeEqualToNumber("entries[0].boundingClientRect.bottom", 58); | |
48 shouldBeEqualToNumber("entries[0].intersectionRect.left", 8); | |
49 shouldBeEqualToNumber("entries[0].intersectionRect.right", 108); | |
50 shouldBeEqualToNumber("entries[0].intersectionRect.top", 0); | |
51 shouldBeEqualToNumber("entries[0].intersectionRect.bottom", 58); | |
52 shouldBeEqualToNumber("entries[0].rootBounds.left", 0); | |
53 shouldBeEqualToNumber("entries[0].rootBounds.right", 785); | |
54 shouldBeEqualToNumber("entries[0].rootBounds.top", 0); | |
55 shouldBeEqualToNumber("entries[0].rootBounds.bottom", 600); | |
56 shouldEvaluateToSameObject("entries[0].target", target); | |
57 } | |
58 document.scrollingElement.scrollTop = 100; | |
59 requestAnimationFrame(step3); | |
60 }); | |
61 } | |
62 | |
63 function step3() { | |
64 setTimeout(function() { | |
65 shouldBeEqualToNumber("entries.length", 2); | |
66 if (entries.length > 1) { | |
67 shouldBeEqualToNumber("entries[1].boundingClientRect.left", 8); | |
68 shouldBeEqualToNumber("entries[1].boundingClientRect.right", 108); | |
69 shouldBeEqualToNumber("entries[1].boundingClientRect.top", -42); | |
70 shouldBeEqualToNumber("entries[1].boundingClientRect.bottom", 58); | |
71 shouldBeEqualToNumber("entries[1].intersectionRect.left", 0); | |
72 shouldBeEqualToNumber("entries[1].intersectionRect.right", 0); | |
73 shouldBeEqualToNumber("entries[1].intersectionRect.top", 0); | |
74 shouldBeEqualToNumber("entries[1].intersectionRect.bottom", 0); | |
75 shouldBeEqualToNumber("entries[1].rootBounds.left", 0); | |
76 shouldBeEqualToNumber("entries[1].rootBounds.right", 785); | |
77 shouldBeEqualToNumber("entries[1].rootBounds.top", 0); | |
78 shouldBeEqualToNumber("entries[1].rootBounds.bottom", 600); | |
79 shouldEvaluateToSameObject("entries[1].target", target); | |
80 } | |
81 finishJSTest(); | |
82 document.scrollingElement.scrollTop = 0; | |
83 }); | |
84 } | |
85 | |
86 step0(); | |
87 } | 82 } |
88 </script> | 83 </script> |
OLD | NEW |