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 <style> | 4 <style> |
5 #root { | 5 #root { |
6 width: 200px; | 6 width: 200px; |
7 height: 200px; | 7 height: 200px; |
8 overflow-y: scroll; | 8 overflow-y: scroll; |
9 } | 9 } |
10 #target { | 10 #target { |
11 width: 100px; | 11 width: 100px; |
12 height: 100px; | 12 height: 100px; |
13 background-color: green; | 13 background-color: green; |
14 position: absolute; | 14 position: absolute; |
15 } | 15 } |
16 </style> | 16 </style> |
17 <div id="root" style="position: absolute"> | 17 <div id="root" style="position: absolute"> |
18 <div id="target" style="left: 50px; top: 250px"></div> | 18 <div id="target" style="left: 50px; top: 250px"></div> |
19 </div> | 19 </div> |
20 | 20 |
21 <script> | 21 <script> |
22 description("Test that no notifications are generated when root is not in the
containing block chain of target."); | 22 description("Test that no notifications are generated when root is not in the co
ntaining block chain of target."); |
23 var root = document.getElementById("root"); | 23 var root = document.getElementById("root"); |
24 var target = document.getElementById("target"); | 24 var target = document.getElementById("target"); |
25 var entries = []; | 25 var entries = []; |
26 | 26 |
27 function observer_callback(changes) { | 27 var observer = new IntersectionObserver( |
28 changes.forEach(function(e) { entries.push(e) }); | 28 changes => { entries = entries.concat(changes) }, |
| 29 { root: root } |
| 30 ); |
| 31 |
| 32 onload = function() { |
| 33 observer.observe(target); |
| 34 shouldBeEqualToNumber("entries.length", 0); |
| 35 target.style.top = "10px"; |
| 36 // See README for explanation of double RAF. |
| 37 requestAnimationFrame(() => { requestAnimationFrame(step1) }); |
| 38 }; |
| 39 |
| 40 function step1() { |
| 41 entries = entries.concat(observer.takeRecords()); |
| 42 shouldBeEqualToNumber("entries.length", 1); |
| 43 if (entries.length > 0) { |
| 44 shouldBeEqualToNumber("entries[0].boundingClientRect.left", 58); |
| 45 shouldBeEqualToNumber("entries[0].boundingClientRect.right", 158); |
| 46 shouldBeEqualToNumber("entries[0].boundingClientRect.top", 18); |
| 47 shouldBeEqualToNumber("entries[0].boundingClientRect.bottom", 118); |
| 48 shouldBeEqualToNumber("entries[0].intersectionRect.left", 58); |
| 49 shouldBeEqualToNumber("entries[0].intersectionRect.right", 158); |
| 50 shouldBeEqualToNumber("entries[0].intersectionRect.top", 18); |
| 51 shouldBeEqualToNumber("entries[0].intersectionRect.bottom", 118); |
| 52 shouldBeEqualToNumber("entries[0].rootBounds.left", 8); |
| 53 shouldBeEqualToNumber("entries[0].rootBounds.right", 193); |
| 54 shouldBeEqualToNumber("entries[0].rootBounds.top", 8); |
| 55 shouldBeEqualToNumber("entries[0].rootBounds.bottom", 208); |
| 56 shouldEvaluateToSameObject("entries[0].target", target); |
29 } | 57 } |
30 new IntersectionObserver(observer_callback, {root: root}).observe(target); | 58 target.style.top = "250px"; |
| 59 requestAnimationFrame(step2); |
| 60 } |
31 | 61 |
32 function step0() { | 62 function step2() { |
33 setTimeout(function() { | 63 entries = entries.concat(observer.takeRecords()); |
34 shouldBeEqualToNumber("entries.length", 0); | 64 shouldBeEqualToNumber("entries.length", 2); |
35 target.style.top = "10px"; | 65 if (entries.length > 1) { |
36 requestAnimationFrame(step1); | 66 shouldBeEqualToNumber("entries[1].boundingClientRect.left", 58); |
37 }); | 67 shouldBeEqualToNumber("entries[1].boundingClientRect.right", 158); |
| 68 shouldBeEqualToNumber("entries[1].boundingClientRect.top", 258); |
| 69 shouldBeEqualToNumber("entries[1].boundingClientRect.bottom", 358); |
| 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", 8); |
| 75 shouldBeEqualToNumber("entries[1].rootBounds.right", 193); |
| 76 shouldBeEqualToNumber("entries[1].rootBounds.top", 8); |
| 77 shouldBeEqualToNumber("entries[1].rootBounds.bottom", 208); |
| 78 shouldEvaluateToSameObject("entries[1].target", target); |
38 } | 79 } |
| 80 root.style.position = "static"; |
| 81 target.style.top = "10px"; |
| 82 requestAnimationFrame(step3); |
| 83 } |
39 | 84 |
40 function step1() { | 85 function step3() { |
41 setTimeout(function() { | 86 entries = entries.concat(observer.takeRecords()); |
42 shouldBeEqualToNumber("entries.length", 1); | 87 shouldBeEqualToNumber("entries.length", 2); |
43 shouldBeEqualToNumber("entries[0].boundingClientRect.left", 58); | 88 target.style.top = "250px"; |
44 shouldBeEqualToNumber("entries[0].boundingClientRect.right", 158); | 89 requestAnimationFrame(step4); |
45 shouldBeEqualToNumber("entries[0].boundingClientRect.top", 18); | 90 } |
46 shouldBeEqualToNumber("entries[0].boundingClientRect.bottom", 118); | |
47 shouldBeEqualToNumber("entries[0].intersectionRect.left", 58); | |
48 shouldBeEqualToNumber("entries[0].intersectionRect.right", 158); | |
49 shouldBeEqualToNumber("entries[0].intersectionRect.top", 18); | |
50 shouldBeEqualToNumber("entries[0].intersectionRect.bottom", 118); | |
51 shouldBeEqualToNumber("entries[0].rootBounds.left", 8); | |
52 shouldBeEqualToNumber("entries[0].rootBounds.right", 193); | |
53 shouldBeEqualToNumber("entries[0].rootBounds.top", 8); | |
54 shouldBeEqualToNumber("entries[0].rootBounds.bottom", 208); | |
55 shouldEvaluateToSameObject("entries[0].target", target); | |
56 target.style.top = "250px"; | |
57 requestAnimationFrame(step2); | |
58 }); | |
59 } | |
60 | 91 |
61 function step2() { | 92 function step4() { |
62 setTimeout(function() { | 93 entries = entries.concat(observer.takeRecords()); |
63 shouldBeEqualToNumber("entries.length", 2); | 94 shouldBeEqualToNumber("entries.length", 2); |
64 shouldBeEqualToNumber("entries[1].boundingClientRect.left", 58); | 95 finishJSTest(); |
65 shouldBeEqualToNumber("entries[1].boundingClientRect.right", 158); | 96 } |
66 shouldBeEqualToNumber("entries[1].boundingClientRect.top", 258); | |
67 shouldBeEqualToNumber("entries[1].boundingClientRect.bottom", 358); | |
68 shouldBeEqualToNumber("entries[1].intersectionRect.left", 0); | |
69 shouldBeEqualToNumber("entries[1].intersectionRect.right", 0); | |
70 shouldBeEqualToNumber("entries[1].intersectionRect.top", 0); | |
71 shouldBeEqualToNumber("entries[1].intersectionRect.bottom", 0); | |
72 shouldBeEqualToNumber("entries[1].rootBounds.left", 8); | |
73 shouldBeEqualToNumber("entries[1].rootBounds.right", 193); | |
74 shouldBeEqualToNumber("entries[1].rootBounds.top", 8); | |
75 shouldBeEqualToNumber("entries[1].rootBounds.bottom", 208); | |
76 shouldEvaluateToSameObject("entries[1].target", target); | |
77 root.style.position = "static"; | |
78 target.style.top = "10px"; | |
79 requestAnimationFrame(step3); | |
80 }); | |
81 } | |
82 | |
83 function step3() { | |
84 setTimeout(function() { | |
85 shouldBeEqualToNumber("entries.length", 2); | |
86 target.style.top = "250px"; | |
87 requestAnimationFrame(step4); | |
88 }); | |
89 } | |
90 | |
91 function step4() { | |
92 setTimeout(function() { | |
93 shouldBeEqualToNumber("entries.length", 2); | |
94 finishJSTest(); | |
95 }); | |
96 } | |
97 | |
98 step0(); | |
99 </script> | 97 </script> |
OLD | NEW |