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="../resources/intersection-observer-helper-functions.js"></script> | 3 <script src="../resources/intersection-observer-helper-functions.js"></script> |
| 4 <style> |
| 5 #root { |
| 6 display: inline-block; |
| 7 overflow-y: scroll; |
| 8 height: 200px; |
| 9 border: 3px solid black; |
| 10 } |
| 11 #target { |
| 12 background-color: green; |
| 13 width: 100px; |
| 14 height: 100px; |
| 15 } |
| 16 </style> |
4 <div style="width:100%; height:700px;"></div> | 17 <div style="width:100%; height:700px;"></div> |
5 <div id="root" style="display: inline-block; overflow-y: scroll; height: 200px;
border: 3px solid black"> | 18 <div id="root"> |
6 <div style="width:100px; height: 300px;"></div> | 19 <div style="width:100px; height: 300px;"></div> |
7 <div id="target" style="background-color: green; width:100px; height:100px"></
div> | 20 <div id="target"></div> |
| 21 <div style="width:100%;height:700px;"></div> |
8 </div> | 22 </div> |
9 <div style="width:100%;height:700px;"></div> | 23 <div style="width:100%;height:700px;"></div> |
10 | 24 |
11 <script> | 25 <script> |
12 description("Simple intersection observer test with explicit root and target in
the same document."); | 26 description("Test that setting display:none will send a not-intersecting notific
ation."); |
13 var target = document.getElementById("target"); | 27 var target = document.getElementById("target"); |
14 var root = document.getElementById("root"); | 28 var root = document.getElementById("root"); |
15 var entries = []; | 29 var entries = []; |
16 var observer = new IntersectionObserver( | 30 var observer = new IntersectionObserver( |
17 changes => { entries = entries.concat(changes) }, | 31 changes => { entries = entries.concat(changes) }, |
18 { root: document.getElementById("root") } | 32 { root: document.getElementById("root") } |
19 ); | 33 ); |
20 | 34 |
21 onload = function() { | 35 onload = function() { |
22 observer.observe(target); | 36 observer.observe(target); |
23 entries = entries.concat(observer.takeRecords()); | 37 entries = entries.concat(observer.takeRecords()); |
24 shouldBeEqualToNumber("entries.length", 0); | 38 shouldBeEqualToNumber("entries.length", 0); |
25 waitForNotification(step0); | 39 waitForNotification(step0); |
26 } | 40 } |
27 | 41 |
28 // Test that notifications are not generated when the target is overflow clipped
by the root. | |
29 function step0() { | 42 function step0() { |
30 shouldBeEqualToNumber("entries.length", 0); | 43 shouldBeEqualToNumber("entries.length", 0); |
31 document.scrollingElement.scrollTop = 600; | 44 document.scrollingElement.scrollTop = 600; |
32 waitForNotification(step1); | 45 waitForNotification(step1); |
33 } | 46 } |
34 | 47 |
35 function step1() { | 48 function step1() { |
36 shouldBeEqualToNumber("entries.length", 0); | 49 shouldBeEqualToNumber("entries.length", 0); |
37 root.scrollTop = 150; | 50 root.scrollTop = 150; |
38 waitForNotification(step2); | 51 waitForNotification(step2); |
39 } | 52 } |
40 | 53 |
41 function step2() { | 54 function step2() { |
42 shouldBeEqualToNumber("entries.length", 1); | 55 shouldBeEqualToNumber("entries.length", 1); |
43 if (entries.length > 0) { | 56 if (entries.length > 0) { |
44 shouldBeEqualToNumber("entries[0].boundingClientRect.left", 11); | 57 shouldBeEqualToNumber("entries[0].boundingClientRect.left", 11); |
45 shouldBeEqualToNumber("entries[0].boundingClientRect.right", 111); | 58 shouldBeEqualToNumber("entries[0].boundingClientRect.right", 111); |
46 shouldBeEqualToNumber("entries[0].boundingClientRect.top", 261); | 59 shouldBeEqualToNumber("entries[0].boundingClientRect.top", 261); |
47 shouldBeEqualToNumber("entries[0].boundingClientRect.bottom", 361); | 60 shouldBeEqualToNumber("entries[0].boundingClientRect.bottom", 361); |
48 shouldBeEqualToNumber("entries[0].intersectionRect.left", 11); | 61 shouldBeEqualToNumber("entries[0].intersectionRect.left", 11); |
49 shouldBeEqualToNumber("entries[0].intersectionRect.right", 111); | 62 shouldBeEqualToNumber("entries[0].intersectionRect.right", 111); |
50 shouldBeEqualToNumber("entries[0].intersectionRect.top", 261); | 63 shouldBeEqualToNumber("entries[0].intersectionRect.top", 261); |
51 shouldBeEqualToNumber("entries[0].intersectionRect.bottom", 311); | 64 shouldBeEqualToNumber("entries[0].intersectionRect.bottom", 311); |
52 shouldBeEqualToNumber("entries[0].rootBounds.left", 11); | 65 shouldBeEqualToNumber("entries[0].rootBounds.left", 11); |
53 shouldBeEqualToNumber("entries[0].rootBounds.right", 111); | 66 shouldBeEqualToNumber("entries[0].rootBounds.right", 111); |
54 shouldBeEqualToNumber("entries[0].rootBounds.top", 111); | 67 shouldBeEqualToNumber("entries[0].rootBounds.top", 111); |
55 shouldBeEqualToNumber("entries[0].rootBounds.bottom", 311); | 68 shouldBeEqualToNumber("entries[0].rootBounds.bottom", 311); |
56 shouldEvaluateToSameObject("entries[0].target", target); | 69 shouldEvaluateToSameObject("entries[0].target", target); |
57 } | 70 } |
58 document.scrollingElement.scrollTop = 0; | 71 target.style.display = "none"; |
59 waitForNotification(step3); | 72 waitForNotification(step3); |
60 } | 73 } |
61 | 74 |
62 function step3() { | 75 function step3() { |
63 shouldBeEqualToNumber("entries.length", 1); | 76 shouldBeEqualToNumber("entries.length", 2); |
64 root.scrollTop = 0; | 77 if (entries.length > 1) { |
| 78 shouldBeEqualToNumber("entries[1].boundingClientRect.left", 0); |
| 79 shouldBeEqualToNumber("entries[1].boundingClientRect.right", 0); |
| 80 shouldBeEqualToNumber("entries[1].boundingClientRect.top", 0); |
| 81 shouldBeEqualToNumber("entries[1].boundingClientRect.bottom", 0); |
| 82 shouldBeEqualToNumber("entries[1].intersectionRect.left", 0); |
| 83 shouldBeEqualToNumber("entries[1].intersectionRect.right", 0); |
| 84 shouldBeEqualToNumber("entries[1].intersectionRect.top", 0); |
| 85 shouldBeEqualToNumber("entries[1].intersectionRect.bottom", 0); |
| 86 shouldBeEqualToNumber("entries[1].rootBounds.left", 0); |
| 87 shouldBeEqualToNumber("entries[1].rootBounds.right", 0); |
| 88 shouldBeEqualToNumber("entries[1].rootBounds.top", 0); |
| 89 shouldBeEqualToNumber("entries[1].rootBounds.bottom", 0); |
| 90 shouldEvaluateToSameObject("entries[1].target", target); |
| 91 } |
| 92 target.style.display = ""; |
65 waitForNotification(step4); | 93 waitForNotification(step4); |
66 } | 94 } |
67 | 95 |
68 function step4() { | 96 function step4() { |
69 shouldBeEqualToNumber("entries.length", 2); | |
70 if (entries.length > 1) { | |
71 shouldBeEqualToNumber("entries[1].boundingClientRect.left", 11); | |
72 shouldBeEqualToNumber("entries[1].boundingClientRect.right", 111); | |
73 shouldBeEqualToNumber("entries[1].boundingClientRect.top", 1011); | |
74 shouldBeEqualToNumber("entries[1].boundingClientRect.bottom", 1111); | |
75 shouldBeEqualToNumber("entries[1].intersectionRect.left", 0); | |
76 shouldBeEqualToNumber("entries[1].intersectionRect.right", 0); | |
77 shouldBeEqualToNumber("entries[1].intersectionRect.top", 0); | |
78 shouldBeEqualToNumber("entries[1].intersectionRect.bottom", 0); | |
79 shouldBeEqualToNumber("entries[1].rootBounds.left", 11); | |
80 shouldBeEqualToNumber("entries[1].rootBounds.right", 111); | |
81 shouldBeEqualToNumber("entries[1].rootBounds.top", 711); | |
82 shouldBeEqualToNumber("entries[1].rootBounds.bottom", 911); | |
83 shouldEvaluateToSameObject("entries[1].target", target); | |
84 } | |
85 root.scrollTop = 150; | |
86 waitForNotification(step5); | |
87 } | |
88 | |
89 // This tests that notifications are generated even when the root element is off
screen. | |
90 function step5() { | |
91 shouldBeEqualToNumber("entries.length", 3); | 97 shouldBeEqualToNumber("entries.length", 3); |
92 if (entries.length > 2) { | 98 if (entries.length > 2) { |
93 shouldBeEqualToNumber("entries[2].boundingClientRect.left", 11); | 99 shouldBeEqualToNumber("entries[2].boundingClientRect.left", 11); |
94 shouldBeEqualToNumber("entries[2].boundingClientRect.right", 111); | 100 shouldBeEqualToNumber("entries[2].boundingClientRect.right", 111); |
95 shouldBeEqualToNumber("entries[2].boundingClientRect.top", 861); | 101 shouldBeEqualToNumber("entries[2].boundingClientRect.top", 261); |
96 shouldBeEqualToNumber("entries[2].boundingClientRect.bottom", 961); | 102 shouldBeEqualToNumber("entries[2].boundingClientRect.bottom", 361); |
97 shouldBeEqualToNumber("entries[2].intersectionRect.left", 11); | 103 shouldBeEqualToNumber("entries[2].intersectionRect.left", 11); |
98 shouldBeEqualToNumber("entries[2].intersectionRect.right", 111); | 104 shouldBeEqualToNumber("entries[2].intersectionRect.right", 111); |
99 shouldBeEqualToNumber("entries[2].intersectionRect.top", 861); | 105 shouldBeEqualToNumber("entries[2].intersectionRect.top", 261); |
100 shouldBeEqualToNumber("entries[2].intersectionRect.bottom", 911); | 106 shouldBeEqualToNumber("entries[2].intersectionRect.bottom", 311); |
101 shouldBeEqualToNumber("entries[2].rootBounds.left", 11); | 107 shouldBeEqualToNumber("entries[2].rootBounds.left", 11); |
102 shouldBeEqualToNumber("entries[2].rootBounds.right", 111); | 108 shouldBeEqualToNumber("entries[2].rootBounds.right", 111); |
103 shouldBeEqualToNumber("entries[2].rootBounds.top", 711); | 109 shouldBeEqualToNumber("entries[2].rootBounds.top", 111); |
104 shouldBeEqualToNumber("entries[2].rootBounds.bottom", 911); | 110 shouldBeEqualToNumber("entries[2].rootBounds.bottom", 311); |
105 shouldEvaluateToSameObject("entries[2].target", target); | 111 shouldEvaluateToSameObject("entries[2].target", target); |
106 } | 112 } |
107 | 113 |
108 finishJSTest(); | 114 finishJSTest(); |
109 } | 115 } |
110 </script> | 116 </script> |
OLD | NEW |