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 style="white-space: nowrap;"> |
6 <div id="target" style="width:100px; height:300px"></div> | 6 <div style="display: inline-block; width: 1000px; height: 100px"></div> |
7 <iframe id="target-iframe" src="../resources/intersection-observer-subframe.ht
ml" style="width: 300px; height: 100px; overflow-y: scroll"></iframe> | 7 <div id="target" style="display: inline-block; background-color: green; width:
100px; height:100px"></div> |
| 8 <div style="display: inline-block; width: 1000px; height: 100px"></div> |
8 </div> | 9 </div> |
9 <div style="width:100%; height:700px;"></div> | 10 <div style="width:100%; height:700px;"></div> |
10 | 11 |
11 <script> | 12 <script> |
12 description("Simple intersection observer test with no explicit root and target
in an iframe."); | 13 description("Intersection observer test with root margin and implicit root."); |
13 var entries = []; | 14 var target = document.getElementById("target"); |
14 var root = document.getElementById("root"); | 15 var entries = []; |
15 var targetIframe = document.getElementById("target-iframe"); | |
16 | 16 |
17 targetIframe.onload = function() { | 17 function observer_callback(changes) { |
18 var target = targetIframe.contentDocument.getElementById("target"); | |
19 var iframeScroller = targetIframe.contentDocument.scrollingElement; | |
20 | |
21 observer_callback = function(changes) { | |
22 for (var i in changes) | 18 for (var i in changes) |
23 entries.push(changes[i]); | 19 entries.push(changes[i]); |
24 }; | 20 } |
25 var observer = new IntersectionObserver(observer_callback, {"root": document.g
etElementById("root")}); | 21 |
| 22 var observer = new IntersectionObserver(observer_callback, { |
| 23 rootMargin: "10px 20% 40% 30px" |
| 24 }); |
26 observer.observe(target); | 25 observer.observe(target); |
27 | 26 |
28 // TODO(szager): It shouldn't be necessary to RAF after the call to observer() | 27 // TODO(szager): It shouldn't be necessary to RAF after the call to observer() |
29 // and before changing the scroll position, but it is. | 28 // and before changing the scroll position, but it is. |
30 | 29 |
| 30 setTimeout(function() { |
| 31 shouldThrow("new IntersectionObserver(observer_callback, { rootMargin: '1' }
)"); |
| 32 shouldThrow("new IntersectionObserver(observer_callback, { rootMargin: '1em'
})"); |
| 33 shouldThrow("new IntersectionObserver(observer_callback, { rootMargin: 'auto
' })"); |
| 34 shouldNotThrow("new IntersectionObserver(observer_callback, { rootMargin: '1
.4px' })"); |
| 35 shouldNotThrow("new IntersectionObserver(observer_callback, { rootMargin: '1
.4px 2px' })"); |
| 36 shouldNotThrow("new IntersectionObserver(observer_callback, { rootMargin: '1
.4px 2px 3%' })"); |
| 37 shouldNotThrow("new IntersectionObserver(observer_callback, { rootMargin: '1
.4px 2px 3% 40px junk junk junk' })"); |
| 38 requestAnimationFrame(step0); |
| 39 }, 0); |
| 40 |
31 function step0() { | 41 function step0() { |
32 setTimeout(function() { | 42 setTimeout(function() { |
33 shouldBeEqualToNumber("entries.length", 0); | 43 shouldBeEqualToNumber("entries.length", 0); |
34 document.scrollingElement.scrollTop = 250; | 44 document.scrollingElement.scrollLeft = 100; |
35 requestAnimationFrame(step1); | 45 requestAnimationFrame(step1); |
36 }); | 46 }); |
37 } | 47 } |
38 | 48 |
39 function step1() { | 49 function step1() { |
40 setTimeout(function() { | 50 setTimeout(function() { |
41 shouldBeEqualToNumber("entries.length", 0); | 51 shouldBeEqualToNumber("entries.length", 1); |
42 iframeScroller.scrollTop = 200; | 52 shouldBeEqualToNumber("entries[0].boundingClientRect.left", 912); |
| 53 shouldBeEqualToNumber("entries[0].boundingClientRect.right", 1012); |
| 54 shouldBeEqualToNumber("entries[0].boundingClientRect.top", 708); |
| 55 shouldBeEqualToNumber("entries[0].boundingClientRect.bottom", 808); |
| 56 shouldBeEqualToNumber("entries[0].intersectionRect.left", 912); |
| 57 shouldBeEqualToNumber("entries[0].intersectionRect.right", 942); |
| 58 shouldBeEqualToNumber("entries[0].intersectionRect.top", 708); |
| 59 shouldBeEqualToNumber("entries[0].intersectionRect.bottom", 808); |
| 60 shouldBeEqualToNumber("entries[0].rootBounds.left", -30); |
| 61 shouldBeEqualToNumber("entries[0].rootBounds.right", 942); |
| 62 shouldBeEqualToNumber("entries[0].rootBounds.top", -10); |
| 63 shouldBeEqualToNumber("entries[0].rootBounds.bottom", 819); |
| 64 shouldEvaluateToSameObject("entries[0].target", target); |
| 65 document.scrollingElement.scrollTop = 800; |
43 requestAnimationFrame(step2); | 66 requestAnimationFrame(step2); |
44 }); | 67 }); |
45 } | 68 } |
46 | 69 |
47 function step2() { | 70 function step2() { |
48 setTimeout(function() { | 71 setTimeout(function() { |
49 shouldBeEqualToNumber("entries.length", 0); | 72 shouldBeEqualToNumber("entries.length", 1); |
50 root.scrollTop = 175; | 73 document.scrollingElement.scrollTop = 900; |
51 requestAnimationFrame(step3); | 74 requestAnimationFrame(step3); |
52 }); | 75 }); |
53 } | 76 } |
54 | 77 |
55 function step3() { | 78 function step3() { |
56 setTimeout(function() { | 79 setTimeout(function() { |
57 shouldBeEqualToNumber("entries.length", 1); | |
58 shouldBeEqualToNumber("entries[0].boundingClientRect.left", 18); | |
59 shouldBeEqualToNumber("entries[0].boundingClientRect.right", 118); | |
60 shouldBeEqualToNumber("entries[0].boundingClientRect.top", 593); | |
61 shouldBeEqualToNumber("entries[0].boundingClientRect.bottom", 693); | |
62 shouldBeEqualToNumber("entries[0].intersectionRect.left", 18); | |
63 shouldBeEqualToNumber("entries[0].intersectionRect.right", 118); | |
64 shouldBeEqualToNumber("entries[0].intersectionRect.top", 593); | |
65 shouldBeEqualToNumber("entries[0].intersectionRect.bottom", 658); | |
66 shouldBeEqualToNumber("entries[0].rootBounds.left", 8); | |
67 shouldBeEqualToNumber("entries[0].rootBounds.right", 312); | |
68 shouldBeEqualToNumber("entries[0].rootBounds.top", 458); | |
69 shouldBeEqualToNumber("entries[0].rootBounds.bottom", 658); | |
70 shouldEvaluateToSameObject("entries[0].target", target); | |
71 document.scrollingElement.scrollTop = 100; | |
72 requestAnimationFrame(step4); | |
73 }); | |
74 } | |
75 | |
76 function step4() { | |
77 setTimeout(function() { | |
78 shouldBeEqualToNumber("entries.length", 1); | |
79 root.scrollTop = 100; | |
80 requestAnimationFrame(step5); | |
81 }); | |
82 } | |
83 | |
84 function step5() { | |
85 setTimeout(function() { | |
86 shouldBeEqualToNumber("entries.length", 2); | 80 shouldBeEqualToNumber("entries.length", 2); |
87 shouldBeEqualToNumber("entries[1].boundingClientRect.left", 18); | 81 shouldBeEqualToNumber("entries[1].boundingClientRect.left", 912); |
88 shouldBeEqualToNumber("entries[1].boundingClientRect.right", 118); | 82 shouldBeEqualToNumber("entries[1].boundingClientRect.right", 1012); |
89 shouldBeEqualToNumber("entries[1].boundingClientRect.top", 818); | 83 shouldBeEqualToNumber("entries[1].boundingClientRect.top", -192); |
90 shouldBeEqualToNumber("entries[1].boundingClientRect.bottom", 918); | 84 shouldBeEqualToNumber("entries[1].boundingClientRect.bottom", -92); |
91 shouldBeEqualToNumber("entries[1].intersectionRect.left", 0); | 85 shouldBeEqualToNumber("entries[1].intersectionRect.left", 0); |
92 shouldBeEqualToNumber("entries[1].intersectionRect.right", 0); | 86 shouldBeEqualToNumber("entries[1].intersectionRect.right", 0); |
93 shouldBeEqualToNumber("entries[1].intersectionRect.top", 0); | 87 shouldBeEqualToNumber("entries[1].intersectionRect.top", 0); |
94 shouldBeEqualToNumber("entries[1].intersectionRect.bottom", 0); | 88 shouldBeEqualToNumber("entries[1].intersectionRect.bottom", 0); |
95 shouldBeEqualToNumber("entries[1].rootBounds.left", 8); | 89 shouldBeEqualToNumber("entries[1].rootBounds.left", -30); |
96 shouldBeEqualToNumber("entries[1].rootBounds.right", 312); | 90 shouldBeEqualToNumber("entries[1].rootBounds.right", 942); |
97 shouldBeEqualToNumber("entries[1].rootBounds.top", 608); | 91 shouldBeEqualToNumber("entries[1].rootBounds.top", -10); |
98 shouldBeEqualToNumber("entries[1].rootBounds.bottom", 808); | 92 shouldBeEqualToNumber("entries[1].rootBounds.bottom", 819); |
99 shouldEvaluateToSameObject("entries[1].target", target); | 93 shouldEvaluateToSameObject("entries[1].target", target); |
100 finishTest(); | 94 finishTest(); |
| 95 document.scrollingElement.scrollLeft = 0; |
101 document.scrollingElement.scrollTop = 0; | 96 document.scrollingElement.scrollTop = 0; |
102 }); | 97 }); |
103 } | 98 } |
104 | |
105 requestAnimationFrame(step0); | |
106 } | |
107 </script> | 99 </script> |
OLD | NEW |